Fix nxos portchannel force option (#27190)

* Add integration tests

* Fix force option

* Enable nxos_portchannel test

* Satisfy ansibot demands
This commit is contained in:
Mike Wiebe 2017-07-28 13:06:41 -04:00 committed by Nathaniel Case
parent fb2b3de5e4
commit 07b097af7c
10 changed files with 183 additions and 12 deletions

View file

@ -255,16 +255,18 @@ def get_existing(module, args):
return existing, interface_exist
def config_portchannel(proposed, mode, group):
def config_portchannel(proposed, mode, group, force):
commands = []
# NOTE: Leading whitespace for force option is important
force = ' force' if force else ''
config_args = {
'mode': 'channel-group {group} mode {mode}',
'mode': 'channel-group {group}{force} mode {mode}',
'min_links': 'lacp min-links {min_links}',
}
for member in proposed.get('members', []):
commands.append('interface {0}'.format(member))
commands.append(config_args.get('mode').format(group=group, mode=mode))
commands.append(config_args.get('mode').format(group=group, force=force, mode=mode))
min_links = proposed.get('min_links', None)
if min_links:
@ -276,7 +278,7 @@ def config_portchannel(proposed, mode, group):
return commands
def get_commands_to_add_members(proposed, existing, module):
def get_commands_to_add_members(proposed, existing, force, module):
try:
proposed_members = proposed['members']
except KeyError:
@ -290,11 +292,13 @@ def get_commands_to_add_members(proposed, existing, module):
members_to_add = list(set(proposed_members).difference(existing_members))
commands = []
# NOTE: Leading whitespace for force option is important
force = ' force' if force else ''
if members_to_add:
for member in members_to_add:
commands.append('interface {0}'.format(member))
commands.append('channel-group {0} mode {1}'.format(
existing['group'], proposed['mode']))
commands.append('channel-group {0}{1} mode {2}'.format(
existing['group'], force, proposed['mode']))
return commands
@ -320,7 +324,7 @@ def get_commands_to_remove_members(proposed, existing, module):
return commands
def get_commands_if_mode_change(proposed, existing, group, mode, module):
def get_commands_if_mode_change(proposed, existing, group, mode, force, module):
try:
proposed_members = proposed['members']
except KeyError:
@ -346,6 +350,8 @@ def get_commands_if_mode_change(proposed, existing, group, mode, module):
members_with_mode_change.append(interface)
commands = []
# NOTE: Leading whitespace for force option is important
force = ' force' if force else ''
if members_with_mode_change:
for member in members_with_mode_change:
commands.append('interface {0}'.format(member))
@ -353,7 +359,7 @@ def get_commands_if_mode_change(proposed, existing, group, mode, module):
for member in members_with_mode_change:
commands.append('interface {0}'.format(member))
commands.append('channel-group {0} mode {1}'.format(group, mode))
commands.append('channel-group {0}{1} mode {2}'.format(group, force, mode))
return commands
@ -388,7 +394,7 @@ def state_present(module, existing, proposed, interface_exist, force, warnings):
min_links = module.params['min_links']
if not interface_exist:
command = config_portchannel(proposed, mode, group)
command = config_portchannel(proposed, mode, group, force)
commands.append(command)
commands.insert(0, 'interface port-channel{0}'.format(group))
warnings.append("The proposed port-channel interface did not "
@ -400,10 +406,10 @@ def state_present(module, existing, proposed, interface_exist, force, warnings):
command = get_commands_to_remove_members(proposed, existing, module)
commands.append(command)
command = get_commands_to_add_members(proposed, existing, module)
command = get_commands_to_add_members(proposed, existing, force, module)
commands.append(command)
mode_command = get_commands_if_mode_change(proposed, existing, group, mode, module)
mode_command = get_commands_if_mode_change(proposed, existing, group, mode, force, module)
commands.insert(0, mode_command)
if min_links: