From 4ec1437212b2fb3c313e44ed5a76b105f2151622 Mon Sep 17 00:00:00 2001 From: GomathiselviS Date: Wed, 12 Feb 2020 11:12:12 -0500 Subject: [PATCH] Fix to - eos_vlans using state parameter replaced is giving odd behavior (#67318) * Added fix for bug # 54400 * Adding files for RM static_routes * Added Integration tests * Revert "Added fix for bug # 54400" This reverts commit bf42db42697d64abbfea4e546f890637d4a5175b. * Revert "Adding files for RM static_routes" This reverts commit dafdd92d4327cfc6dfcebb1e977454b2f77a1daa. * Revert "Added Integration tests" This reverts commit 129dc87682bba9292105fc3b642fdf3930ce79fd. * Adding files for RM static_routes * Added Integration tests * Corrected lint errors * Added fix for bug # 54400 * Revert "Added fix for bug # 54400" This reverts commit bf42db42697d64abbfea4e546f890637d4a5175b. * Revert "Adding files for RM static_routes" This reverts commit dafdd92d4327cfc6dfcebb1e977454b2f77a1daa. * Revert "Added Integration tests" This reverts commit 129dc87682bba9292105fc3b642fdf3930ce79fd. * fix to bug #67313 * fixing rebase issue * fixing rebase issue * addressed review comments * addressed review comments --- .../module_utils/network/eos/config/vlans/vlans.py | 9 +++++---- .../targets/eos_vlans/tests/cli/replaced.yaml | 1 + test/units/modules/network/eos/test_eos_vlans.py | 6 +++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/ansible/module_utils/network/eos/config/vlans/vlans.py b/lib/ansible/module_utils/network/eos/config/vlans/vlans.py index 99cb37cd07e..c2a701637d3 100644 --- a/lib/ansible/module_utils/network/eos/config/vlans/vlans.py +++ b/lib/ansible/module_utils/network/eos/config/vlans/vlans.py @@ -208,16 +208,17 @@ def generate_commands(vlan_id, to_set, to_remove): if "vlan_id" in to_remove: return ["no vlan {0}".format(vlan_id)] + for key in to_remove: + if key in to_set.keys(): + continue + commands.append("no {0}".format(key)) + for key, value in to_set.items(): if key == "vlan_id" or value is None: continue commands.append("{0} {1}".format(key, value)) - for key in to_remove: - commands.append("no {0}".format(key)) - if commands: commands.insert(0, "vlan {0}".format(vlan_id)) - return commands diff --git a/test/integration/targets/eos_vlans/tests/cli/replaced.yaml b/test/integration/targets/eos_vlans/tests/cli/replaced.yaml index ca502ff1568..13d68274d28 100644 --- a/test/integration/targets/eos_vlans/tests/cli/replaced.yaml +++ b/test/integration/targets/eos_vlans/tests/cli/replaced.yaml @@ -5,6 +5,7 @@ config: - vlan_id: 20 state: suspend + name: twentyreplaced other_config: - vlan_id: 10 name: ten diff --git a/test/units/modules/network/eos/test_eos_vlans.py b/test/units/modules/network/eos/test_eos_vlans.py index 5bdc8783054..63f4d38d143 100644 --- a/test/units/modules/network/eos/test_eos_vlans.py +++ b/test/units/modules/network/eos/test_eos_vlans.py @@ -102,12 +102,12 @@ class TestEosVlansModule(TestEosModule): self.execute_show_command.return_value = [] set_module_args(dict( config=[dict( - vlan_id=30, - name="thirty", + vlan_id=10, + name="tenreplaced", state="suspend" )], state="replaced" )) - commands = ['vlan 30', 'name thirty', 'state suspend'] + commands = ['vlan 10', 'name tenreplaced', 'state suspend'] self.execute_module(changed=True, commands=commands) def test_eos_vlan_replaced_idempotent(self):