Skip to content

Commit

Permalink
VMware: fix bug for exceptions thrown in _wait_for_task
Browse files Browse the repository at this point in the history
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 1c1570f)
  • Loading branch information
gkotton authored and openstack-gerrit committed Mar 12, 2014
1 parent 1b790cc commit 5661055
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
26 changes: 26 additions & 0 deletions nova/tests/virt/vmwareapi/test_vmwareapi.py
Expand Up @@ -241,6 +241,32 @@ def _fake_login(_self):
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:
Expand Down
11 changes: 9 additions & 2 deletions nova/virt/vmwareapi/driver.py
Expand Up @@ -910,6 +910,9 @@ def _get_vim(self):
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.
Expand All @@ -920,8 +923,12 @@ def _wait_for_task(self, instance_uuid, task_ref):
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):
Expand Down

0 comments on commit 5661055

Please sign in to comment.