From d95c81aba22fd77b5af01974b497f00126a5c7d5 Mon Sep 17 00:00:00 2001 From: Prince Katiyar Date: Thu, 28 Jul 2016 11:40:40 +0530 Subject: [PATCH] Add error message when OS_USERNAME or OS_PASSWORD not provided Closes-Bug: #1607631 Change-Id: I7be9dbc0a5e496d896435b000b5108fd114206ac --- mistralclient/shell.py | 16 +++++++++++++++- mistralclient/tests/unit/test_shell.py | 12 ++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/mistralclient/shell.py b/mistralclient/shell.py index 9abbda6..ee99e99 100644 --- a/mistralclient/shell.py +++ b/mistralclient/shell.py @@ -31,6 +31,7 @@ import mistralclient.commands.v2.services import mistralclient.commands.v2.tasks import mistralclient.commands.v2.workbooks import mistralclient.commands.v2.workflows +from mistralclient import exceptions as exe from mistralclient.openstack.common import cliutils as c from cliff import app @@ -237,7 +238,7 @@ class MistralShell(app.App): '--os-username', action='store', dest='username', - default=c.env('OS_USERNAME', default='admin'), + default=c.env('OS_USERNAME'), help='Authentication username (Env: OS_USERNAME)' ) @@ -376,6 +377,19 @@ class MistralShell(app.App): if do_help or ('bash-completion' in argv): self.options.auth_url = None + if self.options.auth_url and not self.options.token: + if not self.options.username: + raise exe.IllegalArgumentException( + ("You must provide a username " + "via --os-username env[OS_USERNAME]") + ) + + if not self.options.password: + raise exe.IllegalArgumentException( + ("You must provide a password " + "via --os-password env[OS_PASSWORD]") + ) + kwargs = { 'cert': self.options.os_cert, 'key': self.options.os_key diff --git a/mistralclient/tests/unit/test_shell.py b/mistralclient/tests/unit/test_shell.py index e6b0719..026eb52 100644 --- a/mistralclient/tests/unit/test_shell.py +++ b/mistralclient/tests/unit/test_shell.py @@ -84,7 +84,12 @@ class TestShell(base.BaseShellTests): @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.shell( + '--os-auth-url=https://127.0.0.1:35357/v3 ' + '--os-username=admin ' + '--os-password=1234 ' + 'workbook-list' + ) self.assertTrue(mock.called) params = mock.call_args self.assertEqual('https://127.0.0.1:35357/v3', params[1]['auth_url']) @@ -105,7 +110,10 @@ class TestShell(base.BaseShellTests): @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.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'])