From ea4f6e1539507e0b2be0bb0a3e093e65e5b1a7bc Mon Sep 17 00:00:00 2001 From: nkshrishail <42039941+nkshrishail@users.noreply.github.com> Date: Sun, 10 Nov 2019 00:02:07 -0500 Subject: [PATCH] nxos_lacp: updated tests to handle platforms not supporting lacp system mac command (#64074) * Updated nxos_lacp tests to handle platforms not supporting lacp system mac command * nxos_lacp: addressing comments * nxos_lacp: Updating image tag search to include more tags (cherry picked from commit 00193f27eb107310257efecae1d8ceadaa3acd95) Add changelog for nxos_lacp fix --- .../fragments/64074_update_nxos_lacp.yaml | 2 + .../module_utils/network/common/utils.py | 5 +- .../network/nxos/config/lacp/lacp.py | 4 +- .../targets/nxos_lacp/tests/cli/deleted.yaml | 18 ++++++ .../targets/nxos_lacp/tests/cli/merged.yaml | 17 ++++++ .../targets/nxos_lacp/tests/cli/replaced.yaml | 57 +++++++++++++++++-- 6 files changed, 95 insertions(+), 8 deletions(-) create mode 100644 changelogs/fragments/64074_update_nxos_lacp.yaml diff --git a/changelogs/fragments/64074_update_nxos_lacp.yaml b/changelogs/fragments/64074_update_nxos_lacp.yaml new file mode 100644 index 00000000000..7bf26ee20c3 --- /dev/null +++ b/changelogs/fragments/64074_update_nxos_lacp.yaml @@ -0,0 +1,2 @@ +bugfixes: + - Fix nxos_lacp replace operation (https://github.com/ansible/ansible/pull/64074). diff --git a/lib/ansible/module_utils/network/common/utils.py b/lib/ansible/module_utils/network/common/utils.py index afe419aa89b..fd52bfbf342 100644 --- a/lib/ansible/module_utils/network/common/utils.py +++ b/lib/ansible/module_utils/network/common/utils.py @@ -260,7 +260,10 @@ def dict_diff(base, comparable): if not isinstance(base, dict): raise AssertionError("`base` must be of type ") if not isinstance(comparable, dict): - raise AssertionError("`comparable` must be of type ") + if comparable is None: + comparable = dict() + else: + raise AssertionError("`comparable` must be of type ") updates = dict() diff --git a/lib/ansible/module_utils/network/nxos/config/lacp/lacp.py b/lib/ansible/module_utils/network/nxos/config/lacp/lacp.py index 8d4f24585a9..ebed2501845 100644 --- a/lib/ansible/module_utils/network/nxos/config/lacp/lacp.py +++ b/lib/ansible/module_utils/network/nxos/config/lacp/lacp.py @@ -130,9 +130,11 @@ class Lacp(ConfigBase): del diff[k] deleted_commands = self.del_all(diff) merged_commands = self._state_merged(want, have) + + commands.extend(deleted_commands) if merged_commands: - commands.extend(deleted_commands) commands.extend(merged_commands) + return commands def _state_merged(self, want, have): diff --git a/test/integration/targets/nxos_lacp/tests/cli/deleted.yaml b/test/integration/targets/nxos_lacp/tests/cli/deleted.yaml index d3711a55f50..a9e158e69d3 100644 --- a/test/integration/targets/nxos_lacp/tests/cli/deleted.yaml +++ b/test/integration/targets/nxos_lacp/tests/cli/deleted.yaml @@ -6,11 +6,19 @@ nxos_feature: feature: lacp +- set_fact: + mac: "lacp system-mac 00c1.4c00.bd15 role primary" + when: platform is search('N9K') and imagetag is not search('I[2-6]') + - block: - name: Setup cli_config: config: lacp system-priority 11 + - name: Setup + cli_config: + config: "{{ mac|default(omit) }}" + - name: Gather lacp facts nxos_facts: &facts gather_subset: @@ -29,6 +37,16 @@ - "'no lacp system-priority' in result.commands" - "result.changed == true" - "result.commands|length == 1" + when: platform is not search('N9K') + + - assert: + that: + - "ansible_facts.network_resources.lacp == result.before" + - "'no lacp system-priority' in result.commands" + - "'no lacp system-mac' in result.commands" + - "result.changed == true" + - "result.commands|length == 2" + when: platform is search('N9K') and imagetag is not search('I[2-6]') - name: Gather lacp post facts nxos_facts: *facts diff --git a/test/integration/targets/nxos_lacp/tests/cli/merged.yaml b/test/integration/targets/nxos_lacp/tests/cli/merged.yaml index 0e7423b8db9..45a5bed1db4 100644 --- a/test/integration/targets/nxos_lacp/tests/cli/merged.yaml +++ b/test/integration/targets/nxos_lacp/tests/cli/merged.yaml @@ -6,21 +6,38 @@ nxos_feature: feature: lacp +- set_fact: + mac: + address: 00c1.4c00.bd15 + role: primary + when: platform is search('N9K') and imagetag is not search('I[2-6]') + - block: - name: Merged nxos_lacp: &merged config: system: priority: 11 + mac: "{{ mac|default(omit) }}" state: merged register: result + - assert: + that: + - "result.before|length == 0" + - "result.changed == true" + - "'lacp system-priority 11' in result.commands" + - "'lacp system-mac 00c1.4c00.bd15 role primary' in result.commands" + - "result.commands|length == 2" + when: platform is search('N9K') and imagetag is not search('I[2-6]') + - assert: that: - "result.before|length == 0" - "result.changed == true" - "'lacp system-priority 11' in result.commands" - "result.commands|length == 1" + when: platform is not search('N9K') - name: Gather lacp facts nxos_facts: diff --git a/test/integration/targets/nxos_lacp/tests/cli/replaced.yaml b/test/integration/targets/nxos_lacp/tests/cli/replaced.yaml index 1e9470fec7f..7b367a79580 100644 --- a/test/integration/targets/nxos_lacp/tests/cli/replaced.yaml +++ b/test/integration/targets/nxos_lacp/tests/cli/replaced.yaml @@ -1,4 +1,5 @@ --- + - debug: msg: "Start nxos_lacp replaced integration tests connection={{ ansible_connection }}" @@ -6,11 +7,25 @@ nxos_feature: feature: lacp +- set_fact: + mac1: "lacp system-mac 00c1.4c00.bd20 role primary" + when: platform is search('N9K') and imagetag is not search('I[2-6]') + +- set_fact: + mac2: + address: 00c1.4c00.bd15 + role: secondary + when: platform is search('N9K') and imagetag is not search('I[2-6]') + - block: - - name: Setup + - name: Setup1 cli_config: config: lacp system-priority 11 + - name: Setup2 + cli_config: + config: "{{ mac1|default(omit) }}" + - name: Gather lacp facts nxos_facts: &facts gather_subset: @@ -22,9 +37,8 @@ nxos_lacp: &replaced config: system: - mac: - address: 00c1.4c00.bd15 - role: primary + priority: 12 + mac: "{{ mac2|default(omit) }}" state: replaced register: result @@ -32,9 +46,21 @@ that: - "ansible_facts.network_resources.lacp == result.before" - "result.changed == true" - - "'no lacp system-priority' in result.commands" - - "'lacp system-mac 00c1.4c00.bd15 role primary' in result.commands" - "result.commands|length == 2" + - "'no lacp system-priority' in result.commands" + - "'lacp system-priority 12' in result.commands" + when: platform is not search('N9K') + + - assert: + that: + - "ansible_facts.network_resources.lacp == result.before" + - "result.changed == true" + - "'no lacp system-priority' in result.commands" + - "'no lacp system-mac' in result.commands" + - "'lacp system-priority 12' in result.commands" + - "'lacp system-mac 00c1.4c00.bd15 role secondary' in result.commands" + - "result.commands|length == 4" + when: platform is search('N9K') and imagetag is not search('I[2-6]') - name: Gather lacp interfaces post facts nxos_facts: *facts @@ -42,6 +68,7 @@ - assert: that: - "ansible_facts.network_resources.lacp == result.after" + when: platform is search('N9K') and imagetag is not search('I[2-6]') - name: Idempotence - Replaced nxos_lacp: *replaced @@ -52,6 +79,24 @@ - "result.changed == false" - "result.commands|length == 0" + - name: Setup3 + cli_config: + config: "{{ mac1|default(omit) }}" + + - name: Replaced + nxos_lacp: + state: replaced + register: result + when: platform is search('N9K') and imagetag is not search('I[2-6]') + + - assert: + that: + - "result.changed == true" + - "result.commands|length == 2" + - "'no lacp system-mac' in result.commands" + - "'no lacp system-priority' in result.commands" + when: platform is search('N9K') and imagetag is not search('I[2-6]') + always: - name: teardown nxos_feature: