From: Zane Bitter Date: Thu, 1 Aug 2013 15:22:18 +0000 (+0200) Subject: Make Volumes work with the default AvailabilityZone X-Git-Tag: 2014.1~285^2 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=8ede7612a0fcf56fbce2ac392812de51f2ccb878;p=openstack-build%2Fheat-build.git Make Volumes work with the default AvailabilityZone The most common way to specify an AvailabiltyZone for a volume is to grab it from the Instance it is going to be attached to: "AvailabilityZone" : {"Fn::GetAtt": ["WikiDatabase", "AvailabilityZone"]}, But the first unit tests to check the value passed to Cinder for the AZ, introduced in 134b11ccd145f982b7173bc9a5d0f1bc3e8eef8c, just forced the value instead of obtaining it from the Instance. Add a unit test to check the common case, and fix the resulting error (an empty string is returned instead of None). Fixes bug #1207416 Change-Id: I83ea2f3f0c417eb9e97abdf27a9eaffd441cb070 --- diff --git a/heat/engine/resources/volume.py b/heat/engine/resources/volume.py index fc92fad1..31659336 100644 --- a/heat/engine/resources/volume.py +++ b/heat/engine/resources/volume.py @@ -45,8 +45,10 @@ class Volume(resource.Resource): return self.physical_resource_name() def _create_arguments(self): - return {'size': self.properties['Size'], - 'availability_zone': self.properties['AvailabilityZone']} + return { + 'size': self.properties['Size'], + 'availability_zone': self.properties['AvailabilityZone'] or None, + } def handle_create(self): backup_id = self.properties.get(self._restore_property) diff --git a/heat/tests/test_volume.py b/heat/tests/test_volume.py index 4ee12265..261e852a 100644 --- a/heat/tests/test_volume.py +++ b/heat/tests/test_volume.py @@ -20,6 +20,7 @@ from testtools import skipIf from heat.common import exception from heat.common import template_format from heat.engine import scheduler +from heat.engine.resources import instance from heat.engine.resources import volume as vol from heat.engine import clients from heat.engine import resource @@ -54,7 +55,8 @@ volume_template = ''' "Type" : "AWS::EC2::Volume", "Properties" : { "Size" : "1", - "AvailabilityZone" : "nova", + "AvailabilityZone" : {"Fn::GetAtt": ["WikiDatabase", + "AvailabilityZone"]}, "Tags" : [{ "Key" : "Usage", "Value" : "Wiki Data Volume" }] } }, @@ -156,6 +158,48 @@ class VolumeTest(HeatTestCase): self.m.VerifyAll() + def test_volume_default_az(self): + fv = FakeVolume('creating', 'available') + stack_name = 'test_volume_stack' + + # create script + self.m.StubOutWithMock(instance.Instance, 'handle_create') + self.m.StubOutWithMock(instance.Instance, 'check_create_complete') + self.m.StubOutWithMock(vol.VolumeAttachment, 'handle_create') + self.m.StubOutWithMock(vol.VolumeAttachment, 'check_create_complete') + instance.Instance.handle_create().AndReturn(None) + instance.Instance.check_create_complete(None).AndReturn(True) + clients.OpenStackClients.cinder().MultipleTimes().AndReturn( + self.cinder_fc) + vol_name = utils.PhysName(stack_name, 'DataVolume') + self.cinder_fc.volumes.create( + size=u'1', availability_zone=None, + display_description=vol_name, + display_name=vol_name).AndReturn(fv) + vol.VolumeAttachment.handle_create().AndReturn(None) + vol.VolumeAttachment.check_create_complete(None).AndReturn(True) + + # delete script + self.m.StubOutWithMock(instance.Instance, 'handle_delete') + self.m.StubOutWithMock(vol.VolumeAttachment, 'handle_delete') + instance.Instance.handle_delete().AndReturn(None) + self.cinder_fc.volumes.get('vol-123').AndRaise( + clients.cinderclient.exceptions.NotFound('Not found')) + vol.VolumeAttachment.handle_delete().AndReturn(None) + self.m.ReplayAll() + + t = template_format.parse(volume_template) + stack = parse_stack(t, stack_name=stack_name) + + rsrc = stack['DataVolume'] + self.assertEqual(rsrc.validate(), None) + scheduler.TaskRunner(stack.create)() + self.assertEqual(rsrc.state, (rsrc.CREATE, rsrc.COMPLETE)) + + self.assertEqual(stack.delete(), None) + + self.m.VerifyAll() + def test_volume_create_error(self): fv = FakeVolume('creating', 'error') stack_name = 'test_volume_create_error_stack'