Skip to content

Commit

Permalink
Fix VyOS check mode (ansible#35977)
Browse files Browse the repository at this point in the history
* Revert "commented out check tests (ansible#35788)"

This reverts commit 3df2561.

* `discard_changes()` now uses `exit discard`

instead of just `discard`. Also a slight tweak to avoid a second `exit` after
`exit discard`
  • Loading branch information
Qalthos committed Feb 11, 2018
1 parent d5ae63c commit 6cdf91f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
11 changes: 5 additions & 6 deletions lib/ansible/module_utils/network/vyos/vyos.py
Expand Up @@ -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 = {}

Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions lib/ansible/plugins/cliconf/vyos.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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 = {}
Expand Down
24 changes: 12 additions & 12 deletions 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'

0 comments on commit 6cdf91f

Please sign in to comment.