summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Smith <danms@us.ibm.com>2013-06-04 08:07:24 -0700
committerDan Smith <danms@us.ibm.com>2013-06-04 14:25:38 -0700
commit5d9cb7dd354dc1a1eae9985521c0f4b2ea4d876e (patch)
tree2bc062fca9fe791835d49a2a043015c11923b3e7
parent820135933168feeb6320a23555ca0ebf5e14fa08 (diff)
downloadnova-5d9cb7dd354dc1a1eae9985521c0f4b2ea4d876e.tar.gz
nova-5d9cb7dd354dc1a1eae9985521c0f4b2ea4d876e.tar.xz
nova-5d9cb7dd354dc1a1eae9985521c0f4b2ea4d876e.zip
Make object actions pass positional arguments
This changes the Object API to also pass positional arguments to remotable methods. Previously, we required only keyword arguments to these methods in order to mirror our current RPC behavior. This is not really necessary and could be confusing. Since there are no actual users of these APIs in the tree right now, we can make this change without needing to bump any versions. Related to blueprint unified-object-model Change-Id: Ifb12843d16500d383d4e9c607121d5584400f247
-rw-r--r--nova/conductor/manager.py8
-rw-r--r--nova/conductor/rpcapi.py10
-rw-r--r--nova/objects/base.py27
-rw-r--r--nova/tests/objects/test_instance.py10
4 files changed, 33 insertions, 22 deletions
diff --git a/nova/conductor/manager.py b/nova/conductor/manager.py
index c7f139e4f..1c2f49f76 100644
--- a/nova/conductor/manager.py
+++ b/nova/conductor/manager.py
@@ -479,16 +479,16 @@ class ConductorManager(manager.Manager):
self.compute_api.unrescue(context, instance)
def object_class_action(self, context, objname, objmethod,
- objver, **kwargs):
+ objver, args, kwargs):
"""Perform a classmethod action on an object."""
objclass = nova_object.NovaObject.obj_class_from_name(objname,
objver)
- return getattr(objclass, objmethod)(context, **kwargs)
+ return getattr(objclass, objmethod)(context, *args, **kwargs)
- def object_action(self, context, objinst, objmethod, **kwargs):
+ def object_action(self, context, objinst, objmethod, args, kwargs):
"""Perform an action on an object."""
oldobj = copy.copy(objinst)
- result = getattr(objinst, objmethod)(context, **kwargs)
+ result = getattr(objinst, objmethod)(context, *args, **kwargs)
updates = dict()
# NOTE(danms): Diff the object with the one passed to us and
# generate a list of changes to forward back
diff --git a/nova/conductor/rpcapi.py b/nova/conductor/rpcapi.py
index c2a0e1b93..9568131e1 100644
--- a/nova/conductor/rpcapi.py
+++ b/nova/conductor/rpcapi.py
@@ -444,14 +444,16 @@ class ConductorAPI(nova.openstack.common.rpc.proxy.RpcProxy):
msg = self.make_msg('compute_unrescue', instance=instance_p)
return self.call(context, msg, version='1.48')
- def object_class_action(self, context, objname, objmethod, objver, kwargs):
+ def object_class_action(self, context, objname, objmethod, objver,
+ args, kwargs):
msg = self.make_msg('object_class_action', objname=objname,
- objmethod=objmethod, objver=objver, **kwargs)
+ objmethod=objmethod, objver=objver,
+ args=args, kwargs=kwargs)
return self.call(context, msg, version='1.50')
- def object_action(self, context, objinst, objmethod, kwargs):
+ def object_action(self, context, objinst, objmethod, args, kwargs):
msg = self.make_msg('object_action', objinst=objinst,
- objmethod=objmethod, **kwargs)
+ objmethod=objmethod, args=args, kwargs=kwargs)
return self.call(context, msg, version='1.50')
diff --git a/nova/objects/base.py b/nova/objects/base.py
index 0cfd08e6b..1ba0f03b7 100644
--- a/nova/objects/base.py
+++ b/nova/objects/base.py
@@ -16,9 +16,11 @@
import collections
+from nova import context
from nova import exception
from nova.objects import utils as obj_utils
from nova.openstack.common import log as logging
+from nova.openstack.common.rpc import common as rpc_common
import nova.openstack.common.rpc.dispatcher
import nova.openstack.common.rpc.proxy
import nova.openstack.common.rpc.serializer
@@ -81,12 +83,13 @@ class NovaObjectMetaclass(type):
# requested action and the result will be returned here.
def remotable_classmethod(fn):
"""Decorator for remotable classmethods."""
- def wrapper(cls, context, **kwargs):
+ def wrapper(cls, context, *args, **kwargs):
if NovaObject.indirection_api:
result = NovaObject.indirection_api.object_class_action(
- context, cls.obj_name(), fn.__name__, cls.version, kwargs)
+ context, cls.obj_name(), fn.__name__, cls.version,
+ args, kwargs)
else:
- result = fn(cls, context, **kwargs)
+ result = fn(cls, context, *args, **kwargs)
if isinstance(result, NovaObject):
result._context = context
return result
@@ -100,22 +103,28 @@ def remotable_classmethod(fn):
# "orphaned" and remotable methods cannot be called.
def remotable(fn):
"""Decorator for remotable object methods."""
- def wrapper(self, context=None, **kwargs):
- if context is None:
- context = self._context
- if context is None:
+ def wrapper(self, *args, **kwargs):
+ ctxt = self._context
+ try:
+ if isinstance(args[0], (context.RequestContext,
+ rpc_common.CommonRpcContext)):
+ ctxt = args[0]
+ args = args[1:]
+ except IndexError:
+ pass
+ if ctxt is None:
raise exception.OrphanedObjectError(method=fn.__name__,
objtype=self.obj_name())
if NovaObject.indirection_api:
updates, result = NovaObject.indirection_api.object_action(
- context, self, fn.__name__, kwargs)
+ ctxt, self, fn.__name__, args, kwargs)
for key, value in updates.iteritems():
if key in self.fields:
self[key] = self._attr_from_primitive(key, value)
self._changed_fields = set(updates.get('obj_what_changed', []))
return result
else:
- return fn(self, context, **kwargs)
+ return fn(self, ctxt, *args, **kwargs)
return wrapper
diff --git a/nova/tests/objects/test_instance.py b/nova/tests/objects/test_instance.py
index 8136a4f1c..498767865 100644
--- a/nova/tests/objects/test_instance.py
+++ b/nova/tests/objects/test_instance.py
@@ -101,7 +101,7 @@ class _TestInstanceObject(object):
['metadata', 'system_metadata']).AndReturn(self.fake_instance)
self.mox.ReplayAll()
inst = instance.Instance.get_by_uuid(
- ctxt, uuid='uuid', expected_attrs=['metadata', 'system_metadata'])
+ ctxt, 'uuid', expected_attrs=['metadata', 'system_metadata'])
self.assertTrue(hasattr(inst, '_metadata'))
self.assertTrue(hasattr(inst, '_system_metadata'))
self.assertRemotes()
@@ -117,7 +117,7 @@ class _TestInstanceObject(object):
db.instance_get_by_uuid(ctxt, fake_uuid, ['system_metadata']
).AndReturn(fake_inst2)
self.mox.ReplayAll()
- inst = instance.Instance.get_by_uuid(ctxt, uuid=fake_uuid)
+ inst = instance.Instance.get_by_uuid(ctxt, fake_uuid)
self.assertFalse(hasattr(inst, '_system_metadata'))
sys_meta = inst.system_metadata
self.assertEqual(sys_meta, {'foo': 'bar'})
@@ -135,7 +135,7 @@ class _TestInstanceObject(object):
db.instance_get_by_uuid(ctxt, 'fake-uuid', []).AndReturn(
fake_instance)
self.mox.ReplayAll()
- inst = instance.Instance.get_by_uuid(ctxt, uuid='fake-uuid')
+ inst = instance.Instance.get_by_uuid(ctxt, 'fake-uuid')
self.assertEqual(inst.id, fake_instance['id'])
self.assertEqual(inst.launched_at, fake_instance['launched_at'])
self.assertEqual(str(inst.access_ip_v4),
@@ -153,7 +153,7 @@ class _TestInstanceObject(object):
db.instance_get_by_uuid(ctxt, fake_uuid, []).AndReturn(
dict(self.fake_instance, host='new-host'))
self.mox.ReplayAll()
- inst = instance.Instance.get_by_uuid(ctxt, uuid=fake_uuid)
+ inst = instance.Instance.get_by_uuid(ctxt, fake_uuid)
self.assertEqual(inst.host, 'orig-host')
inst.refresh()
self.assertEqual(inst.host, 'new-host')
@@ -170,7 +170,7 @@ class _TestInstanceObject(object):
ctxt, fake_uuid, {'user_data': 'foo'}).AndReturn(
(fake_inst, dict(fake_inst, host='newhost')))
self.mox.ReplayAll()
- inst = instance.Instance.get_by_uuid(ctxt, uuid=fake_uuid)
+ inst = instance.Instance.get_by_uuid(ctxt, fake_uuid)
inst.user_data = 'foo'
inst.save()
self.assertEqual(inst.host, 'newhost')