cleans up nxos_command and adds some additonal info on exception

This cleans up some of the nxos_command module code function names to
be more consistent and adds additional information of failures
This commit is contained in:
Peter Sprygada 2016-04-04 08:12:27 -04:00
parent ad519c2f5c
commit 11c00c2278

View file

@ -120,7 +120,7 @@ import re
INDEX_RE = re.compile(r'(\[\d+\])') INDEX_RE = re.compile(r'(\[\d+\])')
def to_lines(stdout): def iterlines(stdout):
for item in stdout: for item in stdout:
if isinstance(item, basestring): if isinstance(item, basestring):
item = str(item).split('\n') item = str(item).split('\n')
@ -160,8 +160,9 @@ def main():
try: try:
response = module.execute(commands, **kwargs) response = module.execute(commands, **kwargs)
result['stdout'] = response result['stdout'] = response
except ShellError: except ShellError, exc:
module.fail_json(msg='failed to run commands') module.fail_json(msg='failed to run commands', exc=exc.message,
command=exc.command)
for index, cmd in enumerate(commands): for index, cmd in enumerate(commands):
if cmd.endswith('json'): if cmd.endswith('json'):
@ -169,8 +170,8 @@ def main():
response[index] = module.from_json(response[index]) response[index] = module.from_json(response[index])
except ValueError, exc: except ValueError, exc:
module.fail_json(msg='failed to parse json response', module.fail_json(msg='failed to parse json response',
exc_type=str(type(exc)), exc_message=str(exc), exc_message=str(exc), response=response[index],
response=response[index]) cmd=cmd, response_dict=response)
for item in list(queue): for item in list(queue):
if item(response): if item(response):
@ -185,7 +186,7 @@ def main():
failed_conditions = [item.raw for item in queue] failed_conditions = [item.raw for item in queue]
module.fail_json(msg='timeout waiting for value', failed_conditions=failed_conditions) module.fail_json(msg='timeout waiting for value', failed_conditions=failed_conditions)
result['stdout_lines'] = list(to_lines(result['stdout'])) result['stdout_lines'] = list(iterlines(result['stdout']))
return module.exit_json(**result) return module.exit_json(**result)