summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGary Kotton <gkotton@vmware.com>2013-10-31 12:07:54 -0700
committerGerrit Code Review <review@openstack.org>2014-03-12 23:03:37 +0000
commit5661055b8b138aa027b4e3f3d3d7f8a2ec928adf (patch)
tree3b5bed091cad7b04fb1a61bf19fcf034938f8e7b
parent1b790cc59720edd0cc77b3b5fb2114ce4c56b1ce (diff)
downloadnova-5661055b8b138aa027b4e3f3d3d7f8a2ec928adf.tar.gz
VMware: fix bug for exceptions thrown in _wait_for_task
If the _call_method fails, for example a resource is not found, then the same call will be invoked again due to the fact that the polling task was not stopped. Closes-Bug: #1246848 Change-Id: If4818e41aed5be03395ab22afc0edf9abb3c34e1 (cherry picked from commit 1c1570ff7ac8470d7dba28c893300835b22e0966)
-rwxr-xr-xnova/tests/virt/vmwareapi/test_vmwareapi.py26
-rw-r--r--nova/virt/vmwareapi/driver.py11
2 files changed, 35 insertions, 2 deletions
diff --git a/nova/tests/virt/vmwareapi/test_vmwareapi.py b/nova/tests/virt/vmwareapi/test_vmwareapi.py
index 7058dd9170..746a851c66 100755
--- a/nova/tests/virt/vmwareapi/test_vmwareapi.py
+++ b/nova/tests/virt/vmwareapi/test_vmwareapi.py
@@ -241,6 +241,32 @@ class VMwareAPIVMTestCase(test.NoDBTestCase):
self.conn = driver.VMwareAPISession()
self.assertEqual(self.attempts, 2)
+ def test_wait_for_task_exception(self):
+ self.flags(task_poll_interval=1, group='vmware')
+ self.login_session = vmwareapi_fake.FakeVim()._login()
+ self.stop_called = 0
+
+ def _fake_login(_self):
+ return self.login_session
+
+ self.stubs.Set(vmwareapi_fake.FakeVim, '_login', _fake_login)
+
+ def fake_poll_task(instance_uuid, task_ref, done):
+ done.send_exception(exception.NovaException('fake exception'))
+
+ def fake_stop_loop(loop):
+ self.stop_called += 1
+ return loop.stop()
+
+ self.conn = driver.VMwareAPISession()
+ self.stubs.Set(self.conn, "_poll_task",
+ fake_poll_task)
+ self.stubs.Set(self.conn, "_stop_loop",
+ fake_stop_loop)
+ self.assertRaises(exception.NovaException,
+ self.conn._wait_for_task, 'fake-id', 'fake-ref')
+ self.assertEqual(self.stop_called, 1)
+
def _create_instance_in_the_db(self, node=None, set_image_ref=True,
uuid=None):
if not node:
diff --git a/nova/virt/vmwareapi/driver.py b/nova/virt/vmwareapi/driver.py
index 38e546772d..c61ab63f35 100644
--- a/nova/virt/vmwareapi/driver.py
+++ b/nova/virt/vmwareapi/driver.py
@@ -910,6 +910,9 @@ class VMwareAPISession(object):
self._create_session()
return self.vim
+ def _stop_loop(self, loop):
+ loop.stop()
+
def _wait_for_task(self, instance_uuid, task_ref):
"""
Return a Deferred that will give the result of the given task.
@@ -920,8 +923,12 @@ class VMwareAPISession(object):
instance_uuid,
task_ref, done)
loop.start(CONF.vmware.task_poll_interval)
- ret_val = done.wait()
- loop.stop()
+ try:
+ ret_val = done.wait()
+ except Exception:
+ raise
+ finally:
+ self._stop_loop(loop)
return ret_val
def _poll_task(self, instance_uuid, task_ref, done):