]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Make Volumes work with the default AvailabilityZone
authorZane Bitter <zbitter@redhat.com>
Thu, 1 Aug 2013 15:22:18 +0000 (17:22 +0200)
committerZane Bitter <zbitter@redhat.com>
Thu, 1 Aug 2013 15:22:18 +0000 (17:22 +0200)
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

heat/engine/resources/volume.py
heat/tests/test_volume.py

index fc92fad11b669a4e18a2db77b17da1a45adb82b0..316593364e033e6b9370067c08f7b5484401b91e 100644 (file)
@@ -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)
index 4ee12265d8c5afc67c68c045d623a72ce9cb6ea6..261e852ae15aa982c853c9fd5ee5b4f321ed94c3 100644 (file)
@@ -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'