Sync ProfileAction implementation with latest SDK code

Change-Id: Ia84b785833460af4fc569a8b27d23f55f83d2448
This commit is contained in:
yanyanhu 2015-08-14 04:10:42 -04:00
parent fef1191dc4
commit b38061528d
4 changed files with 20 additions and 24 deletions

View File

@ -162,11 +162,11 @@ def add_global_identity_args(parser):
help=_('Desired API versions, defaults to env[OS_API_VERSION]')) help=_('Desired API versions, defaults to env[OS_API_VERSION]'))
parser.add_argument( parser.add_argument(
'--os-api-visibility', dest='user_preferences', '--os-api-interface', dest='user_preferences',
metavar='<service>=<visibility>', metavar='<service>=<interface>',
action=sdk.ProfileAction, action=sdk.ProfileAction,
default=sdk.ProfileAction.env('OS_API_VISIBILITY'), default=sdk.ProfileAction.env('OS_INTERFACE'),
help=_('Desired API visibility, defaults to env[OS_API_VISIBILITY]')) help=_('Desired API interface, defaults to env[OS_INTERFACE]'))
# parser.add_argument( # parser.add_argument(

View File

@ -27,10 +27,10 @@ prop = base.prop
class ProfileAction(argparse.Action): 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() prof = profile.Profile()
@classmethod @classmethod
@ -45,19 +45,15 @@ class ProfileAction(argparse.Action):
@classmethod @classmethod
def set_option(cls, var, values): def set_option(cls, var, values):
if var == '--os-extensions':
cls.prof.load_extension(values)
return
if var == 'OS_REGION_NAME': if var == 'OS_REGION_NAME':
var = 'region' var = 'region'
var = var.replace('--os-api-', '') var = var.replace('--os-api-', '')
var = var.replace('OS_API_', '') var = var.replace('OS_API_', '')
var = var.lower() var = var.lower()
for kvp in values.split(','): for kvp in values.split(','):
if var == 'region':
if '=' in kvp:
service, value = kvp.split('=')
else:
service = cls.prof.ALL
value = kvp
else:
if '=' in kvp: if '=' in kvp:
service, value = kvp.split('=') service, value = kvp.split('=')
else: else:
@ -69,8 +65,8 @@ class ProfileAction(argparse.Action):
cls.prof.set_region(service, value) cls.prof.set_region(service, value)
elif var == 'version': elif var == 'version':
cls.prof.set_version(service, value) cls.prof.set_version(service, value)
elif var == 'visibility': elif var == 'interface':
cls.prof.set_visibility(service, value) cls.prof.set_interface(service, value)
def __call__(self, parser, namespace, values, option_string=None): def __call__(self, parser, namespace, values, option_string=None):
if getattr(namespace, self.dest, None) is None: if getattr(namespace, self.dest, None) is None:

View File

@ -44,7 +44,7 @@ class TestCliArgs(testtools.TestCase):
'--os-api-name', '--os-api-name',
'--os-api-region', '--os-api-region',
'--os-api-version', '--os-api-version',
'--os-api-visibility' '--os-api-interface'
] ]
options = [arg[0][0] for arg in parser.add_argument.call_args_list] options = [arg[0][0] for arg in parser.add_argument.call_args_list]

View File

@ -50,7 +50,7 @@ class TestSdk(testtools.TestCase):
mock_prof.set_version.assert_called_once_with('test', 'val1') mock_prof.set_version.assert_called_once_with('test', 'val1')
@mock.patch('senlinclient.common.sdk.ProfileAction.prof') @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' mock_prof.ALL = 'mock_prof.ALL'
sdk.ProfileAction.set_option('visibility', 'test=val1') sdk.ProfileAction.set_option('interface', 'test=val1')
mock_prof.set_visibility.assert_called_once_with('test', 'val1') mock_prof.set_interface.assert_called_once_with('test', 'val1')