Add error message when OS_USERNAME or OS_PASSWORD not provided

Closes-Bug: #1607631
Change-Id: I7be9dbc0a5e496d896435b000b5108fd114206ac
This commit is contained in:
Prince Katiyar
2016-07-28 11:40:40 +05:30
parent 1022889045
commit d95c81aba2
2 changed files with 25 additions and 3 deletions

View File

@@ -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

View File

@@ -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'])