Add ObjectActionFailed exception and make Instance use it
The obj_load_attr() code in Instance slipped through review with just a "raise Exception()" for the case where the load cannot complete. This adds a new exception for the case, fixes the Instance.obj_load_attr() method, and adds a test to verify it. Related to blueprint compute-api-objects Change-Id: I73c966deb3c498019370eb83ade64bff2c48aec0
This commit is contained in:
@@ -1290,6 +1290,10 @@ class IncompatibleObjectVersion(NovaException):
|
||||
msg_fmt = _('Version %(objver)s of %(objname)s is not supported')
|
||||
|
||||
|
||||
class ObjectActionError(NovaException):
|
||||
msg_fmt = _('Object action %(action)s failed because: %(reason)s')
|
||||
|
||||
|
||||
class CoreAPIMissing(NovaException):
|
||||
msg_fmt = _("Core API extensions are missing: %(missing_apis)s")
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ import copy
|
||||
from nova.cells import opts as cells_opts
|
||||
from nova.cells import rpcapi as cells_rpcapi
|
||||
from nova import db
|
||||
from nova import exception
|
||||
from nova import notifications
|
||||
from nova.objects import base
|
||||
from nova.objects import instance_fault
|
||||
@@ -394,7 +395,9 @@ class Instance(base.NovaObject):
|
||||
extra.append('fault')
|
||||
|
||||
if not extra:
|
||||
raise Exception('Cannot load "%s" from instance' % attrname)
|
||||
raise exception.ObjectActionError(
|
||||
action='obj_load_attr',
|
||||
reason='attribute %s not lazy-loadable' % attrname)
|
||||
|
||||
# NOTE(danms): This could be optimized to just load the bits we need
|
||||
instance = self.__class__.get_by_uuid(self._context,
|
||||
@@ -405,7 +408,9 @@ class Instance(base.NovaObject):
|
||||
if hasattr(instance, base.get_attrname(attrname)):
|
||||
self[attrname] = instance[attrname]
|
||||
else:
|
||||
raise Exception('Cannot load "%s" from instance' % attrname)
|
||||
raise exception.ObjectActionError(
|
||||
action='obj_load_attr',
|
||||
reason='loading %s requires recursion' % attrname)
|
||||
|
||||
|
||||
def _make_instance_list(context, inst_list, db_inst_list, expected_attrs):
|
||||
|
||||
@@ -21,6 +21,7 @@ import netaddr
|
||||
from nova.cells import rpcapi as cells_rpcapi
|
||||
from nova import context
|
||||
from nova import db
|
||||
from nova import exception
|
||||
from nova.network import model as network_model
|
||||
from nova.objects import base
|
||||
from nova.objects import instance
|
||||
@@ -155,6 +156,11 @@ class _TestInstanceObject(object):
|
||||
self.assertEqual(sys_meta2, {'foo': 'bar'})
|
||||
self.assertRemotes()
|
||||
|
||||
def test_load_invalid(self):
|
||||
inst = instance.Instance()
|
||||
self.assertRaises(exception.ObjectActionError,
|
||||
inst.obj_load_attr, 'foo')
|
||||
|
||||
def test_get_remote(self):
|
||||
# isotime doesn't have microseconds and is always UTC
|
||||
ctxt = context.get_admin_context()
|
||||
|
||||
Reference in New Issue
Block a user