From 2e0abd8a9178fc8599f48964563253e5bc9b9a6e Mon Sep 17 00:00:00 2001 From: NilashishC Date: Sat, 9 May 2020 21:29:30 +0530 Subject: [PATCH] Fix issue with replaced Signed-off-by: NilashishC Add changelog --- changelogs/fragments/nxos_l2_interfaces_replaced.yaml | 3 +++ .../network/nxos/config/l2_interfaces/l2_interfaces.py | 2 +- .../targets/nxos_l2_interfaces/tests/cli/replaced.yaml | 8 +++++++- 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/nxos_l2_interfaces_replaced.yaml diff --git a/changelogs/fragments/nxos_l2_interfaces_replaced.yaml b/changelogs/fragments/nxos_l2_interfaces_replaced.yaml new file mode 100644 index 00000000000000..ef67e399ec61d9 --- /dev/null +++ b/changelogs/fragments/nxos_l2_interfaces_replaced.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: + - Fix issue with nxos_l2_interfaces where replaced doesn't remove superfluous config (https://github.com/ansible-collections/cisco.nxos/pull/55) diff --git a/lib/ansible/module_utils/network/nxos/config/l2_interfaces/l2_interfaces.py b/lib/ansible/module_utils/network/nxos/config/l2_interfaces/l2_interfaces.py index 707ffd95dbc414..6bc3d6cac407be 100644 --- a/lib/ansible/module_utils/network/nxos/config/l2_interfaces/l2_interfaces.py +++ b/lib/ansible/module_utils/network/nxos/config/l2_interfaces/l2_interfaces.py @@ -161,7 +161,7 @@ def _state_replaced(self, w, have): del diff[k] replaced_commands = self.del_attribs(diff) - if merged_commands: + if merged_commands or replaced_commands: cmds = set(replaced_commands).intersection(set(merged_commands)) for cmd in cmds: merged_commands.remove(cmd) diff --git a/test/integration/targets/nxos_l2_interfaces/tests/cli/replaced.yaml b/test/integration/targets/nxos_l2_interfaces/tests/cli/replaced.yaml index 275ce8b6e719eb..764c911f36d84c 100644 --- a/test/integration/targets/nxos_l2_interfaces/tests/cli/replaced.yaml +++ b/test/integration/targets/nxos_l2_interfaces/tests/cli/replaced.yaml @@ -39,6 +39,10 @@ vlan: 8 trunk: allowed_vlans: "10-12" + + - name: '{{ test_int2 }}' + trunk: + allowed_vlans: 25-27 state: replaced register: result @@ -48,7 +52,9 @@ - "'interface {{ test_int1 }}' in result.commands" - "'switchport access vlan 8' in result.commands" - "'switchport trunk allowed vlan 10,11,12' in result.commands" - - "result.commands|length == 3" + - "'interface {{ test_int2 }}' in result.commands" + - "'no switchport trunk native vlan' in result.commands" + - result.commands|length == 5 - name: Gather l2_interfaces post facts nxos_facts: *facts