Skip to content

Commit

Permalink
Fixes 30786 - add server response to the failure (ansible#39371)
Browse files Browse the repository at this point in the history
* Fixes 30786 - add server response to the failure

* replace str(e) with to_native(e) according to code review
  • Loading branch information
gtema authored and samdoran committed Apr 30, 2018
1 parent d39b1ff commit 59b9c5f
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/ansible/modules/cloud/openstack/os_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@

from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs, openstack_cloud_from_module
from ansible.module_utils._text import to_native


def _create_stack(module, stack, cloud, shade):
Expand All @@ -168,7 +169,10 @@ def _create_stack(module, stack, cloud, shade):
else:
module.fail_json(msg="Failure in creating stack: {0}".format(stack))
except shade.OpenStackCloudException as e:
module.fail_json(msg=str(e))
if hasattr(e, 'response'):
module.fail_json(msg=to_native(e), response=e.response.json())
else:
module.fail_json(msg=to_native(e))


def _update_stack(module, stack, cloud, shade):
Expand All @@ -188,7 +192,10 @@ def _update_stack(module, stack, cloud, shade):
module.fail_json(msg="Failure in updating stack: %s" %
stack['stack_status_reason'])
except shade.OpenStackCloudException as e:
module.fail_json(msg=str(e))
if hasattr(e, 'response'):
module.fail_json(msg=to_native(e), response=e.response.json())
else:
module.fail_json(msg=to_native(e))


def _system_state_change(module, stack, cloud):
Expand Down Expand Up @@ -260,7 +267,7 @@ def main():
module.fail_json(msg='delete stack failed for stack: %s' % name)
module.exit_json(changed=changed)
except shade.OpenStackCloudException as e:
module.fail_json(msg=str(e))
module.fail_json(msg=to_native(e))


if __name__ == '__main__':
Expand Down

0 comments on commit 59b9c5f

Please sign in to comment.