diff options
author | Mike Wiebe <mwiebe@cisco.com> | 2019-05-08 11:50:22 -0400 |
---|---|---|
committer | Trishna Guha <trishnaguha17@gmail.com> | 2019-05-08 21:20:22 +0530 |
commit | bceca72eb7f4714a64c6ebee310e005633de1f71 (patch) | |
tree | 1d0f1c88fba6abdf77ee5781eaca1a2615fb51ee | |
parent | a5b6a161b543966521af62a078e04df51c389437 (diff) | |
download | ansible-bceca72eb7f4714a64c6ebee310e005633de1f71.tar.gz |
nxos_interface: Fix admin_state check for n6k (#55673)
* Fix admin_state check for n6k
* Fix rx and tx_rate intent check test
-rw-r--r-- | lib/ansible/modules/network/nxos/nxos_interface.py | 15 | ||||
-rw-r--r-- | test/integration/targets/nxos_interface/tests/common/intent.yaml | 9 |
2 files changed, 22 insertions, 2 deletions
diff --git a/lib/ansible/modules/network/nxos/nxos_interface.py b/lib/ansible/modules/network/nxos/nxos_interface.py index 0cfa6e665c..3e23c015e9 100644 --- a/lib/ansible/modules/network/nxos/nxos_interface.py +++ b/lib/ansible/modules/network/nxos/nxos_interface.py @@ -573,6 +573,11 @@ def map_config_to_obj(want, module): elif intf_type in ('loopback', 'management', 'nve'): obj['name'] = normalize_interface(interface_table.get('interface')) obj['admin_state'] = interface_table.get('admin_state') + if obj['admin_state'] is None and intf_type == 'loopback': + # Some platforms don't have the 'admin_state' key. + # For loopback interfaces it's safe to use the + # 'state' key instead. + obj['admin_state'] = interface_table.get('state') obj['description'] = interface_table.get('desc') elif intf_type == 'portchannel': @@ -581,6 +586,16 @@ def map_config_to_obj(want, module): obj['description'] = interface_table.get('desc') obj['mtu'] = interface_table.get('eth_mtu') + if obj['admin_state'] is None: + # Some nxos platforms do not have the 'admin_state' key. + # Use the 'state_rsn_desc' key instead to determine the + # admin state of the interface. + state_description = interface_table.get('state_rsn_desc') + if state_description == 'Administratively down': + obj['admin_state'] = 'down' + elif state_description is not None: + obj['admin_state'] = 'up' + objs.append(obj) return objs diff --git a/test/integration/targets/nxos_interface/tests/common/intent.yaml b/test/integration/targets/nxos_interface/tests/common/intent.yaml index c91847c037..113c8a353f 100644 --- a/test/integration/targets/nxos_interface/tests/common/intent.yaml +++ b/test/integration/targets/nxos_interface/tests/common/intent.yaml @@ -26,11 +26,16 @@ that: - "result.failed == false" +- name: "Clear interface {{ testint2 }} counters before next task" + nxos_command: + commands: "clear counters interface {{ testint2 }}" + ignore_errors: yes + - name: Check intent arguments (failed condition) nxos_interface: name: "{{ testint2 }}" admin_state: down - tx_rate: gt(0) + tx_rate: gt(10000) rx_rate: lt(0) provider: "{{ connection }}" ignore_errors: yes @@ -39,7 +44,7 @@ - assert: that: - "result.failed == true" - - "'tx_rate gt(0)' in result.failed_conditions" + - "'tx_rate gt(10000)' in result.failed_conditions" - "'rx_rate lt(0)' in result.failed_conditions" - name: aggregate definition of interface |