Start using keystoneauth for keystone sessions

This is being split out from keystoneclient. That's a happymaking.
In order to make this work, we also need to fix glance image data upload
for v2 put. It seems that the internal interface has changed. Pass the file
object and not a size. We could do the work to figure out how to do it
in two discreet steps, but I believe that would involved a chunk of
engineering on a dead interface and is not worth it.

Also, Change ignore-errors to ignore_errors

Change-Id: I816752f8f4d29e40d41622bd8a271eb5c8e5a9fb
This commit is contained in:
Monty Taylor 2015-05-14 15:04:24 -04:00
parent 9a626589a8
commit d084ebd643
24 changed files with 78 additions and 80 deletions

View File

@ -4,4 +4,4 @@ source = shade
omit = shade/tests/* omit = shade/tests/*
[report] [report]
ignore-errors = True ignore_errors = True

View File

@ -3,9 +3,10 @@ pbr>=0.11,<2.0
bunch bunch
decorator decorator
jsonpatch jsonpatch
os-client-config>=1.6.2 os-client-config>=1.7.4
six six
keystoneauth1>=1.0.0
python-novaclient>=2.21.0,!=2.27.0 python-novaclient>=2.21.0,!=2.27.0
python-keystoneclient>=0.11.0 python-keystoneclient>=0.11.0
python-glanceclient>=1.0.0 python-glanceclient>=1.0.0

View File

@ -17,7 +17,6 @@ import hashlib
import inspect import inspect
import logging import logging
import operator import operator
import os
from cinderclient.v1 import client as cinder_client from cinderclient.v1 import client as cinder_client
from designateclient.v1 import Client as designate_client from designateclient.v1 import Client as designate_client
@ -28,12 +27,13 @@ import glanceclient.exc
from ironicclient import client as ironic_client from ironicclient import client as ironic_client
from ironicclient import exceptions as ironic_exceptions from ironicclient import exceptions as ironic_exceptions
import jsonpatch import jsonpatch
from keystoneclient import auth as ksc_auth import keystoneauth1.exceptions
from keystoneclient.auth import token_endpoint from keystoneauth1 import loading
from keystoneauth1 import plugin as ksc_plugin
from keystoneauth1 import session as ksc_session
from keystoneclient.v2_0 import client as k2_client from keystoneclient.v2_0 import client as k2_client
from keystoneclient.v3 import client as k3_client from keystoneclient.v3 import client as k3_client
from keystoneclient import exceptions as keystone_exceptions from keystoneclient import exceptions as keystone_exceptions
from keystoneclient import session as ksc_session
from novaclient import client as nova_client from novaclient import client as nova_client
from novaclient import exceptions as nova_exceptions from novaclient import exceptions as nova_exceptions
from neutronclient.common import exceptions as neutron_exceptions from neutronclient.common import exceptions as neutron_exceptions
@ -229,6 +229,9 @@ class OpenStackCloud(object):
self.auth = cloud_config.get_auth_args() self.auth = cloud_config.get_auth_args()
self.region_name = cloud_config.region_name self.region_name = cloud_config.region_name
self.auth_type = cloud_config.config['auth_type'] self.auth_type = cloud_config.config['auth_type']
# provide backwards compat to the old name of this plugin
if self.auth_type == 'token_endpoint':
self.auth_type = 'admin_token'
self.default_interface = cloud_config.get_interface() self.default_interface = cloud_config.get_interface()
self.private = cloud_config.config.get('private', False) self.private = cloud_config.config.get('private', False)
self.api_timeout = cloud_config.config['api_timeout'] self.api_timeout = cloud_config.config['api_timeout']
@ -344,18 +347,6 @@ class OpenStackCloud(object):
'compute', nova_client.Client) 'compute', nova_client.Client)
return self._nova_client return self._nova_client
def _get_auth_plugin_class(self):
try:
if self.auth_type == 'token_endpoint':
return token_endpoint.Token
else:
return ksc_auth.get_plugin_class(self.auth_type)
except Exception as e:
self.log.debug("keystone auth plugin failure", exc_info=True)
raise OpenStackCloudException(
"Could not find auth plugin: {plugin} {error}".format(
plugin=self.auth_type, error=str(e)))
def _get_identity_client_class(self): def _get_identity_client_class(self):
if self.cloud_config.get_api_version('identity') == '3': if self.cloud_config.get_api_version('identity') == '3':
return k3_client.Client return k3_client.Client
@ -369,9 +360,18 @@ class OpenStackCloud(object):
def keystone_session(self): def keystone_session(self):
if self._keystone_session is None: if self._keystone_session is None:
auth_plugin = self._get_auth_plugin_class()
try: try:
keystone_auth = auth_plugin(**self.auth) loader = loading.get_plugin_loader(self.auth_type)
except keystoneauth1.exceptions.auth_plugins.NoMatchingPlugin:
self.log.debug(
"keystoneauth could not find auth plugin {plugin}".format(
plugin=self.auth_type), exc_info=True)
raise OpenStackCloudException(
"No auth plugin named {plugin}".format(
plugin=self.auth_type))
try:
keystone_auth = loader.plugin_class(**self.auth)
except Exception as e: except Exception as e:
self.log.debug( self.log.debug(
"keystone couldn't construct plugin", exc_info=True) "keystone couldn't construct plugin", exc_info=True)
@ -401,7 +401,7 @@ class OpenStackCloud(object):
@property @property
def service_catalog(self): def service_catalog(self):
return self.keystone_session.auth.get_access( return self.keystone_session.auth.get_access(
self.keystone_session).service_catalog.get_data() self.keystone_session).service_catalog.catalog
@property @property
def auth_token(self): def auth_token(self):
@ -732,7 +732,7 @@ class OpenStackCloud(object):
# keystone is a special case in keystone, because what? # keystone is a special case in keystone, because what?
if service_key == 'identity': if service_key == 'identity':
endpoint = self.keystone_session.get_endpoint( endpoint = self.keystone_session.get_endpoint(
interface=ksc_auth.AUTH_INTERFACE) interface=ksc_plugin.AUTH_INTERFACE)
else: else:
endpoint = self.keystone_session.get_endpoint( endpoint = self.keystone_session.get_endpoint(
service_type=self.cloud_config.get_service_type( service_type=self.cloud_config.get_service_type(
@ -1382,12 +1382,8 @@ class OpenStackCloud(object):
image_kwargs[k] = str(v) image_kwargs[k] = str(v)
image = self.manager.submitTask(_tasks.ImageCreate( image = self.manager.submitTask(_tasks.ImageCreate(
name=name, **image_kwargs)) name=name, **image_kwargs))
curr = image_data.tell()
image_data.seek(0, os.SEEK_END)
data_size = image_data.tell()
image_data.seek(curr)
self.manager.submitTask(_tasks.ImageUpload( self.manager.submitTask(_tasks.ImageUpload(
image_id=image.id, image_data=image_data, image_size=data_size)) image_id=image.id, image_data=image_data))
return image return image
def _upload_image_put_v1(self, name, image_data, **image_kwargs): def _upload_image_put_v1(self, name, image_data, **image_kwargs):

View File

@ -15,9 +15,11 @@ import tempfile
import mock import mock
import os_client_config as occ import os_client_config as occ
import testtools
import yaml import yaml
import shade import shade
from shade import exc
from shade import meta from shade import meta
from shade.tests import fakes from shade.tests import fakes
from shade.tests.unit import base from shade.tests.unit import base
@ -299,7 +301,7 @@ class TestMemoryCache(base.TestCase):
'owner_specified.shade.sha256': mock.ANY} 'owner_specified.shade.sha256': mock.ANY}
glance_mock.images.create.assert_called_with(**args) glance_mock.images.create.assert_called_with(**args)
glance_mock.images.upload.assert_called_with( glance_mock.images.upload.assert_called_with(
image_data=mock.ANY, image_id=fake_image.id, image_size=1) image_data=mock.ANY, image_id=fake_image.id)
fake_image_dict = meta.obj_to_dict(fake_image) fake_image_dict = meta.obj_to_dict(fake_image)
self.assertEqual([fake_image_dict], self.cloud.list_images()) self.assertEqual([fake_image_dict], self.cloud.list_images())
@ -399,3 +401,8 @@ class TestMemoryCache(base.TestCase):
self.cloud.list_images.invalidate(self.cloud) self.cloud.list_images.invalidate(self.cloud)
self.assertEqual( self.assertEqual(
[fi, fi2], [dict(x) for x in self.cloud.list_images()]) [fi, fi2], [dict(x) for x in self.cloud.list_images()])
def test_get_auth_bogus(self):
self.cloud.auth_type = 'bogus'
with testtools.ExpectedException(exc.OpenStackCloudException):
self.cloud.keystone_session

View File

@ -32,7 +32,8 @@ class TestCreateServer(base.TestCase):
def setUp(self): def setUp(self):
super(TestCreateServer, self).setUp() super(TestCreateServer, self).setUp()
config = os_client_config.OpenStackConfig() config = os_client_config.OpenStackConfig()
self.client = OpenStackCloud(cloud_config=config.get_one_cloud()) self.client = OpenStackCloud(
cloud_config=config.get_one_cloud(validate=False))
def test_create_server_with_create_exception(self): def test_create_server_with_create_exception(self):
""" """

View File

@ -42,7 +42,8 @@ class TestDeleteServer(base.TestCase):
def setUp(self): def setUp(self):
super(TestDeleteServer, self).setUp() super(TestDeleteServer, self).setUp()
config = os_client_config.OpenStackConfig() config = os_client_config.OpenStackConfig()
self.cloud = OpenStackCloud(cloud_config=config.get_one_cloud()) self.cloud = OpenStackCloud(
cloud_config=config.get_one_cloud(validate=False))
@mock.patch('shade.OpenStackCloud.nova_client') @mock.patch('shade.OpenStackCloud.nova_client')
def test_delete_server(self, nova_mock): def test_delete_server(self, nova_mock):

View File

@ -26,7 +26,7 @@ class TestDomainParams(base.TestCase):
def setUp(self): def setUp(self):
super(TestDomainParams, self).setUp() super(TestDomainParams, self).setUp()
self.cloud = shade.openstack_cloud() self.cloud = shade.openstack_cloud(validate=False)
@mock.patch.object(occ.cloud_config.CloudConfig, 'get_api_version') @mock.patch.object(occ.cloud_config.CloudConfig, 'get_api_version')
@mock.patch.object(shade.OpenStackCloud, '_get_project') @mock.patch.object(shade.OpenStackCloud, '_get_project')

View File

@ -40,7 +40,8 @@ class TestCloudEndpoints(base.TestCase):
def setUp(self): def setUp(self):
super(TestCloudEndpoints, self).setUp() super(TestCloudEndpoints, self).setUp()
config = os_client_config.OpenStackConfig() config = os_client_config.OpenStackConfig()
self.client = OperatorCloud(cloud_config=config.get_one_cloud()) self.client = OperatorCloud(
cloud_config=config.get_one_cloud(validate=False))
self.mock_ks_endpoints = \ self.mock_ks_endpoints = \
[FakeEndpoint(**kwa) for kwa in self.mock_endpoints] [FakeEndpoint(**kwa) for kwa in self.mock_endpoints]

View File

@ -24,7 +24,7 @@ class TestFlavors(base.TestCase):
def setUp(self): def setUp(self):
super(TestFlavors, self).setUp() super(TestFlavors, self).setUp()
self.op_cloud = shade.operator_cloud() self.op_cloud = shade.operator_cloud(validate=False)
@mock.patch.object(shade.OpenStackCloud, 'nova_client') @mock.patch.object(shade.OpenStackCloud, 'nova_client')
def test_create_flavor(self, mock_nova): def test_create_flavor(self, mock_nova):

View File

@ -31,7 +31,8 @@ class TestFloatingIP(base.TestCase):
def setUp(self): def setUp(self):
super(TestFloatingIP, self).setUp() super(TestFloatingIP, self).setUp()
config = os_client_config.OpenStackConfig() config = os_client_config.OpenStackConfig()
self.client = OpenStackCloud(cloud_config=config.get_one_cloud()) self.client = OpenStackCloud(
cloud_config=config.get_one_cloud(validate=False))
@patch.object(OpenStackCloud, 'get_floating_ip') @patch.object(OpenStackCloud, 'get_floating_ip')
@patch.object(OpenStackCloud, 'attach_ip_to_server') @patch.object(OpenStackCloud, 'attach_ip_to_server')

View File

@ -123,7 +123,8 @@ class TestFloatingIP(base.TestCase):
super(TestFloatingIP, self).setUp() super(TestFloatingIP, self).setUp()
# floating_ip_source='neutron' is default for OpenStackCloud() # floating_ip_source='neutron' is default for OpenStackCloud()
config = os_client_config.OpenStackConfig() config = os_client_config.OpenStackConfig()
self.client = OpenStackCloud(cloud_config=config.get_one_cloud()) self.client = OpenStackCloud(
cloud_config=config.get_one_cloud(validate=False))
@patch.object(OpenStackCloud, 'neutron_client') @patch.object(OpenStackCloud, 'neutron_client')
@patch.object(OpenStackCloud, 'has_service') @patch.object(OpenStackCloud, 'has_service')

View File

@ -71,7 +71,8 @@ class TestFloatingIP(base.TestCase):
def setUp(self): def setUp(self):
super(TestFloatingIP, self).setUp() super(TestFloatingIP, self).setUp()
config = os_client_config.OpenStackConfig() config = os_client_config.OpenStackConfig()
self.client = OpenStackCloud(cloud_config=config.get_one_cloud()) self.client = OpenStackCloud(
cloud_config=config.get_one_cloud(validate=False))
@patch.object(OpenStackCloud, 'nova_client') @patch.object(OpenStackCloud, 'nova_client')
@patch.object(OpenStackCloud, 'has_service') @patch.object(OpenStackCloud, 'has_service')

View File

@ -35,7 +35,8 @@ class TestFloatingIPPool(base.TestCase):
def setUp(self): def setUp(self):
super(TestFloatingIPPool, self).setUp() super(TestFloatingIPPool, self).setUp()
config = os_client_config.OpenStackConfig() config = os_client_config.OpenStackConfig()
self.client = OpenStackCloud(cloud_config=config.get_one_cloud()) self.client = OpenStackCloud(
cloud_config=config.get_one_cloud(validate=False))
@patch.object(OpenStackCloud, '_has_nova_extension') @patch.object(OpenStackCloud, '_has_nova_extension')
@patch.object(OpenStackCloud, 'nova_client') @patch.object(OpenStackCloud, 'nova_client')

View File

@ -32,7 +32,7 @@ class TestIdentityDomains(base.TestCase):
def setUp(self): def setUp(self):
super(TestIdentityDomains, self).setUp() super(TestIdentityDomains, self).setUp()
self.cloud = shade.operator_cloud() self.cloud = shade.operator_cloud(validate=False)
@mock.patch.object(shade.OpenStackCloud, 'keystone_client') @mock.patch.object(shade.OpenStackCloud, 'keystone_client')
def test_list_identity_domains(self, mock_keystone): def test_list_identity_domains(self, mock_keystone):

View File

@ -27,7 +27,7 @@ class TestKeypair(base.TestCase):
def setUp(self): def setUp(self):
super(TestKeypair, self).setUp() super(TestKeypair, self).setUp()
self.cloud = shade.openstack_cloud() self.cloud = shade.openstack_cloud(validate=False)
@patch.object(shade.OpenStackCloud, 'nova_client') @patch.object(shade.OpenStackCloud, 'nova_client')
def test_create_keypair(self, mock_nova): def test_create_keypair(self, mock_nova):

View File

@ -105,7 +105,7 @@ class TestMeta(testtools.TestCase):
def test_get_server_ip(self): def test_get_server_ip(self):
srv = meta.obj_to_dict(FakeServer()) srv = meta.obj_to_dict(FakeServer())
cloud = shade.openstack_cloud() cloud = shade.openstack_cloud(validate=False)
self.assertEqual(PRIVATE_V4, meta.get_server_private_ip(srv)) self.assertEqual(PRIVATE_V4, meta.get_server_private_ip(srv))
self.assertEqual(PUBLIC_V4, meta.get_server_external_ipv4(cloud, srv)) self.assertEqual(PUBLIC_V4, meta.get_server_external_ipv4(cloud, srv))
@ -124,7 +124,7 @@ class TestMeta(testtools.TestCase):
srv = meta.obj_to_dict(fakes.FakeServer( srv = meta.obj_to_dict(fakes.FakeServer(
id='test-id', name='test-name', status='ACTIVE')) id='test-id', name='test-name', status='ACTIVE'))
cloud = shade.openstack_cloud() cloud = shade.openstack_cloud(validate=False)
self.assertEqual(PRIVATE_V4, meta.get_server_private_ip(srv, cloud)) self.assertEqual(PRIVATE_V4, meta.get_server_private_ip(srv, cloud))
mock_has_service.assert_called_once_with('network') mock_has_service.assert_called_once_with('network')
@ -154,7 +154,7 @@ class TestMeta(testtools.TestCase):
srv = meta.obj_to_dict(fakes.FakeServer( srv = meta.obj_to_dict(fakes.FakeServer(
id='test-id', name='test-name', status='ACTIVE')) id='test-id', name='test-name', status='ACTIVE'))
ip = meta.get_server_external_ipv4( ip = meta.get_server_external_ipv4(
cloud=shade.openstack_cloud(), server=srv) cloud=shade.openstack_cloud(validate=False), server=srv)
self.assertEqual(PUBLIC_V4, ip) self.assertEqual(PUBLIC_V4, ip)
self.assertFalse(mock_get_server_ip.called) self.assertFalse(mock_get_server_ip.called)
@ -164,7 +164,7 @@ class TestMeta(testtools.TestCase):
id='test-id', name='test-name', status='ACTIVE', id='test-id', name='test-name', status='ACTIVE',
accessIPv4=PUBLIC_V4)) accessIPv4=PUBLIC_V4))
ip = meta.get_server_external_ipv4( ip = meta.get_server_external_ipv4(
cloud=shade.openstack_cloud(), server=srv) cloud=shade.openstack_cloud(validate=False), server=srv)
self.assertEqual(PUBLIC_V4, ip) self.assertEqual(PUBLIC_V4, ip)
@ -189,7 +189,7 @@ class TestMeta(testtools.TestCase):
srv = meta.obj_to_dict(fakes.FakeServer( srv = meta.obj_to_dict(fakes.FakeServer(
id='test-id', name='test-name', status='ACTIVE')) id='test-id', name='test-name', status='ACTIVE'))
ip = meta.get_server_external_ipv4( ip = meta.get_server_external_ipv4(
cloud=shade.openstack_cloud(), server=srv) cloud=shade.openstack_cloud(validate=False), server=srv)
self.assertEqual(PUBLIC_V4, ip) self.assertEqual(PUBLIC_V4, ip)
self.assertTrue(mock_get_server_ip.called) self.assertTrue(mock_get_server_ip.called)
@ -209,7 +209,7 @@ class TestMeta(testtools.TestCase):
id='test-id', name='test-name', status='ACTIVE', id='test-id', name='test-name', status='ACTIVE',
addresses={'test-net': [{'addr': PUBLIC_V4}]})) addresses={'test-net': [{'addr': PUBLIC_V4}]}))
ip = meta.get_server_external_ipv4( ip = meta.get_server_external_ipv4(
cloud=shade.openstack_cloud(), server=srv) cloud=shade.openstack_cloud(validate=False), server=srv)
self.assertEqual(PUBLIC_V4, ip) self.assertEqual(PUBLIC_V4, ip)
self.assertTrue(mock_get_server_ip.called) self.assertTrue(mock_get_server_ip.called)
@ -230,7 +230,7 @@ class TestMeta(testtools.TestCase):
id='test-id', name='test-name', status='ACTIVE', id='test-id', name='test-name', status='ACTIVE',
addresses={'test-net': [{'addr': PRIVATE_V4}]})) addresses={'test-net': [{'addr': PRIVATE_V4}]}))
ip = meta.get_server_external_ipv4( ip = meta.get_server_external_ipv4(
cloud=shade.openstack_cloud(), server=srv) cloud=shade.openstack_cloud(validate=False), server=srv)
self.assertIsNone(ip) self.assertIsNone(ip)
self.assertTrue(mock_get_server_ip.called) self.assertTrue(mock_get_server_ip.called)

View File

@ -30,7 +30,8 @@ class TestObject(base.TestCase):
def setUp(self): def setUp(self):
super(TestObject, self).setUp() super(TestObject, self).setUp()
config = os_client_config.OpenStackConfig() config = os_client_config.OpenStackConfig()
self.cloud = OpenStackCloud(cloud_config=config.get_one_cloud()) self.cloud = OpenStackCloud(
cloud_config=config.get_one_cloud(validate=False))
@mock.patch.object(swift_client, 'Connection') @mock.patch.object(swift_client, 'Connection')
@mock.patch.object(shade.OpenStackCloud, 'auth_token', @mock.patch.object(shade.OpenStackCloud, 'auth_token',

View File

@ -27,11 +27,15 @@ class TestShadeOperatorNoAuth(base.TestCase):
URL in the auth data. This is permits testing of the basic URL in the auth data. This is permits testing of the basic
mechanism that enables Ironic noauth mode to be utilized with mechanism that enables Ironic noauth mode to be utilized with
Shade. Shade.
@todo(mordred): remove the token in the next patch - occ handles
this right.
""" """
super(TestShadeOperatorNoAuth, self).setUp() super(TestShadeOperatorNoAuth, self).setUp()
self.cloud_noauth = shade.operator_cloud( self.cloud_noauth = shade.operator_cloud(
auth_type='None', auth_type='admin_token',
auth=dict(endpoint="http://localhost:6385") auth=dict(endpoint="http://localhost:6385", token='foo'),
validate=False,
) )
@mock.patch.object(shade.OperatorCloud, 'get_session_endpoint') @mock.patch.object(shade.OperatorCloud, 'get_session_endpoint')
@ -45,5 +49,5 @@ class TestShadeOperatorNoAuth(base.TestCase):
was still called. was still called.
""" """
self.cloud_noauth.patch_machine('name', {}) self.cloud_noauth.patch_machine('name', {})
self.assertFalse(mock_endpoint.called) self.assertTrue(mock_endpoint.called)
self.assertTrue(mock_client.called) self.assertTrue(mock_client.called)

View File

@ -145,7 +145,8 @@ class TestPort(base.TestCase):
def setUp(self): def setUp(self):
super(TestPort, self).setUp() super(TestPort, self).setUp()
config = os_client_config.OpenStackConfig() config = os_client_config.OpenStackConfig()
self.client = OpenStackCloud(cloud_config=config.get_one_cloud()) self.client = OpenStackCloud(
cloud_config=config.get_one_cloud(validate=False))
@patch.object(OpenStackCloud, 'neutron_client') @patch.object(OpenStackCloud, 'neutron_client')
def test_create_port(self, mock_neutron_client): def test_create_port(self, mock_neutron_client):

View File

@ -32,7 +32,8 @@ class TestRebuildServer(base.TestCase):
def setUp(self): def setUp(self):
super(TestRebuildServer, self).setUp() super(TestRebuildServer, self).setUp()
config = os_client_config.OpenStackConfig() config = os_client_config.OpenStackConfig()
self.client = OpenStackCloud(cloud_config=config.get_one_cloud()) self.client = OpenStackCloud(
cloud_config=config.get_one_cloud(validate=False))
def test_rebuild_server_rebuild_exception(self): def test_rebuild_server_rebuild_exception(self):
""" """

View File

@ -57,7 +57,7 @@ class TestSecurityGroups(base.TestCase):
def setUp(self): def setUp(self):
super(TestSecurityGroups, self).setUp() super(TestSecurityGroups, self).setUp()
self.cloud = shade.openstack_cloud() self.cloud = shade.openstack_cloud(validate=False)
@mock.patch.object(shade.OpenStackCloud, 'neutron_client') @mock.patch.object(shade.OpenStackCloud, 'neutron_client')
@mock.patch.object(shade.OpenStackCloud, 'nova_client') @mock.patch.object(shade.OpenStackCloud, 'nova_client')

View File

@ -42,7 +42,8 @@ class CloudServices(base.TestCase):
def setUp(self): def setUp(self):
super(CloudServices, self).setUp() super(CloudServices, self).setUp()
config = os_client_config.OpenStackConfig() config = os_client_config.OpenStackConfig()
self.client = OperatorCloud(cloud_config=config.get_one_cloud()) self.client = OperatorCloud(cloud_config=config.get_one_cloud(
validate=False))
self.mock_ks_services = [FakeService(**kwa) for kwa in self.mock_ks_services = [FakeService(**kwa) for kwa in
self.mock_services] self.mock_services]

View File

@ -15,8 +15,6 @@
import mock import mock
import glanceclient import glanceclient
import keystoneclient.auth.identity.generic.password
import keystoneclient.auth.token_endpoint
from keystoneclient.v2_0 import client as k2_client from keystoneclient.v2_0 import client as k2_client
from keystoneclient.v3 import client as k3_client from keystoneclient.v3 import client as k3_client
from neutronclient.common import exceptions as n_exc from neutronclient.common import exceptions as n_exc
@ -32,30 +30,11 @@ class TestShade(base.TestCase):
def setUp(self): def setUp(self):
super(TestShade, self).setUp() super(TestShade, self).setUp()
self.cloud = shade.openstack_cloud() self.cloud = shade.openstack_cloud(validate=False)
def test_openstack_cloud(self): def test_openstack_cloud(self):
self.assertIsInstance(self.cloud, shade.OpenStackCloud) self.assertIsInstance(self.cloud, shade.OpenStackCloud)
def test_get_auth_token_endpoint(self):
self.cloud.auth_type = 'token_endpoint'
plugin = self.cloud._get_auth_plugin_class()
self.assertIs(plugin, keystoneclient.auth.token_endpoint.Token)
def test_get_auth_bogus(self):
self.cloud.auth_type = 'bogus'
self.assertRaises(
exc.OpenStackCloudException,
self.cloud._get_auth_plugin_class)
def test_get_auth_password(self):
plugin = self.cloud._get_auth_plugin_class()
self.assertIs(
plugin,
keystoneclient.auth.identity.generic.password.Password)
@mock.patch.object( @mock.patch.object(
os_client_config.cloud_config.CloudConfig, 'get_api_version') os_client_config.cloud_config.CloudConfig, 'get_api_version')
def test_get_client_v2(self, mock_api_version): def test_get_client_v2(self, mock_api_version):
@ -123,7 +102,7 @@ class TestShade(base.TestCase):
mock_keystone_session.return_value = None mock_keystone_session.return_value = None
self.cloud.glance_client self.cloud.glance_client
mock_client.assert_called_with( mock_client.assert_called_with(
version='1', region_name='', service_name=None, version='2', region_name='', service_name=None,
interface='public', interface='public',
service_type='image', session=mock.ANY, service_type='image', session=mock.ANY,
) )

View File

@ -12,7 +12,7 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from keystoneclient import auth as ksc_auth from keystoneauth1 import plugin as ksc_plugin
import mock import mock
import testtools import testtools
@ -29,7 +29,7 @@ class TestShadeOperator(base.TestCase):
def setUp(self): def setUp(self):
super(TestShadeOperator, self).setUp() super(TestShadeOperator, self).setUp()
self.cloud = shade.operator_cloud() self.cloud = shade.operator_cloud(validate=False)
def test_operator_cloud(self): def test_operator_cloud(self):
self.assertIsInstance(self.cloud, shade.OperatorCloud) self.assertIsInstance(self.cloud, shade.OperatorCloud)
@ -768,7 +768,7 @@ class TestShadeOperator(base.TestCase):
def test_get_session_endpoint_identity(self, session_mock): def test_get_session_endpoint_identity(self, session_mock):
self.cloud.get_session_endpoint('identity') self.cloud.get_session_endpoint('identity')
session_mock.get_endpoint.assert_called_with( session_mock.get_endpoint.assert_called_with(
interface=ksc_auth.AUTH_INTERFACE) interface=ksc_plugin.AUTH_INTERFACE)
@mock.patch.object(shade.OpenStackCloud, 'keystone_session') @mock.patch.object(shade.OpenStackCloud, 'keystone_session')
def test_has_service_no(self, session_mock): def test_has_service_no(self, session_mock):