diff options
| author | Andrew Bogott <abogott@wikimedia.org> | 2012-04-26 13:54:08 -0500 |
|---|---|---|
| committer | Andrew Bogott <abogott@wikimedia.org> | 2012-05-02 15:37:32 -0500 |
| commit | 2dcd8256662115e6528c2b784c08c5724c8227e8 (patch) | |
| tree | 79815b17864a7d04eba0b0ba14e7838c7dabebc9 /nova/exception.py | |
| parent | 1d97b77ea4c31f1fb17bc20cc4c16a3f6edf2cf1 (diff) | |
Pass context to notification drivers when we can.
Note that previously several notification drivers
created an admin context and embedded it in their
messages. Those drivers now use the passed-in
context instead if it's available.
For blueprint novaplugins.
Change-Id: Icb89030256022d0a68db4a147611fd37fe83316a
Diffstat (limited to 'nova/exception.py')
| -rw-r--r-- | nova/exception.py | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/nova/exception.py b/nova/exception.py index e40fa0ccf..dc1199be3 100644 --- a/nova/exception.py +++ b/nova/exception.py @@ -25,6 +25,7 @@ SHOULD include dedicated exception logging. """ import functools +import inspect import sys import webob.exc @@ -133,8 +134,12 @@ def wrap_exception(notifier=None, publisher_id=None, event_type=None, # propagated. temp_type = f.__name__ - notifier.notify(publisher_id, temp_type, temp_level, - payload) + context = get_context_from_function_and_args(f, + args, + kw) + + notifier.notify(context, publisher_id, temp_type, + temp_level, payload) # re-raise original exception since it may have been clobbered raise exc_info[0], exc_info[1], exc_info[2] @@ -1060,3 +1065,22 @@ class InvalidInstanceIDMalformed(Invalid): class CouldNotFetchImage(NovaException): message = _("Could not fetch image %(image)s") + + +def get_context_from_function_and_args(function, args, kwargs): + """Find an arg named 'context' and return the value. + + This is useful in a couple of decorators where we don't + know much about the function we're wrapping. + """ + context = None + if 'context' in kwargs.keys(): + context = kwargs['context'] + else: + (iargs, _iva, _ikw, _idf) = inspect.getargspec(function) + if 'context' in iargs: + index = iargs.index('context') + if len(args) > index: + context = args[index] + + return context |
