Apply cinder snapshot custom constraint

Apply cinder snapshot custom constraint for resources.

Change-Id: Ifc8c86e97f8ed38b1461ba527be17ba4e6c01bdf
Implements: blueprint cinder-custom-constraints
This commit is contained in:
huangtianhua 2014-11-21 16:57:10 +08:00
parent 6da179356b
commit 3ab3ba944c
12 changed files with 42 additions and 2 deletions

View File

@ -124,6 +124,10 @@ class LaunchConfiguration(resource.Resource):
properties.Schema.STRING,
_('The ID of the snapshot to create '
'a volume from.'),
constraints=[
constraints.CustomConstraint(
'cinder.snapshot')
]
),
VOLUME_SIZE: properties.Schema(
properties.Schema.STRING,

View File

@ -354,6 +354,10 @@ class Instance(resource.Resource):
properties.Schema.STRING,
_('The ID of the snapshot to create '
'a volume from.'),
constraints=[
constraints.CustomConstraint(
'cinder.snapshot')
]
),
VOLUME_SIZE: properties.Schema(
properties.Schema.STRING,

View File

@ -133,7 +133,10 @@ class Server(stack_user.StackUser):
BLOCK_DEVICE_MAPPING_SNAPSHOT_ID: properties.Schema(
properties.Schema.STRING,
_('The ID of the snapshot to create a volume '
'from.')
'from.'),
constraints=[
constraints.CustomConstraint('cinder.snapshot')
]
),
BLOCK_DEVICE_MAPPING_VOLUME_SIZE: properties.Schema(
properties.Schema.INTEGER,

View File

@ -511,7 +511,10 @@ class CinderVolume(Volume):
),
SNAPSHOT_ID: properties.Schema(
properties.Schema.STRING,
_('If specified, the snapshot to create the volume from.')
_('If specified, the snapshot to create the volume from.'),
constraints=[
constraints.CustomConstraint('cinder.snapshot')
]
),
BACKUP_ID: properties.Schema(
properties.Schema.STRING,

View File

@ -33,6 +33,7 @@ class TestAutoScalingGroupValidation(common.HeatTestCase):
cfg.CONF.set_default('heat_waitcondition_server_url',
'http://server.test:8000/v1/waitcondition')
self.stub_keystoneclient()
self.stub_SnapshotConstraint_validate()
def validate_scaling_group(self, t, stack, resource_name):
# create the launch configuration resource

View File

@ -168,3 +168,8 @@ class HeatTestCase(testscenarios.WithScenarios,
self.m.StubOutWithMock(cinder.VolumeConstraint, 'validate')
cinder.VolumeConstraint.validate(
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
def stub_SnapshotConstraint_validate(self):
self.m.StubOutWithMock(cinder.VolumeSnapshotConstraint, 'validate')
cinder.VolumeSnapshotConstraint.validate(
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)

View File

@ -114,6 +114,7 @@ class AutoScalingTest(common.HeatTestCase):
self.m.StubOutWithMock(instance.Instance, 'check_create_complete')
self.stub_ImageConstraint_validate()
self.stub_FlavorConstraint_validate()
self.stub_SnapshotConstraint_validate()
if with_error:
instance.Instance.handle_create().AndRaise(
exception.Error(with_error))
@ -470,6 +471,7 @@ class AutoScalingTest(common.HeatTestCase):
instance.Instance.handle_create().AndRaise(Exception)
self.stub_ImageConstraint_validate()
self.stub_FlavorConstraint_validate()
self.stub_SnapshotConstraint_validate()
self.m.ReplayAll()
@ -753,6 +755,8 @@ class AutoScalingTest(common.HeatTestCase):
rsrc = stack['LaunchConfig']
self.stub_ImageConstraint_validate()
self.stub_FlavorConstraint_validate()
self.stub_SnapshotConstraint_validate()
self.assertIsNone(rsrc.validate())
scheduler.TaskRunner(rsrc.create)()
self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)

View File

@ -116,6 +116,7 @@ class InstancesTest(common.HeatTestCase):
self.m.StubOutWithMock(nova.NovaClientPlugin, '_create')
nova.NovaClientPlugin._create().AndReturn(self.fc)
self.stub_SnapshotConstraint_validate()
if stub_create:
self.m.StubOutWithMock(self.fc.servers, 'create')
@ -217,6 +218,7 @@ class InstancesTest(common.HeatTestCase):
self._mock_get_image_id_success('F17-x86_64-gold', 1)
self.m.StubOutWithMock(nova.NovaClientPlugin, '_create')
nova.NovaClientPlugin._create().MultipleTimes().AndReturn(self.fc)
self.stub_SnapshotConstraint_validate()
self.m.StubOutWithMock(cinder.CinderClientPlugin, 'get_volume')
ex = exception.VolumeNotFound(volume='1234')
cinder.CinderClientPlugin.get_volume('1234').AndRaise(ex)
@ -243,6 +245,7 @@ class InstancesTest(common.HeatTestCase):
resource_defns['WebServer'], stack)
self._mock_get_image_id_success('F17-x86_64-gold', 1)
self.stub_SnapshotConstraint_validate()
self.m.StubOutWithMock(nova.NovaClientPlugin, '_create')
nova.NovaClientPlugin._create().MultipleTimes().AndReturn(self.fc)
@ -531,6 +534,7 @@ class InstancesTest(common.HeatTestCase):
nova.NovaClientPlugin._create().AndReturn(self.fc)
self._mock_get_image_id_success('1', 1)
self.stub_SnapshotConstraint_validate()
self.m.ReplayAll()
self.assertIsNone(instance.validate())

View File

@ -79,6 +79,7 @@ class InstanceGroupTest(common.HeatTestCase):
self.stub_KeypairConstraint_validate()
self.stub_ImageConstraint_validate()
self.stub_FlavorConstraint_validate()
self.stub_SnapshotConstraint_validate()
self.m.StubOutWithMock(instance_class, 'handle_create')
self.m.StubOutWithMock(instance_class, 'check_create_complete')
@ -165,6 +166,7 @@ class InstanceGroupTest(common.HeatTestCase):
self.stub_ImageConstraint_validate()
self.stub_KeypairConstraint_validate()
self.stub_FlavorConstraint_validate()
self.stub_SnapshotConstraint_validate()
self.m.ReplayAll()
@ -183,6 +185,7 @@ class InstanceGroupTest(common.HeatTestCase):
self.stub_KeypairConstraint_validate()
self.stub_ImageConstraint_validate()
self.stub_FlavorConstraint_validate()
self.stub_SnapshotConstraint_validate()
self.m.ReplayAll()
@ -245,6 +248,8 @@ class InstanceGroupTest(common.HeatTestCase):
self.stub_ImageConstraint_validate()
self.stub_KeypairConstraint_validate()
self.stub_FlavorConstraint_validate()
self.stub_SnapshotConstraint_validate()
self.m.StubOutWithMock(instance.Instance, 'handle_create')
instance.Instance.handle_create().AndRaise(Exception)
@ -289,6 +294,8 @@ class InstanceGroupTest(common.HeatTestCase):
self.stub_ImageConstraint_validate()
self.stub_KeypairConstraint_validate()
self.stub_FlavorConstraint_validate()
self.stub_SnapshotConstraint_validate()
self.m.StubOutWithMock(instance.Instance, 'handle_create')
instance.Instance.handle_create().AndRaise(Exception)

View File

@ -159,10 +159,13 @@ class ScaleNotificationTest(common.HeatTestCase):
stack.store()
self.created_time = stack.created_time
self.create_at = timeutils.isotime(self.created_time)
self.stub_SnapshotConstraint_validate()
self.m.ReplayAll()
stack.create()
self.stack = stack
group = stack['WebServerGroup']
self.assertEqual((group.CREATE, group.COMPLETE), group.state)
self.m.VerifyAll()
return group
def mock_stack_except_for_group(self):

View File

@ -1936,6 +1936,7 @@ class ServersTest(common.HeatTestCase):
nova.NovaClientPlugin._create().AndReturn(self.fc)
self._mock_get_image_id_success('F17-x86_64-gold', 'image_id')
self.stub_VolumeConstraint_validate()
self.stub_SnapshotConstraint_validate()
self.m.ReplayAll()
self.assertRaises(exception.ResourcePropertyConflict, server.validate)

View File

@ -812,6 +812,7 @@ class CinderVolumeTest(BaseVolumeTest):
fv = FakeVolume('creating', 'available')
stack_name = 'test_volume_stack'
self.stub_SnapshotConstraint_validate()
cinder.CinderClientPlugin._create().AndReturn(
self.cinder_fc)
self.cinder_fc.volumes.create(