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
Fix for nxos_snmp_host issues #39642
Conversation
@@ -1197,6 +1197,7 @@ lib/ansible/modules/network/nxos/nxos_pim_interface.py E326 | |||
lib/ansible/modules/network/nxos/nxos_pim_rp_address.py E326 | |||
lib/ansible/modules/network/nxos/nxos_reboot.py E325 | |||
lib/ansible/modules/network/nxos/nxos_smu.py E324 | |||
lib/ansible/modules/network/nxos/nxos_snmp_host.py E324 |
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.
New ignores should not be added. The underlying issue should be resolved. If the issue is in module_utils or docs fragments, the fix should be done in a separate PR.
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 was done deliberately to maintain backward compatibility due to the previous code bugs.
Here is the long explanation:
The defaults for snmp_type and snmp_version are 'trap' and 'v1'.
There are 4 different CLIs for nxos_snmp_host.
snmp-server host 1.1.1.1 informs version 2c public udp-port 222
snmp-server host 1.1.1.1 use-vrf default udp-port 222
snmp-server host 1.1.1.1 filter-vrf management udp-port 222
snmp-server host 1.1.1.1 source-interface Ethernet1/1
So basically the user can add use-vrf, filter-vrf and source interface in different tasks without specifying the version and type if the host ip(and udp port) already exists (the first CLI). If we define the defaults in the argument_spec (which is what is needed if we have to get rid of the ignores), the defaults of v1 and trap type are used which is incorrect, as the type is 'inform' and version is '2c' for the existing configuration. So the configuration fails.
The only other way is to make the version and trap type as 'required' parameters but then older playbooks from previous versions cannot work any longer because they were not 'required' before.
Hence this ignore is added. If the code was written properly in the beginning this could have been avoided but I don't see any other way. And please remember that this PR resolves some very MAJOR issues.
We can make a decision to ignore the backward compatibility all together since this module is broken completely before. In that case, I can take make the version as type as 'required' and remove the new ignores.
Which option do you suggest?
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.
Removing the default from the argument spec is itself a non-backwards compatible change. Any playbook which previously relied on the default of 'trap'
will now use None
instead. However, if that is indeed the only way to fix the issue then that change is unavoidable.
However, in that case, the fix for the validation error is simple. Remove the default from the documentation so it matches the actual default.
The same is true for the version
parameter as well. The default in the docs must match the actual default in the arg spec.
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.
Not really. If you look at the code, the way it works is that, if there is no existing snmp host, internally the code will make the version as 1 and type as trap (even though they are not defined in the arg spec). If there is an existing host, it will use the values from that host. So 'None' will not be an issue.
However, if we remove the defaults from documentation to match the arg spec, then the defaults are 'truly' removed and user MUST specify them always which breaks the backward compatibility. Since you are saying that the doc MUST match the arg spec no matter what, I can do by removing the defaults all together for type and version. But as I mentioned, old playbooks won't work if they have no do not specify the version and type.
Just wanted to clarify this before making changes.
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.
Simply remove the default:
entries from the version
and snmp_type
docs. The logic in the code requires no additional changes.
With that change the docs will match the defaults in the arg spec. Any other default-like behavior that occurs outside of the argument spec isn't a true default and should be documented in the description instead.
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.
@mattclay Thanks for the comments. Made the changes and removed the E324 ignore.
cherry-picked to 2.5 |
* fix snmp_host issues * source files * fix shippable * remove defaults to match arg spec (cherry picked from commit f99bae1)
* Handle nxos_feature issue where json isn't supported (#39150) Signed-off-by: Trishna Guha <trishnaguha17@gmail.com> (cherry picked from commit 9eff1f1) * Integration Tests only: nxos_snmp_contact (#39318) * add integration test cases for snmp_contact * removing unnecessary files (cherry picked from commit bdb75cd) * fix nxos_ntp issues (#39178) * fix nxos_ntp issues * review comments * fix idempotent fail case (cherry picked from commit 2f99a17) * nxos_interface: AttributeError: 'NoneType' object has no attribute 'group' (#38544) This fixes an issue we recently encounteredi with nxos_interface: ``` Traceback (most recent call last): File "/tmp/ansible_JmLoba/ansible_module_nxos_interface.py", line 777, in main have = map_config_to_obj(want, module) File "/tmp/ansible_JmLoba/ansible_module_nxos_interface.py", line 606, in map_config_to_obj obj['speed'] = re.search(r'speed (\d+)', body).group(1) AttributeError: 'NoneType' object has no attribute 'group' ``` (cherry picked from commit dca6e2d) * fix nxos_snmp_community issues (#39258) (cherry picked from commit 1afec5a) * Add aggregate example in nxos_l2_interface module doc (#39275) Signed-off-by: Trishna Guha <trishnaguha17@gmail.com> (cherry picked from commit 86817cd) * Fix misuse of 'self' in lib/ansible/module_utils/network/eos/eos.py. … (#39074) * Fix misuse of 'self' in lib/ansible/module_utils/network/eos/eos.py. Method load_config * Fix all instances of self.config(self,... (cherry picked from commit 80d7e22) * Fix for nxos_snmp_host issues (#39642) * fix snmp_host issues * source files * fix shippable * remove defaults to match arg spec (cherry picked from commit f99bae1) * fix nxos_snmp_traps issues (#39444) * fix snmp_traps code * add IT cases * fix shippable * fix shippable without ignore (cherry picked from commit 99748cb) * changelog Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>
* fix snmp_host issues * source files * fix shippable * remove defaults to match arg spec
* fix snmp_host issues * source files * fix shippable * remove defaults to match arg spec
* fix snmp_host issues * source files * fix shippable * remove defaults to match arg spec
* fix snmp_host issues * source files * fix shippable * remove defaults to match arg spec
* fix snmp_host issues * source files * fix shippable * remove defaults to match arg spec
* fix snmp_host issues * source files * fix shippable * remove defaults to match arg spec
* fix snmp_host issues * source files * fix shippable * remove defaults to match arg spec
SUMMARY
fixes #39641
ISSUE TYPE
COMPONENT NAME
nxos_snmp_host
ANSIBLE VERSION
ADDITIONAL INFORMATION