summaryrefslogtreecommitdiffstats
path: root/nova/exception.py
diff options
context:
space:
mode:
authorAndrew Bogott <abogott@wikimedia.org>2012-05-03 02:38:48 -0500
committerAndrew Bogott <abogott@wikimedia.org>2012-05-04 12:10:14 -0500
commitd9099ee332b7dace9f0b73c8131ccd960cff5eaa (patch)
treedaedeec8a24dc57cfe57344efde9a1ab8025ee86 /nova/exception.py
parenteb9e54c1129080ad0f5b569b39dfa09c539f2f11 (diff)
Find context arg by type rather than by name.
This requires changes to all the tests that were passing in a string as a bogus context; that seems like an improvement. Change-Id: Ib8fc83cbda25a1cfa8794b72dc13f666549ef892
Diffstat (limited to 'nova/exception.py')
-rw-r--r--nova/exception.py24
1 files changed, 11 insertions, 13 deletions
diff --git a/nova/exception.py b/nova/exception.py
index df2f79e3d..87eaca243 100644
--- a/nova/exception.py
+++ b/nova/exception.py
@@ -25,7 +25,7 @@ SHOULD include dedicated exception logging.
"""
import functools
-import inspect
+import itertools
import sys
import webob.exc
@@ -1073,19 +1073,17 @@ class CouldNotFetchImage(NovaException):
def get_context_from_function_and_args(function, args, kwargs):
- """Find an arg named 'context' and return the value.
+ """Find an arg of type RequestContext and return it.
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
+
+ # import here to avoid circularity:
+ from nova import context
+
+ for arg in itertools.chain(kwargs.values(), args):
+ if isinstance(arg, context.RequestContext):
+ return arg
+
+ return None