diff options
author | Jenkins <jenkins@review.openstack.org> | 2012-12-12 21:56:55 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2012-12-12 21:56:55 +0000 |
commit | 4a4c6ded461cc18f3112896400d0585cfad22043 (patch) | |
tree | 2e289b65952ad05a3486e020ba2cbdbad7d71c23 /nova/conductor | |
parent | 8267407424f32f1c27e1b3536f8498995ed03efc (diff) | |
parent | 405c67b1c0b8154dbaec8d6cc838bc32125ce634 (diff) | |
download | nova-4a4c6ded461cc18f3112896400d0585cfad22043.tar.gz nova-4a4c6ded461cc18f3112896400d0585cfad22043.tar.xz nova-4a4c6ded461cc18f3112896400d0585cfad22043.zip |
Merge "Allow conductor exceptions to pass over RPC silently"
Diffstat (limited to 'nova/conductor')
-rw-r--r-- | nova/conductor/api.py | 26 | ||||
-rw-r--r-- | nova/conductor/manager.py | 11 |
2 files changed, 36 insertions, 1 deletions
diff --git a/nova/conductor/api.py b/nova/conductor/api.py index b9013c4c6..397cd3fe6 100644 --- a/nova/conductor/api.py +++ b/nova/conductor/api.py @@ -14,10 +14,13 @@ """Handles all requests to the conductor service""" +import functools + from nova.conductor import manager from nova.conductor import rpcapi from nova import exception as exc from nova.openstack.common import cfg +from nova.openstack.common.rpc import common as rpc_common conductor_opts = [ cfg.BoolOpt('use_local', @@ -37,12 +40,33 @@ CONF.register_group(conductor_group) CONF.register_opts(conductor_opts, conductor_group) +class ExceptionHelper(object): + """Class to wrap another and translate the ClientExceptions raised by its + function calls to the actual ones""" + + def __init__(self, target): + self._target = target + + def __getattr__(self, name): + func = getattr(self._target, name) + + @functools.wraps(func) + def wrapper(*args, **kwargs): + try: + return func(*args, **kwargs) + except rpc_common.ClientException, e: + raise e._exc_info + return wrapper + + class LocalAPI(object): """A local version of the conductor API that does database updates locally instead of via RPC""" def __init__(self): - self._manager = manager.ConductorManager() + # TODO(danms): This needs to be something more generic for + # other/future users of this sort of functionality. + self._manager = ExceptionHelper(manager.ConductorManager()) def instance_update(self, context, instance_uuid, **updates): """Perform an instance update in the database""" diff --git a/nova/conductor/manager.py b/nova/conductor/manager.py index 796b99360..b953e0704 100644 --- a/nova/conductor/manager.py +++ b/nova/conductor/manager.py @@ -14,10 +14,12 @@ """Handles database requests from other nova services""" +from nova import exception from nova import manager from nova import notifications from nova.openstack.common import jsonutils from nova.openstack.common import log as logging +from nova.openstack.common.rpc import common as rpc_common from nova.openstack.common import timeutils @@ -47,6 +49,10 @@ class ConductorManager(manager.SchedulerDependentManager): super(ConductorManager, self).__init__(service_name='conductor', *args, **kwargs) + @rpc_common.client_exceptions(KeyError, ValueError, + exception.InvalidUUID, + exception.InstanceNotFound, + exception.UnexpectedTaskStateError) def instance_update(self, context, instance_uuid, updates): for key, value in updates.iteritems(): if key not in allowed_updates: @@ -61,6 +67,7 @@ class ConductorManager(manager.SchedulerDependentManager): notifications.send_update(context, old_ref, instance_ref) return jsonutils.to_primitive(instance_ref) + @rpc_common.client_exceptions(exception.InstanceNotFound) def instance_get_by_uuid(self, context, instance_uuid): return jsonutils.to_primitive( self.db.instance_get_by_uuid(context, instance_uuid)) @@ -69,23 +76,27 @@ class ConductorManager(manager.SchedulerDependentManager): return jsonutils.to_primitive( self.db.instance_get_all_by_host(context.elevated(), host)) + @rpc_common.client_exceptions(exception.MigrationNotFound) def migration_get(self, context, migration_id): migration_ref = self.db.migration_get(context.elevated(), migration_id) return jsonutils.to_primitive(migration_ref) + @rpc_common.client_exceptions(exception.MigrationNotFound) def migration_update(self, context, migration, status): migration_ref = self.db.migration_update(context.elevated(), migration['id'], {'status': status}) return jsonutils.to_primitive(migration_ref) + @rpc_common.client_exceptions(exception.AggregateHostExists) def aggregate_host_add(self, context, aggregate, host): host_ref = self.db.aggregate_host_add(context.elevated(), aggregate['id'], host) return jsonutils.to_primitive(host_ref) + @rpc_common.client_exceptions(exception.AggregateHostNotFound) def aggregate_host_delete(self, context, aggregate, host): self.db.aggregate_host_delete(context.elevated(), aggregate['id'], host) |