diff --git a/nova/tests/functional/api/openstack/placement/base.py b/nova/tests/functional/api/openstack/placement/base.py index 715aafcd2fe0..c5d6e7952efb 100644 --- a/nova/tests/functional/api/openstack/placement/base.py +++ b/nova/tests/functional/api/openstack/placement/base.py @@ -19,6 +19,7 @@ from nova.api.openstack.placement import context from nova.api.openstack.placement import deploy from nova.api.openstack.placement.objects import resource_provider from nova.tests import fixtures +from nova.tests.functional.api.openstack.placement.fixtures import capture from nova.tests.unit import policy_fixture @@ -48,7 +49,7 @@ class TestCase(testtools.TestCase): self.useFixture(policy_fixture.PlacementPolicyFixture()) - self.useFixture(fixtures.StandardLogging()) + self.useFixture(capture.Logging()) self.useFixture(output.CaptureOutput()) # Filter ignorable warnings during test runs. self.useFixture(fixtures.WarningsFixture()) diff --git a/nova/tests/functional/api/openstack/placement/fixtures/capture.py b/nova/tests/functional/api/openstack/placement/fixtures/capture.py new file mode 100644 index 000000000000..26913a458974 --- /dev/null +++ b/nova/tests/functional/api/openstack/placement/fixtures/capture.py @@ -0,0 +1,59 @@ +# 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 fixtures +from oslotest import log + + +class NullHandler(logging.Handler): + """custom default NullHandler to attempt to format the record. + + Used in conjunction with Logging below to detect formatting errors + in debug logs. + """ + def handle(self, record): + self.format(record) + + def emit(self, record): + pass + + def createLock(self): + self.lock = None + + +class Logging(log.ConfigureLogging): + """A logging fixture providing two important fixtures. + + One is to capture logs for later inspection. + + The other is to make sure that DEBUG logs, even if not captured, + are formatted. + """ + + def __init__(self): + super(Logging, self).__init__() + # If level was not otherwise set, default to INFO. + if self.level is None: + self.level = logging.INFO + # Always capture logs, unlike the parent. + self.capture_logs = True + + def setUp(self): + super(Logging, self).setUp() + if self.level > logging.DEBUG: + handler = NullHandler() + self.useFixture(fixtures.LogHandler(handler, nuke_handlers=False)) + handler.setLevel(logging.DEBUG) diff --git a/nova/tests/functional/api/openstack/placement/fixtures/gabbits.py b/nova/tests/functional/api/openstack/placement/fixtures/gabbits.py index 92414a40535d..3e11e3aba9e3 100644 --- a/nova/tests/functional/api/openstack/placement/fixtures/gabbits.py +++ b/nova/tests/functional/api/openstack/placement/fixtures/gabbits.py @@ -30,6 +30,7 @@ from nova.api.openstack.placement import policies from nova import rc_fields as fields from nova.tests import fixtures from nova.tests.functional.api.openstack.placement.db import test_base as tb +from nova.tests.functional.api.openstack.placement.fixtures import capture from nova.tests.unit import policy_fixture from nova.tests import uuidsentinel as uuids @@ -49,7 +50,7 @@ class APIFixture(fixture.GabbiFixture): # existing nova fixtures that do that. This captures the # output that happens outside individual tests (for # example database migrations). - self.standard_logging_fixture = fixtures.StandardLogging() + self.standard_logging_fixture = capture.Logging() self.standard_logging_fixture.setUp() self.output_stream_fixture = output.CaptureOutput() self.output_stream_fixture.setUp() diff --git a/nova/tests/functional/api/openstack/placement/test_placement_api.py b/nova/tests/functional/api/openstack/placement/test_placement_api.py index 5b7bc0ca71be..e2448908383a 100644 --- a/nova/tests/functional/api/openstack/placement/test_placement_api.py +++ b/nova/tests/functional/api/openstack/placement/test_placement_api.py @@ -17,7 +17,7 @@ import wsgi_intercept from gabbi import driver -from nova.tests import fixtures as nova_fixtures +from nova.tests.functional.api.openstack.placement.fixtures import capture # TODO(cdent): This whitespace blight will go away post extraction. from nova.tests.functional.api.openstack.placement.fixtures \ import gabbits as fixtures @@ -35,7 +35,7 @@ def load_tests(loader, tests, pattern): # capture, for cleaner results reporting. inner_fixtures = [ output.CaptureOutput, - nova_fixtures.StandardLogging, + capture.Logging, ] return driver.build_tests(test_dir, loader, host=None, test_loader_name=__name__,