From 72ab1442ad76980f0db13164a697254742775f63 Mon Sep 17 00:00:00 2001 From: Tom Barron Date: Mon, 4 Apr 2016 07:01:28 -0400 Subject: [PATCH] Remove unused logging import and LOG global This patch removes unused global LOG variable and logging imports from various manila modules, and adds a script to be run as part of pep8 that will ensure that these do not creep back into the codebase. Change-Id: I162c4b2478df45aaf6ea8009b102d6de1a4e309e --- manila/api/v2/share_replicas.py | 2 -- manila/compute/nova.py | 3 -- manila/share/drivers/glusterfs/__init__.py | 2 -- .../netapp/dataontap/protocols/cifs_cmode.py | 5 ---- manila/share/utils.py | 4 --- .../share/drivers/emc/plugins/vnx/utils.py | 3 -- .../dataontap/protocols/test_cifs_cmode.py | 7 ----- .../share/drivers/zfssa/test_zfssarest.py | 4 --- manila/volume/cinder.py | 4 --- tools/check_logging.sh | 28 +++++++++++++++++++ tox.ini | 2 ++ 11 files changed, 30 insertions(+), 34 deletions(-) create mode 100755 tools/check_logging.sh diff --git a/manila/api/v2/share_replicas.py b/manila/api/v2/share_replicas.py index b4fb4d6f77..3cca6cda01 100644 --- a/manila/api/v2/share_replicas.py +++ b/manila/api/v2/share_replicas.py @@ -15,7 +15,6 @@ """The Share Replication API.""" -from oslo_log import log import six import webob from webob import exc @@ -30,7 +29,6 @@ from manila.i18n import _ from manila import share -LOG = log.getLogger(__name__) MIN_SUPPORTED_API_VERSION = '2.11' diff --git a/manila/compute/nova.py b/manila/compute/nova.py index d0c4d08299..f273d0ded7 100644 --- a/manila/compute/nova.py +++ b/manila/compute/nova.py @@ -21,7 +21,6 @@ from novaclient import client as nova_client from novaclient import exceptions as nova_exception from novaclient import utils from oslo_config import cfg -from oslo_log import log import six from manila.common import client_auth @@ -102,8 +101,6 @@ CONF.register_opts(nova_opts, NOVA_GROUP) ks_loading.register_session_conf_options(CONF, NOVA_GROUP) ks_loading.register_auth_conf_options(CONF, NOVA_GROUP) -LOG = log.getLogger(__name__) - def list_opts(): return client_auth.AuthClientLoader.list_opts(NOVA_GROUP) diff --git a/manila/share/drivers/glusterfs/__init__.py b/manila/share/drivers/glusterfs/__init__.py index 49dc26e451..9f155b0441 100644 --- a/manila/share/drivers/glusterfs/__init__.py +++ b/manila/share/drivers/glusterfs/__init__.py @@ -29,7 +29,6 @@ import socket import sys from oslo_config import cfg -from oslo_log import log from manila import exception from manila.i18n import _ @@ -39,7 +38,6 @@ from manila.share.drivers.ganesha import utils as ganesha_utils from manila.share.drivers.glusterfs import layout from manila import utils -LOG = log.getLogger(__name__) GlusterfsManilaShare_opts = [ cfg.StrOpt('glusterfs_nfs_server_type', diff --git a/manila/share/drivers/netapp/dataontap/protocols/cifs_cmode.py b/manila/share/drivers/netapp/dataontap/protocols/cifs_cmode.py index 23e4844b11..7ce58aeecf 100644 --- a/manila/share/drivers/netapp/dataontap/protocols/cifs_cmode.py +++ b/manila/share/drivers/netapp/dataontap/protocols/cifs_cmode.py @@ -17,8 +17,6 @@ NetApp cDOT CIFS protocol helper class. import re -from oslo_log import log - from manila.common import constants from manila import exception from manila.i18n import _ @@ -26,9 +24,6 @@ from manila.share.drivers.netapp.dataontap.protocols import base from manila.share.drivers.netapp import utils as na_utils -LOG = log.getLogger(__name__) - - class NetAppCmodeCIFSHelper(base.NetAppBaseHelper): """NetApp cDOT CIFS protocol helper class.""" diff --git a/manila/share/utils.py b/manila/share/utils.py index b96218342f..2bb3c41e8b 100644 --- a/manila/share/utils.py +++ b/manila/share/utils.py @@ -16,10 +16,6 @@ """Share-related Utilities and helpers.""" -from oslo_log import log - -LOG = log.getLogger(__name__) - DEFAULT_POOL_NAME = '_pool0' diff --git a/manila/tests/share/drivers/emc/plugins/vnx/utils.py b/manila/tests/share/drivers/emc/plugins/vnx/utils.py index 055039ab43..2ccbfee9b1 100644 --- a/manila/tests/share/drivers/emc/plugins/vnx/utils.py +++ b/manila/tests/share/drivers/emc/plugins/vnx/utils.py @@ -17,12 +17,9 @@ import doctest from lxml import doctestcompare import mock -from oslo_log import log import six -LOG = log.getLogger(__name__) - CHECKER = doctestcompare.LXMLOutputChecker() PARSE_XML = doctest.register_optionflag('PARSE_XML') diff --git a/manila/tests/share/drivers/netapp/dataontap/protocols/test_cifs_cmode.py b/manila/tests/share/drivers/netapp/dataontap/protocols/test_cifs_cmode.py index 7d1b1f0ace..143ba018b9 100644 --- a/manila/tests/share/drivers/netapp/dataontap/protocols/test_cifs_cmode.py +++ b/manila/tests/share/drivers/netapp/dataontap/protocols/test_cifs_cmode.py @@ -19,7 +19,6 @@ import copy import ddt import mock -from oslo_log import log from manila.common import constants from manila import exception @@ -35,12 +34,6 @@ class NetAppClusteredCIFSHelperTestCase(test.TestCase): def setUp(self): super(NetAppClusteredCIFSHelperTestCase, self).setUp() - # Mock loggers as themselves to allow logger arg validation - mock_logger = log.getLogger('mock_logger') - self.mock_object(cifs_cmode.LOG, - 'error', - mock.Mock(side_effect=mock_logger.error)) - self.mock_context = mock.Mock() self.mock_client = mock.Mock() diff --git a/manila/tests/share/drivers/zfssa/test_zfssarest.py b/manila/tests/share/drivers/zfssa/test_zfssarest.py index 9bb3717117..ae4566618a 100644 --- a/manila/tests/share/drivers/zfssa/test_zfssarest.py +++ b/manila/tests/share/drivers/zfssa/test_zfssarest.py @@ -15,7 +15,6 @@ Unit tests for Oracle's ZFSSA REST API. """ import mock -from oslo_log import log from manila import exception from manila.share.drivers.zfssa import restclient @@ -24,9 +23,6 @@ from manila import test from manila.tests import fake_zfssa -LOG = log.getLogger(__name__) - - class ZFSSAApiTestCase(test.TestCase): """Tests ZFSSAApi.""" diff --git a/manila/volume/cinder.py b/manila/volume/cinder.py index 7e7d9541af..adca896c2d 100644 --- a/manila/volume/cinder.py +++ b/manila/volume/cinder.py @@ -23,7 +23,6 @@ from cinderclient import exceptions as cinder_exception from cinderclient.v2 import client as cinder_client from keystoneauth1 import loading as ks_loading from oslo_config import cfg -from oslo_log import log import six from manila.common import client_auth @@ -107,9 +106,6 @@ ks_loading.register_session_conf_options(CONF, CINDER_GROUP) ks_loading.register_auth_conf_options(CONF, CINDER_GROUP) -LOG = log.getLogger(__name__) - - def list_opts(): return client_auth.AuthClientLoader.list_opts(CINDER_GROUP) diff --git a/tools/check_logging.sh b/tools/check_logging.sh new file mode 100755 index 0000000000..6632dda82e --- /dev/null +++ b/tools/check_logging.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +tree=$1 + +tmpfile=$(mktemp) + +find $tree -name '*.py' \ + | xargs grep -l 'import log' \ + | xargs grep -l '^LOG =' \ + | xargs grep -c 'LOG' \ + | grep ':1$' \ + | awk -F ':' '{print $1}' > $tmpfile + +count=$(wc -l < $tmpfile) + +if [[ count -eq 0 ]]; then + rm $tmpfile + exit 0 +fi + +echo 'Found files with unused LOG variable (see https://review.openstack.org/#/c/301054):' +cat $tmpfile +rm $tmpfile +exit 1 + + + + diff --git a/tox.ini b/tox.ini index 68b5fbbaaa..d465c687a4 100644 --- a/tox.ini +++ b/tox.ini @@ -40,7 +40,9 @@ commands = contrib/ci/post_test_hook.sh \ devstack/plugin.sh \ tools/cover.sh \ + tools/check_logging.sh \ run_tests.sh + {toxinidir}/tools/check_logging.sh {toxinidir}/manila [testenv:genconfig] whitelist_externals = bash