From d0416733a9a59fc684dfcb8edb69dc3ae6913a83 Mon Sep 17 00:00:00 2001 From: Olivier BLIN Date: Thu, 29 Nov 2018 05:53:51 +0100 Subject: [PATCH] Fix nxos modules idempotence issue (#46437) * nxos_interface vlan and port-channel idempotence fix for mtu * Fix MTU reconfiguration at each execution * nxos_interface port-channel idempotence fix for mode (#44248) * Fix trunk mode idempotence for port-channel * Gather ethernet and port-channel code for mode management * nxos_linkagg port-channel idempotence fix for channel-group's mode The regex to retrieve channel-group's mode is not enough accurate. Therefore, the swhitchport mode was matched instead of the channel-group's mode. * This fix add accuracy to match the right configuration command * Add support for switchport mode dot1q-tunnel in nxos_interface * Fix layer reconfiguration at each execution (cherry picked from commit c51407c806ad55e5e9e64b2a0df03ad210c4bb15) --- .../modules/network/nxos/nxos_interface.py | 19 ++++++++----------- .../modules/network/nxos/nxos_linkagg.py | 4 ++-- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/lib/ansible/modules/network/nxos/nxos_interface.py b/lib/ansible/modules/network/nxos/nxos_interface.py index a3ce24eb8ac..b706ca8f2b2 100644 --- a/lib/ansible/modules/network/nxos/nxos_interface.py +++ b/lib/ansible/modules/network/nxos/nxos_interface.py @@ -514,7 +514,12 @@ def map_config_to_obj(want, module): intf_type = get_interface_type(w['name']) if intf_type in ['portchannel', 'ethernet']: - if not interface_table.get('eth_mode'): + mode = interface_table.get('eth_mode') + if mode in ('access', 'trunk', 'dot1q-tunnel'): + obj['mode'] = 'layer2' + elif mode in ('routed', 'layer3'): + obj['mode'] = 'layer3' + else: obj['mode'] = 'layer3' if intf_type == 'ethernet': @@ -524,11 +529,6 @@ def map_config_to_obj(want, module): obj['mtu'] = interface_table.get('eth_mtu') obj['duplex'] = interface_table.get('eth_duplex') speed = interface_table.get('eth_speed') - mode = interface_table.get('eth_mode') - if mode in ('access', 'trunk'): - obj['mode'] = 'layer2' - elif mode in ('routed', 'layer3'): - obj['mode'] = 'layer3' command = 'show run interface {0}'.format(obj['name']) body = execute_show_command(command, module)[0] @@ -557,6 +557,7 @@ def map_config_to_obj(want, module): 'nxapibug')) obj['description'] = str(attributes.get('description', 'nxapi_bug')) + obj['mtu'] = interface_table.get('svi_mtu') command = 'show run interface {0}'.format(obj['name']) body = execute_show_command(command, module)[0] @@ -578,11 +579,7 @@ def map_config_to_obj(want, module): obj['name'] = normalize_interface(interface_table.get('interface')) obj['admin_state'] = interface_table.get('admin_state') obj['description'] = interface_table.get('desc') - mode = interface_table.get('eth_mode') - if mode == 'access': - obj['mode'] = 'layer2' - else: - obj['mode'] = 'layer3' + obj['mtu'] = interface_table.get('eth_mtu') objs.append(obj) diff --git a/lib/ansible/modules/network/nxos/nxos_linkagg.py b/lib/ansible/modules/network/nxos/nxos_linkagg.py index 0a0a41c1f70..2744f50e23c 100644 --- a/lib/ansible/modules/network/nxos/nxos_linkagg.py +++ b/lib/ansible/modules/network/nxos/nxos_linkagg.py @@ -291,9 +291,9 @@ def parse_mode(module, m): flags = ['| section interface.{0}'.format(m)] config = get_config(module, flags=flags) - match = re.search(r'mode (\S+)', config, re.M) + match = re.search(r'channel-group [0-9]+ (force )?mode (\S+)', config, re.M) if match: - mode = match.group(1) + mode = match.group(2) return mode