Browse Source

Merge "Check ready status volume before extend volume"

changes/95/786195/1
Zuul 1 week ago
committed by Gerrit Code Review
parent
commit
d7aee60eec
4 changed files with 52 additions and 3 deletions
  1. +2
    -1
      heat/engine/clients/progress.py
  2. +17
    -0
      heat/engine/resources/openstack/cinder/volume.py
  3. +31
    -2
      heat/tests/openstack/cinder/test_volume.py
  4. +2
    -0
      heat/tests/openstack/cinder/test_volume_utils.py

+ 2
- 1
heat/engine/clients/progress.py View File

@ -129,10 +129,11 @@ class VolumeDeleteProgress(object):
class VolumeResizeProgress(object):
def __init__(self, task_complete=False, size=None):
def __init__(self, task_complete=False, size=None, pre_check=False):
self.called = task_complete
self.complete = task_complete
self.size = size
self.pre_check = pre_check
class VolumeUpdateAccessModeProgress(object):


+ 17
- 0
heat/engine/resources/openstack/cinder/volume.py View File

@ -366,6 +366,16 @@ class CinderVolume(vb.BaseVolume, sh.SchedulerHintsMixin):
return True
def _ready_to_extend_volume(self):
vol = self.client().volumes.get(self.resource_id)
expected_status = (
'available', 'in-use') if vol.multiattach else ('available',)
if vol.status in expected_status:
LOG.debug("Volume %s is ready to extend.", vol.id)
return True
return False
def _check_extend_volume_complete(self):
vol = self.client().volumes.get(self.resource_id)
if vol.status == 'extending':
@ -551,6 +561,13 @@ class CinderVolume(vb.BaseVolume, sh.SchedulerHintsMixin):
return prg_restore.complete and not prg_resize
# resize volume
if prg_resize:
# Make sure volume status ready for resize.
if not prg_resize.pre_check:
prg_resize.pre_check = self._ready_to_extend_volume()
# allow directly extend volume if it's ready
if not prg_resize.pre_check:
return False
if not prg_resize.called:
prg_resize.called = self._extend_volume(prg_resize.size)
return False


+ 31
- 2
heat/tests/openstack/cinder/test_volume.py View File

@ -93,9 +93,13 @@ class CinderVolumeTest(vt_base.VolumeTestCase):
self.t = template_format.parse(cinder_volume_template)
self.use_cinder = True
def create_volume(self, t, stack, resource_name):
return super(CinderVolumeTest, self).create_volume(
def create_volume(self, t, stack, resource_name,
mock_check_extend_ready=True):
rsrc = super(CinderVolumeTest, self).create_volume(
t, stack, resource_name, validate=False)
if mock_check_extend_ready:
rsrc._ready_to_extend_volume = mock.Mock(return_value=True)
return rsrc
def _mock_create_volume(self, fv, stack_name, size=1,
final_status='available', extra_get_mocks=[],
@ -1375,3 +1379,28 @@ class CinderVolumeTest(vt_base.VolumeTestCase):
name=vol_name,
metadata={}
)
def test_ready_to_extend_volume(self):
self.stack_name = 'test_ready_to_extend_volume'
self._mock_create_volume(vt_base.FakeVolume('creating'),
self.stack_name,
extra_get_mocks=[
vt_base.FakeVolume('extending'),
vt_base.FakeVolume('reserved'),
vt_base.FakeVolume('in-use',
multiattach=True),
vt_base.FakeVolume('in-use',
multiattach=False),
vt_base.FakeVolume('available')])
stack = utils.parse_stack(self.t, stack_name=self.stack_name)
rsrc = self.create_volume(self.t, stack, 'volume',
mock_check_extend_ready=False)
self.assertEqual(False, rsrc._ready_to_extend_volume())
self.assertEqual(False, rsrc._ready_to_extend_volume())
self.assertEqual(True, rsrc._ready_to_extend_volume())
self.assertEqual(False, rsrc._ready_to_extend_volume())
self.assertEqual(True, rsrc._ready_to_extend_volume())

+ 2
- 0
heat/tests/openstack/cinder/test_volume_utils.py View File

@ -122,6 +122,8 @@ class FakeVolume(object):
def __init__(self, status, **attrs):
self.status = status
self.multiattach = True
for key, value in attrs.items():
setattr(self, key, value)
if 'id' not in attrs:


Loading…
Cancel
Save