compute: don't trace on InstanceNotFound in reverts_task_state

Commit c43f2b0d70 added logging when
_instance_update fails in reverts_task_state but we shouldn't log
InstanceNotFound since it's a normal (expected) error when we're
deleting an instance shortly after it fails to build.

Closes-Bug: #1431404

Change-Id: Iec3dfaa16b472bc88d56d9c6680a7c247f2f50bd
This commit is contained in:
Matt Riedemann 2015-03-12 09:09:49 -07:00
parent e63a811276
commit 95976ca1af
2 changed files with 25 additions and 0 deletions

View File

@ -304,6 +304,11 @@ def reverts_task_state(function):
self._instance_update(context,
instance_uuid,
task_state=None)
except exception.InstanceNotFound:
# We might delete an instance that failed to build shortly
# after it errored out this is an expected case and we
# should not trace on it.
pass
except Exception as e:
msg = _LW("Failed to revert task state for instance. "
"Error: %s")

View File

@ -2306,6 +2306,26 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
last_refreshed=mock.ANY,
update_cells=False)
def test_reverts_task_state_instance_not_found(self):
# Tests that the reverts_task_state decorator in the compute manager
# will not trace when an InstanceNotFound is raised.
instance = objects.Instance(uuid='fake')
instance_update_mock = mock.Mock(
side_effect=exception.InstanceNotFound(instance_id=instance.uuid))
self.compute._instance_update = instance_update_mock
log_mock = mock.Mock()
manager.LOG = log_mock
@manager.reverts_task_state
def fake_function(self, context, instance):
raise test.TestingException()
self.assertRaises(test.TestingException, fake_function,
self, self.context, instance)
self.assertFalse(log_mock.called)
class ComputeManagerBuildInstanceTestCase(test.NoDBTestCase):
def setUp(self):