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

Fix VyOS check mode #35977

Merged
merged 2 commits into from Feb 11, 2018
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
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'