Handle ConnectionError exception in network modules (#43353)

* Handle ConnectionError exception in network modules

* Catch ConnectionError expection and fail module in case
  expection is raised.

* Fix CI failure
This commit is contained in:
Ganesh Nalawade 2018-07-30 10:24:58 +05:30 committed by GitHub
commit 21dcaa4349
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 241 additions and 117 deletions

View file

@ -131,7 +131,9 @@ backup_path:
"""
import re
from ansible.module_utils._text import to_text
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.connection import ConnectionError
from ansible.module_utils.network.vyos.vyos import load_config, get_config, run_commands
from ansible.module_utils.network.vyos.vyos import vyos_argument_spec, get_connection
@ -208,7 +210,11 @@ def run(module, result):
# create loadable config that includes only the configuration updates
connection = get_connection(module)
response = connection.get_diff(candidate=candidate, running=config, diff_match=module.params['match'])
try:
response = connection.get_diff(candidate=candidate, running=config, diff_match=module.params['match'])
except ConnectionError as exc:
module.fail_json(msg=to_text(exc, errors='surrogate_then_replace'))
commands = response.get('config_diff')
sanitize_config(commands, result)