From 8ddb4e9ac1c18fc3861acf187e561edc87ad3950 Mon Sep 17 00:00:00 2001 From: Angus Salkeld Date: Fri, 9 May 2014 14:28:47 +1000 Subject: [PATCH] Add a test equivalent to default_log_levels This is to mainly kill the migrate script logs but can be used to quieten down any log. Also the migrations were not using the FakeLogger so now both are using the same mechanism. Fixes-bug: 1281226 Change-Id: I2f1efcace6a38450020fcbf516ee5026204359d2 --- heat/tests/common.py | 26 ++++++++++++++++++++++++-- heat/tests/db/test_migrations.py | 6 ++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/heat/tests/common.py b/heat/tests/common.py index 7aa7717415..4d98cf7b48 100644 --- a/heat/tests/common.py +++ b/heat/tests/common.py @@ -30,7 +30,29 @@ from heat.engine import scheduler from heat.tests import utils -class HeatTestCase(testscenarios.WithScenarios, testtools.TestCase): +TEST_DEFAULT_LOGLEVELS = {'migrate': logging.WARN} + + +class FakeLogMixin: + def setup_logging(self): + # Assign default logs to self.logger so we can still + # assert on heat logs. + self.logger = self.useFixture( + fixtures.FakeLogger(level=logging.DEBUG)) + base_list = set([nlog.split('.')[0] + for nlog in logging.Logger.manager.loggerDict]) + for base in base_list: + if base in TEST_DEFAULT_LOGLEVELS: + self.useFixture(fixtures.FakeLogger( + level=TEST_DEFAULT_LOGLEVELS[base], + name=base)) + elif base != 'heat': + self.useFixture(fixtures.FakeLogger( + name=base)) + + +class HeatTestCase(testscenarios.WithScenarios, + testtools.TestCase, FakeLogMixin): TIME_STEP = 0.1 @@ -38,7 +60,7 @@ class HeatTestCase(testscenarios.WithScenarios, testtools.TestCase): super(HeatTestCase, self).setUp() self.m = mox.Mox() self.addCleanup(self.m.UnsetStubs) - self.logger = self.useFixture(fixtures.FakeLogger(level=logging.DEBUG)) + self.setup_logging() scheduler.ENABLE_SLEEP = False self.useFixture(fixtures.MonkeyPatch( 'heat.common.exception._FATAL_EXCEPTION_FORMAT_ERRORS', diff --git a/heat/tests/db/test_migrations.py b/heat/tests/db/test_migrations.py index b44b75f415..9aacf81efb 100644 --- a/heat/tests/db/test_migrations.py +++ b/heat/tests/db/test_migrations.py @@ -36,7 +36,7 @@ from heat.db.sqlalchemy import migrate_repo from heat.db.sqlalchemy import migration from heat.openstack.common.db.sqlalchemy import test_migrations from heat.openstack.common import log as logging - +from heat.tests import common LOG = logging.getLogger(__name__) @@ -53,7 +53,8 @@ def get_table(engine, name): class TestHeatMigrations(test_migrations.BaseMigrationTestCase, - test_migrations.WalkVersionsMixin): + test_migrations.WalkVersionsMixin, + common.FakeLogMixin): """Test sqlalchemy-migrate migrations.""" def __init__(self, *args, **kwargs): @@ -74,6 +75,7 @@ class TestHeatMigrations(test_migrations.BaseMigrationTestCase, os.environ["HEAT_LOCK_PATH"] = lock_dir super(TestHeatMigrations, self).setUp() + self.setup_logging() def clean_lock_dir(): shutil.rmtree(lock_dir, ignore_errors=True)