From e1ced9ea312d386416c486176fd5feed102702c3 Mon Sep 17 00:00:00 2001 From: whoami-rajat Date: Fri, 26 Nov 2021 04:35:00 -0500 Subject: [PATCH] Correct attachment_complete call Cinder's attachment_complete API is called to mark the volume from "attaching" state to "in-use" state stating that the volume is ready to use. In the current code, attachment_complete is called before the brick connection is complete. This should be done after the connection to brick is successful and we have a volume path to write the image into. This patch corrects the behavior. The wrong sequence of execution won't have any issues functionally since we open the volume after all steps are completed but flow wise it is incorrect. This change won't have any end user impact. Change-Id: Ia9652a4ff6d7efbabb58511f0ce93a87b3a4dfa8 --- glance_store/_drivers/cinder.py | 5 ++++- glance_store/tests/unit/test_cinder_store.py | 2 -- glance_store/tests/unit/test_multistore_cinder.py | 2 -- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/glance_store/_drivers/cinder.py b/glance_store/_drivers/cinder.py index 3ccfe299..6ac82095 100644 --- a/glance_store/_drivers/cinder.py +++ b/glance_store/_drivers/cinder.py @@ -710,7 +710,6 @@ class Store(glance_store.driver.Store): attachment = self.volume_api.attachment_update( client, attachment['id'], connector_prop, mountpoint='glance_store') - self.volume_api.attachment_complete(client, attachment.id) volume = volume.manager.get(volume_id) connection_info = attachment.connection_info @@ -751,6 +750,10 @@ class Store(glance_store.driver.Store): device = connect_volume_nfs() else: device = conn.connect_volume(connection_info) + + # Complete the attachment (marking the volume "in-use") after + # the connection with os-brick is complete + self.volume_api.attachment_complete(client, attachment.id) if (connection_info['driver_volume_type'] == 'rbd' and not conn.do_local_attach): yield device['path'] diff --git a/glance_store/tests/unit/test_cinder_store.py b/glance_store/tests/unit/test_cinder_store.py index 437cfa0f..9283312f 100644 --- a/glance_store/tests/unit/test_cinder_store.py +++ b/glance_store/tests/unit/test_cinder_store.py @@ -279,8 +279,6 @@ class TestCinderStore(base.StoreBaseTest, attach_update.assert_called_once_with( fake_client, fake_attachment_id, fake_conn_info, mountpoint='glance_store') - attach_complete.assert_called_once_with( - fake_client, fake_attachment_id) attach_delete.assert_called_once_with( fake_client, fake_attachment_id) diff --git a/glance_store/tests/unit/test_multistore_cinder.py b/glance_store/tests/unit/test_multistore_cinder.py index 167b3798..a57e1980 100644 --- a/glance_store/tests/unit/test_multistore_cinder.py +++ b/glance_store/tests/unit/test_multistore_cinder.py @@ -312,8 +312,6 @@ class TestMultiCinderStore(base.MultiStoreBaseTest, attach_update.assert_called_once_with( fake_client, fake_attachment_id, fake_conn_info, mountpoint='glance_store') - attach_complete.assert_called_once_with( - fake_client, fake_attachment_id) attach_delete.assert_called_once_with( fake_client, fake_attachment_id)