diff --git a/glanceclient/shell.py b/glanceclient/shell.py index 8f2a205..ea1d313 100644 --- a/glanceclient/shell.py +++ b/glanceclient/shell.py @@ -285,9 +285,7 @@ class OpenStackImagesShell(object): return (v2_auth_url, v3_auth_url) - def _get_keystone_session(self, **kwargs): - ks_session = session.Session.construct(kwargs) - + def _get_keystone_auth_plugin(self, ks_session, **kwargs): # discover the supported keystone versions using the given auth url auth_url = kwargs.pop('auth_url', None) (v2_auth_url, v3_auth_url) = self._discover_auth_versions( @@ -347,10 +345,9 @@ class OpenStackImagesShell(object): "may not able to handle Keystone V3 credentials. " "Please provide a correct Keystone V3 auth_url.") - ks_session.auth = auth - return ks_session + return auth - def _get_kwargs_for_create_session(self, args): + def _get_kwargs_to_create_auth_plugin(self, args): if not args.os_username: raise exc.CommandError( _("You must provide a username via" @@ -417,10 +414,6 @@ class OpenStackImagesShell(object): 'project_id': args.os_project_id, 'project_domain_name': args.os_project_domain_name, 'project_domain_id': args.os_project_domain_id, - 'insecure': args.insecure, - 'cacert': args.os_cacert, - 'cert': args.os_cert, - 'key': args.os_key } return kwargs @@ -441,17 +434,19 @@ class OpenStackImagesShell(object): 'ssl_compression': args.ssl_compression } else: - kwargs = self._get_kwargs_for_create_session(args) - ks_session = self._get_keystone_session(**kwargs) + ks_session = session.Session.load_from_cli_options(args) + auth_plugin_kwargs = self._get_kwargs_to_create_auth_plugin(args) + ks_session.auth = self._get_keystone_auth_plugin( + ks_session=ks_session, **auth_plugin_kwargs) kwargs = {'session': ks_session} - if endpoint is None: - endpoint_type = args.os_endpoint_type or 'public' - service_type = args.os_service_type or 'image' - endpoint = ks_session.get_endpoint( - service_type=service_type, - interface=endpoint_type, - region_name=args.os_region_name) + if endpoint is None: + endpoint_type = args.os_endpoint_type or 'public' + service_type = args.os_service_type or 'image' + endpoint = ks_session.get_endpoint( + service_type=service_type, + interface=endpoint_type, + region_name=args.os_region_name) return glanceclient.Client(api_version, endpoint, **kwargs) diff --git a/glanceclient/tests/unit/test_shell.py b/glanceclient/tests/unit/test_shell.py index 6054bfc..87eef7a 100644 --- a/glanceclient/tests/unit/test_shell.py +++ b/glanceclient/tests/unit/test_shell.py @@ -207,14 +207,14 @@ class ShellTest(testutils.TestCase): def test_help(self): shell = openstack_shell.OpenStackImagesShell() argstr = '--os-image-api-version 2 help' - with mock.patch.object(shell, '_get_keystone_session') as et_mock: + with mock.patch.object(shell, '_get_keystone_auth_plugin') as et_mock: actual = shell.main(argstr.split()) self.assertEqual(0, actual) self.assertFalse(et_mock.called) def test_blank_call(self): shell = openstack_shell.OpenStackImagesShell() - with mock.patch.object(shell, '_get_keystone_session') as et_mock: + with mock.patch.object(shell, '_get_keystone_auth_plugin') as et_mock: actual = shell.main('') self.assertEqual(0, actual) self.assertFalse(et_mock.called) @@ -226,21 +226,21 @@ class ShellTest(testutils.TestCase): def test_help_v2_no_schema(self): shell = openstack_shell.OpenStackImagesShell() argstr = '--os-image-api-version 2 help image-create' - with mock.patch.object(shell, '_get_keystone_session') as et_mock: + with mock.patch.object(shell, '_get_keystone_auth_plugin') as et_mock: actual = shell.main(argstr.split()) self.assertEqual(0, actual) self.assertNotIn('', actual) self.assertFalse(et_mock.called) argstr = '--os-image-api-version 2 help md-namespace-create' - with mock.patch.object(shell, '_get_keystone_session') as et_mock: + with mock.patch.object(shell, '_get_keystone_auth_plugin') as et_mock: actual = shell.main(argstr.split()) self.assertEqual(0, actual) self.assertNotIn('', actual) self.assertFalse(et_mock.called) argstr = '--os-image-api-version 2 help md-resource-type-associate' - with mock.patch.object(shell, '_get_keystone_session') as et_mock: + with mock.patch.object(shell, '_get_keystone_auth_plugin') as et_mock: actual = shell.main(argstr.split()) self.assertEqual(0, actual) self.assertNotIn('', actual) @@ -413,7 +413,7 @@ class ShellTest(testutils.TestCase): mock_getpass.assert_called_with('OS Password: ') @mock.patch( - 'glanceclient.shell.OpenStackImagesShell._get_keystone_session') + 'glanceclient.shell.OpenStackImagesShell._get_keystone_auth_plugin') @mock.patch.object(openstack_shell.OpenStackImagesShell, '_cache_schemas', return_value=False) def test_no_auth_with_proj_name(self, cache_schemas, session):