Add cinder volume type constraint for resources
Add cinder volume type constraint for resources. Change-Id: I2860418b8d4ee8ec076c35836d48a2c60aea7274 Notes: missed in bp/cinder-custom-constraints
This commit is contained in:
parent
d91f36a621
commit
537860e2f9
@ -244,6 +244,10 @@ class VolumeSnapshotNotFound(HeatException):
|
||||
msg_fmt = _("The VolumeSnapshot (%(snapshot)s) could not be found.")
|
||||
|
||||
|
||||
class VolumeTypeNotFound(HeatException):
|
||||
msg_fmt = _("The VolumeType (%(volume_type)s) could not be found.")
|
||||
|
||||
|
||||
class PhysicalResourceNameAmbiguity(HeatException):
|
||||
msg_fmt = _(
|
||||
"Multiple physical resources were found with name (%(name)s).")
|
||||
|
@ -102,6 +102,21 @@ class CinderClientPlugin(client_plugin.ClientPlugin):
|
||||
{'snapshot': snapshot, 'ex': ex})
|
||||
raise exception.VolumeSnapshotNotFound(snapshot=snapshot)
|
||||
|
||||
def get_volume_type(self, volume_type):
|
||||
vt_id = None
|
||||
volume_type_list = self.client().volume_types.list()
|
||||
for vt in volume_type_list:
|
||||
if vt.name == volume_type:
|
||||
vt_id = vt.id
|
||||
break
|
||||
if vt.id == volume_type:
|
||||
vt_id = vt.id
|
||||
break
|
||||
if vt_id is None:
|
||||
raise exception.VolumeTypeNotFound(volume_type=volume_type)
|
||||
|
||||
return vt_id
|
||||
|
||||
def is_not_found(self, ex):
|
||||
return isinstance(ex, exceptions.NotFound)
|
||||
|
||||
@ -127,3 +142,11 @@ class VolumeSnapshotConstraint(constraints.BaseCustomConstraint):
|
||||
|
||||
def validate_with_client(self, client, snapshot):
|
||||
client.client_plugin('cinder').get_volume_snapshot(snapshot)
|
||||
|
||||
|
||||
class VolumeTypeConstraint(constraints.BaseCustomConstraint):
|
||||
|
||||
expected_exceptions = (exception.VolumeTypeNotFound,)
|
||||
|
||||
def validate_with_client(self, client, volume_type):
|
||||
client.client_plugin('cinder').get_volume_type(volume_type)
|
||||
|
@ -94,6 +94,9 @@ class SaharaNodeGroupTemplate(resource.Resource):
|
||||
VOLUME_TYPE: properties.Schema(
|
||||
properties.Schema.STRING,
|
||||
_("Type of the volume to create on Cinder backend."),
|
||||
constraints=[
|
||||
constraints.CustomConstraint('cinder.vtype')
|
||||
]
|
||||
),
|
||||
SECURITY_GROUPS: properties.Schema(
|
||||
properties.Schema.LIST,
|
||||
|
@ -538,7 +538,10 @@ class CinderVolume(Volume):
|
||||
VOLUME_TYPE: properties.Schema(
|
||||
properties.Schema.STRING,
|
||||
_('If specified, the type of volume to use, mapping to a '
|
||||
'specific backend.')
|
||||
'specific backend.'),
|
||||
constraints=[
|
||||
constraints.CustomConstraint('cinder.vtype')
|
||||
]
|
||||
),
|
||||
METADATA: properties.Schema(
|
||||
properties.Schema.MAP,
|
||||
|
@ -173,3 +173,8 @@ class HeatTestCase(testscenarios.WithScenarios,
|
||||
self.m.StubOutWithMock(cinder.VolumeSnapshotConstraint, 'validate')
|
||||
cinder.VolumeSnapshotConstraint.validate(
|
||||
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
|
||||
|
||||
def stub_VolumeTypeConstraint_validate(self):
|
||||
self.m.StubOutWithMock(cinder.VolumeTypeConstraint, 'validate')
|
||||
cinder.VolumeTypeConstraint.validate(
|
||||
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
|
||||
|
@ -100,3 +100,23 @@ class VolumeSnapshotConstraintTest(common.HeatTestCase):
|
||||
self.mock_get_snapshot.side_effect = exception.VolumeSnapshotNotFound(
|
||||
snapshot='bar')
|
||||
self.assertFalse(self.constraint.validate("bar", self.ctx))
|
||||
|
||||
|
||||
class VolumeTypeConstraintTest(common.HeatTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(VolumeTypeConstraintTest, self).setUp()
|
||||
self.ctx = utils.dummy_context()
|
||||
self.mock_get_volume_type = mock.Mock()
|
||||
self.ctx.clients.client_plugin(
|
||||
'cinder').get_volume_type = self.mock_get_volume_type
|
||||
self.constraint = cinder.VolumeTypeConstraint()
|
||||
|
||||
def test_validation(self):
|
||||
self.mock_get_volume_type.return_value = 'volume_type'
|
||||
self.assertTrue(self.constraint.validate("foo", self.ctx))
|
||||
|
||||
def test_validation_error(self):
|
||||
self.mock_get_volume_type.side_effect = exception.VolumeTypeNotFound(
|
||||
volume_type='bar')
|
||||
self.assertFalse(self.constraint.validate("bar", self.ctx))
|
||||
|
@ -37,6 +37,7 @@ resources:
|
||||
plugin_name: vanilla
|
||||
hadoop_version: 2.3.0
|
||||
flavor: m1.large
|
||||
volume_type: lvm
|
||||
floating_ip_pool: some_pool_name
|
||||
node_processes:
|
||||
- namenode
|
||||
@ -114,7 +115,7 @@ class SaharaNodeGroupTemplateTest(common.HeatTestCase):
|
||||
expected_kwargs = {'description': "",
|
||||
'volumes_per_node': None,
|
||||
'volumes_size': None,
|
||||
'volume_type': None,
|
||||
'volume_type': 'lvm',
|
||||
'security_groups': None,
|
||||
'auto_security_group': None,
|
||||
'availability_zone': None,
|
||||
|
@ -817,6 +817,7 @@ class CinderVolumeTest(BaseVolumeTest):
|
||||
|
||||
self.stub_SnapshotConstraint_validate()
|
||||
self.stub_VolumeConstraint_validate()
|
||||
self.stub_VolumeTypeConstraint_validate()
|
||||
cinder.CinderClientPlugin._create().AndReturn(
|
||||
self.cinder_fc)
|
||||
self.cinder_fc.volumes.create(
|
||||
|
@ -59,6 +59,7 @@ heat.constraints =
|
||||
nova.keypair = heat.engine.clients.os.nova:KeypairConstraint
|
||||
cinder.volume = heat.engine.clients.os.cinder:VolumeConstraint
|
||||
cinder.snapshot = heat.engine.clients.os.cinder:VolumeSnapshotConstraint
|
||||
cinder.vtype = heat.engine.clients.os.cinder:VolumeTypeConstraint
|
||||
|
||||
heat.stack_lifecycle_plugins =
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user