Merge "Require auth URL if keystone strategy is enabled."

This commit is contained in:
Jenkins 2012-02-16 15:09:33 +00:00 committed by Gerrit Code Review
commit 941e160dc2
3 changed files with 37 additions and 2 deletions

View File

@ -66,6 +66,8 @@ def catch_error(action):
print "Not authorized to make this request. Check "\
"your credentials (OS_AUTH_USER, OS_AUTH_KEY, ...)."
return FAILURE
except exception.ClientConfigurationError:
raise
except Exception, e:
options = args[0]
if options.debug:
@ -731,10 +733,12 @@ def get_client(options):
specified by the --host and --port options
supplied to the CLI
"""
if options.auth_url or os.getenv('OS_AUTH_URL'):
force_strategy = 'keystone'
else:
force_strategy = None
creds = dict(username=options.username or \
os.getenv('OS_AUTH_USER', os.getenv('OS_USERNAME')),
password=options.password or \
@ -746,6 +750,11 @@ def get_client(options):
strategy=force_strategy or options.auth_strategy or \
os.getenv('OS_AUTH_STRATEGY', 'noauth'))
if creds['strategy'] == 'keystone' and not creds['auth_url']:
msg = ("--auth_url option or OS_AUTH_URL environment variable "
"required when keystone authentication strategy is enabled\n")
raise exception.ClientConfigurationError(msg)
use_ssl = (options.use_ssl or (
creds['auth_url'] is not None and
creds['auth_url'].find('https') != -1))
@ -981,5 +990,9 @@ Member Commands:
if options.verbose:
print "Completed in %-0.4f sec." % (end_time - start_time)
sys.exit(result)
except (RuntimeError, NotImplementedError), e:
print "ERROR: ", e
except (RuntimeError,
NotImplementedError,
exception.ClientConfigurationError), e:
oparser.print_usage()
print >> sys.stderr, "ERROR: ", e
sys.exit(1)

View File

@ -124,6 +124,10 @@ class ClientConnectionError(GlanceException):
message = _("There was an error connecting to a server")
class ClientConfigurationError(GlanceException):
message = _("There was an error configuring the client.")
class MultipleChoices(GlanceException):
message = _("The request returned a 302 Multiple Choices. This generally "
"means that you have not included a version indicator in a "

View File

@ -879,3 +879,21 @@ class TestPrivateImagesCli(keystone_utils.KeystoneTests):
os.environ['OS_AUTH_KEY'] = 'secrete'
cmd = "bin/glance --port=%d add name=MyImage" % self.api_port
self._do_test_glance_cli(cmd)
@skip_if_disabled
def test_glance_cli_keystone_strategy_without_auth_url(self):
"""
Test the CLI with the keystone strategy enabled but
auth url missing.
"""
substitutions = (self.api_port, 'keystone', 'pattieblack', 'secrete')
cmd = ("bin/glance --port=%d --auth_strategy=%s "
"--username=%s --password=%s index" % substitutions)
exitcode, out, err = execute(cmd, raise_error=False)
self.assertEqual(1, exitcode)
msg = ("--auth_url option or OS_AUTH_URL environment variable "
"required when keystone authentication strategy is enabled")
self.assertTrue(msg in err, 'expected "%s" in "%s"' % (msg, err))