From a052d7a7e0d54522512c8c3f4fc4bcf7e47a029c Mon Sep 17 00:00:00 2001 From: Sam Thursfield Date: Tue, 9 Dec 2014 16:19:11 +0000 Subject: 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`.) --- morphlib/exts/openstack.check | 15 +++++++++++---- 1 file 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() -- cgit v1.2.1