Move heat_keystoneclient to clients package

This moves the heat_keystoneclient wrapper to
heat.engine.clients package.

Change-Id: I39636abb946a7608014145d9edca5297d9f929d0
Related-Bug: #1554533
This commit is contained in:
rabi 2016-05-24 14:16:06 +05:30
parent 2c05a61328
commit e0e92b9d6d
11 changed files with 183 additions and 161 deletions

View File

@ -4,7 +4,7 @@ wrap_width = 79
namespace = heat.common.config namespace = heat.common.config
namespace = heat.common.context namespace = heat.common.context
namespace = heat.common.crypt namespace = heat.common.crypt
namespace = heat.common.heat_keystoneclient namespace = heat.engine.clients.keystone.heat_keystoneclient
namespace = heat.common.wsgi namespace = heat.common.wsgi
namespace = heat.engine.clients namespace = heat.engine.clients
namespace = heat.engine.notification namespace = heat.engine.notification

View File

@ -14,11 +14,8 @@
from keystoneclient import exceptions from keystoneclient import exceptions
from heat.common import exception from heat.common import exception
from heat.common import heat_keystoneclient as hkc
from heat.engine.clients import client_plugin from heat.engine.clients import client_plugin
from heat.engine import constraints from heat.engine.clients.os.keystone import heat_keystoneclient as hkc
CLIENT_NAME = 'keystone'
class KeystoneClientPlugin(client_plugin.ClientPlugin): class KeystoneClientPlugin(client_plugin.ClientPlugin):
@ -132,63 +129,3 @@ class KeystoneClientPlugin(client_plugin.ClientPlugin):
except exceptions.NotFound: except exceptions.NotFound:
raise exception.EntityNotFound(entity='KeystoneRegion', raise exception.EntityNotFound(entity='KeystoneRegion',
name=region) name=region)
class KeystoneBaseConstraint(constraints.BaseCustomConstraint):
resource_client_name = CLIENT_NAME
entity = None
def validate_with_client(self, client, resource_id):
# when user specify empty value in template, do not get the
# responding resource from backend, otherwise an error will happen
if resource_id == '':
raise exception.EntityNotFound(entity=self.entity,
name=resource_id)
super(KeystoneBaseConstraint, self).validate_with_client(client,
resource_id)
class KeystoneRoleConstraint(KeystoneBaseConstraint):
resource_getter_name = 'get_role_id'
entity = 'KeystoneRole'
class KeystoneDomainConstraint(KeystoneBaseConstraint):
resource_getter_name = 'get_domain_id'
entity = 'KeystoneDomain'
class KeystoneProjectConstraint(KeystoneBaseConstraint):
resource_getter_name = 'get_project_id'
entity = 'KeystoneProject'
class KeystoneGroupConstraint(KeystoneBaseConstraint):
resource_getter_name = 'get_group_id'
entity = 'KeystoneGroup'
class KeystoneServiceConstraint(KeystoneBaseConstraint):
expected_exceptions = (exception.EntityNotFound,
exception.KeystoneServiceNameConflict,)
resource_getter_name = 'get_service_id'
entity = 'KeystoneService'
class KeystoneUserConstraint(KeystoneBaseConstraint):
resource_getter_name = 'get_user_id'
entity = 'KeystoneUser'
class KeystoneRegionConstraint(KeystoneBaseConstraint):
resource_getter_name = 'get_region_id'
entity = 'KeystoneRegion'

View File

@ -33,11 +33,12 @@ from heat.common.i18n import _
from heat.common.i18n import _LE from heat.common.i18n import _LE
from heat.common.i18n import _LW from heat.common.i18n import _LW
LOG = logging.getLogger('heat.common.keystoneclient') LOG = logging.getLogger('heat.engine.clients.keystoneclient')
AccessKey = collections.namedtuple('AccessKey', ['id', 'access', 'secret']) AccessKey = collections.namedtuple('AccessKey', ['id', 'access', 'secret'])
_default_keystone_backend = "heat.common.heat_keystoneclient.KeystoneClientV3" _default_keystone_backend = (
'heat.engine.clients.os.keystone.heat_keystoneclient.KsClientWrapper')
keystone_opts = [ keystone_opts = [
cfg.StrOpt('keystone_backend', cfg.StrOpt('keystone_backend',
@ -47,7 +48,7 @@ keystone_opts = [
cfg.CONF.register_opts(keystone_opts) cfg.CONF.register_opts(keystone_opts)
class KeystoneClientV3(object): class KsClientWrapper(object):
"""Wrap keystone client so we can encapsulate logic used in resources. """Wrap keystone client so we can encapsulate logic used in resources.
Note this is intended to be initialized from a resource on a per-session Note this is intended to be initialized from a resource on a per-session
@ -558,7 +559,7 @@ class KeystoneClient(object):
def __new__(cls, context): def __new__(cls, context):
if cfg.CONF.keystone_backend == _default_keystone_backend: if cfg.CONF.keystone_backend == _default_keystone_backend:
return KeystoneClientV3(context) return KsClientWrapper(context)
else: else:
return importutils.import_object( return importutils.import_object(
cfg.CONF.keystone_backend, cfg.CONF.keystone_backend,

View File

@ -0,0 +1,77 @@
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from heat.common import exception
from heat.engine import constraints
CLIENT_NAME = 'keystone'
class KeystoneBaseConstraint(constraints.BaseCustomConstraint):
resource_client_name = CLIENT_NAME
entity = None
def validate_with_client(self, client, resource_id):
# when user specify empty value in template, do not get the
# responding resource from backend, otherwise an error will happen
if resource_id == '':
raise exception.EntityNotFound(entity=self.entity,
name=resource_id)
super(KeystoneBaseConstraint, self).validate_with_client(client,
resource_id)
class KeystoneRoleConstraint(KeystoneBaseConstraint):
resource_getter_name = 'get_role_id'
entity = 'KeystoneRole'
class KeystoneDomainConstraint(KeystoneBaseConstraint):
resource_getter_name = 'get_domain_id'
entity = 'KeystoneDomain'
class KeystoneProjectConstraint(KeystoneBaseConstraint):
resource_getter_name = 'get_project_id'
entity = 'KeystoneProject'
class KeystoneGroupConstraint(KeystoneBaseConstraint):
resource_getter_name = 'get_group_id'
entity = 'KeystoneGroup'
class KeystoneServiceConstraint(KeystoneBaseConstraint):
expected_exceptions = (exception.EntityNotFound,
exception.KeystoneServiceNameConflict,)
resource_getter_name = 'get_service_id'
entity = 'KeystoneService'
class KeystoneUserConstraint(KeystoneBaseConstraint):
resource_getter_name = 'get_user_id'
entity = 'KeystoneUser'
class KeystoneRegionConstraint(KeystoneBaseConstraint):
resource_getter_name = 'get_region_id'
entity = 'KeystoneRegion'

View File

@ -29,7 +29,7 @@ import six
from heat.common import config from heat.common import config
from heat.common import exception from heat.common import exception
from heat.common import heat_keystoneclient from heat.engine.clients.os.keystone import heat_keystoneclient
from heat.tests import common from heat.tests import common
from heat.tests import utils from heat.tests import utils

View File

@ -11,25 +11,26 @@
# 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 exceptions as keystone_exceptions
import mock import mock
import six import six
from keystoneclient import exceptions as keystone_exceptions
from heat.common import exception from heat.common import exception
from heat.engine.clients.os import keystone as client from heat.engine.clients.os import keystone
from heat.engine.clients.os.keystone import keystone_constraints as ks_constr
from heat.tests import common from heat.tests import common
class KeystoneRoleConstraintTest(common.HeatTestCase): class KeystoneRoleConstraintTest(common.HeatTestCase):
def test_expected_exceptions(self): def test_expected_exceptions(self):
self.assertEqual((exception.EntityNotFound,), self.assertEqual(
client.KeystoneRoleConstraint.expected_exceptions, (exception.EntityNotFound,),
"KeystoneRoleConstraint expected exceptions error") ks_constr.KeystoneRoleConstraint.expected_exceptions,
"KeystoneRoleConstraint expected exceptions error")
def test_constraint(self): def test_constraint(self):
constraint = client.KeystoneRoleConstraint() constraint = ks_constr.KeystoneRoleConstraint()
client_mock = mock.MagicMock() client_mock = mock.MagicMock()
client_plugin_mock = mock.MagicMock() client_plugin_mock = mock.MagicMock()
client_plugin_mock.get_role_id.return_value = None client_plugin_mock.get_role_id.return_value = None
@ -47,12 +48,13 @@ class KeystoneRoleConstraintTest(common.HeatTestCase):
class KeystoneProjectConstraintTest(common.HeatTestCase): class KeystoneProjectConstraintTest(common.HeatTestCase):
def test_expected_exceptions(self): def test_expected_exceptions(self):
self.assertEqual((exception.EntityNotFound,), self.assertEqual(
client.KeystoneProjectConstraint.expected_exceptions, (exception.EntityNotFound,),
"KeystoneProjectConstraint expected exceptions error") ks_constr.KeystoneProjectConstraint.expected_exceptions,
"KeystoneProjectConstraint expected exceptions error")
def test_constraint(self): def test_constraint(self):
constraint = client.KeystoneProjectConstraint() constraint = ks_constr.KeystoneProjectConstraint()
client_mock = mock.MagicMock() client_mock = mock.MagicMock()
client_plugin_mock = mock.MagicMock() client_plugin_mock = mock.MagicMock()
client_plugin_mock.get_project_id.return_value = None client_plugin_mock.get_project_id.return_value = None
@ -70,12 +72,13 @@ class KeystoneProjectConstraintTest(common.HeatTestCase):
class KeystoneGroupConstraintTest(common.HeatTestCase): class KeystoneGroupConstraintTest(common.HeatTestCase):
def test_expected_exceptions(self): def test_expected_exceptions(self):
self.assertEqual((exception.EntityNotFound,), self.assertEqual(
client.KeystoneGroupConstraint.expected_exceptions, (exception.EntityNotFound,),
"KeystoneGroupConstraint expected exceptions error") ks_constr.KeystoneGroupConstraint.expected_exceptions,
"KeystoneGroupConstraint expected exceptions error")
def test_constraint(self): def test_constraint(self):
constraint = client.KeystoneGroupConstraint() constraint = ks_constr.KeystoneGroupConstraint()
client_mock = mock.MagicMock() client_mock = mock.MagicMock()
client_plugin_mock = mock.MagicMock() client_plugin_mock = mock.MagicMock()
client_plugin_mock.get_group_id.return_value = None client_plugin_mock.get_group_id.return_value = None
@ -93,12 +96,13 @@ class KeystoneGroupConstraintTest(common.HeatTestCase):
class KeystoneDomainConstraintTest(common.HeatTestCase): class KeystoneDomainConstraintTest(common.HeatTestCase):
def test_expected_exceptions(self): def test_expected_exceptions(self):
self.assertEqual((exception.EntityNotFound,), self.assertEqual(
client.KeystoneDomainConstraint.expected_exceptions, (exception.EntityNotFound,),
"KeystoneDomainConstraint expected exceptions error") ks_constr.KeystoneDomainConstraint.expected_exceptions,
"KeystoneDomainConstraint expected exceptions error")
def test_constraint(self): def test_constraint(self):
constraint = client.KeystoneDomainConstraint() constraint = ks_constr.KeystoneDomainConstraint()
client_mock = mock.MagicMock() client_mock = mock.MagicMock()
client_plugin_mock = mock.MagicMock() client_plugin_mock = mock.MagicMock()
client_plugin_mock.get_domain_id.return_value = None client_plugin_mock.get_domain_id.return_value = None
@ -118,13 +122,13 @@ class KeystoneServiceConstraintTest(common.HeatTestCase):
sample_uuid = '477e8273-60a7-4c41-b683-fdb0bc7cd151' sample_uuid = '477e8273-60a7-4c41-b683-fdb0bc7cd151'
def test_expected_exceptions(self): def test_expected_exceptions(self):
self.assertEqual((exception.EntityNotFound, self.assertEqual(
exception.KeystoneServiceNameConflict,), (exception.EntityNotFound, exception.KeystoneServiceNameConflict,),
client.KeystoneServiceConstraint.expected_exceptions, ks_constr.KeystoneServiceConstraint.expected_exceptions,
"KeystoneServiceConstraint expected exceptions error") "KeystoneServiceConstraint expected exceptions error")
def test_constraint(self): def test_constraint(self):
constraint = client.KeystoneServiceConstraint() constraint = ks_constr.KeystoneServiceConstraint()
client_mock = mock.MagicMock() client_mock = mock.MagicMock()
client_plugin_mock = mock.MagicMock() client_plugin_mock = mock.MagicMock()
client_plugin_mock.get_service_id.return_value = self.sample_uuid client_plugin_mock.get_service_id.return_value = self.sample_uuid
@ -143,12 +147,13 @@ class KeystoneServiceConstraintTest(common.HeatTestCase):
class KeystoneUserConstraintTest(common.HeatTestCase): class KeystoneUserConstraintTest(common.HeatTestCase):
def test_expected_exceptions(self): def test_expected_exceptions(self):
self.assertEqual((exception.EntityNotFound,), self.assertEqual(
client.KeystoneUserConstraint.expected_exceptions, (exception.EntityNotFound,),
"KeystoneUserConstraint expected exceptions error") ks_constr.KeystoneUserConstraint.expected_exceptions,
"KeystoneUserConstraint expected exceptions error")
def test_constraint(self): def test_constraint(self):
constraint = client.KeystoneUserConstraint() constraint = ks_constr.KeystoneUserConstraint()
client_mock = mock.MagicMock() client_mock = mock.MagicMock()
client_plugin_mock = mock.MagicMock() client_plugin_mock = mock.MagicMock()
client_plugin_mock.get_user_id.return_value = None client_plugin_mock.get_user_id.return_value = None
@ -167,12 +172,13 @@ class KeystoneRegionConstraintTest(common.HeatTestCase):
sample_uuid = '477e8273-60a7-4c41-b683-fdb0bc7cd151' sample_uuid = '477e8273-60a7-4c41-b683-fdb0bc7cd151'
def test_expected_exceptions(self): def test_expected_exceptions(self):
self.assertEqual((exception.EntityNotFound,), self.assertEqual(
client.KeystoneRegionConstraint.expected_exceptions, (exception.EntityNotFound,),
"KeystoneRegionConstraint expected exceptions error") ks_constr.KeystoneRegionConstraint.expected_exceptions,
"KeystoneRegionConstraint expected exceptions error")
def test_constraint(self): def test_constraint(self):
constraint = client.KeystoneRegionConstraint() constraint = ks_constr.KeystoneRegionConstraint()
client_mock = mock.MagicMock() client_mock = mock.MagicMock()
client_plugin_mock = mock.MagicMock() client_plugin_mock = mock.MagicMock()
client_plugin_mock.get_region_id.return_value = self.sample_uuid client_plugin_mock.get_region_id.return_value = self.sample_uuid
@ -203,14 +209,14 @@ class KeystoneClientPluginServiceTest(common.HeatTestCase):
super(KeystoneClientPluginServiceTest, self).setUp() super(KeystoneClientPluginServiceTest, self).setUp()
self._client = mock.MagicMock() self._client = mock.MagicMock()
@mock.patch.object(client.KeystoneClientPlugin, 'client') @mock.patch.object(keystone.KeystoneClientPlugin, 'client')
def test_get_service_id(self, client_keystone): def test_get_service_id(self, client_keystone):
self._client.client.services.get.return_value = (self self._client.client.services.get.return_value = (self
._get_mock_service()) ._get_mock_service())
client_keystone.return_value = self._client client_keystone.return_value = self._client
client_plugin = client.KeystoneClientPlugin( client_plugin = keystone.KeystoneClientPlugin(
context=mock.MagicMock() context=mock.MagicMock()
) )
@ -219,7 +225,7 @@ class KeystoneClientPluginServiceTest(common.HeatTestCase):
self._client.client.services.get.assert_called_once_with( self._client.client.services.get.assert_called_once_with(
self.sample_uuid) self.sample_uuid)
@mock.patch.object(client.KeystoneClientPlugin, 'client') @mock.patch.object(keystone.KeystoneClientPlugin, 'client')
def test_get_service_id_with_name(self, client_keystone): def test_get_service_id_with_name(self, client_keystone):
self._client.client.services.get.side_effect = (keystone_exceptions self._client.client.services.get.side_effect = (keystone_exceptions
.NotFound) .NotFound)
@ -228,7 +234,7 @@ class KeystoneClientPluginServiceTest(common.HeatTestCase):
] ]
client_keystone.return_value = self._client client_keystone.return_value = self._client
client_plugin = client.KeystoneClientPlugin( client_plugin = keystone.KeystoneClientPlugin(
context=mock.MagicMock() context=mock.MagicMock()
) )
@ -240,7 +246,7 @@ class KeystoneClientPluginServiceTest(common.HeatTestCase):
self._client.client.services.list.assert_called_once_with( self._client.client.services.list.assert_called_once_with(
name=self.sample_name) name=self.sample_name)
@mock.patch.object(client.KeystoneClientPlugin, 'client') @mock.patch.object(keystone.KeystoneClientPlugin, 'client')
def test_get_service_id_with_name_conflict(self, client_keystone): def test_get_service_id_with_name_conflict(self, client_keystone):
self._client.client.services.get.side_effect = (keystone_exceptions self._client.client.services.get.side_effect = (keystone_exceptions
.NotFound) .NotFound)
@ -250,7 +256,7 @@ class KeystoneClientPluginServiceTest(common.HeatTestCase):
] ]
client_keystone.return_value = self._client client_keystone.return_value = self._client
client_plugin = client.KeystoneClientPlugin( client_plugin = keystone.KeystoneClientPlugin(
context=mock.MagicMock() context=mock.MagicMock()
) )
@ -267,7 +273,7 @@ class KeystoneClientPluginServiceTest(common.HeatTestCase):
self._client.client.services.list.assert_called_once_with( self._client.client.services.list.assert_called_once_with(
name=self.sample_name) name=self.sample_name)
@mock.patch.object(client.KeystoneClientPlugin, 'client') @mock.patch.object(keystone.KeystoneClientPlugin, 'client')
def test_get_service_id_not_found(self, client_keystone): def test_get_service_id_not_found(self, client_keystone):
self._client.client.services.get.side_effect = (keystone_exceptions self._client.client.services.get.side_effect = (keystone_exceptions
.NotFound) .NotFound)
@ -275,7 +281,7 @@ class KeystoneClientPluginServiceTest(common.HeatTestCase):
] ]
client_keystone.return_value = self._client client_keystone.return_value = self._client
client_plugin = client.KeystoneClientPlugin( client_plugin = keystone.KeystoneClientPlugin(
context=mock.MagicMock() context=mock.MagicMock()
) )
@ -307,13 +313,13 @@ class KeystoneClientPluginRoleTest(common.HeatTestCase):
super(KeystoneClientPluginRoleTest, self).setUp() super(KeystoneClientPluginRoleTest, self).setUp()
self._client = mock.MagicMock() self._client = mock.MagicMock()
@mock.patch.object(client.KeystoneClientPlugin, 'client') @mock.patch.object(keystone.KeystoneClientPlugin, 'client')
def test_get_role_id(self, client_keystone): def test_get_role_id(self, client_keystone):
self._client.client.roles.get.return_value = (self self._client.client.roles.get.return_value = (self
._get_mock_role()) ._get_mock_role())
client_keystone.return_value = self._client client_keystone.return_value = self._client
client_plugin = client.KeystoneClientPlugin( client_plugin = keystone.KeystoneClientPlugin(
context=mock.MagicMock() context=mock.MagicMock()
) )
@ -322,7 +328,7 @@ class KeystoneClientPluginRoleTest(common.HeatTestCase):
self._client.client.roles.get.assert_called_once_with( self._client.client.roles.get.assert_called_once_with(
self.sample_uuid) self.sample_uuid)
@mock.patch.object(client.KeystoneClientPlugin, 'client') @mock.patch.object(keystone.KeystoneClientPlugin, 'client')
def test_get_role_id_with_name(self, client_keystone): def test_get_role_id_with_name(self, client_keystone):
self._client.client.roles.get.side_effect = (keystone_exceptions self._client.client.roles.get.side_effect = (keystone_exceptions
.NotFound) .NotFound)
@ -331,7 +337,7 @@ class KeystoneClientPluginRoleTest(common.HeatTestCase):
] ]
client_keystone.return_value = self._client client_keystone.return_value = self._client
client_plugin = client.KeystoneClientPlugin( client_plugin = keystone.KeystoneClientPlugin(
context=mock.MagicMock() context=mock.MagicMock()
) )
@ -343,7 +349,7 @@ class KeystoneClientPluginRoleTest(common.HeatTestCase):
self._client.client.roles.list.assert_called_once_with( self._client.client.roles.list.assert_called_once_with(
name=self.sample_name) name=self.sample_name)
@mock.patch.object(client.KeystoneClientPlugin, 'client') @mock.patch.object(keystone.KeystoneClientPlugin, 'client')
def test_get_role_id_not_found(self, client_keystone): def test_get_role_id_not_found(self, client_keystone):
self._client.client.roles.get.side_effect = (keystone_exceptions self._client.client.roles.get.side_effect = (keystone_exceptions
.NotFound) .NotFound)
@ -351,7 +357,7 @@ class KeystoneClientPluginRoleTest(common.HeatTestCase):
] ]
client_keystone.return_value = self._client client_keystone.return_value = self._client
client_plugin = client.KeystoneClientPlugin( client_plugin = keystone.KeystoneClientPlugin(
context=mock.MagicMock() context=mock.MagicMock()
) )
@ -383,13 +389,13 @@ class KeystoneClientPluginProjectTest(common.HeatTestCase):
super(KeystoneClientPluginProjectTest, self).setUp() super(KeystoneClientPluginProjectTest, self).setUp()
self._client = mock.MagicMock() self._client = mock.MagicMock()
@mock.patch.object(client.KeystoneClientPlugin, 'client') @mock.patch.object(keystone.KeystoneClientPlugin, 'client')
def test_get_project_id(self, client_keystone): def test_get_project_id(self, client_keystone):
self._client.client.projects.get.return_value = (self self._client.client.projects.get.return_value = (self
._get_mock_project()) ._get_mock_project())
client_keystone.return_value = self._client client_keystone.return_value = self._client
client_plugin = client.KeystoneClientPlugin( client_plugin = keystone.KeystoneClientPlugin(
context=mock.MagicMock() context=mock.MagicMock()
) )
@ -398,7 +404,7 @@ class KeystoneClientPluginProjectTest(common.HeatTestCase):
self._client.client.projects.get.assert_called_once_with( self._client.client.projects.get.assert_called_once_with(
self.sample_uuid) self.sample_uuid)
@mock.patch.object(client.KeystoneClientPlugin, 'client') @mock.patch.object(keystone.KeystoneClientPlugin, 'client')
def test_get_project_id_with_name(self, client_keystone): def test_get_project_id_with_name(self, client_keystone):
self._client.client.projects.get.side_effect = (keystone_exceptions self._client.client.projects.get.side_effect = (keystone_exceptions
.NotFound) .NotFound)
@ -407,7 +413,7 @@ class KeystoneClientPluginProjectTest(common.HeatTestCase):
] ]
client_keystone.return_value = self._client client_keystone.return_value = self._client
client_plugin = client.KeystoneClientPlugin( client_plugin = keystone.KeystoneClientPlugin(
context=mock.MagicMock() context=mock.MagicMock()
) )
@ -419,7 +425,7 @@ class KeystoneClientPluginProjectTest(common.HeatTestCase):
self._client.client.projects.list.assert_called_once_with( self._client.client.projects.list.assert_called_once_with(
name=self.sample_name) name=self.sample_name)
@mock.patch.object(client.KeystoneClientPlugin, 'client') @mock.patch.object(keystone.KeystoneClientPlugin, 'client')
def test_get_project_id_not_found(self, client_keystone): def test_get_project_id_not_found(self, client_keystone):
self._client.client.projects.get.side_effect = (keystone_exceptions self._client.client.projects.get.side_effect = (keystone_exceptions
.NotFound) .NotFound)
@ -427,7 +433,7 @@ class KeystoneClientPluginProjectTest(common.HeatTestCase):
] ]
client_keystone.return_value = self._client client_keystone.return_value = self._client
client_plugin = client.KeystoneClientPlugin( client_plugin = keystone.KeystoneClientPlugin(
context=mock.MagicMock() context=mock.MagicMock()
) )
@ -459,13 +465,13 @@ class KeystoneClientPluginDomainTest(common.HeatTestCase):
super(KeystoneClientPluginDomainTest, self).setUp() super(KeystoneClientPluginDomainTest, self).setUp()
self._client = mock.MagicMock() self._client = mock.MagicMock()
@mock.patch.object(client.KeystoneClientPlugin, 'client') @mock.patch.object(keystone.KeystoneClientPlugin, 'client')
def test_get_domain_id(self, client_keystone): def test_get_domain_id(self, client_keystone):
self._client.client.domains.get.return_value = (self self._client.client.domains.get.return_value = (self
._get_mock_domain()) ._get_mock_domain())
client_keystone.return_value = self._client client_keystone.return_value = self._client
client_plugin = client.KeystoneClientPlugin( client_plugin = keystone.KeystoneClientPlugin(
context=mock.MagicMock() context=mock.MagicMock()
) )
@ -474,7 +480,7 @@ class KeystoneClientPluginDomainTest(common.HeatTestCase):
self._client.client.domains.get.assert_called_once_with( self._client.client.domains.get.assert_called_once_with(
self.sample_uuid) self.sample_uuid)
@mock.patch.object(client.KeystoneClientPlugin, 'client') @mock.patch.object(keystone.KeystoneClientPlugin, 'client')
def test_get_domain_id_with_name(self, client_keystone): def test_get_domain_id_with_name(self, client_keystone):
self._client.client.domains.get.side_effect = (keystone_exceptions self._client.client.domains.get.side_effect = (keystone_exceptions
.NotFound) .NotFound)
@ -483,7 +489,7 @@ class KeystoneClientPluginDomainTest(common.HeatTestCase):
] ]
client_keystone.return_value = self._client client_keystone.return_value = self._client
client_plugin = client.KeystoneClientPlugin( client_plugin = keystone.KeystoneClientPlugin(
context=mock.MagicMock() context=mock.MagicMock()
) )
@ -495,7 +501,7 @@ class KeystoneClientPluginDomainTest(common.HeatTestCase):
self._client.client.domains.list.assert_called_once_with( self._client.client.domains.list.assert_called_once_with(
name=self.sample_name) name=self.sample_name)
@mock.patch.object(client.KeystoneClientPlugin, 'client') @mock.patch.object(keystone.KeystoneClientPlugin, 'client')
def test_get_domain_id_not_found(self, client_keystone): def test_get_domain_id_not_found(self, client_keystone):
self._client.client.domains.get.side_effect = (keystone_exceptions self._client.client.domains.get.side_effect = (keystone_exceptions
.NotFound) .NotFound)
@ -503,7 +509,7 @@ class KeystoneClientPluginDomainTest(common.HeatTestCase):
] ]
client_keystone.return_value = self._client client_keystone.return_value = self._client
client_plugin = client.KeystoneClientPlugin( client_plugin = keystone.KeystoneClientPlugin(
context=mock.MagicMock() context=mock.MagicMock()
) )
@ -535,13 +541,13 @@ class KeystoneClientPluginGroupTest(common.HeatTestCase):
super(KeystoneClientPluginGroupTest, self).setUp() super(KeystoneClientPluginGroupTest, self).setUp()
self._client = mock.MagicMock() self._client = mock.MagicMock()
@mock.patch.object(client.KeystoneClientPlugin, 'client') @mock.patch.object(keystone.KeystoneClientPlugin, 'client')
def test_get_group_id(self, client_keystone): def test_get_group_id(self, client_keystone):
self._client.client.groups.get.return_value = (self self._client.client.groups.get.return_value = (self
._get_mock_group()) ._get_mock_group())
client_keystone.return_value = self._client client_keystone.return_value = self._client
client_plugin = client.KeystoneClientPlugin( client_plugin = keystone.KeystoneClientPlugin(
context=mock.MagicMock() context=mock.MagicMock()
) )
@ -550,7 +556,7 @@ class KeystoneClientPluginGroupTest(common.HeatTestCase):
self._client.client.groups.get.assert_called_once_with( self._client.client.groups.get.assert_called_once_with(
self.sample_uuid) self.sample_uuid)
@mock.patch.object(client.KeystoneClientPlugin, 'client') @mock.patch.object(keystone.KeystoneClientPlugin, 'client')
def test_get_group_id_with_name(self, client_keystone): def test_get_group_id_with_name(self, client_keystone):
self._client.client.groups.get.side_effect = (keystone_exceptions self._client.client.groups.get.side_effect = (keystone_exceptions
.NotFound) .NotFound)
@ -559,7 +565,7 @@ class KeystoneClientPluginGroupTest(common.HeatTestCase):
] ]
client_keystone.return_value = self._client client_keystone.return_value = self._client
client_plugin = client.KeystoneClientPlugin( client_plugin = keystone.KeystoneClientPlugin(
context=mock.MagicMock() context=mock.MagicMock()
) )
@ -571,7 +577,7 @@ class KeystoneClientPluginGroupTest(common.HeatTestCase):
self._client.client.groups.list.assert_called_once_with( self._client.client.groups.list.assert_called_once_with(
name=self.sample_name) name=self.sample_name)
@mock.patch.object(client.KeystoneClientPlugin, 'client') @mock.patch.object(keystone.KeystoneClientPlugin, 'client')
def test_get_group_id_not_found(self, client_keystone): def test_get_group_id_not_found(self, client_keystone):
self._client.client.groups.get.side_effect = (keystone_exceptions self._client.client.groups.get.side_effect = (keystone_exceptions
.NotFound) .NotFound)
@ -579,7 +585,7 @@ class KeystoneClientPluginGroupTest(common.HeatTestCase):
] ]
client_keystone.return_value = self._client client_keystone.return_value = self._client
client_plugin = client.KeystoneClientPlugin( client_plugin = keystone.KeystoneClientPlugin(
context=mock.MagicMock() context=mock.MagicMock()
) )
@ -611,12 +617,12 @@ class KeystoneClientPluginUserTest(common.HeatTestCase):
super(KeystoneClientPluginUserTest, self).setUp() super(KeystoneClientPluginUserTest, self).setUp()
self._client = mock.MagicMock() self._client = mock.MagicMock()
@mock.patch.object(client.KeystoneClientPlugin, 'client') @mock.patch.object(keystone.KeystoneClientPlugin, 'client')
def test_get_user_id(self, client_keystone): def test_get_user_id(self, client_keystone):
self._client.client.users.get.return_value = self._get_mock_user() self._client.client.users.get.return_value = self._get_mock_user()
client_keystone.return_value = self._client client_keystone.return_value = self._client
client_plugin = client.KeystoneClientPlugin( client_plugin = keystone.KeystoneClientPlugin(
context=mock.MagicMock() context=mock.MagicMock()
) )
@ -625,7 +631,7 @@ class KeystoneClientPluginUserTest(common.HeatTestCase):
self._client.client.users.get.assert_called_once_with( self._client.client.users.get.assert_called_once_with(
self.sample_uuid) self.sample_uuid)
@mock.patch.object(client.KeystoneClientPlugin, 'client') @mock.patch.object(keystone.KeystoneClientPlugin, 'client')
def test_get_user_id_with_name(self, client_keystone): def test_get_user_id_with_name(self, client_keystone):
self._client.client.users.get.side_effect = (keystone_exceptions self._client.client.users.get.side_effect = (keystone_exceptions
.NotFound) .NotFound)
@ -634,7 +640,7 @@ class KeystoneClientPluginUserTest(common.HeatTestCase):
] ]
client_keystone.return_value = self._client client_keystone.return_value = self._client
client_plugin = client.KeystoneClientPlugin( client_plugin = keystone.KeystoneClientPlugin(
context=mock.MagicMock() context=mock.MagicMock()
) )
@ -646,14 +652,14 @@ class KeystoneClientPluginUserTest(common.HeatTestCase):
self._client.client.users.list.assert_called_once_with( self._client.client.users.list.assert_called_once_with(
name=self.sample_name) name=self.sample_name)
@mock.patch.object(client.KeystoneClientPlugin, 'client') @mock.patch.object(keystone.KeystoneClientPlugin, 'client')
def test_get_user_id_not_found(self, client_keystone): def test_get_user_id_not_found(self, client_keystone):
self._client.client.users.get.side_effect = (keystone_exceptions self._client.client.users.get.side_effect = (keystone_exceptions
.NotFound) .NotFound)
self._client.client.users.list.return_value = [] self._client.client.users.list.return_value = []
client_keystone.return_value = self._client client_keystone.return_value = self._client
client_plugin = client.KeystoneClientPlugin( client_plugin = keystone.KeystoneClientPlugin(
context=mock.MagicMock() context=mock.MagicMock()
) )
@ -685,12 +691,12 @@ class KeystoneClientPluginRegionTest(common.HeatTestCase):
super(KeystoneClientPluginRegionTest, self).setUp() super(KeystoneClientPluginRegionTest, self).setUp()
self._client = mock.MagicMock() self._client = mock.MagicMock()
@mock.patch.object(client.KeystoneClientPlugin, 'client') @mock.patch.object(keystone.KeystoneClientPlugin, 'client')
def test_get_region_id(self, client_keystone): def test_get_region_id(self, client_keystone):
self._client.client.regions.get.return_value = self._get_mock_region() self._client.client.regions.get.return_value = self._get_mock_region()
client_keystone.return_value = self._client client_keystone.return_value = self._client
client_plugin = client.KeystoneClientPlugin( client_plugin = keystone.KeystoneClientPlugin(
context=mock.MagicMock() context=mock.MagicMock()
) )
@ -699,12 +705,12 @@ class KeystoneClientPluginRegionTest(common.HeatTestCase):
self._client.client.regions.get.assert_called_once_with( self._client.client.regions.get.assert_called_once_with(
self.sample_uuid) self.sample_uuid)
@mock.patch.object(client.KeystoneClientPlugin, 'client') @mock.patch.object(keystone.KeystoneClientPlugin, 'client')
def test_get_region_id_not_found(self, client_keystone): def test_get_region_id_not_found(self, client_keystone):
self._client.client.regions.get.side_effect = (keystone_exceptions self._client.client.regions.get.side_effect = (keystone_exceptions
.NotFound) .NotFound)
client_keystone.return_value = self._client client_keystone.return_value = self._client
client_plugin = client.KeystoneClientPlugin( client_plugin = keystone.KeystoneClientPlugin(
context=mock.MagicMock() context=mock.MagicMock()
) )

View File

@ -29,6 +29,7 @@ from heat.engine.clients.os import barbican
from heat.engine.clients.os import cinder from heat.engine.clients.os import cinder
from heat.engine.clients.os import glance from heat.engine.clients.os import glance
from heat.engine.clients.os import keystone from heat.engine.clients.os import keystone
from heat.engine.clients.os.keystone import keystone_constraints as ks_constr
from heat.engine.clients.os.neutron import neutron_constraints as neutron from heat.engine.clients.os.neutron import neutron_constraints as neutron
from heat.engine.clients.os import nova from heat.engine.clients.os import nova
from heat.engine.clients.os import sahara from heat.engine.clients.os import sahara
@ -41,7 +42,6 @@ from heat.tests import fakes
from heat.tests import generic_resource as generic_rsrc from heat.tests import generic_resource as generic_rsrc
from heat.tests import utils from heat.tests import utils
TEST_DEFAULT_LOGLEVELS = {'migrate': logging.WARN, TEST_DEFAULT_LOGLEVELS = {'migrate': logging.WARN,
'sqlalchemy': logging.WARN, 'sqlalchemy': logging.WARN,
'heat.engine.environment': logging.ERROR} 'heat.engine.environment': logging.ERROR}
@ -292,7 +292,7 @@ class HeatTestCase(testscenarios.WithScenarios,
validate.return_value = True validate.return_value = True
def stub_KeystoneProjectConstraint(self): def stub_KeystoneProjectConstraint(self):
validate = self.patchobject(keystone.KeystoneProjectConstraint, validate = self.patchobject(ks_constr.KeystoneProjectConstraint,
'validate') 'validate')
validate.return_value = True validate.return_value = True

View File

@ -26,7 +26,8 @@ from heat.common import auth_password
from heat.tests import common from heat.tests import common
cfg.CONF.import_opt('keystone_backend', 'heat.common.heat_keystoneclient') cfg.CONF.import_opt('keystone_backend',
'heat.engine.clients.os.keystone.heat_keystoneclient')
EXPECTED_ENV_RESPONSE = { EXPECTED_ENV_RESPONSE = {

View File

@ -14,12 +14,12 @@
import collections import collections
import copy import copy
import datetime import datetime
import eventlet
import fixtures
import json import json
import logging import logging
import time import time
import eventlet
import fixtures
import mock import mock
import mox import mox
from oslo_config import cfg from oslo_config import cfg

View File

@ -12,18 +12,18 @@
# under the License. # under the License.
import copy import copy
import fixtures
from oslo_log import log as logging
import time import time
from keystoneclient import exceptions as kc_exceptions import fixtures
from keystoneauth1 import exceptions as kc_exceptions
import mock import mock
from oslo_log import log as logging
from heat.common import exception from heat.common import exception
from heat.common import heat_keystoneclient as hkc
from heat.common import template_format from heat.common import template_format
from heat.common import timeutils from heat.common import timeutils
from heat.engine.clients.os import keystone from heat.engine.clients.os import keystone
from heat.engine.clients.os.keystone import heat_keystoneclient as hkc
from heat.engine import scheduler from heat.engine import scheduler
from heat.engine import stack from heat.engine import stack
from heat.engine import template from heat.engine import template

View File

@ -43,7 +43,7 @@ oslo.config.opts =
heat.common.config = heat.common.config:list_opts heat.common.config = heat.common.config:list_opts
heat.common.context = heat.common.context:list_opts heat.common.context = heat.common.context:list_opts
heat.common.crypt = heat.common.crypt:list_opts heat.common.crypt = heat.common.crypt:list_opts
heat.common.heat_keystoneclient = heat.common.heat_keystoneclient:list_opts heat.common.heat_keystoneclient = heat.engine.clients.os.keystone.heat_keystoneclient:list_opts
heat.common.wsgi = heat.common.wsgi:list_opts heat.common.wsgi = heat.common.wsgi:list_opts
heat.engine.clients = heat.engine.clients:list_opts heat.engine.clients = heat.engine.clients:list_opts
heat.engine.notification = heat.engine.notification:list_opts heat.engine.notification = heat.engine.notification:list_opts
@ -94,13 +94,13 @@ heat.constraints =
cinder.vtype = heat.engine.clients.os.cinder:VolumeTypeConstraint cinder.vtype = heat.engine.clients.os.cinder:VolumeTypeConstraint
designate.domain = heat.engine.clients.os.designate:DesignateDomainConstraint designate.domain = heat.engine.clients.os.designate:DesignateDomainConstraint
glance.image = heat.engine.clients.os.glance:ImageConstraint glance.image = heat.engine.clients.os.glance:ImageConstraint
keystone.domain = heat.engine.clients.os.keystone:KeystoneDomainConstraint keystone.domain = heat.engine.clients.os.keystone.keystone_constraints:KeystoneDomainConstraint
keystone.group = heat.engine.clients.os.keystone:KeystoneGroupConstraint keystone.group = heat.engine.clients.os.keystone.keystone_constraints:KeystoneGroupConstraint
keystone.project = heat.engine.clients.os.keystone:KeystoneProjectConstraint keystone.project = heat.engine.clients.os.keystone.keystone_constraints:KeystoneProjectConstraint
keystone.region = heat.engine.clients.os.keystone:KeystoneRegionConstraint keystone.region = heat.engine.clients.os.keystone.keystone_constraints:KeystoneRegionConstraint
keystone.role = heat.engine.clients.os.keystone:KeystoneRoleConstraint keystone.role = heat.engine.clients.os.keystone.keystone_constraints:KeystoneRoleConstraint
keystone.service = heat.engine.clients.os.keystone:KeystoneServiceConstraint keystone.service = heat.engine.clients.os.keystone.keystone_constraints:KeystoneServiceConstraint
keystone.user = heat.engine.clients.os.keystone:KeystoneUserConstraint keystone.user = heat.engine.clients.os.keystone.keystone_constraints:KeystoneUserConstraint
magnum.baymodel = heat.engine.clients.os.magnum:BaymodelConstraint magnum.baymodel = heat.engine.clients.os.magnum:BaymodelConstraint
manila.share_network = heat.engine.clients.os.manila:ManilaShareNetworkConstraint manila.share_network = heat.engine.clients.os.manila:ManilaShareNetworkConstraint
manila.share_snapshot = heat.engine.clients.os.manila:ManilaShareSnapshotConstraint manila.share_snapshot = heat.engine.clients.os.manila:ManilaShareSnapshotConstraint