From 5423c530955bdc5d1dbea0c4bf860b19655d5e2c Mon Sep 17 00:00:00 2001 From: Lee Yarwood Date: Thu, 17 Dec 2020 11:24:46 +0000 Subject: [PATCH] scenario: Use wait_for_volume_attachment_remove_from_server in nova_volume_detach Detaching a volume from an instance in Nova is an asynchronous operation. While the request can be accepted the underlying act of detaching the device from the instance, disconnecting the volume from the host, updating cinder and deleting records in Nova can take some considerable time. As such when detaching a volume callers should continue to poll the os-volume_attachments Nova API to determine when the underlying volume attachment, also known as a Block Device Mapping or BDM, is removed. Bug #1908399 outlines an issue where the scenario helper method nova_volume_detach was being called multiple times during tests and cleanup while only waiting for the volume status to change to available. This allowed for a race to occur where additional requests could be made to detach the volume while the volume attachment still remained in Nova resulting in a 400 error being returned by n-api. This change addresses this by switching between the volume resource status and the volume attachment removal waiters. Closes-Bug: #1908399 Change-Id: Ib6ae2c30be65eb444976b0330fd23d9457146284 --- tempest/scenario/manager.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tempest/scenario/manager.py b/tempest/scenario/manager.py index f369d5d997..a08388b36d 100644 --- a/tempest/scenario/manager.py +++ b/tempest/scenario/manager.py @@ -741,14 +741,12 @@ class ScenarioTest(tempest.test.BaseTestCase): def nova_volume_detach(self, server, volume): """Compute volume detach - This utility detaches volume from compute and check whether the - volume status is 'available' state, and if not, an exception - will be thrown. + This utility detaches the volume from the server and checks whether the + volume attachment has been removed from Nova. """ self.servers_client.detach_volume(server['id'], volume['id']) - waiters.wait_for_volume_resource_status(self.volumes_client, - volume['id'], 'available') - volume = self.volumes_client.show_volume(volume['id'])['volume'] + waiters.wait_for_volume_attachment_remove_from_server( + self.servers_client, server['id'], volume['id']) def ping_ip_address(self, ip_address, should_succeed=True, ping_timeout=None, mtu=None, server=None):