Skip to content

Commit 9a1cac7

Browse files
committed
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
1 parent 6fd071b commit 9a1cac7

File tree

1 file changed

+23
-30
lines changed

1 file changed

+23
-30
lines changed

nova/tests/functional/integrated_helpers.py

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -202,43 +202,36 @@ def _wait_for_instance_action_event(
202202
'actions: %s. Events in the last matching action: %s'
203203
% (event_name, actions, events))
204204

205-
# TODO(lyarwood): Rewrite this waiter to use os-volume_attachments
206205
def _wait_for_volume_attach(self, server_id, volume_id):
207206
timeout = 0.0
208-
server = self.api.get_server(server_id)
209-
attached_vols = [vol['id'] for vol in
210-
server['os-extended-volumes:volumes_attached']]
211-
212-
while volume_id not in attached_vols and timeout < 10.0:
213-
time.sleep(.1)
214-
timeout += .1
215-
server = self.api.get_server(server_id)
216-
attached_vols = [vol['id'] for vol in
217-
server['os-extended-volumes:volumes_attached']]
218-
219-
if volume_id not in attached_vols:
220-
self.fail('Timed out waiting for volume %s to be attached to '
207+
while timeout < 10.0:
208+
try:
209+
self.api.get_server_volume(server_id, volume_id)
210+
return
211+
except api_client.OpenStackApiNotFoundException:
212+
time.sleep(.1)
213+
timeout += .1
214+
215+
attached_vols = self.api.get_server_volumes(server_id)
216+
self.fail('Timed out waiting for volume %s to be attached to '
221217
'server %s. Currently attached volumes: %s' %
222218
(volume_id, server_id, attached_vols))
223219

224-
# TODO(lyarwood): Rewrite this waiter to use os-volume_attachments
225220
def _wait_for_volume_detach(self, server_id, volume_id):
226221
timeout = 0.0
227-
server = self.api.get_server(server_id)
228-
attached_vols = [vol['id'] for vol in
229-
server['os-extended-volumes:volumes_attached']]
230-
231-
while volume_id in attached_vols and timeout < 10.0:
232-
time.sleep(.1)
233-
timeout += .1
234-
server = self.api.get_server(server_id)
235-
attached_vols = [vol['id'] for vol in
236-
server['os-extended-volumes:volumes_attached']]
237-
238-
if volume_id in attached_vols:
239-
self.fail('Timed out waiting for volume %s to be detached from '
240-
'server %s. Currently attached volumes: %s' %
241-
(volume_id, server_id, attached_vols))
222+
223+
while timeout < 10.0:
224+
try:
225+
self.api.get_server_volume(server_id, volume_id)
226+
time.sleep(.1)
227+
timeout += .1
228+
except api_client.OpenStackApiNotFoundException:
229+
return
230+
231+
attached_vols = self.api.get_server_volumes(server_id)
232+
self.fail('Timed out waiting for volume %s to be detached from '
233+
'server %s. Currently attached volumes: %s' %
234+
(volume_id, server_id, attached_vols))
242235

243236
def _assert_resize_migrate_action_fail(self, server, action, error_in_tb):
244237
"""Waits for the conductor_migrate_server action event to fail for

0 commit comments

Comments
 (0)