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
This commit is contained in:
Lee Yarwood 2020-12-17 11:24:46 +00:00
parent 7d775d6d1c
commit 5423c53095
1 changed files with 4 additions and 6 deletions

View File

@ -741,14 +741,12 @@ class ScenarioTest(tempest.test.BaseTestCase):
def nova_volume_detach(self, server, volume): def nova_volume_detach(self, server, volume):
"""Compute volume detach """Compute volume detach
This utility detaches volume from compute and check whether the This utility detaches the volume from the server and checks whether the
volume status is 'available' state, and if not, an exception volume attachment has been removed from Nova.
will be thrown.
""" """
self.servers_client.detach_volume(server['id'], volume['id']) self.servers_client.detach_volume(server['id'], volume['id'])
waiters.wait_for_volume_resource_status(self.volumes_client, waiters.wait_for_volume_attachment_remove_from_server(
volume['id'], 'available') self.servers_client, server['id'], volume['id'])
volume = self.volumes_client.show_volume(volume['id'])['volume']
def ping_ip_address(self, ip_address, should_succeed=True, def ping_ip_address(self, ip_address, should_succeed=True,
ping_timeout=None, mtu=None, server=None): ping_timeout=None, mtu=None, server=None):