summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2014-12-09 16:19:11 +0000
committerSam Thursfield <sam.thursfield@codethink.co.uk>2014-12-09 16:37:54 +0000
commitde88869eff96b3f9c09f61f4c9f67c0a710e1974 (patch)
tree69c8e963b75591c03e68e8c4d5e036bb0bea1d43
parent5a070828829e4c28d6e0a44c047a116ee1bbd1ae (diff)
downloaddefinitions-de88869eff96b3f9c09f61f4c9f67c0a710e1974.tar.gz
openstack.check: Be more careful when claiming credentials are invalid
In order to check the user's credentials at the start of deployment, we try to run `glance image-list`. I found a situation where this command failed despite my credentials being correct. Morph outputted a misleading error message that said 'Wrong OpenStack credentials' The code now checks that the error returned by 'glance' does indeed look like a credentials error. If it doesn't, the full error output is displayed. The error I encountered now gets a message like this: ERROR: openstack.check failed with code 1: ERROR: Failed to connect to OpenStack instance at https://example.com:5000/v2.0: [('SSL routines', 'SSL3_GET_SERVER_CERTIFICATE', 'certificate verify failed')] (If you are curious, I fixed this by running `update-ca-certificates`.)
-rwxr-xr-xopenstack.check15
1 files changed, 11 insertions, 4 deletions
diff --git a/openstack.check b/openstack.check
index edc37cc1..a6856c31 100755
--- a/openstack.check
+++ b/openstack.check
@@ -77,9 +77,16 @@ class OpenStackCheckExtension(morphlib.writeexts.WriteExtension):
'--os-password', password,
'--os-auth-url', auth_url,
'image-list']
- try:
- cliapp.runcmd(cmdline)
- except cliapp.AppException:
- raise cliapp.AppException('Wrong OpenStack credentals.')
+
+ exit, out, err = cliapp.runcmd_unchecked(cmdline)
+
+ if exit != 0:
+ if err.startswith('The request you have made requires ' \
+ 'authentication. (HTTP 401)'):
+ raise cliapp.AppException('Invalid OpenStack credentials.')
+ else:
+ raise cliapp.AppException(
+ 'Failed to connect to OpenStack instance at %s: %s' %
+ (auth_url, err))
OpenStackCheckExtension().run()