Skip to content

Commit f600c0e

Browse files
committed
only generate one clientmanager instance in interactive mode
Currently, we repeated to generate clientmanager instance when run command in interactive mode. This should be avoided. Change-Id: I0536a690bc173be38af08a2e4443115532041efd Closes-Bug: #1383083
1 parent 2166d7d commit f600c0e

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

‎openstackclient/shell.py‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ def __init__(self):
6868
# Assume TLS host certificate verification is enabled
6969
self.verify = True
7070

71+
self.client_manager = None
72+
7173
# NOTE(dtroyer): This hack changes the help action that Cliff
7274
# automatically adds to the parser so we can defer
7375
# its execution until after the api-versioned commands
@@ -204,8 +206,12 @@ def build_option_parser(self, description, version):
204206

205207
return clientmanager.build_plugin_option_parser(parser)
206208

207-
def authenticate_user(self):
208-
"""Verify the required authentication credentials are present"""
209+
def initialize_clientmanager(self):
210+
"""Validating authentication options and generate a clientmanager"""
211+
212+
if self.client_manager:
213+
self.log.debug('The clientmanager has been initialized already')
214+
return
209215

210216
self.log.debug("validating authentication options")
211217

@@ -370,11 +376,11 @@ def prepare_to_run_command(self, cmd):
370376
return
371377
if cmd.best_effort:
372378
try:
373-
self.authenticate_user()
379+
self.initialize_clientmanager()
374380
except Exception:
375381
pass
376382
else:
377-
self.authenticate_user()
383+
self.initialize_clientmanager()
378384
return
379385

380386
def clean_up(self, cmd, result, err):
@@ -409,7 +415,7 @@ def clean_up(self, cmd, result, err):
409415
def interact(self):
410416
# NOTE(dtroyer): Maintain the old behaviour for interactive use as
411417
# this path does not call prepare_to_run_command()
412-
self.authenticate_user()
418+
self.initialize_clientmanager()
413419
super(OpenStackShell, self).interact()
414420

415421

0 commit comments

Comments
 (0)