diff options
author | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2014-12-09 16:19:11 +0000 |
---|---|---|
committer | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2014-12-09 16:37:54 +0000 |
commit | a052d7a7e0d54522512c8c3f4fc4bcf7e47a029c (patch) | |
tree | 4aca00851e14dae9cfa79cfe2d075c2f84969931 /morphlib/exts/openstack.check | |
parent | cb880f3554d9cf8daa3839dcd7a7ed2c336df85b (diff) | |
download | morph-a052d7a7e0d54522512c8c3f4fc4bcf7e47a029c.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`.)
Diffstat (limited to 'morphlib/exts/openstack.check')
-rwxr-xr-x | morphlib/exts/openstack.check | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/morphlib/exts/openstack.check b/morphlib/exts/openstack.check index edc37cc1..a6856c31 100755 --- a/morphlib/exts/openstack.check +++ b/morphlib/exts/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() |