From 9a1cac7110ae759fe3962e7e104c816e904cc27b Mon Sep 17 00:00:00 2001 From: Lee Yarwood Date: Thu, 23 Sep 2021 21:03:03 +0100 Subject: [PATCH] fup: Move _wait_for_volume_{attach,detach} to os-volume_attachments As documented in the api-ref this is the API end users would poll to determine the state of a volume operation so use it in our func tests. Change-Id: I88e827603bb1cd6265bf234f4286ba3b204c3ce1 --- nova/tests/functional/integrated_helpers.py | 47 +++++++++------------ 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/nova/tests/functional/integrated_helpers.py b/nova/tests/functional/integrated_helpers.py index 32cdba3df6..8710ecd768 100644 --- a/nova/tests/functional/integrated_helpers.py +++ b/nova/tests/functional/integrated_helpers.py @@ -202,43 +202,36 @@ class InstanceHelperMixin: 'actions: %s. Events in the last matching action: %s' % (event_name, actions, events)) - # TODO(lyarwood): Rewrite this waiter to use os-volume_attachments def _wait_for_volume_attach(self, server_id, volume_id): timeout = 0.0 - server = self.api.get_server(server_id) - attached_vols = [vol['id'] for vol in - server['os-extended-volumes:volumes_attached']] + while timeout < 10.0: + try: + self.api.get_server_volume(server_id, volume_id) + return + except api_client.OpenStackApiNotFoundException: + time.sleep(.1) + timeout += .1 - while volume_id not in attached_vols and timeout < 10.0: - time.sleep(.1) - timeout += .1 - server = self.api.get_server(server_id) - attached_vols = [vol['id'] for vol in - server['os-extended-volumes:volumes_attached']] - - if volume_id not in attached_vols: - self.fail('Timed out waiting for volume %s to be attached to ' + attached_vols = self.api.get_server_volumes(server_id) + self.fail('Timed out waiting for volume %s to be attached to ' 'server %s. Currently attached volumes: %s' % (volume_id, server_id, attached_vols)) - # TODO(lyarwood): Rewrite this waiter to use os-volume_attachments def _wait_for_volume_detach(self, server_id, volume_id): timeout = 0.0 - server = self.api.get_server(server_id) - attached_vols = [vol['id'] for vol in - server['os-extended-volumes:volumes_attached']] - while volume_id in attached_vols and timeout < 10.0: - time.sleep(.1) - timeout += .1 - server = self.api.get_server(server_id) - attached_vols = [vol['id'] for vol in - server['os-extended-volumes:volumes_attached']] + while timeout < 10.0: + try: + self.api.get_server_volume(server_id, volume_id) + time.sleep(.1) + timeout += .1 + except api_client.OpenStackApiNotFoundException: + return - if volume_id in attached_vols: - self.fail('Timed out waiting for volume %s to be detached from ' - 'server %s. Currently attached volumes: %s' % - (volume_id, server_id, attached_vols)) + attached_vols = self.api.get_server_volumes(server_id) + self.fail('Timed out waiting for volume %s to be detached from ' + 'server %s. Currently attached volumes: %s' % + (volume_id, server_id, attached_vols)) def _assert_resize_migrate_action_fail(self, server, action, error_in_tb): """Waits for the conductor_migrate_server action event to fail for