Remove deprecated construct method from session init

construct method is marked as deprecated and might be deleted
in one of future releases. So glanceclient need to be aware of
that and initialize sesssion from command line arguments directly.

Change-Id: Ie81b62b7e70bb177f178caadc41554ae88e51b05
This commit is contained in:
kairat_kushaev
2016-02-01 14:58:42 +03:00
committed by Nikhil Komawar
parent 10ad2886e1
commit 2ab2678140
2 changed files with 20 additions and 25 deletions
+14 -19
View File
@@ -285,9 +285,7 @@ class OpenStackImagesShell(object):
return (v2_auth_url, v3_auth_url) return (v2_auth_url, v3_auth_url)
def _get_keystone_session(self, **kwargs): def _get_keystone_auth_plugin(self, ks_session, **kwargs):
ks_session = session.Session.construct(kwargs)
# discover the supported keystone versions using the given auth url # discover the supported keystone versions using the given auth url
auth_url = kwargs.pop('auth_url', None) auth_url = kwargs.pop('auth_url', None)
(v2_auth_url, v3_auth_url) = self._discover_auth_versions( (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. " "may not able to handle Keystone V3 credentials. "
"Please provide a correct Keystone V3 auth_url.") "Please provide a correct Keystone V3 auth_url.")
ks_session.auth = auth return auth
return ks_session
def _get_kwargs_for_create_session(self, args): def _get_kwargs_to_create_auth_plugin(self, args):
if not args.os_username: if not args.os_username:
raise exc.CommandError( raise exc.CommandError(
_("You must provide a username via" _("You must provide a username via"
@@ -417,10 +414,6 @@ class OpenStackImagesShell(object):
'project_id': args.os_project_id, 'project_id': args.os_project_id,
'project_domain_name': args.os_project_domain_name, 'project_domain_name': args.os_project_domain_name,
'project_domain_id': args.os_project_domain_id, '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 return kwargs
@@ -441,17 +434,19 @@ class OpenStackImagesShell(object):
'ssl_compression': args.ssl_compression 'ssl_compression': args.ssl_compression
} }
else: else:
kwargs = self._get_kwargs_for_create_session(args) ks_session = session.Session.load_from_cli_options(args)
ks_session = self._get_keystone_session(**kwargs) 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} kwargs = {'session': ks_session}
if endpoint is None: if endpoint is None:
endpoint_type = args.os_endpoint_type or 'public' endpoint_type = args.os_endpoint_type or 'public'
service_type = args.os_service_type or 'image' service_type = args.os_service_type or 'image'
endpoint = ks_session.get_endpoint( endpoint = ks_session.get_endpoint(
service_type=service_type, service_type=service_type,
interface=endpoint_type, interface=endpoint_type,
region_name=args.os_region_name) region_name=args.os_region_name)
return glanceclient.Client(api_version, endpoint, **kwargs) return glanceclient.Client(api_version, endpoint, **kwargs)
+6 -6
View File
@@ -207,14 +207,14 @@ class ShellTest(testutils.TestCase):
def test_help(self): def test_help(self):
shell = openstack_shell.OpenStackImagesShell() shell = openstack_shell.OpenStackImagesShell()
argstr = '--os-image-api-version 2 help' 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()) actual = shell.main(argstr.split())
self.assertEqual(0, actual) self.assertEqual(0, actual)
self.assertFalse(et_mock.called) self.assertFalse(et_mock.called)
def test_blank_call(self): def test_blank_call(self):
shell = openstack_shell.OpenStackImagesShell() 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('') actual = shell.main('')
self.assertEqual(0, actual) self.assertEqual(0, actual)
self.assertFalse(et_mock.called) self.assertFalse(et_mock.called)
@@ -226,21 +226,21 @@ class ShellTest(testutils.TestCase):
def test_help_v2_no_schema(self): def test_help_v2_no_schema(self):
shell = openstack_shell.OpenStackImagesShell() shell = openstack_shell.OpenStackImagesShell()
argstr = '--os-image-api-version 2 help image-create' 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()) actual = shell.main(argstr.split())
self.assertEqual(0, actual) self.assertEqual(0, actual)
self.assertNotIn('<unavailable>', actual) self.assertNotIn('<unavailable>', actual)
self.assertFalse(et_mock.called) self.assertFalse(et_mock.called)
argstr = '--os-image-api-version 2 help md-namespace-create' 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()) actual = shell.main(argstr.split())
self.assertEqual(0, actual) self.assertEqual(0, actual)
self.assertNotIn('<unavailable>', actual) self.assertNotIn('<unavailable>', actual)
self.assertFalse(et_mock.called) self.assertFalse(et_mock.called)
argstr = '--os-image-api-version 2 help md-resource-type-associate' 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()) actual = shell.main(argstr.split())
self.assertEqual(0, actual) self.assertEqual(0, actual)
self.assertNotIn('<unavailable>', actual) self.assertNotIn('<unavailable>', actual)
@@ -413,7 +413,7 @@ class ShellTest(testutils.TestCase):
mock_getpass.assert_called_with('OS Password: ') mock_getpass.assert_called_with('OS Password: ')
@mock.patch( @mock.patch(
'glanceclient.shell.OpenStackImagesShell._get_keystone_session') 'glanceclient.shell.OpenStackImagesShell._get_keystone_auth_plugin')
@mock.patch.object(openstack_shell.OpenStackImagesShell, '_cache_schemas', @mock.patch.object(openstack_shell.OpenStackImagesShell, '_cache_schemas',
return_value=False) return_value=False)
def test_no_auth_with_proj_name(self, cache_schemas, session): def test_no_auth_with_proj_name(self, cache_schemas, session):