fixes error when trying to run show start over eapi (#26800)

This commit is contained in:
Peter Sprygada 2017-07-14 09:07:44 -04:00 committed by Ricardo Carrillo Cruz
parent 156b29b26b
commit 3bbb32cac5
3 changed files with 54 additions and 7 deletions

View file

@ -170,15 +170,15 @@ options:
changes are not copied to non-volatile storage by default. Using changes are not copied to non-volatile storage by default. Using
this argument will change that before. If the argument is set to this argument will change that before. If the argument is set to
I(always), then the running-config will always be copied to the I(always), then the running-config will always be copied to the
startup-config and the I(changed) flag will always be set to startup-config and the I(modified) flag will always be set to
True. If the argument is set to I(changed), then the running-config True. If the argument is set to I(modified), then the running-config
will only be copied to the startup-config if it has changed since will only be copied to the startup-config if it has changed since
the last save to startup-config. If the argument is set to the last save to startup-config. If the argument is set to
I(never), the running-config will never be copied to the the I(never), the running-config will never be copied to the the
startup-config startup-config
required: false required: false
default: never default: never
choices: ['always', 'never', 'changed'] choices: ['always', 'never', 'modified']
version_added: "2.4" version_added: "2.4"
diff_against: diff_against:
description: description:
@ -316,7 +316,7 @@ def main():
defaults=dict(type='bool', default=False), defaults=dict(type='bool', default=False),
backup=dict(type='bool', default=False), backup=dict(type='bool', default=False),
save_when=dict(choices=['always', 'never', 'changed'], default='never'), save_when=dict(choices=['always', 'never', 'modified'], default='never'),
diff_against=dict(choices=['startup', 'session', 'intended', 'running'], default='session'), diff_against=dict(choices=['startup', 'session', 'intended', 'running'], default='session'),
diff_ignore_lines=dict(type='list'), diff_ignore_lines=dict(type='list'),
@ -408,7 +408,8 @@ def main():
diff_ignore_lines = module.params['diff_ignore_lines'] diff_ignore_lines = module.params['diff_ignore_lines']
if module.params['save_when'] != 'never': if module.params['save_when'] != 'never':
output = run_commands(module, ['show running-config', 'show startup-config']) output = run_commands(module, [{'command': 'show running-config', 'output': 'text'},
{'command': 'show startup-config', 'output': 'text'}])
running_config = NetworkConfig(indent=1, contents=output[0], ignore_lines=diff_ignore_lines) running_config = NetworkConfig(indent=1, contents=output[0], ignore_lines=diff_ignore_lines)
startup_config = NetworkConfig(indent=1, contents=output[1], ignore_lines=diff_ignore_lines) startup_config = NetworkConfig(indent=1, contents=output[1], ignore_lines=diff_ignore_lines)
@ -425,7 +426,7 @@ def main():
if module._diff: if module._diff:
if not running_config: if not running_config:
output = run_commands(module, 'show running-config') output = run_commands(module, {'command': 'show running-config', 'output': 'text'})
contents = output[0] contents = output[0]
else: else:
contents = running_config.config_text contents = running_config.config_text
@ -442,7 +443,7 @@ def main():
elif module.params['diff_against'] == 'startup': elif module.params['diff_against'] == 'startup':
if not startup_config: if not startup_config:
output = run_commands(module, 'show startup-config') output = run_commands(module, {'command': 'show startup-config', 'output': 'text'})
contents = output[0] contents = output[0]
else: else:
contents = startup_config.config_text contents = startup_config.config_text

View file

@ -0,0 +1,26 @@
!
hostname changed
ip domain-name eng.ansible.com
!
vrf definition mgmt
!
vrf definition test
!
interface Management1
ip address 192.168.1.1/24
!
interface Ethernet1
shutdown
!
interface Ethernet2
shutdown
!
interface Ethernet3
shutdown
!
interface Ethernet4
shutdown
!
interface Ethernet5
shutdown
!

View file

@ -132,3 +132,23 @@ class TestEosConfigModule(TestEosModule):
set_module_args(args) set_module_args(args)
result = self.execute_module() result = self.execute_module()
self.assertIn('__backup__', result) self.assertIn('__backup__', result)
def test_eos_config_save_when(self):
mock_run_commands = patch('ansible.modules.network.eos.eos_config.run_commands')
run_commands = mock_run_commands.start()
run_commands.return_value = [load_fixture('eos_config_config.cfg'),
load_fixture('eos_config_config.cfg')]
args = dict(save_when='modified')
set_module_args(args)
result = self.execute_module()
run_commands.return_value = [load_fixture('eos_config_config.cfg'),
load_fixture('eos_config_config_updated.cfg')]
args = dict(save_when='modified')
set_module_args(args)
result = self.execute_module(changed=True)
mock_run_commands.stop()