From e1def05ba236012fec8ec521955925a8468073e4 Mon Sep 17 00:00:00 2001 From: Nathaniel Case Date: Tue, 22 Aug 2017 14:02:55 -0400 Subject: [PATCH] fix networking *_command check_mode (#28407) * Fix check_mode in nxos_command * Fix check_mode for ios_command * fix check_mode for iosxr_command * Fix check_mode in vyos_command * Fix check_mode in eos_command * Fix check_mode in junos_config --- lib/ansible/modules/network/eos/eos_command.py | 14 ++++++++------ lib/ansible/modules/network/ios/ios_command.py | 3 ++- .../modules/network/iosxr/iosxr_command.py | 3 ++- .../modules/network/junos/junos_command.py | 1 + lib/ansible/modules/network/nxos/nxos_command.py | 15 +++++++++------ lib/ansible/modules/network/vyos/vyos_command.py | 12 +++++++----- 6 files changed, 29 insertions(+), 19 deletions(-) diff --git a/lib/ansible/modules/network/eos/eos_command.py b/lib/ansible/modules/network/eos/eos_command.py index 39d2fa0b51b..a12d146cbc7 100644 --- a/lib/ansible/modules/network/eos/eos_command.py +++ b/lib/ansible/modules/network/eos/eos_command.py @@ -163,12 +163,14 @@ def parse_commands(module, warnings): transform = ComplexList(spec, module) commands = transform(module.params['commands']) - for index, item in enumerate(commands): - if module.check_mode and not item['command'].startswith('show'): - warnings.append( - 'Only show commands are supported when using check_mode, not ' - 'executing %s' % item['command'] - ) + if module.check_mode: + for item in list(commands): + if not item['command'].startswith('show'): + warnings.append( + 'Only show commands are supported when using check_mode, not ' + 'executing %s' % item['command'] + ) + commands.remove(item) return commands diff --git a/lib/ansible/modules/network/ios/ios_command.py b/lib/ansible/modules/network/ios/ios_command.py index 08795a07f2f..1c90df5efa9 100644 --- a/lib/ansible/modules/network/ios/ios_command.py +++ b/lib/ansible/modules/network/ios/ios_command.py @@ -151,12 +151,13 @@ def parse_commands(module, warnings): answer=dict() ), module) commands = command(module.params['commands']) - for index, item in enumerate(commands): + for item in list(commands): if module.check_mode and not item['command'].startswith('show'): warnings.append( 'only show commands are supported when using check mode, not ' 'executing `%s`' % item['command'] ) + commands.remove(item) elif item['command'].startswith('conf'): module.fail_json( msg='ios_command does not support running config mode ' diff --git a/lib/ansible/modules/network/iosxr/iosxr_command.py b/lib/ansible/modules/network/iosxr/iosxr_command.py index 683193a6e07..00463b5912b 100644 --- a/lib/ansible/modules/network/iosxr/iosxr_command.py +++ b/lib/ansible/modules/network/iosxr/iosxr_command.py @@ -145,12 +145,13 @@ def parse_commands(module, warnings): ), module) commands = command(module.params['commands']) - for index, item in enumerate(commands): + for item in list(commands): if module.check_mode and not item['command'].startswith('show'): warnings.append( 'only show commands are supported when using check mode, not ' 'executing `%s`' % item['command'] ) + commands.remove(item) elif item['command'].startswith('conf'): module.fail_json( msg='iosxr_command does not support running config mode ' diff --git a/lib/ansible/modules/network/junos/junos_command.py b/lib/ansible/modules/network/junos/junos_command.py index 37505f1de9d..8b8d87a0161 100644 --- a/lib/ansible/modules/network/junos/junos_command.py +++ b/lib/ansible/modules/network/junos/junos_command.py @@ -314,6 +314,7 @@ def parse_commands(module, warnings): 'Only show commands are supported when using check_mode, not ' 'executing %s' % command ) + continue parts = command.split('|') text = parts[0] diff --git a/lib/ansible/modules/network/nxos/nxos_command.py b/lib/ansible/modules/network/nxos/nxos_command.py index 7f13890ea0e..812d2112b03 100644 --- a/lib/ansible/modules/network/nxos/nxos_command.py +++ b/lib/ansible/modules/network/nxos/nxos_command.py @@ -181,15 +181,18 @@ def parse_commands(module, warnings): commands = transform(module.params['commands']) - for index, item in enumerate(commands): - if module.check_mode and not item['command'].startswith('show'): - warnings.append( - 'Only show commands are supported when using check_mode, not ' - 'executing %s' % item['command'] - ) + if module.check_mode: + for item in list(commands): + if not item['command'].startswith('show'): + warnings.append( + 'Only show commands are supported when using check_mode, not ' + 'executing %s' % item['command'] + ) + commands.remove(item) return commands + def to_cli(obj): cmd = obj['command'] if obj.get('output') == 'json': diff --git a/lib/ansible/modules/network/vyos/vyos_command.py b/lib/ansible/modules/network/vyos/vyos_command.py index 3726fd96597..8603f9dacb9 100644 --- a/lib/ansible/modules/network/vyos/vyos_command.py +++ b/lib/ansible/modules/network/vyos/vyos_command.py @@ -155,14 +155,16 @@ def parse_commands(module, warnings): answer=dict(), ), module) commands = command(module.params['commands']) + items = [] - for index, cmd in enumerate(commands): - if module.check_mode and not cmd['command'].startswith('show'): + for item in commands: + if module.check_mode and not item['command'].startswith('show'): warnings.append('only show commands are supported when using ' - 'check mode, not executing `%s`' % cmd['command']) - commands[index] = module.jsonify(cmd) + 'check mode, not executing `%s`' % item['command']) + else: + items.append(module.jsonify(item)) - return commands + return items def main():