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

Run save inside config mode. #23977

Merged
merged 4 commits into from
Apr 27, 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
8 changes: 5 additions & 3 deletions lib/ansible/modules/network/vyos/vyos_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,11 @@ def main():
run(module, result)

if module.params['save']:
if not module.check_mode:
run_commands(module, ['save'])
result['changed'] = True
diff = run_commands(module, commands=['configure', 'compare saved'])[1]
if diff != '[edit]':
run_commands(module, commands=['save'])
result['changed'] = True
run_commands(module, commands=['exit'])

module.exit_json(**result)

Expand Down
60 changes: 60 additions & 0 deletions test/integration/targets/vyos_config/tests/cli/save.yaml
Original file line number Diff line number Diff line change
@@ -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"
9 changes: 0 additions & 9 deletions test/units/modules/network/vyos/test_vyos_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,6 @@ def test_vyos_config_backup(self):
result = self.execute_module()
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):
commands = ['set system host-name foo']
set_module_args(dict(lines=commands))
Expand Down