Browse Source

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
(cherry picked from commit 50d72b8c0b)
changes/18/709918/1
Feilong Wang 1 year ago
parent
commit
77b8395e7d
  1. 3
      heat/engine/resources/openstack/cinder/volume.py
  2. 23
      heat/tests/openstack/cinder/test_volume.py
  3. 6
      releasenotes/notes/support-handling-empty-string-for-volume-az-22ad78eb0f931954.yaml

3
heat/engine/resources/openstack/cinder/volume.py

@ -279,7 +279,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(

23
heat/tests/openstack/cinder/test_volume.py

@ -1234,3 +1234,26 @@ class CinderVolumeTest(vt_base.VolumeTestCase):
}
self.assertEqual(expected, reality)
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={}
)

6
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.
Loading…
Cancel
Save