Sync ProfileAction implementation with latest SDK code
Change-Id: Ia84b785833460af4fc569a8b27d23f55f83d2448
This commit is contained in:
parent
fef1191dc4
commit
b38061528d
@ -162,11 +162,11 @@ def add_global_identity_args(parser):
|
||||
help=_('Desired API versions, defaults to env[OS_API_VERSION]'))
|
||||
|
||||
parser.add_argument(
|
||||
'--os-api-visibility', dest='user_preferences',
|
||||
metavar='<service>=<visibility>',
|
||||
'--os-api-interface', dest='user_preferences',
|
||||
metavar='<service>=<interface>',
|
||||
action=sdk.ProfileAction,
|
||||
default=sdk.ProfileAction.env('OS_API_VISIBILITY'),
|
||||
help=_('Desired API visibility, defaults to env[OS_API_VISIBILITY]'))
|
||||
default=sdk.ProfileAction.env('OS_INTERFACE'),
|
||||
help=_('Desired API interface, defaults to env[OS_INTERFACE]'))
|
||||
|
||||
|
||||
# parser.add_argument(
|
||||
|
@ -27,10 +27,10 @@ prop = base.prop
|
||||
|
||||
|
||||
class ProfileAction(argparse.Action):
|
||||
'''A custom action to parse profiles as key=value pairs
|
||||
"""A custom action to parse user proferences as key=value pairs
|
||||
|
||||
Stores results in profiles object.
|
||||
'''
|
||||
Stores results in users proferences object.
|
||||
"""
|
||||
prof = profile.Profile()
|
||||
|
||||
@classmethod
|
||||
@ -45,32 +45,28 @@ class ProfileAction(argparse.Action):
|
||||
|
||||
@classmethod
|
||||
def set_option(cls, var, values):
|
||||
if var == '--os-extensions':
|
||||
cls.prof.load_extension(values)
|
||||
return
|
||||
if var == 'OS_REGION_NAME':
|
||||
var = 'region'
|
||||
var = var.replace('--os-api-', '')
|
||||
var = var.replace('OS_API_', '')
|
||||
var = var.lower()
|
||||
for kvp in values.split(','):
|
||||
if var == 'region':
|
||||
if '=' in kvp:
|
||||
service, value = kvp.split('=')
|
||||
else:
|
||||
service = cls.prof.ALL
|
||||
value = kvp
|
||||
if '=' in kvp:
|
||||
service, value = kvp.split('=')
|
||||
else:
|
||||
if '=' in kvp:
|
||||
service, value = kvp.split('=')
|
||||
else:
|
||||
service = cls.prof.ALL
|
||||
value = kvp
|
||||
service = cls.prof.ALL
|
||||
value = kvp
|
||||
if var == 'name':
|
||||
cls.prof.set_name(service, value)
|
||||
elif var == 'region':
|
||||
cls.prof.set_region(service, value)
|
||||
elif var == 'version':
|
||||
cls.prof.set_version(service, value)
|
||||
elif var == 'visibility':
|
||||
cls.prof.set_visibility(service, value)
|
||||
elif var == 'interface':
|
||||
cls.prof.set_interface(service, value)
|
||||
|
||||
def __call__(self, parser, namespace, values, option_string=None):
|
||||
if getattr(namespace, self.dest, None) is None:
|
||||
|
@ -44,7 +44,7 @@ class TestCliArgs(testtools.TestCase):
|
||||
'--os-api-name',
|
||||
'--os-api-region',
|
||||
'--os-api-version',
|
||||
'--os-api-visibility'
|
||||
'--os-api-interface'
|
||||
]
|
||||
|
||||
options = [arg[0][0] for arg in parser.add_argument.call_args_list]
|
||||
|
@ -50,7 +50,7 @@ class TestSdk(testtools.TestCase):
|
||||
mock_prof.set_version.assert_called_once_with('test', 'val1')
|
||||
|
||||
@mock.patch('senlinclient.common.sdk.ProfileAction.prof')
|
||||
def test_set_option_set_visibility(self, mock_prof):
|
||||
def test_set_option_set_interface(self, mock_prof):
|
||||
mock_prof.ALL = 'mock_prof.ALL'
|
||||
sdk.ProfileAction.set_option('visibility', 'test=val1')
|
||||
mock_prof.set_visibility.assert_called_once_with('test', 'val1')
|
||||
sdk.ProfileAction.set_option('interface', 'test=val1')
|
||||
mock_prof.set_interface.assert_called_once_with('test', 'val1')
|
||||
|
Loading…
Reference in New Issue
Block a user