Skip to content

Commit

Permalink
cloudengine: Modify exception handling method to make display informa…
Browse files Browse the repository at this point in the history
…tion more obvious (#51)

* update ce.py

* update changelog
  • Loading branch information
yanzhangi authored Jun 7, 2020
1 parent 88aa570 commit d6a1faf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- "ce - Modify exception handling method to make display information more obvious (https://github.com/ansible-collections/community.network/pull/51)."
26 changes: 20 additions & 6 deletions plugins/module_utils/network/cloudengine/ce.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,17 @@ def set_nc_config(module, xml_str):
try:
out = conn.edit_config(target='running', config=xml_str, default_operation='merge',
error_option='rollback-on-error')
finally:
except Exception as e:
message = re.findall(r'<error-message xml:lang=\"en\">(.*)</error-message>', str(e))
if message:
module.fail_json(msg='Error: %s' % message[0])
else:
module.fail_json(msg='Error: %s' % str(e))
else:
return to_string(to_xml(out))
# finally:
# conn.unlock(target = 'candidate')
pass
return to_string(to_xml(out))
# pass


def get_nc_next(module, xml_str):
Expand Down Expand Up @@ -376,12 +383,19 @@ def get_nc_config(module, xml_str):

conn = get_nc_connection(module)
if xml_str is not None:
response = conn.get(xml_str)
try:
response = conn.get(xml_str)
except Exception as e:
message = re.findall(r'<error-message xml:lang=\"en\">(.*)</error-message>', str(e))
if message:
module.fail_json(msg='Error: %s' % message[0])
else:
module.fail_json(msg='Error: %s' % str(e))
else:
return to_string(to_xml(response))
else:
return None

return to_string(to_xml(response))


def execute_nc_action(module, xml_str):
""" huawei execute-action """
Expand Down

0 comments on commit d6a1faf

Please sign in to comment.