Handle external events in extend volume

The support to extend attached volumes is being added to glance
cinder store with change[1].
Currently, cinder sends external events to nova if the volume is
in ``in-use`` state irrespective of the instance uuid value in the
attachment records.
When using glance cinder store, the instance_uuid field is None in
the attachment record and that signifies that the volume is attached
to glance host and not to a nova instance. We should not send any
external events in this case.

With this change, we check if the instance UUIDs are not None and
send external events to nova. If None, we don't send any external
events.

[1] https://review.opendev.org/c/openstack/glance_store/+/868742

Closes-Bug: 2000724
Change-Id: Ia0c8ff77139524e9934ef354b1455ea01b4c31ef
This commit is contained in:
whoami-rajat 2023-01-03 14:21:11 +05:30
parent d55a004e52
commit 78f8a7bbe6
3 changed files with 40 additions and 5 deletions

View File

@ -2838,7 +2838,8 @@ class VolumeTestCase(base.BaseVolumeTestCase):
detail=message_field.Detail.DRIVER_FAILED_EXTEND)
@mock.patch('cinder.compute.API')
def _test_extend_volume_manager_successful(self, volume, nova_api):
def _test_extend_volume_manager_successful(self, volume, nova_api,
attached_to_glance=False):
"""Test volume can be extended at the manager level."""
def fake_extend(volume, new_size):
volume['size'] = new_size
@ -2866,8 +2867,11 @@ class VolumeTestCase(base.BaseVolumeTestCase):
instance_uuids = [
attachment.instance_uuid
for attachment in volume.volume_attachment]
nova_extend_volume.assert_called_with(
self.context, instance_uuids, volume.id)
if attached_to_glance:
nova_extend_volume.assert_not_called()
else:
nova_extend_volume.assert_called_with(
self.context, instance_uuids, volume.id)
def test_extend_volume_manager_available_fails_with_exception(self):
volume = tests_utils.create_volume(self.context, size=2,
@ -2913,6 +2917,22 @@ class VolumeTestCase(base.BaseVolumeTestCase):
self.volume.detach_volume(self.context, volume.id, attachment.id)
self.volume.delete_volume(self.context, volume)
def test_extend_volume_manager_in_use_glance_store(self):
volume = tests_utils.create_volume(self.context, size=2,
status='creating', host=CONF.host)
self.volume.create_volume(self.context, volume)
instance_uuid = None
attachment = db.volume_attach(self.context,
{'volume_id': volume.id,
'attached_host': 'fake-host'})
db.volume_attached(self.context, attachment.id, instance_uuid,
'fake-host', 'vdb')
volume.refresh()
self._test_extend_volume_manager_successful(volume,
attached_to_glance=True)
self.volume.detach_volume(self.context, volume.id, attachment.id)
self.volume.delete_volume(self.context, volume)
@mock.patch('cinder.volume.rpcapi.VolumeAPI.extend_volume')
def test_extend_volume_with_volume_type(self, mock_rpc_extend):
elevated = context.get_admin_context()

View File

@ -2984,9 +2984,15 @@ class VolumeManager(manager.CleanableManager,
if orig_volume_status == 'in-use':
nova_api = compute.API()
# If instance_uuid field is None on attachment, it means the
# request is coming from glance and not nova
instance_uuids = [attachment.instance_uuid
for attachment in attachments]
nova_api.extend_volume(context, instance_uuids, volume.id)
for attachment in attachments
if attachment.instance_uuid]
# If we are using glance cinder store, we should not send any
# external events to nova
if instance_uuids:
nova_api.extend_volume(context, instance_uuids, volume.id)
pool = volume_utils.extract_host(volume.host, 'pool')
if pool is None:

View File

@ -0,0 +1,9 @@
---
fixes:
- |
`bug #2000724
<https://bugs.launchpad.net/cinder/+bug/2000724>`_:
Handled the case when glance is calling online extend
and externals events were being sent to nova.
Now Cinder will only send external events when the volume,
to be extended, is attached to a nova instance.