Skip to content

Commit

Permalink
Fix nxos modules idempotence issue (#46437)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
OlivierB authored and trishnaguha committed Nov 29, 2018
1 parent af1e687 commit c51407c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
19 changes: 8 additions & 11 deletions lib/ansible/modules/network/nxos/nxos_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand All @@ -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]
Expand Down Expand Up @@ -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]
Expand All @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions lib/ansible/modules/network/nxos/nxos_linkagg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit c51407c

Please sign in to comment.