From 57428c48a2111f672cf835b8dce4ccb701f79eae Mon Sep 17 00:00:00 2001 From: Nacho Coloma Date: Wed, 23 Jul 2014 16:45:24 +0200 Subject: [PATCH 1/2] Bugfix: bulletproof unexpected_error_msg at gce.py This method was still failing for me with a "missing http_code" message. After applying this change, the error message is: ``` msg: Unexpected response: {'value': 'PyCrypto library required for Service Account Authentication.'} ``` I wanted to contribute a rock-solid `unexpected_error_msg` implementation. --- lib/ansible/module_utils/gce.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/ansible/module_utils/gce.py b/lib/ansible/module_utils/gce.py index 6d6fb158ff..2b50d9f5ab 100644 --- a/lib/ansible/module_utils/gce.py +++ b/lib/ansible/module_utils/gce.py @@ -64,7 +64,5 @@ def gce_connect(module): def unexpected_error_msg(error): """Create an error string based on passed in error.""" - msg='Unexpected response: HTTP return_code[' - msg+='%s], API error code[%s] and message: %s' % ( - error.http_code, error.code, str(error.value)) - return msg + import pprint + return 'Unexpected response: ' + pprint.pformat(vars(error)) From 979824eedcb04d61c376f70b91e2b657aab8e4e5 Mon Sep 17 00:00:00 2001 From: Nacho Coloma Date: Mon, 28 Jul 2014 08:36:56 +0200 Subject: [PATCH 2/2] Moved import to the top --- lib/ansible/module_utils/gce.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/ansible/module_utils/gce.py b/lib/ansible/module_utils/gce.py index 2b50d9f5ab..7f26d3f807 100644 --- a/lib/ansible/module_utils/gce.py +++ b/lib/ansible/module_utils/gce.py @@ -27,6 +27,8 @@ # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # +import pprint + USER_AGENT_PRODUCT="Ansible-gce" USER_AGENT_VERSION="v1" @@ -64,5 +66,4 @@ def gce_connect(module): def unexpected_error_msg(error): """Create an error string based on passed in error.""" - import pprint return 'Unexpected response: ' + pprint.pformat(vars(error))