Merge "Stop using LoopingCall in nova.virt.xenapi_conn:wait_for_task()"
This commit is contained in:
@@ -65,7 +65,7 @@ import time
|
|||||||
import urlparse
|
import urlparse
|
||||||
import xmlrpclib
|
import xmlrpclib
|
||||||
|
|
||||||
from eventlet import event
|
from eventlet import greenthread
|
||||||
from eventlet import queue
|
from eventlet import queue
|
||||||
from eventlet import tpool
|
from eventlet import tpool
|
||||||
from eventlet import timeout
|
from eventlet import timeout
|
||||||
@@ -563,54 +563,44 @@ class XenAPISession(object):
|
|||||||
def wait_for_task(self, task, uuid=None):
|
def wait_for_task(self, task, uuid=None):
|
||||||
"""Return the result of the given task. The task is polled
|
"""Return the result of the given task. The task is polled
|
||||||
until it completes."""
|
until it completes."""
|
||||||
done = event.Event()
|
while True:
|
||||||
loop = utils.LoopingCall(f=None)
|
|
||||||
|
|
||||||
def _poll_task():
|
|
||||||
"""Poll the given XenAPI task, and return the result if the
|
"""Poll the given XenAPI task, and return the result if the
|
||||||
action was completed successfully or not.
|
action was completed successfully or not.
|
||||||
"""
|
"""
|
||||||
try:
|
ctxt = context.get_admin_context()
|
||||||
ctxt = context.get_admin_context()
|
name = self.call_xenapi("task.get_name_label", task)
|
||||||
name = self.call_xenapi("task.get_name_label", task)
|
status = self.call_xenapi("task.get_status", task)
|
||||||
status = self.call_xenapi("task.get_status", task)
|
|
||||||
|
# Ensure action is never > 255
|
||||||
|
action = dict(action=name[:255], error=None)
|
||||||
|
log_instance_actions = (FLAGS.xenapi_log_instance_actions and
|
||||||
|
uuid)
|
||||||
|
if log_instance_actions:
|
||||||
|
action["instance_uuid"] = uuid
|
||||||
|
|
||||||
|
if status == "pending":
|
||||||
|
pass
|
||||||
|
elif status == "success":
|
||||||
|
result = self.call_xenapi("task.get_result", task)
|
||||||
|
LOG.info(_("Task [%(name)s] %(task)s status:"
|
||||||
|
" success %(result)s") % locals())
|
||||||
|
|
||||||
# Ensure action is never > 255
|
|
||||||
action = dict(action=name[:255], error=None)
|
|
||||||
log_instance_actions = (FLAGS.xenapi_log_instance_actions and
|
|
||||||
uuid)
|
|
||||||
if log_instance_actions:
|
if log_instance_actions:
|
||||||
action["instance_uuid"] = uuid
|
db.instance_action_create(ctxt, action)
|
||||||
|
|
||||||
if status == "pending":
|
return _parse_xmlrpc_value(result)
|
||||||
return
|
else:
|
||||||
elif status == "success":
|
error_info = self.call_xenapi("task.get_error_info", task)
|
||||||
result = self.call_xenapi("task.get_result", task)
|
LOG.warn(_("Task [%(name)s] %(task)s status:"
|
||||||
LOG.info(_("Task [%(name)s] %(task)s status:"
|
" %(status)s %(error_info)s") % locals())
|
||||||
" success %(result)s") % locals())
|
|
||||||
|
|
||||||
if log_instance_actions:
|
if log_instance_actions:
|
||||||
db.instance_action_create(ctxt, action)
|
action["error"] = str(error_info)
|
||||||
|
db.instance_action_create(ctxt, action)
|
||||||
|
|
||||||
done.send(_parse_xmlrpc_value(result))
|
raise self.XenAPI.Failure(error_info)
|
||||||
else:
|
|
||||||
error_info = self.call_xenapi("task.get_error_info", task)
|
|
||||||
LOG.warn(_("Task [%(name)s] %(task)s status:"
|
|
||||||
" %(status)s %(error_info)s") % locals())
|
|
||||||
|
|
||||||
if log_instance_actions:
|
greenthread.sleep(FLAGS.xenapi_task_poll_interval)
|
||||||
action["error"] = str(error_info)
|
|
||||||
db.instance_action_create(ctxt, action)
|
|
||||||
|
|
||||||
done.send_exception(self.XenAPI.Failure(error_info))
|
|
||||||
except self.XenAPI.Failure, exc:
|
|
||||||
LOG.warn(exc)
|
|
||||||
done.send_exception(*sys.exc_info())
|
|
||||||
loop.stop()
|
|
||||||
|
|
||||||
loop.f = _poll_task
|
|
||||||
loop.start(FLAGS.xenapi_task_poll_interval, now=True)
|
|
||||||
return done.wait()
|
|
||||||
|
|
||||||
def _create_session(self, url):
|
def _create_session(self, url):
|
||||||
"""Stubout point. This can be replaced with a mock session."""
|
"""Stubout point. This can be replaced with a mock session."""
|
||||||
|
Reference in New Issue
Block a user