From 15d5958e17e8ec00f5efc7d4da23f84c9e094450 Mon Sep 17 00:00:00 2001 From: "John L. Villalovos" Date: Thu, 1 Feb 2018 16:32:48 -0800 Subject: [PATCH] Replace use of functools.wraps() with six.wraps() In Python 2.7, functools.wraps() does not provide the '__wrapped__' attribute. This attribute is used by oslo_utils.reflection.get_signature() when getting the signature of a function. If a function is decorated without the '__wrapped__' attribute then the signature will be of the decorator rather than the underlying function. From the six documentation for six.wraps(): This is exactly the functools.wraps() decorator, but it sets the __wrapped__ attribute on what it decorates as functools.wraps() does on Python versions after 3.2. Change-Id: I11bf2fa945d36bfbc89ec8239e7c9259e3e12496 --- ironic_inspector/main.py | 6 +++--- ironic_inspector/pxe_filter/base.py | 4 ++-- ironic_inspector/test/unit/test_process.py | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ironic_inspector/main.py b/ironic_inspector/main.py index 8c508dff2..6c5ba75d5 100644 --- a/ironic_inspector/main.py +++ b/ironic_inspector/main.py @@ -11,12 +11,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -import functools import os import re import flask from oslo_utils import uuidutils +import six import werkzeug from ironic_inspector import api_tools @@ -70,7 +70,7 @@ def error_response(exc, code=500): def convert_exceptions(func): - @functools.wraps(func) + @six.wraps(func) def wrapper(*args, **kwargs): try: return func(*args, **kwargs) @@ -168,7 +168,7 @@ def api(path, is_public_api=False, rule=None, verb_to_rule_map=None, def outer(func): @app.route(path, **flask_kwargs) @convert_exceptions - @functools.wraps(func) + @six.wraps(func) def wrapper(*args, **kwargs): flask.request.context = context.RequestContext.from_environ( flask.request.environ, diff --git a/ironic_inspector/pxe_filter/base.py b/ironic_inspector/pxe_filter/base.py index 3e0901b00..3b78b6af0 100644 --- a/ironic_inspector/pxe_filter/base.py +++ b/ironic_inspector/pxe_filter/base.py @@ -14,7 +14,6 @@ """Base code for PXE boot filtering.""" import contextlib -import functools from automaton import exceptions as automaton_errors from automaton import machines @@ -23,6 +22,7 @@ from futurist import periodics from oslo_concurrency import lockutils from oslo_config import cfg from oslo_log import log +import six import stevedore from ironic_inspector.common.i18n import _ @@ -74,7 +74,7 @@ State_space = [ def locked_driver_event(event): """Call driver method having processed the fsm event.""" def outer(method): - @functools.wraps(method) + @six.wraps(method) def inner(self, *args, **kwargs): with self.lock, self.fsm_reset_on_error() as fsm: fsm.process_event(event) diff --git a/ironic_inspector/test/unit/test_process.py b/ironic_inspector/test/unit/test_process.py index adb1d6043..2a1e9f4fc 100644 --- a/ironic_inspector/test/unit/test_process.py +++ b/ironic_inspector/test/unit/test_process.py @@ -12,7 +12,6 @@ # limitations under the License. import copy -import functools import json import os import shutil @@ -26,6 +25,7 @@ from oslo_config import cfg from oslo_serialization import base64 from oslo_utils import timeutils from oslo_utils import uuidutils +import six from ironic_inspector.common import ironic as ir_utils from ironic_inspector import db @@ -524,7 +524,7 @@ class TestProcessNode(BaseTest): @mock.patch.object(node_cache, 'get_node', autospec=True) class TestReapply(BaseTest): def prepare_mocks(func): - @functools.wraps(func) + @six.wraps(func) def wrapper(self, pop_mock, *args, **kw): pop_mock.return_value = node_cache.NodeInfo( uuid=self.node.uuid, @@ -600,7 +600,7 @@ class TestReapplyNode(BaseTest): self.node_info.release_lock.assert_called_once_with(self.node_info) def prepare_mocks(fn): - @functools.wraps(fn) + @six.wraps(fn) def wrapper(self, release_mock, finished_mock, swift_mock, *args, **kw): finished_mock.side_effect = lambda *a, **kw: \