diff options
author | Jenkins <jenkins@review.openstack.org> | 2015-04-22 17:49:49 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2015-04-22 17:49:49 +0000 |
commit | ad52e70d8bc6fbb9c386c005c7ee14a6921e3821 (patch) | |
tree | a840fa01b51cdca6f1d7b10f3d0fe3e6e02c087a | |
parent | 623fc7151655d1b5efbf9b5dfb89def1e860cc85 (diff) | |
parent | a4e9a146c3993f5775501716a21632f34a63a3ad (diff) | |
download | nova-ad52e70d8bc6fbb9c386c005c7ee14a6921e3821.tar.gz |
Merge "Fix kwargs['migration'] KeyError in @errors_out_migration decorator" into stable/kilo
-rw-r--r-- | nova/compute/manager.py | 5 | ||||
-rw-r--r-- | nova/tests/unit/compute/test_compute_mgr.py | 26 |
2 files changed, 30 insertions, 1 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 5be25d4f13..0e3527d87b 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -269,7 +269,10 @@ def errors_out_migration(function): return function(self, context, *args, **kwargs) except Exception: with excutils.save_and_reraise_exception(): - migration = kwargs['migration'] + wrapped_func = utils.get_wrapped_function(function) + keyed_args = safe_utils.getcallargs(wrapped_func, context, + *args, **kwargs) + migration = keyed_args['migration'] status = migration.status if status not in ['migrating', 'post-migrating']: return diff --git a/nova/tests/unit/compute/test_compute_mgr.py b/nova/tests/unit/compute/test_compute_mgr.py index 0379306e02..399a1e4ff0 100644 --- a/nova/tests/unit/compute/test_compute_mgr.py +++ b/nova/tests/unit/compute/test_compute_mgr.py @@ -3520,6 +3520,32 @@ class ComputeManagerMigrationTestCase(test.NoDBTestCase): self.migration.status = 'migrating' fake_server_actions.stub_out_action_events(self.stubs) + @mock.patch.object(objects.Migration, 'save') + @mock.patch.object(objects.Migration, 'obj_as_admin') + def test_errors_out_migration_decorator(self, mock_save, + mock_obj_as_admin): + # Tests that errors_out_migration decorator in compute manager + # sets migration status to 'error' when an exception is raised + # from decorated method + instance = fake_instance.fake_instance_obj(self.context) + + migration = objects.Migration() + migration.instance_uuid = instance.uuid + migration.status = 'migrating' + migration.id = 0 + + @manager.errors_out_migration + def fake_function(self, context, instance, migration): + raise test.TestingException() + + mock_obj_as_admin.return_value = mock.MagicMock() + + self.assertRaises(test.TestingException, fake_function, + self, self.context, instance, migration) + self.assertEqual('error', migration.status) + mock_save.assert_called_once_with() + mock_obj_as_admin.assert_called_once_with() + def test_finish_resize_failure(self): with contextlib.nested( mock.patch.object(self.compute, '_finish_resize', |