Merge "Don't generate notifications when reaping running_deleted instances"

This commit is contained in:
Jenkins 2013-09-16 12:08:23 +00:00 committed by Gerrit Code Review
commit 8e0d9dacfd
2 changed files with 14 additions and 6 deletions

View File

@ -1632,13 +1632,15 @@ class ComputeManager(manager.SchedulerDependentManager):
self._set_instance_error_state(context, instance['uuid'])
def _shutdown_instance(self, context, instance,
bdms, requested_networks=None):
bdms, requested_networks=None, notify=True):
"""Shutdown an instance on this host."""
context = context.elevated()
LOG.audit(_('%(action_str)s instance') % {'action_str': 'Terminating'},
context=context, instance=instance)
self._notify_about_instance_usage(context, instance, "shutdown.start")
if notify:
self._notify_about_instance_usage(context, instance,
"shutdown.start")
# get network info before tearing down
try:
@ -1685,7 +1687,9 @@ class ComputeManager(manager.SchedulerDependentManager):
LOG.warn(_('Ignoring VolumeNotFound: %s') % exc,
instance=instance)
self._notify_about_instance_usage(context, instance, "shutdown.end")
if notify:
self._notify_about_instance_usage(context, instance,
"shutdown.end")
def _cleanup_volumes(self, context, instance_uuid, bdms):
for bdm in bdms:
@ -4871,7 +4875,8 @@ class ComputeManager(manager.SchedulerDependentManager):
"DELETED but still present on host."),
instance['name'], instance=instance)
try:
self._shutdown_instance(context, instance, bdms)
self._shutdown_instance(context, instance, bdms,
notify=False)
self._cleanup_volumes(context, instance['uuid'], bdms)
except Exception as e:
LOG.warning(_("Periodic cleanup failed to delete "

View File

@ -4826,10 +4826,13 @@ class ComputeTestCase(BaseTestCase):
# Simulate an error and make sure cleanup proceeds with next instance.
self.compute._shutdown_instance(admin_context,
instance1,
bdms).AndRaise(test.TestingException)
bdms,
notify=False).\
AndRaise(test.TestingException)
self.compute._shutdown_instance(admin_context,
instance2,
bdms).AndReturn(None)
bdms,
notify=False).AndReturn(None)
self.mox.StubOutWithMock(self.compute, "_cleanup_volumes")
self.compute._cleanup_volumes(admin_context,