diff --git a/neutron/common/log.py b/neutron/common/log.py index 7cee18e9cdb..496d09e46b0 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 aeb731071ef..d7705167221 100644 --- a/neutron/plugins/ml2/plugin.py +++ b/neutron/plugins/ml2/plugin.py @@ -17,6 +17,7 @@ from eventlet import greenthread 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 @@ -39,7 +40,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 @@ -162,7 +162,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 91f8ad9d03c..289f81d1b3d 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 b6ed65b43a3..00000000000 --- 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 e6abe77d055..7b8252271c1 100644 --- a/tox.ini +++ b/tox.ini @@ -222,7 +222,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 \