diff --git a/heat/engine/resources/openstack/cinder/volume.py b/heat/engine/resources/openstack/cinder/volume.py index 9ac9f21c42..764a7b655a 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 4023b3a823..41f5f6ad01 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={} + ) diff --git a/releasenotes/notes/support-handling-empty-string-for-volume-az-22ad78eb0f931954.yaml b/releasenotes/notes/support-handling-empty-string-for-volume-az-22ad78eb0f931954.yaml new file mode 100644 index 0000000000..e1b71be43f --- /dev/null +++ b/releasenotes/notes/support-handling-empty-string-for-volume-az-22ad78eb0f931954.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + Empty string passing in for volume availability_zone can be correctly + handled now. For this case, it's same as no AZ set, so the default AZ in + cinder.conf will be used.