Switch to using Oslo logging

This commit removes the tempest.common.log module and switches to
using the Oslo log module. The Oslo log module is required by
lockutils and it's dependent modules, so this patch migrates all of
Tempest to it so that there is only one logger in the project. This
also has the advantage of bringing Tempest's logging configuration
in line with other OpenStack projects.

Change-Id: I31b460e454123a4211c0a8a1dc91bbfd562ce81a
This commit is contained in:
Matthew Treinish 2013-07-26 16:58:26 -04:00
parent 6a97094c24
commit f4a9b0f55f
42 changed files with 52 additions and 169 deletions

View File

@ -1,3 +1,6 @@
[DEFAULT]
# log_config = /opt/stack/tempest/etc/logging.conf.sample
[identity]
# This section contains configuration options that a variety of Tempest
# test clients use when authenticating with different user/tenant

View File

@ -15,9 +15,9 @@
# License for the specific language governing permissions and limitations
# under the License.
from tempest.common import log as logging
from tempest import config
from tempest.exceptions import InvalidConfiguration
from tempest.openstack.common import log as logging
LOG = logging.getLogger(__name__)

View File

@ -19,9 +19,9 @@ import time
from tempest.api import compute
from tempest import clients
from tempest.common import log as logging
from tempest.common.utils.data_utils import parse_image_id
from tempest.common.utils.data_utils import rand_name
from tempest.openstack.common import log as logging
import tempest.test

View File

@ -16,9 +16,9 @@
# under the License.
from tempest.api.compute import base
from tempest.common import log as logging
from tempest.common.utils.data_utils import parse_image_id
from tempest import exceptions
from tempest.openstack.common import log as logging
from tempest.test import attr

View File

@ -15,7 +15,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from tempest.common import log as logging
from tempest.openstack.common import log as logging
LOG = logging.getLogger(__name__)

View File

@ -15,9 +15,9 @@
# under the License.
from tempest import clients
from tempest.common import log as logging
from tempest.common.utils.data_utils import rand_name
from tempest import exceptions
from tempest.openstack.common import log as logging
import tempest.test
LOG = logging.getLogger(__name__)

View File

@ -12,11 +12,11 @@
# License for the specific language governing permissions and limitations
# under the License.
from tempest.common import log as logging
import time
from tempest import clients
from tempest.common.utils.data_utils import rand_name
from tempest.openstack.common import log as logging
import tempest.test

View File

@ -13,13 +13,13 @@
# under the License.
import json
from tempest.common import log as logging
import testtools
from tempest.api.orchestration import base
from tempest.common.utils.data_utils import rand_name
from tempest.common.utils.linux.remote_client import RemoteClient
import tempest.config
from tempest.openstack.common import log as logging
from tempest.test import attr

View File

@ -12,10 +12,9 @@
# License for the specific language governing permissions and limitations
# under the License.
from tempest.common import log as logging
from tempest.api.orchestration import base
from tempest.common.utils.data_utils import rand_name
from tempest.openstack.common import log as logging
from tempest.test import attr

View File

@ -13,8 +13,8 @@
# under the License.
from tempest.api.volume import base
from tempest.common import log as logging
from tempest.common.utils.data_utils import rand_name
from tempest.openstack.common import log as logging
from tempest.services.volume.json.admin import volume_types_client
from tempest.services.volume.json import volumes_client
from tempest.test import attr

View File

@ -18,7 +18,7 @@
import time
from tempest import clients
from tempest.common import log as logging
from tempest.openstack.common import log as logging
import tempest.test
LOG = logging.getLogger(__name__)

View File

@ -13,8 +13,8 @@
# under the License.
from tempest.api.volume import base
from tempest.common import log as logging
from tempest.common.utils.data_utils import rand_name
from tempest.openstack.common import log as logging
from tempest.test import attr
LOG = logging.getLogger(__name__)

View File

@ -22,7 +22,7 @@ import subprocess
from oslo.config import cfg
import tempest.cli.output_parser
from tempest.common import log as logging
from tempest.openstack.common import log as logging
import tempest.test

View File

@ -17,11 +17,10 @@
"""Collection of utilities for parsing CLI clients output."""
from tempest.common import log as logging
import re
from tempest.openstack.common import log as logging
LOG = logging.getLogger(__name__)

View File

@ -21,7 +21,7 @@ from oslo.config import cfg
import testtools
import tempest.cli
from tempest.common import log as logging
from tempest.openstack.common import log as logging
CONF = cfg.CONF

View File

@ -18,7 +18,7 @@
import subprocess
import tempest.cli
from tempest.common import log as logging
from tempest.openstack.common import log as logging
LOG = logging.getLogger(__name__)

View File

@ -19,7 +19,7 @@ import re
import subprocess
import tempest.cli
from tempest.common import log as logging
from tempest.openstack.common import log as logging
LOG = logging.getLogger(__name__)

View File

@ -19,7 +19,7 @@ import re
import subprocess
import tempest.cli
from tempest.common import log as logging
from tempest.openstack.common import log as logging
LOG = logging.getLogger(__name__)

View File

@ -22,7 +22,7 @@ from oslo.config import cfg
import testtools
import tempest.cli
from tempest.common import log as logging
from tempest.openstack.common import log as logging
CONF = cfg.CONF

View File

@ -15,9 +15,9 @@
# License for the specific language governing permissions and limitations
# under the License.
from tempest.common import log as logging
from tempest import config
from tempest import exceptions
from tempest.openstack.common import log as logging
from tempest.services import botoclients
from tempest.services.compute.json.aggregates_client import \
AggregatesClientJSON

View File

@ -34,9 +34,8 @@ if not hasattr(urlparse, 'parse_qsl'):
import OpenSSL
from tempest.common import log as logging
from tempest import exceptions as exc
from tempest.openstack.common import log as logging
LOG = logging.getLogger(__name__)
USER_AGENT = 'tempest'

View File

@ -1,116 +0,0 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2013 NEC Corporation.
# All Rights Reserved.
#
# 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 ConfigParser
import inspect
import logging
import logging.config
import os
import re
from oslo.config import cfg
_DEFAULT_LOG_FORMAT = "%(asctime)s %(levelname)8s [%(name)s] %(message)s"
_DEFAULT_LOG_DATE_FORMAT = "%Y-%m-%d %H:%M:%S"
_loggers = {}
def getLogger(name='unknown'):
if len(_loggers) == 0:
loaded = _load_log_config()
getLogger.adapter = TestsAdapter if loaded else None
if name not in _loggers:
logger = logging.getLogger(name)
if getLogger.adapter:
_loggers[name] = getLogger.adapter(logger, name)
else:
_loggers[name] = logger
return _loggers[name]
def _load_log_config():
conf_dir = os.environ.get('TEMPEST_LOG_CONFIG_DIR', None)
conf_file = os.environ.get('TEMPEST_LOG_CONFIG', None)
if not conf_dir or not conf_file:
return False
log_config = os.path.join(conf_dir, conf_file)
try:
logging.config.fileConfig(log_config)
except ConfigParser.Error as exc:
raise cfg.ConfigFileParseError(log_config, str(exc))
return True
class TestsAdapter(logging.LoggerAdapter):
def __init__(self, logger, project_name):
self.logger = logger
self.project = project_name
self.regexp = re.compile(r"test_\w+\.py")
def __getattr__(self, key):
return getattr(self.logger, key)
def _get_test_name(self):
frames = inspect.stack()
for frame in frames:
binary_name = frame[1]
if self.regexp.search(binary_name) and 'self' in frame[0].f_locals:
return frame[0].f_locals.get('self').id()
elif frame[3] == '_run_cleanups':
#NOTE(myamazaki): method calling addCleanup
return frame[0].f_locals.get('self').case.id()
elif frame[3] in ['setUpClass', 'tearDownClass']:
#NOTE(myamazaki): setUpClass or tearDownClass
return "%s.%s.%s" % (frame[0].f_locals['cls'].__module__,
frame[0].f_locals['cls'].__name__,
frame[3])
return None
def process(self, msg, kwargs):
if 'extra' not in kwargs:
kwargs['extra'] = {}
extra = kwargs['extra']
test_name = self._get_test_name()
if test_name:
extra.update({'testname': test_name})
extra['extra'] = extra.copy()
return msg, kwargs
class TestsFormatter(logging.Formatter):
def __init__(self, fmt=None, datefmt=None):
super(TestsFormatter, self).__init__()
self.default_format = _DEFAULT_LOG_FORMAT
self.testname_format =\
"%(asctime)s %(levelname)8s [%(testname)s] %(message)s"
self.datefmt = _DEFAULT_LOG_DATE_FORMAT
def format(self, record):
extra = record.__dict__.get('extra', None)
if extra and 'testname' in extra:
self._fmt = self.testname_format
else:
self._fmt = self.default_format
return logging.Formatter.format(self, record)

View File

@ -24,8 +24,8 @@ from lxml import etree
import re
import time
from tempest.common import log as logging
from tempest import exceptions
from tempest.openstack.common import log as logging
from tempest.services.compute.xml.common import xml_to_json
# redrive rate limited calls at most twice

View File

@ -23,10 +23,9 @@ import sys
from oslo.config import cfg
from tempest.common import log as logging
from tempest.common.utils.misc import singleton
from tempest.openstack.common import log as logging
LOG = logging.getLogger(__name__)
identity_group = cfg.OptGroup(name='identity',
title="Keystone Configuration Options")
@ -603,7 +602,6 @@ class TempestConfig:
def __init__(self):
"""Initialize a configuration from a conf directory and conf file."""
config_files = []
failsafe_path = "/etc/tempest/" + self.DEFAULT_CONFIG_FILE
# Environment variables override defaults...
@ -618,8 +616,6 @@ class TempestConfig:
'TEMPEST_CONFIG' in os.environ):
path = failsafe_path
LOG.info("Using tempest config file %s" % path)
if not os.path.exists(path):
msg = "Config file %s not found" % path
print(RuntimeError(msg), file=sys.stderr)
@ -627,6 +623,9 @@ class TempestConfig:
config_files.append(path)
cfg.CONF([], project='tempest', default_config_files=config_files)
logging.setup('tempest')
LOG = logging.getLogger('tempest')
LOG.info("Using tempest config file %s" % path)
register_compute_opts(cfg.CONF)
register_identity_opts(cfg.CONF)

View File

@ -29,10 +29,10 @@ import novaclient.client
from tempest.api.network import common as net_common
from tempest.common import log as logging
from tempest.common import ssh
from tempest.common.utils.data_utils import rand_name
import tempest.manager
from tempest.openstack.common import log as logging
import tempest.test

View File

@ -15,8 +15,8 @@
# License for the specific language governing permissions and limitations
# under the License.
from tempest.common import log as logging
from tempest.common.utils.data_utils import rand_name
from tempest.openstack.common import log as logging
from tempest.scenario import manager

View File

@ -15,10 +15,9 @@
# License for the specific language governing permissions and limitations
# under the License.
from tempest.common import log as logging
from tempest.common.utils.data_utils import rand_name
from tempest.common.utils.linux.remote_client import RemoteClient
from tempest.openstack.common import log as logging
from tempest.scenario import manager

View File

@ -15,8 +15,8 @@
# License for the specific language governing permissions and limitations
# under the License.
from tempest.common import log as logging
from tempest.common.utils.data_utils import rand_name
from tempest.openstack.common import log as logging
from tempest.scenario import manager
LOG = logging.getLogger(__name__)

View File

@ -15,8 +15,8 @@
# License for the specific language governing permissions and limitations
# under the License.
from tempest.common import log as logging
from tempest.common.utils.data_utils import rand_name
from tempest.openstack.common import log as logging
from tempest.scenario import manager
LOG = logging.getLogger(__name__)

View File

@ -15,10 +15,9 @@
# License for the specific language governing permissions and limitations
# under the License.
from tempest.common import log as logging
from tempest.common.utils.data_utils import rand_name
from tempest.common.utils.linux.remote_client import RemoteClient
from tempest.openstack.common import log as logging
from tempest.scenario import manager

View File

@ -20,10 +20,10 @@ import time
from cinderclient import exceptions as cinder_exceptions
import testtools
from tempest.common import log as logging
from tempest.common.utils.data_utils import rand_name
from tempest.common.utils.linux.remote_client import RemoteClient
from tempest import exceptions
from tempest.openstack.common import log as logging
from tempest.scenario import manager
import tempest.test

View File

@ -21,9 +21,9 @@ import urllib
from lxml import etree
from tempest.common import log as logging
from tempest.common.rest_client import RestClientXML
from tempest import exceptions
from tempest.openstack.common import log as logging
from tempest.services.compute.xml.common import Document
from tempest.services.compute.xml.common import Element
from tempest.services.compute.xml.common import Text

View File

@ -23,9 +23,9 @@ import time
import urllib
from tempest.common import glance_http
from tempest.common import log as logging
from tempest.common.rest_client import RestClient
from tempest import exceptions
from tempest.openstack.common import log as logging
LOG = logging.getLogger(__name__)

View File

@ -16,9 +16,9 @@ import json
import time
import urllib
from tempest.common import log as logging
from tempest.common.rest_client import RestClient
from tempest import exceptions
from tempest.openstack.common import log as logging
LOG = logging.getLogger(__name__)

View File

@ -17,9 +17,9 @@ import urllib
from lxml import etree
from tempest.common import log as logging
from tempest.common.rest_client import RestClientXML
from tempest import exceptions
from tempest.openstack.common import log as logging
from tempest.services.compute.xml.common import Document
from tempest.services.compute.xml.common import Element
from tempest.services.compute.xml.common import xml_to_json

View File

@ -23,10 +23,10 @@ import testresources
import testtools
from tempest import clients
from tempest.common import log as logging
from tempest.common.utils.data_utils import rand_name
from tempest import config
from tempest import exceptions
from tempest.openstack.common import log as logging
LOG = logging.getLogger(__name__)

View File

@ -28,10 +28,10 @@ from boto import s3
import keystoneclient.exceptions
import tempest.clients
from tempest.common import log as logging
from tempest.common.utils.file_utils import have_effective_read_access
import tempest.config
from tempest import exceptions
from tempest.openstack.common import log as logging
import tempest.test
from tempest.thirdparty.boto.utils.wait import re_search_wait
from tempest.thirdparty.boto.utils.wait import state_wait
@ -58,8 +58,9 @@ def decision_maker():
A_I_IMAGES_READY = all_read(ami_path, aki_path, ari_path)
boto_logger = logging.getLogger('boto')
level = boto_logger.level
boto_logger.setLevel(orig_logging.CRITICAL) # suppress logging for these
level = boto_logger.logger.level
boto_logger.logger.setLevel(orig_logging.CRITICAL) # suppress logging
# for these
def _cred_sub_check(connection_data):
if not id_matcher.match(connection_data["aws_access_key_id"]):
@ -99,7 +100,7 @@ def decision_maker():
except keystoneclient.exceptions.Unauthorized:
S3_CAN_CONNECT_ERROR = "AWS credentials not set," +\
" faild to get them even by keystoneclient"
boto_logger.setLevel(level)
boto_logger.logger.setLevel(level)
return {'A_I_IMAGES_READY': A_I_IMAGES_READY,
'S3_CAN_CONNECT_ERROR': S3_CAN_CONNECT_ERROR,
'EC2_CAN_CONNECT_ERROR': EC2_CAN_CONNECT_ERROR}

View File

@ -19,10 +19,10 @@ from boto import exception
import testtools
from tempest import clients
from tempest.common import log as logging
from tempest.common.utils.data_utils import rand_name
from tempest.common.utils.linux.remote_client import RemoteClient
from tempest import exceptions
from tempest.openstack.common import log as logging
from tempest.test import attr
from tempest.thirdparty.boto.test import BotoTestCase
from tempest.thirdparty.boto.utils.s3 import s3_upload_dir

View File

@ -16,7 +16,7 @@
# under the License.
from tempest import clients
from tempest.common import log as logging
from tempest.openstack.common import log as logging
from tempest.test import attr
from tempest.thirdparty.boto.test import BotoTestCase

View File

@ -22,7 +22,7 @@ import re
import boto
import boto.s3.key
from tempest.common import log as logging
from tempest.openstack.common import log as logging
LOG = logging.getLogger(__name__)

View File

@ -21,8 +21,8 @@ import time
import boto.exception
from testtools import TestCase
from tempest.common import log as logging
import tempest.config
from tempest.openstack.common import log as logging
LOG = logging.getLogger(__name__)

View File

@ -21,10 +21,11 @@ import subprocess
import sys
from sqlalchemy import create_engine, MetaData
from tempest.common import log as logging
from tempest.common.ssh import Client
from tempest.common.utils.data_utils import rand_name
from tempest import exceptions
from tempest.openstack.common import log as logging
from tempest.scenario import manager
LOG = logging.getLogger(__name__)