From: Cedric Brandily Date: Wed, 15 Jul 2015 21:39:49 +0000 (+0200) Subject: Use oslo_log.helpers.log_method_call X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=1b3c7c6ee07fd79bee3b54ea0d4ca0a53bf0d9b7;p=openstack-build%2Fneutron-build.git Use oslo_log.helpers.log_method_call 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 --- diff --git a/neutron/common/log.py b/neutron/common/log.py index 7cee18e9c..496d09e46 100644 --- a/neutron/common/log.py +++ b/neutron/common/log.py @@ -13,26 +13,11 @@ # 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) diff --git a/neutron/plugins/ml2/plugin.py b/neutron/plugins/ml2/plugin.py index cd64d7210..46f57b380 100644 --- a/neutron/plugins/ml2/plugin.py +++ b/neutron/plugins/ml2/plugin.py @@ -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 diff --git a/neutron/services/l3_router/l3_router_plugin.py b/neutron/services/l3_router/l3_router_plugin.py index 91f8ad9d0..289f81d1b 100644 --- a/neutron/services/l3_router/l3_router_plugin.py +++ b/neutron/services/l3_router/l3_router_plugin.py @@ -14,12 +14,12 @@ # 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 index b6ed65b43..000000000 --- a/neutron/tests/unit/common/test_log.py +++ /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 19dbef457..acc761abb 100644 --- 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 \