Skip to content

Commit

Permalink
Handle unexpected clear events call
Browse files Browse the repository at this point in the history
Currently we don't check if we have access to events at the time of
calling clear_events for an instance. This could result in operations
failing (like deleting an instance) for the user.

Add a check and a log message that this shouldn't happen (but it does).

Change-Id: I29852662cbfe38f37f9d5154147e6b17b7b8b454
Closes-Bug: 1454149
(cherry picked from commit bb4511b)
  • Loading branch information
zoltan authored and Matt Riedemann committed Jul 9, 2015
1 parent b8c4f1b commit e459add
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions nova/compute/manager.py
Expand Up @@ -554,6 +554,10 @@ def clear_events_for_instance(self, instance):
"""
@utils.synchronized(self._lock_name(instance))
def _clear_events():
if self._events is None:
LOG.debug('Unexpected attempt to clear events during shutdown',
instance=instance)
return dict()
return self._events.pop(instance.uuid, {})
return _clear_events()

Expand Down
6 changes: 6 additions & 0 deletions nova/tests/unit/compute/test_compute_mgr.py
Expand Up @@ -1756,6 +1756,12 @@ def test_pop_events_fails_gracefully(self):
self.assertIsNone(
self.compute.instance_events.pop_instance_event(inst, event))

def test_clear_events_fails_gracefully(self):
inst = objects.Instance(uuid='uuid')
self.compute.instance_events._events = None
self.assertEqual(
self.compute.instance_events.clear_events_for_instance(inst), {})

def test_retry_reboot_pending_soft(self):
instance = objects.Instance(self.context)
instance.uuid = 'foo'
Expand Down

0 comments on commit e459add

Please sign in to comment.