Fix getting instance events on subsequent attempts

When the code for getting the list of events for a given instance
was moved into the InstanceEvents object, an indenting error was
introduced, which causes the get method to return None instead of
the list if the instance already has some events waiting.

This corrects that issue.

Closes-bug: #1296808
Change-Id: I099a605980dd9c2ae0659b82c633caeb8a19bbe9
This commit is contained in:
Dan Smith 2014-03-31 07:37:22 -07:00
parent c032ab8696
commit bdd064f95f
2 changed files with 18 additions and 2 deletions

View File

@ -447,8 +447,8 @@ class InstanceEvents(object):
def _create_or_get_event():
if instance.uuid not in self._events:
self._events.setdefault(instance.uuid, {})
return self._events[instance.uuid].setdefault(
event_name, eventlet.event.Event())
return self._events[instance.uuid].setdefault(
event_name, eventlet.event.Event())
LOG.debug(_('Preparing to wait for external event %(event)s'),
{'event': event_name}, instance=instance)
return _create_or_get_event()

View File

@ -1013,6 +1013,22 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
self.compute.instance_events._events['foo']['test-event'])
self.assertTrue(hasattr(result, 'send'))
def test_prepare_for_instance_event_again(self):
inst_obj = instance_obj.Instance(uuid='foo')
self.compute.instance_events.prepare_for_instance_event(
inst_obj, 'test-event')
# A second attempt will avoid creating a new list; make sure we
# get the current list
result = self.compute.instance_events.prepare_for_instance_event(
inst_obj, 'test-event')
self.assertIn('foo', self.compute.instance_events._events)
self.assertIn('test-event',
self.compute.instance_events._events['foo'])
self.assertEqual(
result,
self.compute.instance_events._events['foo']['test-event'])
self.assertTrue(hasattr(result, 'send'))
def test_process_instance_event(self):
event = eventlet_event.Event()
self.compute.instance_events._events = {