]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Use oslo_log.helpers.log_method_call
authorCedric Brandily <zzelle@gmail.com>
Wed, 15 Jul 2015 21:39:49 +0000 (23:39 +0200)
committerCedric Brandily <zzelle@gmail.com>
Fri, 17 Jul 2015 07:34:07 +0000 (07:34 +0000)
log[1] decorator is deprecated, this change replaces it with oslo_log
log_method_call[2].

[1] neutron.common.log
[2] oslo_log.helpers.log_method_call

Change-Id: I61cf3c010e1f33a45ff700f4e8d4824ebdb378c7

neutron/common/log.py
neutron/plugins/ml2/plugin.py
neutron/services/l3_router/l3_router_plugin.py
neutron/tests/unit/common/test_log.py [deleted file]
tox.ini

index 7cee18e9cdb13c3e103701bfe698f4f8c5753915..496d09e46b09779c916c5340a651151751db9ffb 100644 (file)
 # under the License.
 
 """Log helper functions."""
-import functools
 
-from oslo_log import log as logging
+from oslo_log import helpers
 from oslo_log import versionutils
 
 
-@versionutils.deprecated(as_of=versionutils.deprecated.LIBERTY,
-                         in_favor_of='oslo_log.helpers.log_method_call')
-def log(method):
-    """Decorator helping to log method calls."""
-    LOG = logging.getLogger(method.__module__)
-
-    @functools.wraps(method)
-    def wrapper(*args, **kwargs):
-        instance = args[0]
-        data = {"class_name": "%s.%s" % (instance.__class__.__module__,
-                                         instance.__class__.__name__),
-                "method_name": method.__name__,
-                "args": args[1:], "kwargs": kwargs}
-        LOG.debug('%(class_name)s method %(method_name)s'
-                  ' called with arguments %(args)s %(kwargs)s', data)
-        return method(*args, **kwargs)
-    return wrapper
+log = versionutils.deprecated(
+    as_of=versionutils.deprecated.LIBERTY,
+    in_favor_of='oslo_log.helpers.log_method_call')(helpers.log_method_call)
index cd64d7210fb2c00de0515424802cd3c5a9368210..46f57b380a08c21f606a643c10902447cae2c965 100644 (file)
@@ -18,6 +18,7 @@ from oslo_concurrency import lockutils
 from oslo_config import cfg
 from oslo_db import api as oslo_db_api
 from oslo_db import exception as os_db_exception
+from oslo_log import helpers as log_helpers
 from oslo_log import log
 from oslo_serialization import jsonutils
 from oslo_utils import excutils
@@ -40,7 +41,6 @@ from neutron.callbacks import resources
 from neutron.common import constants as const
 from neutron.common import exceptions as exc
 from neutron.common import ipv6_utils
-from neutron.common import log as neutron_log
 from neutron.common import rpc as n_rpc
 from neutron.common import topics
 from neutron.common import utils
@@ -163,7 +163,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
         )
         self.start_periodic_dhcp_agent_status_check()
 
-    @neutron_log.log
+    @log_helpers.log_method_call
     def start_rpc_listeners(self):
         """Start the RPC loop to let the plugin communicate with agents."""
         self.topic = topics.PLUGIN
index 91f8ad9d03cc5671bb82bb54edb956f33055b61f..289f81d1b3d6cffa238f265dcd55794082ffb2a4 100644 (file)
 #    under the License.
 
 from oslo_config import cfg
+from oslo_log import helpers as log_helpers
 from oslo_utils import importutils
 
 from neutron.api.rpc.agentnotifiers import l3_rpc_agent_api
 from neutron.api.rpc.handlers import l3_rpc
 from neutron.common import constants as n_const
-from neutron.common import log as neutron_log
 from neutron.common import rpc as n_rpc
 from neutron.common import topics
 from neutron.db import common_db_mixin
@@ -62,7 +62,7 @@ class L3RouterPlugin(common_db_mixin.CommonDbMixin,
             l3_dvrscheduler_db.subscribe()
         l3_db.subscribe()
 
-    @neutron_log.log
+    @log_helpers.log_method_call
     def setup_rpc(self):
         # RPC support
         self.topic = topics.L3PLUGIN
diff --git a/neutron/tests/unit/common/test_log.py b/neutron/tests/unit/common/test_log.py
deleted file mode 100644 (file)
index b6ed65b..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-# Copyright (c) 2013 OpenStack Foundation.
-#
-#    Licensed under the Apache License, Version 2.0 (the "License"); you may
-#    not use this file except in compliance with the License. You may obtain
-#    a copy of the License at
-#
-#         http://www.apache.org/licenses/LICENSE-2.0
-#
-#    Unless required by applicable law or agreed to in writing, software
-#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-#    License for the specific language governing permissions and limitations
-#    under the License.
-
-import mock
-
-from neutron.common import log as call_log
-from neutron.tests import base
-
-
-class TargetKlass(object):
-
-    @call_log.log
-    def test_method(self, arg1, arg2, *args, **kwargs):
-        pass
-
-
-class TestCallLog(base.BaseTestCase):
-    def setUp(self):
-        super(TestCallLog, self).setUp()
-        self.klass = TargetKlass()
-        logger = self.klass.test_method.__func__.__closure__[0].cell_contents
-        self.log_debug = mock.patch.object(logger, 'debug').start()
-
-    def _test_call_log(self, *args, **kwargs):
-        expected_format = ('%(class_name)s method %(method_name)s '
-                           'called with arguments %(args)s %(kwargs)s')
-        expected_data = {'class_name': '%s.%s' % (
-                         __name__,
-                         self.klass.__class__.__name__),
-                         'method_name': 'test_method',
-                         'args': args,
-                         'kwargs': kwargs}
-        self.klass.test_method(*args, **kwargs)
-        self.log_debug.assert_called_once_with(expected_format, expected_data)
-
-    def test_call_log_all_args(self):
-        self._test_call_log(10, 20)
-
-    def test_call_log_all_kwargs(self):
-        self._test_call_log(arg1=10, arg2=20)
-
-    def test_call_log_known_args_unknown_args_kwargs(self):
-        self._test_call_log(10, 20, 30, arg4=40)
-
-    def test_call_log_known_args_kwargs_unknown_kwargs(self):
-        self._test_call_log(10, arg2=20, arg3=30, arg4=40)
diff --git a/tox.ini b/tox.ini
index 19dbef4577630189b4d18b4e5e9eeb68d03edc23..acc761abb84ac0b2cbf598fbfca73234d3b74b27 100644 (file)
--- a/tox.ini
+++ b/tox.ini
@@ -207,7 +207,6 @@ commands = python -m testtools.run \
     neutron.tests.unit.hacking.test_checks \
     neutron.tests.unit.common.test_config \
     neutron.tests.unit.common.test_rpc \
-    neutron.tests.unit.common.test_log \
     neutron.tests.unit.common.test_ipv6_utils \
     neutron.tests.unit.cmd.test_ovs_cleanup \
     neutron.tests.unit.cmd.test_netns_cleanup \