summaryrefslogtreecommitdiff
path: root/heat
diff options
context:
space:
mode:
authorFeilong Wang <flwang@catalyst.net.nz>2020-02-24 17:59:17 +1300
committerFeilong Wang <flwang@catalyst.net.nz>2020-02-24 21:53:57 +0000
commit50d72b8c0b6ef9d025c8de3fe036c414f73dbd06 (patch)
tree82efa13069f9bc6f7ed0cd04338f47dd4b2e6249 /heat
parentc61170e4e802577f40986a384ce8d912368c3f36 (diff)
downloadheat-50d72b8c0b6ef9d025c8de3fe036c414f73dbd06.tar.gz
Support handling empty string for volume AZ
When building a complex stack, instance and volume are both necessary. But the support of AZ in Nova and Cinder are slightly different which is causing troubles to build the Heat template. Without setting, the property availability_zone of volume always got "", an empty string, instead of None. As a result, Cinder will return 400 BadRequest error. This patch will turn the empty string into None, to make sure Cinder can correctly handle the scenario when availability_zone of volume is not set. Task: 38853 Story: 2007330 Change-Id: Ib5bddf12ca63849a030d1d579d0a2e853e8b848a
Diffstat (limited to 'heat')
-rw-r--r--heat/engine/resources/openstack/cinder/volume.py3
-rw-r--r--heat/tests/openstack/cinder/test_volume.py23
2 files changed, 25 insertions, 1 deletions
diff --git a/heat/engine/resources/openstack/cinder/volume.py b/heat/engine/resources/openstack/cinder/volume.py
index 9ac9f21c4..764a7b655 100644
--- a/heat/engine/resources/openstack/cinder/volume.py
+++ b/heat/engine/resources/openstack/cinder/volume.py
@@ -280,7 +280,8 @@ class CinderVolume(vb.BaseVolume, sh.SchedulerHintsMixin):
def _create_arguments(self):
arguments = {
'size': self.properties[self.SIZE],
- 'availability_zone': self.properties[self.AVAILABILITY_ZONE],
+ 'availability_zone': (self.properties[self.AVAILABILITY_ZONE] or
+ None),
}
scheduler_hints = self._scheduler_hints(
diff --git a/heat/tests/openstack/cinder/test_volume.py b/heat/tests/openstack/cinder/test_volume.py
index 4023b3a82..41f5f6ad0 100644
--- a/heat/tests/openstack/cinder/test_volume.py
+++ b/heat/tests/openstack/cinder/test_volume.py
@@ -1349,3 +1349,26 @@ class CinderVolumeTest(vt_base.VolumeTestCase):
prg_attach = mock.MagicMock(called=False, srv_id='InstanceInActive')
self.assertEqual(False, rsrc._attach_volume_to_complete(prg_attach))
self.assertEqual('vol-123', prg_attach.called)
+
+ def test_empty_string_az(self):
+ fv = vt_base.FakeVolume('creating')
+ self.stack_name = 'test_cvolume_default_stack'
+
+ vol_name = utils.PhysName(self.stack_name, 'volume')
+ self.cinder_fc.volumes.create.return_value = fv
+ fv_ready = vt_base.FakeVolume('available', id=fv.id)
+ self.cinder_fc.volumes.get.side_effect = [fv, fv_ready]
+
+ self.t['resources']['volume']['properties'] = {
+ 'size': '1',
+ 'availability_zone': "",
+ }
+ stack = utils.parse_stack(self.t, stack_name=self.stack_name)
+ self.create_volume(self.t, stack, 'volume')
+
+ self.cinder_fc.volumes.create.assert_called_once_with(
+ size=1, availability_zone=None,
+ description=None,
+ name=vol_name,
+ metadata={}
+ )