-
Notifications
You must be signed in to change notification settings - Fork 107
[bugfix] Added fix to support ansible-core 2.19 to the aci_rest module (DCNE-504) #806
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
f674cda to
d092cbb
Compare
plugins/modules/aci_rest.py
Outdated
| return {k: convert_payload_values_to_str(v) for k, v in data.items()} | ||
| elif isinstance(data, list): | ||
| return [convert_payload_values_to_str(item) for item in data] | ||
| elif isinstance(data, int) or isinstance(data, bool) or isinstance(data, float): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this handle JSON Null types? Looks like it does as null in JSON won't be converted to a string.
Would it be possible to add a test when a JSON value is explicitly set to null?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
plugins/modules/aci_rest.py
Outdated
| convert_values_to_str: | ||
| description: | ||
| - When O(convert_values_to_str=true), this attribute converts input object values to strings. | ||
| - This ensures compatibility with Jinja2 version 3.1.6 and above. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps mention the ansible version here also which introduced the change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
plugins/modules/aci_rest.py
Outdated
| description: | ||
| - The page number to return. | ||
| type: int | ||
| convert_values_to_str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we use full name, and do aliases for abbreviated versions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we still use str and int, should we use full naming? Also as mentioned in you function naming I think we should align the two.
plugins/modules/aci_rest.py
Outdated
|
|
||
|
|
||
| def convert_payload_values_to_str(data): | ||
| if data in [None, ""]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a None value is provided should this be set to an empty string? In our collection for None we typically ignore the value being added to the payload, why diverge form this behaviour here?
This could unintentionally lead to values being overwritten on an existing MO to an empty string, which should be ignored. Like a description attribute for example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also I do not understand why look for empty string, this is just a valid value that requires no translation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, I don't think we should be translating JSON Null to an empty string. Instead I think null values should be ignored in the request body. Although I am unsure if ACI actually accepts null json as a valid option anywhere.
plugins/modules/aci_rest.py
Outdated
| description: | ||
| - The page number to return. | ||
| type: int | ||
| convert_values_to_str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need this option, when apic typically only allows string values? there is one exception in aci rest test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This parameter is required to control the convertion, so I keep it for now.
plugins/modules/aci_rest.py
Outdated
| return {k: convert_payload_values_to_str(v) for k, v in data.items()} | ||
| elif isinstance(data, list): | ||
| return [convert_payload_values_to_str(item) for item in data] | ||
| elif isinstance(data, int) or isinstance(data, bool) or isinstance(data, float): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how are boolean values handled in 2.18 vs 2.19? Is this required to convert to string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I changed the logic.
plugins/modules/aci_rest.py
Outdated
|
|
||
|
|
||
| def convert_payload_values_to_str(data): | ||
| if data in [None, ""]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, I don't think we should be translating JSON Null to an empty string. Instead I think null values should be ignored in the request body. Although I am unsure if ACI actually accepts null json as a valid option anywhere.
|
Hi Team, FYI, there is a difference between Ansible Core 2.18 and 2.19 when using a list of YAML/JSON values to populate task values in an Ansible playbook. Sample task:
But, no differences are observed when the values are used directly within the task.
|
plugins/modules/aci_rest.py
Outdated
| return {k: convert_payload_values_to_str(v) for k, v in data.items()} | ||
| elif isinstance(data, list): | ||
| return [convert_payload_values_to_str(item) for item in data] | ||
| elif (isinstance(data, int) and not isinstance(data, bool)) or isinstance(data, float): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean only int and float types are converted to strings?
I am curious how the not bool condition is used here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Python, the bool type is a subclass of the int type. Therefore, to prevent a Boolean from being converted to its string representation ("True" or "False"), we should explicitly check its type using not isinstance(data, bool).
samiib
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. However, looks like there are other outstanding comments.
plugins/modules/aci_rest.py
Outdated
| convert_values_to_str: | ||
| description: | ||
| - When O(convert_values_to_str=true), this attribute converts input object values to strings. | ||
| - This ensures compatibility with Jinja2 version 3.1.6 and above. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As Akini commented, we should mention the Ansible version here as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
17b0811 to
d6adc5b
Compare
| validate_certs: '{{ aci_validate_certs | default(false) }}' | ||
| use_ssl: '{{ aci_use_ssl | default(true) }}' | ||
| use_proxy: '{{ aci_use_proxy | default(true) }}' | ||
| host: "{{ aci_hostname }}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we are changing this, why not set it as fact 1 time, and use those with <<?
alternatively we can also set/leverage defaults when used on every task
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
shrsr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
shrsr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
gmicol
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
anvitha-jain
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
akinross
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
Please resolve conflict |
…s_to_str function
…e convert_payload_values_to_str function in aci_rest module
…and renamed the function to recursive_convert_none_int_float_to_str_in_dict_list
… the aci_rest module
…o str converstion logic
…to normalize_payload_values in the aci_rest module
bafa1aa
shrsr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
akinross
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
samiib
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
anvitha-jain
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
gmicol
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
lhercot
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
No description provided.