From 17b6ecf1016386a68d214bf755b4eac5f65a298f Mon Sep 17 00:00:00 2001 From: Trishna Guha Date: Tue, 29 May 2018 21:44:19 +0530 Subject: [PATCH] nxos_vlan fix (#40822) * nxos_vlan fix Signed-off-by: Trishna Guha * uncomment mode test as nxapi now has get_capabilities Signed-off-by: Trishna Guha --- lib/ansible/modules/network/nxos/nxos_vlan.py | 32 +++++--- .../nxos_vlan/tests/common/sanity.yaml | 77 ++++++++++--------- 2 files changed, 63 insertions(+), 46 deletions(-) diff --git a/lib/ansible/modules/network/nxos/nxos_vlan.py b/lib/ansible/modules/network/nxos/nxos_vlan.py index 94eded7192b..152c9c09589 100644 --- a/lib/ansible/modules/network/nxos/nxos_vlan.py +++ b/lib/ansible/modules/network/nxos/nxos_vlan.py @@ -454,21 +454,31 @@ def parse_vni(module, vlan_id): return str(vni) +def get_vlan_int(interfaces): + vlan_int = [] + for i in interfaces.split(','): + if 'eth' in i.lower() and '-' in i: + int_range = i.split('-') + stop = int((int_range)[1]) + start = int(int_range[0].split('/')[1]) + eth = int_range[0].split('/')[0] + for r in range(start, stop + 1): + vlan_int.append(eth + '/' + str(r)) + else: + vlan_int.append(i) + return vlan_int + + def parse_interfaces(module, vlan): vlan_int = [] interfaces = vlan.get('vlanshowplist-ifidx') if interfaces: - for i in interfaces.split(','): - if 'eth' in i.lower() and '-' in i: - int_range = i.split('-') - stop = int((int_range)[1]) - start = int(int_range[0].split('/')[1]) - eth = int_range[0].split('/')[0] - for r in range(start, stop + 1): - vlan_int.append(eth + '/' + str(r)) - else: - vlan_int.append(i) - + if isinstance(interfaces, list): + interfaces_list = [i.strip() for i in interfaces] + interfaces_str = ','.join(interfaces_list) + vlan_int = get_vlan_int(interfaces_str) + else: + vlan_int = get_vlan_int(interfaces) return vlan_int diff --git a/test/integration/targets/nxos_vlan/tests/common/sanity.yaml b/test/integration/targets/nxos_vlan/tests/common/sanity.yaml index 92941ab2f18..54351275d65 100644 --- a/test/integration/targets/nxos_vlan/tests/common/sanity.yaml +++ b/test/integration/targets/nxos_vlan/tests/common/sanity.yaml @@ -7,6 +7,13 @@ - set_fact: testint2="{{ nxos_int2 }}" - block: + - name: Install and Enable FabricPath feature set + nxos_config: + lines: + - install feature-set fabricpath + - feature-set fabricpath + when: platform is search('N5K|N7K') + - name: "Enable feature vn segment" nxos_config: commands: @@ -114,41 +121,41 @@ when: platform is search('N3K|N7K') # Uncomment this once the get_capabilities() work on nxapi as well -# - name: Change mode -# nxos_vlan: &mode1 -# vlan_id: 50 -# mode: fabricpath -# register: result -# when: platform is search('N5k|N7K') -# -# - assert: *true -# when: platform is search('N5k|N7K') -# -# - name: "mode1 Idempotence" -# nxos_vlan: *mode1 -# register: result -# when: platform is search('N5k|N7K') -# -# - assert: *false -# when: platform is search('N5k|N7K') -# -# - name: Change mode again -# nxos_vlan: &mode2 -# vlan_id: 50 -# mode: ce -# register: result -# when: platform is search('N5k|N7K') -# -# - assert: *true -# when: platform is search('N5k|N7K') -# -# - name: "mode2 Idempotence" -# nxos_vlan: *mode2 -# register: result -# when: platform is search('N5k|N7K') -# -# - assert: *false -# when: platform is search('N5k|N7K') + - name: Change mode + nxos_vlan: &mode1 + vlan_id: 50 + mode: fabricpath + register: result + when: platform is search('N5K|N7K') + + - assert: *true + when: platform is search('N5K|N7K') + + - name: "mode1 Idempotence" + nxos_vlan: *mode1 + register: result + when: platform is search('N5K|N7K') + + - assert: *false + when: platform is search('N5K|N7K') + + - name: Change mode again + nxos_vlan: &mode2 + vlan_id: 50 + mode: ce + register: result + when: platform is search('N5K|N7K') + + - assert: *true + when: platform is search('N5K|N7K') + + - name: "mode2 Idempotence" + nxos_vlan: *mode2 + register: result + when: platform is search('N5K|N7K') + + - assert: *false + when: platform is search('N5K|N7K') - name: Ensure VLAN is NOT on the device nxos_vlan: &no_vlan