diff --git a/octavia/amphorae/backends/agent/api_server/haproxy_compatibility.py b/octavia/amphorae/backends/agent/api_server/haproxy_compatibility.py index dd8b136175..85451c5228 100644 --- a/octavia/amphorae/backends/agent/api_server/haproxy_compatibility.py +++ b/octavia/amphorae/backends/agent/api_server/haproxy_compatibility.py @@ -12,10 +12,11 @@ # License for the specific language governing permissions and limitations # under the License. -import logging import re import subprocess +from oslo_log import log as logging + LOG = logging.getLogger(__name__) diff --git a/octavia/amphorae/backends/agent/api_server/keepalived.py b/octavia/amphorae/backends/agent/api_server/keepalived.py index e0400e7a14..26f9fcf133 100644 --- a/octavia/amphorae/backends/agent/api_server/keepalived.py +++ b/octavia/amphorae/backends/agent/api_server/keepalived.py @@ -12,13 +12,13 @@ # License for the specific language governing permissions and limitations # under the License. -import logging import os import stat import subprocess import flask import jinja2 +from oslo_log import log as logging import webob from octavia.amphorae.backends.agent.api_server import listener diff --git a/octavia/amphorae/backends/agent/api_server/listener.py b/octavia/amphorae/backends/agent/api_server/listener.py index e74ab5ecf6..57cd24d651 100644 --- a/octavia/amphorae/backends/agent/api_server/listener.py +++ b/octavia/amphorae/backends/agent/api_server/listener.py @@ -14,7 +14,6 @@ import hashlib import io -import logging import os import re import shutil @@ -24,6 +23,7 @@ import subprocess import flask import jinja2 from oslo_config import cfg +from oslo_log import log as logging import six import webob from werkzeug import exceptions diff --git a/octavia/amphorae/backends/agent/api_server/osutils.py b/octavia/amphorae/backends/agent/api_server/osutils.py index d4c881ce99..d246de057a 100644 --- a/octavia/amphorae/backends/agent/api_server/osutils.py +++ b/octavia/amphorae/backends/agent/api_server/osutils.py @@ -13,7 +13,6 @@ # under the License. import ipaddress -import logging import os import platform import shutil @@ -22,6 +21,7 @@ import subprocess import jinja2 from oslo_config import cfg +from oslo_log import log as logging import six import webob from werkzeug import exceptions diff --git a/octavia/amphorae/backends/agent/api_server/plug.py b/octavia/amphorae/backends/agent/api_server/plug.py index df2500cade..d8ffbae8c2 100644 --- a/octavia/amphorae/backends/agent/api_server/plug.py +++ b/octavia/amphorae/backends/agent/api_server/plug.py @@ -14,7 +14,6 @@ # under the License. import ipaddress -import logging import os import socket import stat @@ -23,6 +22,7 @@ import subprocess import jinja2 import netifaces from oslo_config import cfg +from oslo_log import log as logging import pyroute2 import six import webob diff --git a/octavia/api/root_controller.py b/octavia/api/root_controller.py index 43e513118d..d56caf4d56 100644 --- a/octavia/api/root_controller.py +++ b/octavia/api/root_controller.py @@ -12,9 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. -import logging - from oslo_config import cfg +from oslo_log import log as logging from pecan import rest from wsme import types as wtypes from wsmeext import pecan as wsme_pecan diff --git a/octavia/api/v1/controllers/base.py b/octavia/api/v1/controllers/base.py index 48aea54685..7b289a4d28 100644 --- a/octavia/api/v1/controllers/base.py +++ b/octavia/api/v1/controllers/base.py @@ -12,9 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. -import logging - from oslo_config import cfg +from oslo_log import log as logging from pecan import rest from stevedore import driver as stevedore_driver diff --git a/octavia/api/v1/controllers/health_monitor.py b/octavia/api/v1/controllers/health_monitor.py index 0889be5b29..2b387a616d 100644 --- a/octavia/api/v1/controllers/health_monitor.py +++ b/octavia/api/v1/controllers/health_monitor.py @@ -13,9 +13,8 @@ # License for the specific language governing permissions and limitations # under the License. -import logging - from oslo_db import exception as odb_exceptions +from oslo_log import log as logging from oslo_utils import excutils import pecan from wsmeext import pecan as wsme_pecan diff --git a/octavia/api/v1/controllers/l7policy.py b/octavia/api/v1/controllers/l7policy.py index 0edbfb7274..2a5a3b06a5 100644 --- a/octavia/api/v1/controllers/l7policy.py +++ b/octavia/api/v1/controllers/l7policy.py @@ -12,9 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. -import logging - import oslo_db.exception as oslo_exc +from oslo_log import log as logging from oslo_utils import excutils import pecan from wsme import types as wtypes diff --git a/octavia/api/v1/controllers/l7rule.py b/octavia/api/v1/controllers/l7rule.py index 2b2e84e452..ae0c83e027 100644 --- a/octavia/api/v1/controllers/l7rule.py +++ b/octavia/api/v1/controllers/l7rule.py @@ -12,9 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. -import logging - import oslo_db.exception as oslo_exc +from oslo_log import log as logging from oslo_utils import excutils import pecan from wsme import types as wtypes diff --git a/octavia/api/v1/controllers/listener.py b/octavia/api/v1/controllers/listener.py index 2bfdc7c707..e07303a4dd 100644 --- a/octavia/api/v1/controllers/listener.py +++ b/octavia/api/v1/controllers/listener.py @@ -13,9 +13,8 @@ # License for the specific language governing permissions and limitations # under the License. -import logging - from oslo_db import exception as odb_exceptions +from oslo_log import log as logging from oslo_utils import excutils import pecan from wsme import types as wtypes diff --git a/octavia/api/v1/controllers/member.py b/octavia/api/v1/controllers/member.py index 972635d8b1..a08642bfc3 100644 --- a/octavia/api/v1/controllers/member.py +++ b/octavia/api/v1/controllers/member.py @@ -13,9 +13,8 @@ # License for the specific language governing permissions and limitations # under the License. -import logging - import oslo_db.exception as oslo_exc +from oslo_log import log as logging from oslo_utils import excutils import pecan from wsme import types as wtypes diff --git a/octavia/api/v1/controllers/pool.py b/octavia/api/v1/controllers/pool.py index f499b6862c..ed17a0fd07 100644 --- a/octavia/api/v1/controllers/pool.py +++ b/octavia/api/v1/controllers/pool.py @@ -13,9 +13,8 @@ # License for the specific language governing permissions and limitations # under the License. -import logging - from oslo_db import exception as odb_exceptions +from oslo_log import log as logging from oslo_utils import excutils import pecan from wsme import types as wtypes diff --git a/octavia/api/v2/controllers/amphora.py b/octavia/api/v2/controllers/amphora.py index c67f11cbd6..ee638aa23c 100644 --- a/octavia/api/v2/controllers/amphora.py +++ b/octavia/api/v2/controllers/amphora.py @@ -13,9 +13,8 @@ # License for the specific language governing permissions and limitations # under the License. -import logging - from oslo_config import cfg +from oslo_log import log as logging import oslo_messaging as messaging from oslo_utils import excutils import pecan diff --git a/octavia/api/v2/controllers/base.py b/octavia/api/v2/controllers/base.py index f9c143e468..14565c5f08 100644 --- a/octavia/api/v2/controllers/base.py +++ b/octavia/api/v2/controllers/base.py @@ -12,9 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. -import logging - from oslo_config import cfg +from oslo_log import log as logging from pecan import rest from wsme import types as wtypes diff --git a/octavia/api/v2/controllers/health_monitor.py b/octavia/api/v2/controllers/health_monitor.py index be0e66d73b..072da77e34 100644 --- a/octavia/api/v2/controllers/health_monitor.py +++ b/octavia/api/v2/controllers/health_monitor.py @@ -13,10 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. -import logging - from oslo_config import cfg from oslo_db import exception as odb_exceptions +from oslo_log import log as logging from oslo_utils import excutils import pecan from wsme import types as wtypes diff --git a/octavia/api/v2/controllers/l7policy.py b/octavia/api/v2/controllers/l7policy.py index 9aa0099706..66f27d2941 100644 --- a/octavia/api/v2/controllers/l7policy.py +++ b/octavia/api/v2/controllers/l7policy.py @@ -12,10 +12,9 @@ # License for the specific language governing permissions and limitations # under the License. -import logging - from oslo_config import cfg from oslo_db import exception as odb_exceptions +from oslo_log import log as logging from oslo_utils import excutils import pecan from wsme import types as wtypes diff --git a/octavia/api/v2/controllers/l7rule.py b/octavia/api/v2/controllers/l7rule.py index 442f6c4a20..9a8e9f5c91 100644 --- a/octavia/api/v2/controllers/l7rule.py +++ b/octavia/api/v2/controllers/l7rule.py @@ -12,9 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. -import logging - from oslo_db import exception as odb_exceptions +from oslo_log import log as logging from oslo_utils import excutils import pecan from wsme import types as wtypes diff --git a/octavia/api/v2/controllers/listener.py b/octavia/api/v2/controllers/listener.py index dbcf6a45b8..e67eedc4c6 100644 --- a/octavia/api/v2/controllers/listener.py +++ b/octavia/api/v2/controllers/listener.py @@ -13,10 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. -import logging - from oslo_config import cfg from oslo_db import exception as odb_exceptions +from oslo_log import log as logging from oslo_utils import excutils import pecan from stevedore import driver as stevedore_driver diff --git a/octavia/api/v2/controllers/member.py b/octavia/api/v2/controllers/member.py index d4e11008c4..54276f8375 100644 --- a/octavia/api/v2/controllers/member.py +++ b/octavia/api/v2/controllers/member.py @@ -13,9 +13,8 @@ # License for the specific language governing permissions and limitations # under the License. -import logging - from oslo_db import exception as odb_exceptions +from oslo_log import log as logging from oslo_utils import excutils import pecan from wsme import types as wtypes diff --git a/octavia/api/v2/controllers/pool.py b/octavia/api/v2/controllers/pool.py index 0c4e27ffdb..863fd56f9c 100644 --- a/octavia/api/v2/controllers/pool.py +++ b/octavia/api/v2/controllers/pool.py @@ -13,10 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. -import logging - from oslo_config import cfg from oslo_db import exception as odb_exceptions +from oslo_log import log as logging from oslo_utils import excutils import pecan from wsme import types as wtypes diff --git a/octavia/common/policy.py b/octavia/common/policy.py index c2a676c0a3..0009406f30 100644 --- a/octavia/common/policy.py +++ b/octavia/common/policy.py @@ -12,9 +12,8 @@ """Policy Engine For Octavia.""" -import logging - from oslo_config import cfg +from oslo_log import log as logging from oslo_policy import policy as oslo_policy from oslo_utils import excutils diff --git a/octavia/common/stats.py b/octavia/common/stats.py index b795545b60..5e35de3125 100644 --- a/octavia/common/stats.py +++ b/octavia/common/stats.py @@ -12,7 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. -import logging +from oslo_log import log as logging from octavia.common import constants from octavia.common import data_models diff --git a/octavia/controller/worker/controller_worker.py b/octavia/controller/worker/controller_worker.py index db16ab293a..4fbcd44b0f 100644 --- a/octavia/controller/worker/controller_worker.py +++ b/octavia/controller/worker/controller_worker.py @@ -13,9 +13,9 @@ # under the License. # -import logging from oslo_config import cfg +from oslo_log import log as logging from oslo_utils import excutils from sqlalchemy.orm import exc as db_exceptions from taskflow.listeners import logging as tf_logging diff --git a/octavia/controller/worker/task_utils.py b/octavia/controller/worker/task_utils.py index c5bc3f93be..34d955d4a8 100644 --- a/octavia/controller/worker/task_utils.py +++ b/octavia/controller/worker/task_utils.py @@ -14,7 +14,7 @@ """ Methods common to the controller work tasks.""" -import logging +from oslo_log import log as logging from octavia.common import constants from octavia.db import api as db_apis diff --git a/octavia/controller/worker/tasks/amphora_driver_tasks.py b/octavia/controller/worker/tasks/amphora_driver_tasks.py index e1635e3e67..097ca2eaa0 100644 --- a/octavia/controller/worker/tasks/amphora_driver_tasks.py +++ b/octavia/controller/worker/tasks/amphora_driver_tasks.py @@ -13,9 +13,8 @@ # under the License. # -import logging - from oslo_config import cfg +from oslo_log import log as logging import six from stevedore import driver as stevedore_driver from taskflow import task diff --git a/octavia/controller/worker/tasks/compute_tasks.py b/octavia/controller/worker/tasks/compute_tasks.py index e6cc50a05d..cd0fb3c6de 100644 --- a/octavia/controller/worker/tasks/compute_tasks.py +++ b/octavia/controller/worker/tasks/compute_tasks.py @@ -13,10 +13,10 @@ # under the License. # -import logging import time from oslo_config import cfg +from oslo_log import log as logging import six from stevedore import driver as stevedore_driver from taskflow import task diff --git a/octavia/controller/worker/tasks/database_tasks.py b/octavia/controller/worker/tasks/database_tasks.py index c43d5946f5..e2a45be386 100644 --- a/octavia/controller/worker/tasks/database_tasks.py +++ b/octavia/controller/worker/tasks/database_tasks.py @@ -13,10 +13,9 @@ # under the License. # -import logging - from oslo_config import cfg from oslo_db import exception as odb_exceptions +from oslo_log import log as logging from oslo_utils import excutils from oslo_utils import uuidutils import six diff --git a/octavia/controller/worker/tasks/network_tasks.py b/octavia/controller/worker/tasks/network_tasks.py index 43a09a69f5..0c1f949f4e 100644 --- a/octavia/controller/worker/tasks/network_tasks.py +++ b/octavia/controller/worker/tasks/network_tasks.py @@ -13,9 +13,8 @@ # under the License. # -import logging - from oslo_config import cfg +from oslo_log import log as logging import six from taskflow import task from taskflow.types import failure diff --git a/octavia/db/migration/alembic_migrations/env.py b/octavia/db/migration/alembic_migrations/env.py index 0aed3848be..f290773c9e 100644 --- a/octavia/db/migration/alembic_migrations/env.py +++ b/octavia/db/migration/alembic_migrations/env.py @@ -14,7 +14,6 @@ from __future__ import with_statement -from logging import config as logging_config import sys from alembic import context @@ -30,10 +29,6 @@ except AttributeError: " alembic actions.") sys.exit(1) -# Interpret the config file for Python logging. -# This line sets up loggers basically. -logging_config.fileConfig(config.config_file_name) - # add your model's MetaData object here # for 'autogenerate' support # from myapp import mymodel diff --git a/octavia/db/migration/cli.py b/octavia/db/migration/cli.py index b6e8b6daa1..f38fd8e099 100644 --- a/octavia/db/migration/cli.py +++ b/octavia/db/migration/cli.py @@ -20,11 +20,15 @@ from alembic import config as alembic_cfg from alembic import util as alembic_u from oslo_config import cfg from oslo_db import options +from oslo_log import log from octavia.i18n import _ CONF = cfg.CONF options.set_defaults(CONF) +log.set_defaults() +log.register_options(CONF) +log.setup(CONF, 'octavia-db-manage') def do_alembic_command(config, cmd, *args, **kwargs): diff --git a/octavia/hacking/checks.py b/octavia/hacking/checks.py index f3a328b23f..91a2ada4ec 100644 --- a/octavia/hacking/checks.py +++ b/octavia/hacking/checks.py @@ -69,6 +69,7 @@ no_basestring_re = re.compile(r"\bbasestring\b") no_iteritems_re = re.compile(r".*\.iteritems\(\)") no_eventlet_re = re.compile(r'(import|from)\s+[(]?eventlet') no_line_continuation_backslash_re = re.compile(r'.*(\\)\n') +no_logging_re = re.compile(r'(import|from)\s+[(]?logging') def _translation_checks_not_enforced(filename): @@ -288,6 +289,19 @@ def revert_must_have_kwargs(logical_line): yield 0, msg +def check_no_logging_imports(logical_line): + """O348 - Usage of Python logging module not allowed. + + :param logical_line: The logical line to check. + :returns: None if the logical line passes the check, otherwise a tuple + is yielded that contains the offending index in logical line + and a message describe the check validation failure. + """ + if no_logging_re.match(logical_line): + msg = 'O348 Usage of Python logging module not allowed, use oslo_log' + yield logical_line.index('logging'), msg + + def factory(register): register(assert_true_instance) register(assert_equal_or_not_none) @@ -304,3 +318,4 @@ def factory(register): register(check_no_eventlet_imports) register(check_line_continuation_no_backslash) register(revert_must_have_kwargs) + register(check_no_logging_imports) diff --git a/octavia/tests/unit/common/test_policy.py b/octavia/tests/unit/common/test_policy.py index e43b0bb388..3ea60c90cf 100644 --- a/octavia/tests/unit/common/test_policy.py +++ b/octavia/tests/unit/common/test_policy.py @@ -12,10 +12,10 @@ """Test of Policy Engine For Octavia.""" -import logging import tempfile from oslo_config import fixture as oslo_fixture +from oslo_log import log as logging from oslo_policy import policy as oslo_policy import requests_mock