Merge "Remove unused object_compat decorator"

This commit is contained in:
Zuul 2020-06-02 16:06:09 +00:00 committed by Gerrit Code Review
commit 57691a29c8
2 changed files with 0 additions and 87 deletions
nova
compute
tests/unit/compute

@ -240,51 +240,6 @@ def delete_image_on_error(function):
return decorated_function
# TODO(danms): Remove me after Icehouse
# TODO(alaski): Actually remove this after Newton, assuming a major RPC bump
# NOTE(mikal): if the method being decorated has more than one decorator, then
# put this one first. Otherwise the various exception handling decorators do
# not function correctly.
def object_compat(function):
"""Wraps a method that expects a new-world instance
This provides compatibility for callers passing old-style dict
instances.
"""
@functools.wraps(function)
def decorated_function(self, context, *args, **kwargs):
def _load_instance(instance_or_dict):
if isinstance(instance_or_dict, dict):
# try to get metadata and system_metadata for most cases but
# only attempt to load those if the db instance already has
# those fields joined
metas = [meta for meta in ('metadata', 'system_metadata')
if meta in instance_or_dict]
instance = objects.Instance._from_db_object(
context, objects.Instance(), instance_or_dict,
expected_attrs=metas)
instance._context = context
return instance
return instance_or_dict
try:
kwargs['instance'] = _load_instance(kwargs['instance'])
except KeyError:
args = (_load_instance(args[0]),) + args[1:]
migration = kwargs.get('migration')
if isinstance(migration, dict):
migration = objects.Migration._from_db_object(
context.elevated(), objects.Migration(),
migration)
kwargs['migration'] = migration
return function(self, context, *args, **kwargs)
return decorated_function
class InstanceEvents(object):
def __init__(self):
self._events = {}

@ -1561,48 +1561,6 @@ class ComputeTestCase(BaseTestCase,
self.assertFalse(called['fault_added'])
def test_object_compat(self):
db_inst = fake_instance.fake_db_instance()
@compute_manager.object_compat
def test_fn(_self, context, instance):
self.assertIsInstance(instance, objects.Instance)
self.assertEqual(instance.uuid, db_inst['uuid'])
self.assertEqual(instance.metadata, db_inst['metadata'])
self.assertEqual(instance.system_metadata,
db_inst['system_metadata'])
test_fn(None, self.context, instance=db_inst)
def test_object_compat_no_metas(self):
# Tests that we don't try to set metadata/system_metadata on the
# instance object using fields that aren't in the db object.
db_inst = fake_instance.fake_db_instance()
db_inst.pop('metadata', None)
db_inst.pop('system_metadata', None)
@compute_manager.object_compat
def test_fn(_self, context, instance):
self.assertIsInstance(instance, objects.Instance)
self.assertEqual(instance.uuid, db_inst['uuid'])
self.assertNotIn('metadata', instance)
self.assertNotIn('system_metadata', instance)
test_fn(None, self.context, instance=db_inst)
def test_object_compat_more_positional_args(self):
db_inst = fake_instance.fake_db_instance()
@compute_manager.object_compat
def test_fn(_self, context, instance, pos_arg_1, pos_arg_2):
self.assertIsInstance(instance, objects.Instance)
self.assertEqual(instance.uuid, db_inst['uuid'])
self.assertEqual(instance.metadata, db_inst['metadata'])
self.assertEqual(instance.system_metadata,
db_inst['system_metadata'])
self.assertEqual(pos_arg_1, 'fake_pos_arg1')
self.assertEqual(pos_arg_2, 'fake_pos_arg2')
test_fn(None, self.context, db_inst, 'fake_pos_arg1', 'fake_pos_arg2')
def test_create_instance_with_img_ref_associates_config_drive(self):
# Make sure create associates a config drive.