Remove unnecessary use of LoopingCall in nova/virt/xenapi/vm_utils.py

The code synchronously blocks waiting on the LoopingCall to finish
anyway and the use of a maximum of number of attempts ends up being
awkwardly fit in.

Also, remove an out-of-date comment about future use of LoopingCall

Change-Id: Ife397e171f28fff5e73c70e6957cecdd09a42d68
This commit is contained in:
Johannes Erdfelt
2012-02-08 23:05:53 +00:00
parent e456d2b4e2
commit 1815aaf13a

View File

@@ -33,6 +33,8 @@ import uuid
from decimal import Decimal, InvalidOperation from decimal import Decimal, InvalidOperation
from xml.dom import minidom from xml.dom import minidom
from eventlet import greenthread
from nova import exception from nova import exception
from nova import flags from nova import flags
from nova.image import glance from nova.image import glance
@@ -1211,16 +1213,7 @@ def _wait_for_vhd_coalesce(session, instance, sr_ref, vdi_ref,
snapshot snapshot
""" """
max_attempts = FLAGS.xenapi_vhd_coalesce_max_attempts max_attempts = FLAGS.xenapi_vhd_coalesce_max_attempts
attempts = {'counter': 0} for i in xrange(max_attempts):
def _poll_vhds():
attempts['counter'] += 1
if attempts['counter'] > max_attempts:
counter = attempts['counter']
msg = (_("VHD coalesce attempts exceeded (%(counter)d >"
" %(max_attempts)d), giving up...") % locals())
raise exception.Error(msg)
VMHelper.scan_sr(session, instance, sr_ref) VMHelper.scan_sr(session, instance, sr_ref)
parent_uuid = get_vhd_parent_uuid(session, vdi_ref) parent_uuid = get_vhd_parent_uuid(session, vdi_ref)
if original_parent_uuid and (parent_uuid != original_parent_uuid): if original_parent_uuid and (parent_uuid != original_parent_uuid):
@@ -1228,13 +1221,13 @@ def _wait_for_vhd_coalesce(session, instance, sr_ref, vdi_ref,
" %(original_parent_uuid)s, waiting for coalesce...") " %(original_parent_uuid)s, waiting for coalesce...")
% locals()) % locals())
else: else:
# Breakout of the loop (normally) and return the parent_uuid return parent_uuid
raise utils.LoopingCallDone(parent_uuid)
loop = utils.LoopingCall(_poll_vhds) greenthread.sleep(FLAGS.xenapi_vhd_coalesce_poll_interval)
loop.start(FLAGS.xenapi_vhd_coalesce_poll_interval, now=True)
parent_uuid = loop.wait() msg = (_("VHD coalesce attempts exceeded (%(max_attempts)d)"
return parent_uuid ", giving up...") % locals())
raise exception.Error(msg)
def remap_vbd_dev(dev): def remap_vbd_dev(dev):
@@ -1319,7 +1312,6 @@ def vbd_unplug_with_retry(session, vbd_ref):
DEVICE_DETACH_REJECTED. For reasons which I don't understand, we're DEVICE_DETACH_REJECTED. For reasons which I don't understand, we're
seeing the device still in use, even when all processes using the device seeing the device still in use, even when all processes using the device
should be dead.""" should be dead."""
# FIXME(sirp): We can use LoopingCall here w/o blocking sleep()
while True: while True:
try: try:
session.call_xenapi("VBD.unplug", vbd_ref) session.call_xenapi("VBD.unplug", vbd_ref)
@@ -1329,7 +1321,7 @@ def vbd_unplug_with_retry(session, vbd_ref):
if (len(e.details) > 0 and if (len(e.details) > 0 and
e.details[0] == 'DEVICE_DETACH_REJECTED'): e.details[0] == 'DEVICE_DETACH_REJECTED'):
LOG.debug(_('VBD.unplug rejected: retrying...')) LOG.debug(_('VBD.unplug rejected: retrying...'))
time.sleep(1) greenthread.sleep(1)
LOG.debug(_('Not sleeping anymore!')) LOG.debug(_('Not sleeping anymore!'))
elif (len(e.details) > 0 and elif (len(e.details) > 0 and
e.details[0] == 'DEVICE_ALREADY_DETACHED'): e.details[0] == 'DEVICE_ALREADY_DETACHED'):