Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes ios and eos command modules #20989

Merged
merged 1 commit into from
Feb 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/ansible/module_utils/ios.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def get_config(module, flags=[]):
def run_commands(module, commands, check_rc=True):
responses = list()
for cmd in to_list(commands):
cmd = module.jsonify(cmd)
rc, out, err = module.exec_command(cmd)
if check_rc and rc != 0:
module.fail_json(msg=err, rc=rc)
Expand Down
7 changes: 3 additions & 4 deletions lib/ansible/modules/network/eos/eos_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,21 +165,22 @@ def to_lines(stdout):
return lines

def parse_commands(module, warnings):
cast = ComplexList(dict(
transform = ComplexList(dict(
command=dict(key=True),
output=dict(),
prompt=dict(),
response=dict()
))

commands = cast(module.params['commands'])
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']
)

return commands

def to_cli(obj):
Expand Down Expand Up @@ -223,8 +224,6 @@ def main():
interval = module.params['interval']
match = module.params['match']

commands = [to_cli(c) for c in commands]

while retries > 0:
responses = run_commands(module, commands)

Expand Down
2 changes: 0 additions & 2 deletions lib/ansible/modules/network/ios/ios_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ def parse_commands(module, warnings):
response=dict()
))
commands = command(module.params['commands'])

for index, item in enumerate(commands):
if module.check_mode and not item['command'].startswith('show'):
warnings.append(
Expand All @@ -200,7 +199,6 @@ def parse_commands(module, warnings):
msg='ios_command does not support running config mode '
'commands. Please use ios_config instead'
)
commands[index] = module.jsonify(item)
return commands

def main():
Expand Down
4 changes: 2 additions & 2 deletions test/units/modules/network/eos/test_eos_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ def load_from_file(*args, **kwargs):

for item in commands:
try:
obj = json.loads(item)
obj = json.loads(item['command'])
command = obj['command']
except ValueError:
command = item
command = item['command']
filename = str(command).replace(' ', '_')
filename = 'eos_command_%s.txt' % filename
output.append(load_fixture(filename))
Expand Down
4 changes: 2 additions & 2 deletions test/units/modules/network/ios/test_ios_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ def load_from_file(*args, **kwargs):

for item in commands:
try:
obj = json.loads(item)
obj = json.loads(item['command'])
command = obj['command']
except ValueError:
command = item
command = item['command']
filename = str(command).replace(' ', '_')
output.append(load_fixture(filename))
return output
Expand Down