]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Move from Python logging to Openstack logging
authorAkash Gangil <akashg1611@gmail.com>
Sat, 2 Aug 2014 09:53:14 +0000 (02:53 -0700)
committerAkash Gangil <akashg1611@gmail.com>
Sat, 2 Aug 2014 11:04:33 +0000 (04:04 -0700)
Replacing usage of python standard logging module
with Openstack common logging module. Apart from
the said replacements, this patch also removes
basicConfig() setup from a couple of modules since
its not needed. Also removes unused LOG & imports.

Change-Id: I6a391951e00fb63905b2027270af9f401841d5b9
Closes-Bug: #1350937

17 files changed:
neutron/db/migration/alembic_migrations/heal_script.py
neutron/plugins/cisco/common/cisco_credentials_v2.py
neutron/plugins/cisco/models/virt_phy_sw_v2.py
neutron/plugins/cisco/network_plugin.py
neutron/plugins/cisco/nexus/cisco_nexus_network_driver_v2.py
neutron/plugins/cisco/nexus/cisco_nexus_plugin_v2.py
neutron/plugins/cisco/nexus/cisco_nexus_snippets.py
neutron/plugins/ml2/drivers/cisco/nexus/nexus_snippets.py
neutron/plugins/vmware/plugins/base.py
neutron/tests/base.py
neutron/tests/unit/cisco/test_network_plugin.py
neutron/tests/unit/db/firewall/test_db_firewall.py
neutron/tests/unit/db/loadbalancer/test_db_loadbalancer.py
neutron/tests/unit/db/metering/test_db_metering.py
neutron/tests/unit/ml2/test_helpers.py
neutron/tests/unit/test_servicetype.py
neutron/tests/unit/vmware/apiclient/test_api_eventlet_request.py

index 0c49df3b790441f226f944a7f408e1ee1d076f2b..276008171f74164bded158fd9ed912592cb1ba48 100644 (file)
@@ -34,6 +34,8 @@ METHODS = {}
 
 
 def heal():
+    # This is needed else the heal script will start spewing
+    # a lot of pointless warning messages from alembic.
     LOG.setLevel(logging.INFO)
     if context.is_offline_mode():
         return
index c7af2bca83f8f16338a1dd5dc6c461c40fbdbc1b..115cab488aa5516a941c1a05f2ae4539041b7e1b 100644 (file)
 #
 # @author: Sumit Naiksatam, Cisco Systems, Inc.
 
-import logging as LOG
 
 from neutron.plugins.cisco.common import cisco_constants as const
 from neutron.plugins.cisco.common import cisco_exceptions as cexc
 from neutron.plugins.cisco.common import config
 from neutron.plugins.cisco.db import network_db_v2 as cdb
 
-LOG.basicConfig(level=LOG.WARN)
-LOG.getLogger(const.LOGGER_COMPONENT_NAME)
-
 
 class Store(object):
     """Credential Store."""
index 4702e0a752ad9e0c3b51f9a772115c84359505e5..619c006261b18c8d5919bfbb5e5e71474272f44a 100644 (file)
@@ -18,7 +18,6 @@
 #
 
 import inspect
-import logging
 import sys
 
 from neutron.api.v2 import attributes
@@ -27,6 +26,7 @@ from neutron.extensions import portbindings
 from neutron.extensions import providernet as provider
 from neutron import neutron_plugin_base_v2
 from neutron.openstack.common import importutils
+from neutron.openstack.common import log as logging
 from neutron.plugins.cisco.common import cisco_constants as const
 from neutron.plugins.cisco.common import cisco_credentials_v2 as cred
 from neutron.plugins.cisco.common import cisco_exceptions as cexc
index 4c61340735e83dbc8ad99e659254df945c80382d..b3f679e9dcec17ab561d3f75a5a0c0d995b4051d 100644 (file)
@@ -14,7 +14,6 @@
 #
 # @author: Sumit Naiksatam, Cisco Systems, Inc.
 
-import logging
 
 import webob.exc as wexc
 
@@ -22,6 +21,7 @@ from neutron.api import extensions as neutron_extensions
 from neutron.api.v2 import base
 from neutron.db import db_base_plugin_v2
 from neutron.openstack.common import importutils
+from neutron.openstack.common import log as logging
 from neutron.plugins.cisco.common import cisco_exceptions as cexc
 from neutron.plugins.cisco.common import config
 from neutron.plugins.cisco.db import network_db_v2 as cdb
index f55a800148b8ea881943072917c42964d6ce145b..9ee95bf36f9aeb8c84e6508bf07f33bce149201d 100644 (file)
 Implements a Nexus-OS NETCONF over SSHv2 API Client
 """
 
-import logging
 
 from ncclient import manager
 
 from neutron.openstack.common import excutils
+from neutron.openstack.common import log as logging
 from neutron.plugins.cisco.common import cisco_constants as const
 from neutron.plugins.cisco.common import cisco_credentials_v2 as cred
 from neutron.plugins.cisco.common import cisco_exceptions as cexc
index 012c85604c5127f5095b5a8135e34d356f6fa519..a0fc4d4bb145b6cd24dc4f9a1405eda3d191a72b 100644 (file)
 PlugIn for Nexus OS driver
 """
 
-import logging
 
 from neutron.openstack.common import excutils
 from neutron.openstack.common import importutils
+from neutron.openstack.common import log as logging
 from neutron.plugins.cisco.common import cisco_constants as const
 from neutron.plugins.cisco.common import cisco_exceptions as cisco_exc
 from neutron.plugins.cisco.common import config as conf
index 81a93f537e405006066ef8135e37a5c20faa518c..e8c8e2633f63ff873bcf9a1b29aaa18f45e9a3c1 100644 (file)
 Nexus-OS XML-based configuration snippets
 """
 
-import logging
-
-
-LOG = logging.getLogger(__name__)
-
 
 # The following are standard strings, messages used to communicate with Nexus,
 EXEC_CONF_SNIPPET = """
index fb38e4199fa5c11bd7b4673020dcd52367233dae..99f38251bfcb7927961287630202288478ba604a 100644 (file)
 Cisco Nexus-OS XML-based configuration snippets.
 """
 
-import logging
-
-
-LOG = logging.getLogger(__name__)
-
 
 # The following are standard strings, messages used to communicate with Nexus.
 EXEC_CONF_SNIPPET = """
index e59c527ee130438a2cc653fec316d161fbdac370..f015e28a5ced5f1e4642f16909128cfb8d673fad 100644 (file)
@@ -13,7 +13,6 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
-import logging
 import uuid
 
 from oslo.config import cfg
@@ -51,7 +50,9 @@ from neutron.extensions import portsecurity as psec
 from neutron.extensions import providernet as pnet
 from neutron.extensions import securitygroup as ext_sg
 from neutron.openstack.common import excutils
+from neutron.openstack.common.gettextutils import _LE
 from neutron.openstack.common import lockutils
+from neutron.openstack.common import log as logging
 from neutron.plugins.common import constants as plugin_const
 from neutron.plugins import vmware
 from neutron.plugins.vmware.api_client import exception as api_exc
@@ -2080,12 +2081,10 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin,
     def _get_nsx_device_id(self, context, device_id):
         return self._get_gateway_device(context, device_id)['nsx_id']
 
-    def _rollback_gw_device(self, context, device_id,
-                            gw_data=None, new_status=None,
-                            is_create=False, log_level=logging.ERROR):
-        LOG.log(log_level,
-                _("Rolling back database changes for gateway device %s "
-                  "because of an error in the NSX backend"), device_id)
+    def _rollback_gw_device(self, context, device_id, gw_data=None,
+                            new_status=None, is_create=False):
+        LOG.error(_LE("Rolling back database changes for gateway device %s "
+                      "because of an error in the NSX backend"), device_id)
         with context.session.begin(subtransactions=True):
             query = self._model_query(
                 context, networkgw_db.NetworkGatewayDevice).filter(
index b0bccef37f387656d5a51f1d1d034718d45d6a34..99a91affaf0a179e839342f91bfcff18512a8ba0 100644 (file)
@@ -17,7 +17,7 @@
 
 import contextlib
 import gc
-import logging
+import logging as std_logging
 import os
 import os.path
 import sys
@@ -110,7 +110,6 @@ class BaseTestCase(testtools.TestCase):
 
     def setUp(self):
         super(BaseTestCase, self).setUp()
-
         # Ensure plugin cleanup is triggered last so that
         # test-specific cleanup has a chance to release references.
         self.addCleanup(self.cleanup_core_plugin)
@@ -120,12 +119,12 @@ class BaseTestCase(testtools.TestCase):
             self.addOnException(post_mortem_debug.exception_handler)
 
         if os.environ.get('OS_DEBUG') in TRUE_STRING:
-            _level = logging.DEBUG
+            _level = std_logging.DEBUG
         else:
-            _level = logging.INFO
+            _level = std_logging.INFO
         capture_logs = os.environ.get('OS_LOG_CAPTURE') in TRUE_STRING
         if not capture_logs:
-            logging.basicConfig(format=LOG_FORMAT, level=_level)
+            std_logging.basicConfig(format=LOG_FORMAT, level=_level)
         self.log_fixture = self.useFixture(
             fixtures.FakeLogger(
                 format=LOG_FORMAT,
@@ -138,7 +137,7 @@ class BaseTestCase(testtools.TestCase):
             fixtures.FakeLogger(
                 name='neutron.api.extensions',
                 format=LOG_FORMAT,
-                level=logging.ERROR,
+                level=std_logging.ERROR,
                 nuke_handlers=capture_logs,
             ))
 
index 4e7be3e873b626dcb0448e7edd396eb57a5eb448..bde9cb55159a060e225fd3aab661cec042f7a054 100644 (file)
@@ -16,7 +16,7 @@
 import contextlib
 import copy
 import inspect
-import logging
+import logging as std_logging
 import mock
 
 import six
@@ -33,6 +33,7 @@ from neutron.extensions import portbindings
 from neutron.extensions import providernet as provider
 from neutron import manager
 from neutron.openstack.common import gettextutils
+from neutron.openstack.common import log as logging
 from neutron.plugins.cisco.common import cisco_constants as const
 from neutron.plugins.cisco.common import cisco_exceptions as c_exc
 from neutron.plugins.cisco.common import config as cisco_config
@@ -923,7 +924,7 @@ class TestCiscoNetworksV2(CiscoNetworkPluginV2TestCase,
                                                 *args, **kwargs)
                 patched_plugin.side_effect = side_effect
                 res = self._create_network_bulk(self.fmt, 2, 'test', True)
-                LOG.debug("response is %s" % res)
+                LOG.debug('response is %s', res)
                 # We expect an internal server error as we injected a fault
                 self._validate_behavior_on_bulk_failure(
                     res,
@@ -1052,10 +1053,10 @@ class TestCiscoRouterInterfacesV2(CiscoNetworkPluginV2TestCase):
         def _count_exception_logs(*args, **kwargs):
             self.log_exc_count += 1
 
-        mock.patch.object(logging.LoggerAdapter, 'exception',
+        mock.patch.object(std_logging.LoggerAdapter, 'exception',
                           autospec=True,
                           side_effect=_count_exception_logs,
-                          wraps=logging.LoggerAdapter.exception).start()
+                          wraps=std_logging.LoggerAdapter.exception).start()
         super(TestCiscoRouterInterfacesV2, self).setUp()
         ext_mgr = extensions.PluginAwareExtensionManager.get_instance()
         self.ext_api = test_extensions.setup_extensions_middleware(ext_mgr)
index 0abd354646ee7651d010a46e78cb544207ed9c04..b1234d48160cf318862368ebe25d8b3b053b708d 100644 (file)
@@ -16,7 +16,6 @@
 # @author: Sumit Naiksatam, sumitnaiksatam@gmail.com, Big Switch Networks, Inc.
 
 import contextlib
-import logging
 
 import mock
 import webob.exc
@@ -35,7 +34,6 @@ from neutron.services.firewall import fwaas_plugin
 from neutron.tests.unit import test_db_plugin
 
 
-LOG = logging.getLogger(__name__)
 DB_FW_PLUGIN_KLASS = (
     "neutron.db.firewall.firewall_db.Firewall_db_mixin"
 )
index fec26b77b11e1ee4820243fcc70253bce43b9688..b47d61167640c980919b9210a9f2a56173a97af7 100644 (file)
@@ -14,7 +14,6 @@
 # limitations under the License.
 
 import contextlib
-import logging
 
 import mock
 from oslo.config import cfg
@@ -40,8 +39,6 @@ from neutron.services import provider_configuration as pconf
 from neutron.tests.unit import test_db_plugin
 
 
-LOG = logging.getLogger(__name__)
-
 DB_CORE_PLUGIN_KLASS = 'neutron.db.db_base_plugin_v2.NeutronDbPluginV2'
 DB_LB_PLUGIN_KLASS = (
     "neutron.services.loadbalancer."
index 06ec8b1464a1646ce1315aa3e34cfb551285b5d9..4c05632b711d86c75c40e199fe37b6caffebd0ed 100644 (file)
@@ -15,7 +15,6 @@
 # under the License.
 
 import contextlib
-import logging
 
 import webob.exc
 
@@ -28,8 +27,6 @@ from neutron.plugins.common import constants
 from neutron.services.metering import metering_plugin
 from neutron.tests.unit import test_db_plugin
 
-LOG = logging.getLogger(__name__)
-
 DB_METERING_PLUGIN_KLASS = (
     "neutron.services.metering."
     "metering_plugin.MeteringPlugin"
index b1543261a8c7a7dc595d4f98b1f710eadc1201bb..7c74a53870e4bc94d4bd7e3775c5551030dccdca 100644 (file)
@@ -14,7 +14,7 @@
 #    under the License.
 
 import fixtures
-import logging
+import logging as std_logging
 import mock
 from sqlalchemy.orm import query
 
@@ -48,7 +48,7 @@ class HelpersTest(base.BaseTestCase):
             fixtures.FakeLogger(
                 name=helpers.__name__,
                 format=base.LOG_FORMAT,
-                level=logging.DEBUG
+                level=std_logging.DEBUG
             ))
 
     def check_raw_segment(self, expected, observed):
index 633e4bb4c8c115b9f20a75ebd7330a09abd243a2..6db85b79f4c959ebd2a86a3c15149dbacef35f6e 100644 (file)
@@ -16,8 +16,6 @@
 #    @author: Salvatore Orlando, VMware
 #
 
-import logging
-
 import mock
 from oslo.config import cfg
 import webob.exc as webexc
@@ -39,7 +37,6 @@ from neutron.tests.unit import test_extensions
 from neutron.tests.unit import testlib_api
 
 
-LOG = logging.getLogger(__name__)
 DEFAULT_SERVICE_DEFS = [{'service_class': constants.DUMMY,
                          'plugin': dp.DUMMY_PLUGIN_NAME}]
 
index c77b855687bca89c31362eec82afa2ed8dca9a2a..536b7ea5a67c05f1dd9753458a9d7b7d675963ac 100644 (file)
@@ -13,7 +13,6 @@
 #    under the License.
 
 import httplib
-import logging
 import new
 import random
 
@@ -21,13 +20,14 @@ import eventlet
 from eventlet.green import urllib2
 import mock
 
+from neutron.openstack.common.gettextutils import _LI
+from neutron.openstack.common import log as logging
 from neutron.plugins.vmware.api_client import eventlet_client as client
 from neutron.plugins.vmware.api_client import eventlet_request as request
 from neutron.tests import base
 from neutron.tests.unit import vmware
 
 
-logging.basicConfig(level=logging.DEBUG)
 LOG = logging.getLogger("test_api_request_eventlet")
 
 
@@ -60,7 +60,7 @@ class ApiRequestEventletTest(base.BaseTestCase):
     def test_apirequest_spawn(self):
         def x(id):
             eventlet.greenthread.sleep(random.random())
-            LOG.info('spawned: %d' % id)
+            LOG.info(_LI('spawned: %d'), id)
 
         for i in range(10):
             request.EventletApiRequest._spawn(x, i)
@@ -72,8 +72,8 @@ class ApiRequestEventletTest(base.BaseTestCase):
             a._handle_request = mock.Mock()
             a.start()
             eventlet.greenthread.sleep(0.1)
-            logging.info('_handle_request called: %s' %
-                         a._handle_request.called)
+            LOG.info(_LI('_handle_request called: %s'),
+                     a._handle_request.called)
         request.EventletApiRequest.joinall()
 
     def test_join_with_handle_request(self):