Merge "Don't create client for help and bash completion" into stable/pike
This commit is contained in:
commit
291501ae6d
|
@ -523,7 +523,13 @@ class MistralShell(app.App):
|
|||
|
||||
self._set_shell_commands(self._get_commands(ver))
|
||||
|
||||
do_help = ('help' in argv) or ('-h' in argv) or not argv
|
||||
# bash-completion and help messages should not require client creation
|
||||
need_client = not (
|
||||
('bash-completion' in argv) or
|
||||
('help' in argv) or
|
||||
('-h' in argv) or
|
||||
('--help' 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.
|
||||
|
@ -532,10 +538,6 @@ class MistralShell(app.App):
|
|||
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
|
||||
|
||||
if self.options.auth_url and not self.options.token:
|
||||
if not self.options.username:
|
||||
raise exe.IllegalArgumentException(
|
||||
|
@ -549,6 +551,19 @@ class MistralShell(app.App):
|
|||
"via --os-password env[OS_PASSWORD]")
|
||||
)
|
||||
|
||||
self.client = self._create_client() if need_client else None
|
||||
|
||||
# Adding client_manager variable to make mistral client work with
|
||||
# unified OpenStack client.
|
||||
ClientManager = type(
|
||||
'ClientManager',
|
||||
(object,),
|
||||
dict(workflow_engine=self.client)
|
||||
)
|
||||
|
||||
self.client_manager = ClientManager()
|
||||
|
||||
def _create_client(self):
|
||||
kwargs = {
|
||||
'cert': self.options.os_cert,
|
||||
'key': self.options.os_key,
|
||||
|
@ -556,7 +571,7 @@ class MistralShell(app.App):
|
|||
'project_domain_name': self.options.project_domain_name
|
||||
}
|
||||
|
||||
self.client = client.client(
|
||||
return client.client(
|
||||
mistral_url=self.options.mistral_url,
|
||||
username=self.options.username,
|
||||
api_key=self.options.password,
|
||||
|
@ -585,16 +600,6 @@ class MistralShell(app.App):
|
|||
**kwargs
|
||||
)
|
||||
|
||||
# Adding client_manager variable to make mistral client work with
|
||||
# unified OpenStack client.
|
||||
ClientManager = type(
|
||||
'ClientManager',
|
||||
(object,),
|
||||
dict(workflow_engine=self.client)
|
||||
)
|
||||
|
||||
self.client_manager = ClientManager()
|
||||
|
||||
def _set_shell_commands(self, cmds_dict):
|
||||
for k, v in cmds_dict.items():
|
||||
self.command_manager.add_command(k, v)
|
||||
|
|
|
@ -19,6 +19,17 @@ import mistralclient.tests.unit.base_shell_test as base
|
|||
|
||||
class TestShell(base.BaseShellTests):
|
||||
|
||||
def test_help(self):
|
||||
"""Test that client is not created for help and bash complete"""
|
||||
for command in ('-h',
|
||||
'--help',
|
||||
'help',
|
||||
'help workbook-list',
|
||||
'bash-completion'):
|
||||
with mock.patch('mistralclient.api.client.client') as client_mock:
|
||||
self.shell(command)
|
||||
self.assertFalse(client_mock.called)
|
||||
|
||||
@mock.patch('mistralclient.api.client.client')
|
||||
def test_command_no_mistral_url(self, client_mock):
|
||||
self.shell(
|
||||
|
|
Loading…
Reference in New Issue