Add more useful information from exception

When the module faces API exception we can give much more useful
information to the user. Let us do this for the modules inheriting from
the base class, since all modules should do this at some point in time

Change-Id: I5f1ef01765829900334aa2ecae5dab3ba96f1a49
This commit is contained in:
Artem Goncharov 2020-06-19 10:29:54 +02:00 committed by Sagi Shnaidman
parent 4b64ebe623
commit 32ef77d9fd

View File

@ -389,6 +389,14 @@ class OpenStackModule:
if results and isinstance(results, dict):
self.ansible.exit_json(**results)
except self.sdk.exceptions.OpenStackCloudException as e:
self.ansible.fail_json(msg=str(e), extra_data=e.extra_data)
params = {
'msg': str(e),
'extra_data': {
'data': e.extra_data,
'details': e.details,
'response': e.response.text
}
}
self.ansible.fail_json(**params)
# if we got to this place, modules didn't exit
self.ansible.exit_json(**self.results)