Fix defect of 'separate log level for Rally'

Change-Id: I4b765a6c3f5c8407ecf1fc4066d7774f0bab7ada
This commit is contained in:
Oleh Anufriiev 2014-11-17 17:21:10 +02:00
parent 7873ffb495
commit 3641bb922c
10 changed files with 140 additions and 6 deletions

View File

@ -1,7 +1,7 @@
from oslo.config import cfg
from rally.benchmark.context import base
from rally.openstack.common import log as logging
from rally import log as logging
from rally import osclients
from rally import utils

View File

@ -8,6 +8,15 @@
#fatal_exception_format_errors=false
#
# Options defined in rally.log
#
# Print debugging output only for Rally. Off-site components
# stay quiet. (boolean value)
#rally_debug=false
#
# Options defined in rally.openstack.common.eventlet_backdoor
#
@ -372,6 +381,13 @@
# Cluster status polling interval in seconds (integer value)
#cluster_check_interval=5
# A timeout in seconds for a cluster create operation (integer
# value)
#job_execution_timeout=600
# Cluster status polling interval in seconds (integer value)
#job_check_interval=5
[database]
@ -514,7 +530,7 @@
# How many concurrent threads use for serving users context
# (integer value)
#concurrent=30
#resource_management_workers=30
# ID of domain in which projects will be created. (string
# value)

View File

@ -17,7 +17,7 @@ from rally.benchmark.context import base
from rally.benchmark.context.cleanup import manager
from rally import exceptions
from rally.i18n import _
from rally.openstack.common import log as logging
from rally import log as logging
from rally import utils as rutils

View File

@ -20,7 +20,7 @@ from oslo.config import cfg
from rally.benchmark.context.cleanup import base
from rally import broker
from rally.i18n import _
from rally.openstack.common import log as logging
from rally import log as logging
from rally import osclients
from rally import utils as rutils

View File

@ -18,7 +18,7 @@ from neutronclient.common import exceptions as neutron_exceptions
from rally.benchmark.context.cleanup import base
from rally.benchmark.scenarios.keystone import utils as kutils
from rally.benchmark.wrappers import keystone as keystone_wrapper
from rally.openstack.common import log as logging
from rally import log as logging
LOG = logging.getLogger(__name__)

View File

@ -1,4 +1,4 @@
# Copyright 2013: Mirantis Inc.
# Copyright 2014: Mirantis Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may

View File

@ -11,3 +11,4 @@ Rally Specific Commandments
- [N301] Ensure that ``assert_*`` methods from ``mock`` library is used correctly
- [N302] Sub-error of N301, related to nonexistent "assert_called"
- [N303] Sub-error of N301, related to nonexistent "assert_called_once"
- [N310] Ensure that ``rally.log`` is used instead of ``rally.openstack.common.log``

View File

@ -79,5 +79,22 @@ def check_assert_methods_from_mock(logical_line, filename):
"custom_msg": custom_msg})
def check_import_of_logging(logical_line, filename):
"""Check correctness import of logging module N310."""
excluded_files = ["./rally/log.py"]
forbidden_imports = ["from rally.openstack.common import log",
"import rally.openstack.common.log"
"import logging"]
if filename not in excluded_files:
for forbidden_import in forbidden_imports:
if logical_line.startswith(forbidden_import):
yield (0, "N310 Wrong module for logging is imported. Please "
"use `rally.log` instead.")
def factory(register):
register(check_assert_methods_from_mock)
register(check_import_of_logging)

View File

@ -60,3 +60,25 @@ class HackingTestCase(test.TestCase):
fake_method, 'tests/fake/test'))
self.assertEqual(4, actual_number)
self.assertTrue(actual_msg.startswith('N303'))
def test_check_wrong_logging_import(self):
fake_imports = ["from rally.openstack.common import log",
"import rally.openstack.common.log"
"import logging"]
good_imports = ["from rally import log",
"from rally.log",
"import rally.log"]
for fake_import in fake_imports:
checkres = checks.check_import_of_logging(fake_import, "fakefile")
self.assertIsNotNone(next(checkres))
for fake_import in fake_imports:
checkres = checks.check_import_of_logging(fake_import,
"./rally/log.py")
self.assertEqual([], list(checkres))
for fake_import in good_imports:
checkres = checks.check_import_of_logging(fake_import,
"fakefile")
self.assertEqual([], list(checkres))

78
tests/unit/test_log.py Normal file
View File

@ -0,0 +1,78 @@
# Copyright 2014: Mirantis Inc.
# 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 logging
import mock
from rally import log
from tests.unit import test
class LogTestCase(test.TestCase):
@mock.patch("rally.log.CONF")
@mock.patch("rally.log.oslogging")
def test_setup(self, mock_oslogger, mock_conf):
proj = "fakep"
version = "fakev"
mock_oslogger.ColorHandler.LEVEL_COLORS = {
logging.DEBUG: "debug_color"}
mock_conf.rally_debug = True
log.setup(proj, version)
self.assertIn(logging.RDEBUG, mock_oslogger.ColorHandler.LEVEL_COLORS)
self.assertEqual(
mock_oslogger.ColorHandler.LEVEL_COLORS[logging.DEBUG],
mock_oslogger.ColorHandler.LEVEL_COLORS[logging.RDEBUG])
mock_oslogger.setup.assert_called_once_with(proj, version)
mock_oslogger.getLogger(None).logger.setLevel.assert_called_once_with(
logging.RDEBUG)
@mock.patch("rally.log.logging")
@mock.patch("rally.log.RallyContextAdapter")
@mock.patch("rally.log.oslogging")
def test_getLogger(self, mock_oslogger, mock_radapter, mock_pylogging):
proj = "fake"
vers = "fake"
mock_oslogger._loggers = dict()
returned_logger = log.getLogger(proj, vers)
self.assertIn(proj, mock_oslogger._loggers)
mock_radapter.assert_called_once_with(mock_pylogging.getLogger(proj),
proj, vers)
self.assertEqual(mock_oslogger._loggers[proj], returned_logger)
class LogRallyContaxtAdapter(test.TestCase):
@mock.patch("rally.log.logging")
@mock.patch("rally.log.oslogging.ContextAdapter")
def test_debug(self, mock_oslo_adapter, mock_logging):
mock_logging.RDEBUG = 123
fake_msg = "fake message"
radapter = log.RallyContextAdapter(mock.MagicMock(), "fakep", "fakev")
radapter.log = mock.MagicMock()
radapter.debug(fake_msg)
radapter.log.assert_called_once_with(mock_logging.RDEBUG,
fake_msg)