From 85122a6c389bc020df6a4f69447d7ea56e4f842f Mon Sep 17 00:00:00 2001 From: Nilashish Chakraborty Date: Mon, 23 Jul 2018 21:55:18 +0530 Subject: [PATCH] Fix ios_vlan issue CP in 2.5 (#42668) * Make ios_vlan identify vlans starting with 9 (#42247) * Make ios_vlan identify vlans starting with 9 * Add unit test for vlan id start with 9 (cherry picked from commit 70e33ef92c7a453032ad068198ea82fc1f9838a8) * Added changelog for ios_vlan fix --- changelogs/fragments/fix_ios_vlan.yaml | 2 ++ lib/ansible/modules/network/ios/ios_vlan.py | 2 +- .../network/ios/fixtures/ios_vlan_config.cfg | 3 ++- test/units/modules/network/ios/test_ios_vlan.py | 14 ++++++++++++++ 4 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/fix_ios_vlan.yaml diff --git a/changelogs/fragments/fix_ios_vlan.yaml b/changelogs/fragments/fix_ios_vlan.yaml new file mode 100644 index 00000000000..1672125802f --- /dev/null +++ b/changelogs/fragments/fix_ios_vlan.yaml @@ -0,0 +1,2 @@ +- bugfixes: + - ios_vlan - fix unable to identify correct vlan issue (https://github.com/ansible/ansible/pull/42247) diff --git a/lib/ansible/modules/network/ios/ios_vlan.py b/lib/ansible/modules/network/ios/ios_vlan.py index fece8876f4a..7a186777c77 100644 --- a/lib/ansible/modules/network/ios/ios_vlan.py +++ b/lib/ansible/modules/network/ios/ios_vlan.py @@ -218,7 +218,7 @@ def parse_to_logical_rows(out): if not l: """Skip empty lines.""" continue - if '0' < l[0] < '9': + if '0' < l[0] <= '9': """Line starting with a number.""" if started_yielding: yield cur_row diff --git a/test/units/modules/network/ios/fixtures/ios_vlan_config.cfg b/test/units/modules/network/ios/fixtures/ios_vlan_config.cfg index 945b8b4aa2b..69ac0b5e55e 100644 --- a/test/units/modules/network/ios/fixtures/ios_vlan_config.cfg +++ b/test/units/modules/network/ios/fixtures/ios_vlan_config.cfg @@ -4,5 +4,6 @@ VLAN Name Status Ports Gi1/0/52 Gi1/0/54 2 vlan2 active Gi1/0/6, Gi1/0/7 +9 vlan9 active Gi1/0/6 1002 fddi-default act/unsup -1003 fddo-default act/unsup \ No newline at end of file +1003 fddo-default act/unsup diff --git a/test/units/modules/network/ios/test_ios_vlan.py b/test/units/modules/network/ios/test_ios_vlan.py index 8315e8343e6..6c8926fb092 100644 --- a/test/units/modules/network/ios/test_ios_vlan.py +++ b/test/units/modules/network/ios/test_ios_vlan.py @@ -59,6 +59,12 @@ class TestIosVlanModule(TestIosModule): ] self.assertEqual(result['commands'], expected_commands) + def test_ios_vlan_id_startwith_9(self): + set_module_args({'vlan_id': '9', 'name': 'vlan9', 'state': 'present'}) + result = self.execute_module(changed=False) + expected_commands = [] + self.assertEqual(result['commands'], expected_commands) + def test_ios_vlan_rename(self): set_module_args({'vlan_id': '2', 'name': 'test', 'state': 'present'}) result = self.execute_module(changed=True) @@ -121,6 +127,14 @@ class TestIosVlanModule(TestIosModule): 'state': 'active', 'vlan_id': '2', }, + { + 'name': 'vlan9', + 'interfaces': [ + 'GigabitEthernet1/0/6', + ], + 'state': 'active', + 'vlan_id': '9', + }, { 'name': 'fddi-default', 'interfaces': [],