Skip to content

Commit

Permalink
Move from Python logging to Openstack logging
Browse files Browse the repository at this point in the history
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
  • Loading branch information
akashgangil committed Aug 2, 2014
1 parent 1d8afc7 commit 1a0be0e
Show file tree
Hide file tree
Showing 17 changed files with 29 additions and 53 deletions.
2 changes: 2 additions & 0 deletions neutron/db/migration/alembic_migrations/heal_script.py
Expand Up @@ -34,6 +34,8 @@


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
Expand Down
4 changes: 0 additions & 4 deletions neutron/plugins/cisco/common/cisco_credentials_v2.py
Expand Up @@ -14,16 +14,12 @@
#
# @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."""
Expand Down
2 changes: 1 addition & 1 deletion neutron/plugins/cisco/models/virt_phy_sw_v2.py
Expand Up @@ -18,7 +18,6 @@
#

import inspect
import logging
import sys

from neutron.api.v2 import attributes
Expand All @@ -27,6 +26,7 @@
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
Expand Down
2 changes: 1 addition & 1 deletion neutron/plugins/cisco/network_plugin.py
Expand Up @@ -14,14 +14,14 @@
#
# @author: Sumit Naiksatam, Cisco Systems, Inc.

import logging

import webob.exc as wexc

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
Expand Down
Expand Up @@ -19,11 +19,11 @@
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
Expand Down
2 changes: 1 addition & 1 deletion neutron/plugins/cisco/nexus/cisco_nexus_plugin_v2.py
Expand Up @@ -22,10 +22,10 @@
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
Expand Down
5 changes: 0 additions & 5 deletions neutron/plugins/cisco/nexus/cisco_nexus_snippets.py
Expand Up @@ -19,11 +19,6 @@
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 = """
Expand Down
5 changes: 0 additions & 5 deletions neutron/plugins/ml2/drivers/cisco/nexus/nexus_snippets.py
Expand Up @@ -18,11 +18,6 @@
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 = """
Expand Down
13 changes: 6 additions & 7 deletions neutron/plugins/vmware/plugins/base.py
Expand Up @@ -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
Expand Down Expand Up @@ -51,7 +50,9 @@
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
Expand Down Expand Up @@ -2080,12 +2081,10 @@ def disconnect_network(self, context, network_gateway_id,
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(
Expand Down
11 changes: 5 additions & 6 deletions neutron/tests/base.py
Expand Up @@ -17,7 +17,7 @@

import contextlib
import gc
import logging
import logging as std_logging
import os
import os.path
import sys
Expand Down Expand Up @@ -110,7 +110,6 @@ def config_parse(conf=None, args=None):

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)
Expand All @@ -120,12 +119,12 @@ def setUp(self):
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,
Expand All @@ -138,7 +137,7 @@ def setUp(self):
fixtures.FakeLogger(
name='neutron.api.extensions',
format=LOG_FORMAT,
level=logging.ERROR,
level=std_logging.ERROR,
nuke_handlers=capture_logs,
))

Expand Down
9 changes: 5 additions & 4 deletions neutron/tests/unit/cisco/test_network_plugin.py
Expand Up @@ -16,7 +16,7 @@
import contextlib
import copy
import inspect
import logging
import logging as std_logging
import mock

import six
Expand All @@ -33,6 +33,7 @@
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
Expand Down Expand Up @@ -923,7 +924,7 @@ def side_effect(*args, **kwargs):
*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,
Expand Down Expand Up @@ -1052,10 +1053,10 @@ def setUp(self):
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)
Expand Down
2 changes: 0 additions & 2 deletions neutron/tests/unit/db/firewall/test_db_firewall.py
Expand Up @@ -16,7 +16,6 @@
# @author: Sumit Naiksatam, sumitnaiksatam@gmail.com, Big Switch Networks, Inc.

import contextlib
import logging

import mock
import webob.exc
Expand All @@ -35,7 +34,6 @@
from neutron.tests.unit import test_db_plugin


LOG = logging.getLogger(__name__)
DB_FW_PLUGIN_KLASS = (
"neutron.db.firewall.firewall_db.Firewall_db_mixin"
)
Expand Down
3 changes: 0 additions & 3 deletions neutron/tests/unit/db/loadbalancer/test_db_loadbalancer.py
Expand Up @@ -14,7 +14,6 @@
# limitations under the License.

import contextlib
import logging

import mock
from oslo.config import cfg
Expand All @@ -40,8 +39,6 @@
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."
Expand Down
3 changes: 0 additions & 3 deletions neutron/tests/unit/db/metering/test_db_metering.py
Expand Up @@ -15,7 +15,6 @@
# under the License.

import contextlib
import logging

import webob.exc

Expand All @@ -28,8 +27,6 @@
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"
Expand Down
4 changes: 2 additions & 2 deletions neutron/tests/unit/ml2/test_helpers.py
Expand Up @@ -14,7 +14,7 @@
# under the License.

import fixtures
import logging
import logging as std_logging
import mock
from sqlalchemy.orm import query

Expand Down Expand Up @@ -48,7 +48,7 @@ def setUp(self):
fixtures.FakeLogger(
name=helpers.__name__,
format=base.LOG_FORMAT,
level=logging.DEBUG
level=std_logging.DEBUG
))

def check_raw_segment(self, expected, observed):
Expand Down
3 changes: 0 additions & 3 deletions neutron/tests/unit/test_servicetype.py
Expand Up @@ -16,8 +16,6 @@
# @author: Salvatore Orlando, VMware
#

import logging

import mock
from oslo.config import cfg
import webob.exc as webexc
Expand All @@ -39,7 +37,6 @@
from neutron.tests.unit import testlib_api


LOG = logging.getLogger(__name__)
DEFAULT_SERVICE_DEFS = [{'service_class': constants.DUMMY,
'plugin': dp.DUMMY_PLUGIN_NAME}]

Expand Down
10 changes: 5 additions & 5 deletions neutron/tests/unit/vmware/apiclient/test_api_eventlet_request.py
Expand Up @@ -13,21 +13,21 @@
# under the License.

import httplib
import logging
import new
import random

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")


Expand Down Expand Up @@ -60,7 +60,7 @@ def test_construct_eventlet_api_request(self):
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)
Expand All @@ -72,8 +72,8 @@ def test_apirequest_start(self):
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):
Expand Down

0 comments on commit 1a0be0e

Please sign in to comment.