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