mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
fixes error when trying to run show start over eapi (#26800)
This commit is contained in:
parent
156b29b26b
commit
3bbb32cac5
3 changed files with 54 additions and 7 deletions
|
@ -170,15 +170,15 @@ options:
|
|||
changes are not copied to non-volatile storage by default. Using
|
||||
this argument will change that before. If the argument is set to
|
||||
I(always), then the running-config will always be copied to the
|
||||
startup-config and the I(changed) flag will always be set to
|
||||
True. If the argument is set to I(changed), then the running-config
|
||||
startup-config and the I(modified) flag will always be set to
|
||||
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
|
||||
the last save to startup-config. If the argument is set to
|
||||
I(never), the running-config will never be copied to the the
|
||||
startup-config
|
||||
required: false
|
||||
default: never
|
||||
choices: ['always', 'never', 'changed']
|
||||
choices: ['always', 'never', 'modified']
|
||||
version_added: "2.4"
|
||||
diff_against:
|
||||
description:
|
||||
|
@ -316,7 +316,7 @@ def main():
|
|||
defaults=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_ignore_lines=dict(type='list'),
|
||||
|
@ -408,7 +408,8 @@ def main():
|
|||
diff_ignore_lines = module.params['diff_ignore_lines']
|
||||
|
||||
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)
|
||||
startup_config = NetworkConfig(indent=1, contents=output[1], ignore_lines=diff_ignore_lines)
|
||||
|
@ -425,7 +426,7 @@ def main():
|
|||
|
||||
if module._diff:
|
||||
if not running_config:
|
||||
output = run_commands(module, 'show running-config')
|
||||
output = run_commands(module, {'command': 'show running-config', 'output': 'text'})
|
||||
contents = output[0]
|
||||
else:
|
||||
contents = running_config.config_text
|
||||
|
@ -442,7 +443,7 @@ def main():
|
|||
|
||||
elif module.params['diff_against'] == 'startup':
|
||||
if not startup_config:
|
||||
output = run_commands(module, 'show startup-config')
|
||||
output = run_commands(module, {'command': 'show startup-config', 'output': 'text'})
|
||||
contents = output[0]
|
||||
else:
|
||||
contents = startup_config.config_text
|
||||
|
|
|
@ -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
|
||||
!
|
|
@ -132,3 +132,23 @@ class TestEosConfigModule(TestEosModule):
|
|||
set_module_args(args)
|
||||
result = self.execute_module()
|
||||
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()
|
||||
|
|
Loading…
Reference in a new issue