diff options
| author | Soren Hansen <soren@linux2go.dk> | 2011-03-01 20:49:46 +0100 |
|---|---|---|
| committer | Soren Hansen <soren@linux2go.dk> | 2011-03-01 20:49:46 +0100 |
| commit | be9004ffa4c70358c8edda1f33ffe7ba7e1ae1ee (patch) | |
| tree | 4833b57a2735900bc0fcdcd607365a273e631ca7 | |
| parent | d5736e925f288462f6325130be0af49f0ace5884 (diff) | |
| download | nova-be9004ffa4c70358c8edda1f33ffe7ba7e1ae1ee.tar.gz nova-be9004ffa4c70358c8edda1f33ffe7ba7e1ae1ee.tar.xz nova-be9004ffa4c70358c8edda1f33ffe7ba7e1ae1ee.zip | |
Use functools.wraps to make sure wrapped method's metadata (docstring and name) doesn't get mangled.
| -rw-r--r-- | nova/tests/test_misc.py | 12 | ||||
| -rw-r--r-- | nova/utils.py | 6 |
2 files changed, 14 insertions, 4 deletions
diff --git a/nova/tests/test_misc.py b/nova/tests/test_misc.py index 154b6fae6..9f572b58e 100644 --- a/nova/tests/test_misc.py +++ b/nova/tests/test_misc.py @@ -14,11 +14,9 @@ # License for the specific language governing permissions and limitations # under the License. -from datetime import datetime import errno import os import select -import time from nova import test from nova.utils import parse_mailmap, str_dict_replace, synchronized @@ -62,6 +60,16 @@ class ProjectTestCase(test.TestCase): class LockTestCase(test.TestCase): + def test_synchronized_wrapped_function_metadata(self): + @synchronized('whatever') + def foo(): + """Bar""" + pass + self.assertEquals(foo.__doc__, 'Bar', "Wrapped function's docstring " + "got lost") + self.assertEquals(foo.__name__, 'foo', "Wrapped function's name " + "got mangled") + def test_synchronized(self): rpipe, wpipe = os.pipe() pid = os.fork() diff --git a/nova/utils.py b/nova/utils.py index 48f12350f..9929e6fef 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -23,11 +23,14 @@ System-level utilities and helper functions. import base64 import datetime +import functools import inspect import json import lockfile +import netaddr import os import random +import re import socket import string import struct @@ -35,8 +38,6 @@ import sys import time import types from xml.sax import saxutils -import re -import netaddr from eventlet import event from eventlet import greenthread @@ -496,6 +497,7 @@ def loads(s): def synchronized(name): def wrap(f): + @functools.wraps(f) def inner(*args, **kwargs): lock = lockfile.FileLock(os.path.join(FLAGS.lock_path, 'nova-%s.lock' % name)) |
