From e9b8e75b725e09dab3706dae96038fddcbf1f88e Mon Sep 17 00:00:00 2001 From: Winson Chan Date: Thu, 8 Oct 2015 02:20:35 +0000 Subject: [PATCH] Fix support of dev use case with no auth If --os-auth-url is not provided, then assume auth is not enabled. However, if --os-password or --os-auth-token is provided, then use default auth URL if it is not provided. Change-Id: Iaba14949e1b507f440b1609eb2d58eb6b6399f1d Closes-Bug: #1503915 --- mistralclient/shell.py | 11 ++++++++-- mistralclient/tests/unit/test_shell.py | 28 ++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/mistralclient/shell.py b/mistralclient/shell.py index 594fc072..223c21ff 100644 --- a/mistralclient/shell.py +++ b/mistralclient/shell.py @@ -224,7 +224,7 @@ class MistralShell(app.App): '--os-password', action='store', dest='password', - default=c.env('OS_PASSWORD', default='openstack'), + default=c.env('OS_PASSWORD'), help='Authentication password (Env: OS_PASSWORD)' ) parser.add_argument( @@ -252,7 +252,7 @@ class MistralShell(app.App): '--os-auth-url', action='store', dest='auth_url', - default=c.env('OS_AUTH_URL', default='http://localhost:35357/v3'), + default=c.env('OS_AUTH_URL'), help='Authentication URL (Env: OS_AUTH_URL)' ) parser.add_argument( @@ -273,6 +273,13 @@ class MistralShell(app.App): do_help = ('help' in argv) or ('-h' in argv) or not argv + # Set default for auth_url if not supplied. The default is not + # set at the parser to support use cases where auth is not enabled. + # An example use case would be a developer's environment. + if not self.options.auth_url: + if self.options.password or self.options.token: + self.options.auth_url = 'http://localhost:35357/v3' + # bash-completion should not require authentification. if do_help or ('bash-completion' in argv): self.options.auth_url = None diff --git a/mistralclient/tests/unit/test_shell.py b/mistralclient/tests/unit/test_shell.py index 661f7acf..2e7e373f 100644 --- a/mistralclient/tests/unit/test_shell.py +++ b/mistralclient/tests/unit/test_shell.py @@ -81,3 +81,31 @@ class TestShell(base.BaseShellTests): self.assertTrue(mock.called) params = mock.call_args self.assertEqual('publicURL', params[1]['endpoint_type']) + + @mock.patch('mistralclient.api.client.client') + def test_auth_url(self, mock): + self.shell('--os-auth-url=https://127.0.0.1:35357/v3 workbook-list') + self.assertTrue(mock.called) + params = mock.call_args + self.assertEqual('https://127.0.0.1:35357/v3', params[1]['auth_url']) + + @mock.patch('mistralclient.api.client.client') + def test_no_auth_url(self, mock): + self.shell('workbook-list') + self.assertTrue(mock.called) + params = mock.call_args + self.assertEqual('', params[1]['auth_url']) + + @mock.patch('mistralclient.api.client.client') + def test_default_auth_url_with_os_password(self, mock): + self.shell('--os-username=admin --os-password=1234 workbook-list') + self.assertTrue(mock.called) + params = mock.call_args + self.assertEqual('http://localhost:35357/v3', params[1]['auth_url']) + + @mock.patch('mistralclient.api.client.client') + def test_default_auth_url_with_os_auth_token(self, mock): + self.shell('--os-auth-token=abcd1234 workbook-list') + self.assertTrue(mock.called) + params = mock.call_args + self.assertEqual('http://localhost:35357/v3', params[1]['auth_url'])