Merge "Added constraint for barbican order"

This commit is contained in:
Jenkins 2016-03-23 08:01:06 +00:00 committed by Gerrit Code Review
commit 1642f5a7c1
4 changed files with 41 additions and 0 deletions

View File

@ -63,8 +63,25 @@ class BarbicanClientPlugin(client_plugin.ClientPlugin):
name=secret_ref) name=secret_ref)
raise ex raise ex
def get_container_by_ref(self, container_ref):
try:
return self.client().containers.get(
container_ref)._get_formatted_entity()
except Exception as ex:
if self.is_not_found(ex):
raise exception.EntityNotFound(
entity="Container",
name=container_ref)
raise ex
class SecretConstraint(constraints.BaseCustomConstraint): class SecretConstraint(constraints.BaseCustomConstraint):
resource_client_name = CLIENT_NAME resource_client_name = CLIENT_NAME
resource_getter_name = 'get_secret_by_ref' resource_getter_name = 'get_secret_by_ref'
expected_exceptions = (exception.EntityNotFound,) expected_exceptions = (exception.EntityNotFound,)
class ContainerConstraint(constraints.BaseCustomConstraint):
resource_client_name = CLIENT_NAME
resource_getter_name = 'get_container_by_ref'
expected_exceptions = (exception.EntityNotFound,)

View File

@ -134,6 +134,9 @@ class Order(resource.Resource):
properties.Schema.STRING, properties.Schema.STRING,
_('The source of certificate request.'), _('The source of certificate request.'),
support_status=support.SupportStatus(version='5.0.0'), support_status=support.SupportStatus(version='5.0.0'),
constraints=[
constraints.CustomConstraint('barbican.container')
],
), ),
CA_ID: properties.Schema( CA_ID: properties.Schema(
properties.Schema.STRING, properties.Schema.STRING,

View File

@ -69,3 +69,23 @@ class SecretConstraintTest(common.HeatTestCase):
self.mock_get_secret_by_ref.side_effect = exception.EntityNotFound( self.mock_get_secret_by_ref.side_effect = exception.EntityNotFound(
entity='Secret', name='bar') entity='Secret', name='bar')
self.assertFalse(self.constraint.validate("bar", self.ctx)) self.assertFalse(self.constraint.validate("bar", self.ctx))
class ContainerConstraintTest(common.HeatTestCase):
def setUp(self):
super(ContainerConstraintTest, self).setUp()
self.ctx = utils.dummy_context()
self.mock_get_container_by_ref = mock.Mock()
self.ctx.clients.client_plugin(
'barbican').get_container_by_ref = self.mock_get_container_by_ref
self.constraint = barbican.ContainerConstraint()
def test_validation(self):
self.mock_get_container_by_ref.return_value = {}
self.assertTrue(self.constraint.validate("foo", self.ctx))
def test_validation_error(self):
self.mock_get_container_by_ref.side_effect = exception.EntityNotFound(
entity='Container', name='bar')
self.assertFalse(self.constraint.validate("bar", self.ctx))

View File

@ -86,6 +86,7 @@ heat.constraints =
test_constr = heat.engine.constraint.common_constraints:TestConstraintDelay test_constr = heat.engine.constraint.common_constraints:TestConstraintDelay
timezone = heat.engine.constraint.common_constraints:TimezoneConstraint timezone = heat.engine.constraint.common_constraints:TimezoneConstraint
# service constraints # service constraints
barbican.container = heat.engine.clients.os.barbican:ContainerConstraint
barbican.secret = heat.engine.clients.os.barbican:SecretConstraint barbican.secret = heat.engine.clients.os.barbican:SecretConstraint
cinder.backup = heat.engine.clients.os.cinder:VolumeBackupConstraint cinder.backup = heat.engine.clients.os.cinder:VolumeBackupConstraint
cinder.snapshot = heat.engine.clients.os.cinder:VolumeSnapshotConstraint cinder.snapshot = heat.engine.clients.os.cinder:VolumeSnapshotConstraint