From 0b5b19698e2fac767d7ab7d8a68ace4b146a61b2 Mon Sep 17 00:00:00 2001 From: Nathaniel Case Date: Fri, 9 Feb 2018 12:34:34 -0500 Subject: [PATCH 1/2] Revert "commented out check tests (#35788)" This reverts commit 3df2561405aae65b6592b2dc25a8b72b1804f0c7. --- .../vyos_smoke/tests/cli/misc_tests.yaml | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/test/integration/targets/vyos_smoke/tests/cli/misc_tests.yaml b/test/integration/targets/vyos_smoke/tests/cli/misc_tests.yaml index 312fa41c24395a..a56d057cca5388 100644 --- a/test/integration/targets/vyos_smoke/tests/cli/misc_tests.yaml +++ b/test/integration/targets/vyos_smoke/tests/cli/misc_tests.yaml @@ -1,13 +1,13 @@ # hit check conditional in module_utils.network.vyos -> load_config() -# - name: configure simple config command -# vyos_config: -# lines: set system host-name check-test -# check_mode: yes -# -# - name: get host name -# vyos_command: -# commands: show host name -# register: result -# -# - assert: -# that: '"check-test" not in result.stdout' +- name: configure simple config command + vyos_config: + lines: set system host-name check-test + check_mode: yes + +- name: get host name + vyos_command: + commands: show host name + register: result + +- assert: + that: '"check-test" not in result.stdout' From 9b820b60c1258a2bec66ff288aa5e5242e073232 Mon Sep 17 00:00:00 2001 From: Nathaniel Case Date: Fri, 9 Feb 2018 12:51:08 -0500 Subject: [PATCH 2/2] `discard_changes()` now uses `exit discard` instead of just `discard`. Also a slight tweak to avoid a second `exit` after `exit discard` --- lib/ansible/module_utils/network/vyos/vyos.py | 11 +++++------ lib/ansible/plugins/cliconf/vyos.py | 4 ++-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/ansible/module_utils/network/vyos/vyos.py b/lib/ansible/module_utils/network/vyos/vyos.py index a545378db8dc72..660156da692c2e 100644 --- a/lib/ansible/module_utils/network/vyos/vyos.py +++ b/lib/ansible/module_utils/network/vyos/vyos.py @@ -29,7 +29,7 @@ from ansible.module_utils._text import to_text from ansible.module_utils.basic import env_fallback, return_values from ansible.module_utils.network.common.utils import to_list -from ansible.module_utils.connection import Connection +from ansible.module_utils.connection import Connection, ConnectionError _DEVICE_CONFIGS = {} @@ -143,14 +143,13 @@ def load_config(module, commands, commit=False, comment=None): if commit: try: out = connection.commit(comment) - except: + except ConnectionError: connection.discard_changes() module.fail_json(msg='commit failed: %s' % out) - - if not commit: - connection.discard_changes() + else: + connection.get('exit') else: - connection.get('exit') + connection.discard_changes() if diff: return diff diff --git a/lib/ansible/plugins/cliconf/vyos.py b/lib/ansible/plugins/cliconf/vyos.py index 57b60b3761eef3..d341a2bd35e1ec 100644 --- a/lib/ansible/plugins/cliconf/vyos.py +++ b/lib/ansible/plugins/cliconf/vyos.py @@ -26,7 +26,7 @@ from ansible.module_utils._text import to_bytes, to_text from ansible.module_utils.network.common.utils import to_list -from ansible.plugins.cliconf import CliconfBase, enable_mode +from ansible.plugins.cliconf import CliconfBase class Cliconf(CliconfBase): @@ -69,7 +69,7 @@ def commit(self, comment=None): self.send_command(to_bytes(command)) def discard_changes(self, *args, **kwargs): - self.send_command(b'discard') + self.send_command(b'exit discard') def get_capabilities(self): result = {}