Fix VyOS check mode (#35977)
* Revert "commented out check tests (#35788)"
This reverts commit 3df2561405
.
* `discard_changes()` now uses `exit discard`
instead of just `discard`. Also a slight tweak to avoid a second `exit` after
`exit discard`
This commit is contained in:
parent
d5ae63c0ea
commit
6cdf91fd35
3 changed files with 19 additions and 20 deletions
|
@ -29,7 +29,7 @@ import json
|
||||||
from ansible.module_utils._text import to_text
|
from ansible.module_utils._text import to_text
|
||||||
from ansible.module_utils.basic import env_fallback, return_values
|
from ansible.module_utils.basic import env_fallback, return_values
|
||||||
from ansible.module_utils.network.common.utils import to_list
|
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 = {}
|
_DEVICE_CONFIGS = {}
|
||||||
|
|
||||||
|
@ -143,14 +143,13 @@ def load_config(module, commands, commit=False, comment=None):
|
||||||
if commit:
|
if commit:
|
||||||
try:
|
try:
|
||||||
out = connection.commit(comment)
|
out = connection.commit(comment)
|
||||||
except:
|
except ConnectionError:
|
||||||
connection.discard_changes()
|
connection.discard_changes()
|
||||||
module.fail_json(msg='commit failed: %s' % out)
|
module.fail_json(msg='commit failed: %s' % out)
|
||||||
|
else:
|
||||||
if not commit:
|
connection.get('exit')
|
||||||
connection.discard_changes()
|
|
||||||
else:
|
else:
|
||||||
connection.get('exit')
|
connection.discard_changes()
|
||||||
|
|
||||||
if diff:
|
if diff:
|
||||||
return diff
|
return diff
|
||||||
|
|
|
@ -26,7 +26,7 @@ from itertools import chain
|
||||||
|
|
||||||
from ansible.module_utils._text import to_bytes, to_text
|
from ansible.module_utils._text import to_bytes, to_text
|
||||||
from ansible.module_utils.network.common.utils import to_list
|
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):
|
class Cliconf(CliconfBase):
|
||||||
|
@ -69,7 +69,7 @@ class Cliconf(CliconfBase):
|
||||||
self.send_command(to_bytes(command))
|
self.send_command(to_bytes(command))
|
||||||
|
|
||||||
def discard_changes(self, *args, **kwargs):
|
def discard_changes(self, *args, **kwargs):
|
||||||
self.send_command(b'discard')
|
self.send_command(b'exit discard')
|
||||||
|
|
||||||
def get_capabilities(self):
|
def get_capabilities(self):
|
||||||
result = {}
|
result = {}
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
# hit check conditional in module_utils.network.vyos -> load_config()
|
# hit check conditional in module_utils.network.vyos -> load_config()
|
||||||
# - name: configure simple config command
|
- name: configure simple config command
|
||||||
# vyos_config:
|
vyos_config:
|
||||||
# lines: set system host-name check-test
|
lines: set system host-name check-test
|
||||||
# check_mode: yes
|
check_mode: yes
|
||||||
#
|
|
||||||
# - name: get host name
|
- name: get host name
|
||||||
# vyos_command:
|
vyos_command:
|
||||||
# commands: show host name
|
commands: show host name
|
||||||
# register: result
|
register: result
|
||||||
#
|
|
||||||
# - assert:
|
- assert:
|
||||||
# that: '"check-test" not in result.stdout'
|
that: '"check-test" not in result.stdout'
|
||||||
|
|
Loading…
Reference in a new issue