summaryrefslogtreecommitdiffstats
path: root/nova/virt
diff options
context:
space:
mode:
authorSandy Walsh <sandy.walsh@rackspace.com>2011-01-10 04:20:11 -0400
committerSandy Walsh <sandy.walsh@rackspace.com>2011-01-10 04:20:11 -0400
commitd09511edeef2a8f6dc866ea3011bd8cc4632ac38 (patch)
treef20afd197796b67a2761db66d1b4538c4b6777df /nova/virt
parent4830cb5d8959c06fbe480481823bc922a2a59e3e (diff)
Fixed xenapi_conn wait_for_task to properly terminate LoopingCall on exception
Diffstat (limited to 'nova/virt')
-rw-r--r--nova/virt/xenapi_conn.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/nova/virt/xenapi_conn.py b/nova/virt/xenapi_conn.py
index 3aaaf09ed..ad32e890d 100644
--- a/nova/virt/xenapi_conn.py
+++ b/nova/virt/xenapi_conn.py
@@ -198,6 +198,7 @@ class XenAPISession(object):
self.XenAPI = self.get_imported_xenapi()
self._session = self._create_session(url)
self._session.login_with_password(user, pw)
+ self.loop = None
def get_imported_xenapi(self):
"""Stubout point. This can be replaced with a mock xenapi module."""
@@ -234,14 +235,19 @@ class XenAPISession(object):
def wait_for_task(self, id, task):
"""Return the result of the given task. The task is polled
- until it completes."""
+ until it completes. Not re-entrant."""
done = event.Event()
- loop = utils.LoopingCall(self._poll_task, id, task, done)
- loop.start(FLAGS.xenapi_task_poll_interval, now=True)
+ self.loop = utils.LoopingCall(self._poll_task, id, task, done)
+ self.loop.start(FLAGS.xenapi_task_poll_interval, now=True)
rv = done.wait()
- loop.stop()
+ self.loop.stop()
return rv
+ def stop_loop(self):
+ # Had to break this call out to support unit tests.
+ if self.loop:
+ self.loop.stop()
+
def _create_session(self, url):
"""Stubout point. This can be replaced with a mock session."""
return self.XenAPI.Session(url)
@@ -278,6 +284,7 @@ class XenAPISession(object):
except self.XenAPI.Failure, exc:
LOG.warn(exc)
done.send_exception(*sys.exc_info())
+ self.stop_loop()
def _unwrap_plugin_exceptions(self, func, *args, **kwargs):
"""Parse exception details"""