mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Run save
inside config mode. (#23977)
* Run `save` before exiting config mode. * Fix unit tests for `save` * Allow `save` to be on its own again and introspect success * Introspecting `compare running` makes this a lot harder. Move `save` tests to integration tests
This commit is contained in:
parent
9c4daded94
commit
fc0bf87c20
3 changed files with 65 additions and 12 deletions
|
@ -269,9 +269,11 @@ def main():
|
||||||
run(module, result)
|
run(module, result)
|
||||||
|
|
||||||
if module.params['save']:
|
if module.params['save']:
|
||||||
if not module.check_mode:
|
diff = run_commands(module, commands=['configure', 'compare saved'])[1]
|
||||||
run_commands(module, ['save'])
|
if diff != '[edit]':
|
||||||
|
run_commands(module, commands=['save'])
|
||||||
result['changed'] = True
|
result['changed'] = True
|
||||||
|
run_commands(module, commands=['exit'])
|
||||||
|
|
||||||
module.exit_json(**result)
|
module.exit_json(**result)
|
||||||
|
|
||||||
|
|
60
test/integration/targets/vyos_config/tests/cli/save.yaml
Normal file
60
test/integration/targets/vyos_config/tests/cli/save.yaml
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
---
|
||||||
|
- debug: msg="START cli/save.yaml"
|
||||||
|
|
||||||
|
- name: setup
|
||||||
|
vyos_config:
|
||||||
|
lines: set system host-name {{ inventory_hostname_short }}
|
||||||
|
provider: "{{ cli }}"
|
||||||
|
match: none
|
||||||
|
|
||||||
|
- name: configure hostaname and save
|
||||||
|
vyos_config:
|
||||||
|
lines: set system host-name foo
|
||||||
|
provider: "{{ cli }}"
|
||||||
|
save: true
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- "result.changed == true"
|
||||||
|
- "'set system host-name foo' in result.commands"
|
||||||
|
|
||||||
|
- name: configure hostaname and don't save
|
||||||
|
vyos_config:
|
||||||
|
lines: set system host-name bar
|
||||||
|
provider: "{{ cli }}"
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- "result.changed == true"
|
||||||
|
- "'set system host-name bar' in result.commands"
|
||||||
|
|
||||||
|
- name: save config
|
||||||
|
vyos_config:
|
||||||
|
save: true
|
||||||
|
provider: "{{ cli }}"
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- "result.changed == true"
|
||||||
|
|
||||||
|
- name: save config again
|
||||||
|
vyos_config:
|
||||||
|
save: true
|
||||||
|
provider: "{{ cli }}"
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- "result.changed == false"
|
||||||
|
|
||||||
|
- name: teardown
|
||||||
|
vyos_config:
|
||||||
|
lines: set system host-name {{ inventory_hostname_short }}
|
||||||
|
provider: "{{ cli }}"
|
||||||
|
match: none
|
||||||
|
save: true
|
||||||
|
|
||||||
|
- debug: msg="END cli/simple.yaml"
|
|
@ -73,15 +73,6 @@ class TestVyosConfigModule(TestVyosModule):
|
||||||
result = self.execute_module()
|
result = self.execute_module()
|
||||||
self.assertIn('__backup__', result)
|
self.assertIn('__backup__', result)
|
||||||
|
|
||||||
def test_vyos_config_save(self):
|
|
||||||
set_module_args(dict(save=True))
|
|
||||||
self.execute_module(changed=True)
|
|
||||||
self.assertEqual(self.run_commands.call_count, 1)
|
|
||||||
self.assertEqual(self.get_config.call_count, 0)
|
|
||||||
self.assertEqual(self.load_config.call_count, 0)
|
|
||||||
args = self.run_commands.call_args[0][1]
|
|
||||||
self.assertIn('save', args)
|
|
||||||
|
|
||||||
def test_vyos_config_lines(self):
|
def test_vyos_config_lines(self):
|
||||||
commands = ['set system host-name foo']
|
commands = ['set system host-name foo']
|
||||||
set_module_args(dict(lines=commands))
|
set_module_args(dict(lines=commands))
|
||||||
|
|
Loading…
Reference in a new issue