From 92f52735cbf3db33e3877b0bfd9854a33b632e59 Mon Sep 17 00:00:00 2001 From: tengqm Date: Wed, 10 Aug 2016 03:12:59 -0400 Subject: [PATCH] Remove 'ProfileAction' and related arguments The 'ProfileAction' class and the related user_preferences are pre-history relics. Keeping them in senlinclient is only causing confusion considering that 1) senlin shell will be deprecated someday; 2) SDK has some tweaks to the design that we cannot follow up; 3) these arguments are rarely used. Change-Id: Ia79a069bde4fd94bc1bd00f719b4e6b4a56770f8 --- senlinclient/cliargs.py | 30 -------------- senlinclient/common/sdk.py | 55 ------------------------- senlinclient/shell.py | 3 +- senlinclient/tests/unit/test_cliargs.py | 4 -- senlinclient/tests/unit/test_sdk.py | 37 ----------------- senlinclient/tests/unit/test_shell.py | 4 +- 6 files changed, 3 insertions(+), 130 deletions(-) diff --git a/senlinclient/cliargs.py b/senlinclient/cliargs.py index 694d017..e2f28dc 100644 --- a/senlinclient/cliargs.py +++ b/senlinclient/cliargs.py @@ -13,7 +13,6 @@ import argparse from senlinclient.common.i18n import _ -from senlinclient.common import sdk from senlinclient.common import utils @@ -140,35 +139,6 @@ def add_global_identity_args(parser): default=utils.env('OS_ACCESS_INFO'), help=_('Access info, defaults to env[OS_ACCESS_INFO]')) - parser.add_argument( - '--os-api-name', dest='user_preferences', - metavar='=', - action=sdk.ProfileAction, - default=sdk.ProfileAction.env('OS_API_NAME'), - help=_('Desired API names, defaults to env[OS_API_NAME]')) - - parser.add_argument( - '--os-api-region', dest='user_preferences', - metavar='=', - action=sdk.ProfileAction, - default=sdk.ProfileAction.env('OS_API_REGION', 'OS_REGION_NAME'), - help=_('Desired API region, defaults to env[OS_API_REGION]')) - - parser.add_argument( - '--os-api-version', dest='user_preferences', - metavar='=', - action=sdk.ProfileAction, - default=sdk.ProfileAction.env('OS_API_VERSION'), - help=_('Desired API versions, defaults to env[OS_API_VERSION]')) - - parser.add_argument( - '--os-api-interface', dest='user_preferences', - metavar='=', - action=sdk.ProfileAction, - default=sdk.ProfileAction.env('OS_INTERFACE'), - help=_('Desired API interface, defaults to env[OS_INTERFACE]')) - - # parser.add_argument( # '--os-cert', # help=_('Path of certificate file to use in SSL connection. This ' diff --git a/senlinclient/common/sdk.py b/senlinclient/common/sdk.py index 8604960..6f1a7c2 100644 --- a/senlinclient/common/sdk.py +++ b/senlinclient/common/sdk.py @@ -10,67 +10,12 @@ # License for the specific language governing permissions and limitations # under the License. -import argparse -import os - from openstack import connection from openstack import exceptions from openstack import profile -from openstack import resource as base from senlinclient.common import exc -# Alias here for consistency -prop = base.prop - - -class ProfileAction(argparse.Action): - """A custom action to parse user preferences as key=value pairs - - Stores results in users preferences object. - """ - prof = profile.Profile() - - @classmethod - def env(cls, *vars): - for v in vars: - values = os.environ.get(v, None) - if values is None: - continue - cls.set_option(v, values) - return cls.prof - return cls.prof - - @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 '=' in kvp: - service, value = kvp.split('=') - else: - 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 == 'interface': - cls.prof.set_interface(service, value) - - def __call__(self, parser, namespace, values, option_string=None): - if getattr(namespace, self.dest, None) is None: - setattr(namespace, self.dest, ProfileAction.prof) - self.set_option(option_string, values) - def create_connection(prof=None, user_agent=None, **kwargs): if not prof: diff --git a/senlinclient/shell.py b/senlinclient/shell.py index ecc129d..75dd973 100644 --- a/senlinclient/shell.py +++ b/senlinclient/shell.py @@ -235,8 +235,7 @@ class SenlinShell(object): 'trust_id': args.trust_id, } - return senlin_client.Client('1', prof=args.user_preferences, - user_agent=USER_AGENT, **kwargs) + return senlin_client.Client('1', user_agent=USER_AGENT, **kwargs) def main(self, argv): # Parse args once to find version diff --git a/senlinclient/tests/unit/test_cliargs.py b/senlinclient/tests/unit/test_cliargs.py index 8bc6df8..89833f3 100644 --- a/senlinclient/tests/unit/test_cliargs.py +++ b/senlinclient/tests/unit/test_cliargs.py @@ -41,10 +41,6 @@ class TestCliArgs(testtools.TestCase): '--os-trust-id', '--os-token', '--os-access-info', - '--os-api-name', - '--os-api-region', - '--os-api-version', - '--os-api-interface' ] options = [arg[0][0] for arg in parser.add_argument.call_args_list] diff --git a/senlinclient/tests/unit/test_sdk.py b/senlinclient/tests/unit/test_sdk.py index dbbb0ce..57cbcc3 100644 --- a/senlinclient/tests/unit/test_sdk.py +++ b/senlinclient/tests/unit/test_sdk.py @@ -11,7 +11,6 @@ # under the License. import mock -import os import testtools from openstack import connection as sdk_connection @@ -22,42 +21,6 @@ from senlinclient.common import sdk class TestSdk(testtools.TestCase): - @mock.patch('senlinclient.common.sdk.ProfileAction.set_option') - def test_env(self, mock_set_option): - os.environ['test_senlin_sdk_env'] = '1' - sdk.ProfileAction.env('test_senlin_sdk_env') - mock_set_option.assert_called_once_with('test_senlin_sdk_env', '1') - - @mock.patch('senlinclient.common.sdk.ProfileAction.prof') - def test_set_option_set_name(self, mock_prof): - mock_prof.ALL = 'mock_prof.ALL' - sdk.ProfileAction.set_option('name', 'test=val1') - mock_prof.set_name.assert_called_once_with('test', 'val1') - mock_prof.reset_mock() - sdk.ProfileAction.set_option('name', 'val2') - mock_prof.set_name.assert_called_once_with(mock_prof.ALL, 'val2') - - @mock.patch('senlinclient.common.sdk.ProfileAction.prof') - def test_set_option_set_region(self, mock_prof): - mock_prof.ALL = 'mock_prof.ALL' - sdk.ProfileAction.set_option('OS_REGION_NAME', 'test=val1') - mock_prof.set_region.assert_called_once_with('test', 'val1') - mock_prof.reset_mock() - sdk.ProfileAction.set_option('OS_REGION_NAME', 'val2') - mock_prof.set_region.assert_called_once_with(mock_prof.ALL, 'val2') - - @mock.patch('senlinclient.common.sdk.ProfileAction.prof') - def test_set_option_set_version(self, mock_prof): - mock_prof.ALL = 'mock_prof.ALL' - sdk.ProfileAction.set_option('version', 'test=val1') - mock_prof.set_version.assert_called_once_with('test', 'val1') - - @mock.patch('senlinclient.common.sdk.ProfileAction.prof') - def test_set_option_set_interface(self, mock_prof): - mock_prof.ALL = 'mock_prof.ALL' - sdk.ProfileAction.set_option('interface', 'test=val1') - mock_prof.set_interface.assert_called_once_with('test', 'val1') - @mock.patch.object(sdk_connection, 'Connection') def test_create_connection_with_profile(self, mock_connection): mock_prof = mock.Mock() diff --git a/senlinclient/tests/unit/test_shell.py b/senlinclient/tests/unit/test_shell.py index 9c27990..edabb0c 100644 --- a/senlinclient/tests/unit/test_shell.py +++ b/senlinclient/tests/unit/test_shell.py @@ -366,8 +366,8 @@ class ShellTest(testtools.TestCase): mock_conn.return_value = conn conn.session = mock.Mock() sh._setup_senlin_client('1', args) - mock_conn.assert_called_once_with(prof=args.user_preferences, - user_agent=USER_AGENT, **kwargs) + mock_conn.assert_called_once_with(prof=None, user_agent=USER_AGENT, + **kwargs) client = mock.Mock() senlin_client.Client = mock.MagicMock(return_value=client) self.assertEqual(client, sh._setup_senlin_client('1', args))