[placement] Manage log and other output in gabbi fixure

Recent changes to the placement API added more verbose logging and
output across both stdout and stderr. In test runs this resulted in
a combination of far too much output as well as output that was
impossible to read because it was interleaved.

This change uses fixtures from nova.tests.fixtures to capture
stray output streams and logs.

It also adds a specific logger for the ERROR level that overrides
the fixture log handling to send that level to the default stderr.
This is required in order to effectively see error messages on both
side of the wsgi-intercept used when running gabbi. Without this,
the errors are swallowed and test development and debugging,
especially locally for TDD, is hamstrung.

Closes-Bug: #1623573
Change-Id: I300456b0261dfc0ae46c799e5a03cbeab25106c2
This commit is contained in:
Chris Dent 2016-09-21 15:41:58 +00:00
parent 48a4fee10f
commit 687984bcb4
1 changed files with 22 additions and 0 deletions

View File

@ -10,6 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import logging
import os
from gabbi import fixture
@ -37,6 +38,25 @@ class APIFixture(fixture.GabbiFixture):
self.conf = None
def start_fixture(self):
# Set up a logger for errors that will display to screen,
# otherwise gabbi failures can be hard to debug while doing
# TDD. Establish here but don't add until after the logging
# fixture is started, because that cares about handler
# ordering.
error_log = logging.StreamHandler()
error_log.setLevel(logging.ERROR)
# Set up stderr and stdout captures by directly driving the
# existing nova fixtures that do that.
self.standard_logging_fixture = fixtures.StandardLogging()
self.standard_logging_fixture.setUp()
self.output_stream_fixture = fixtures.OutputStreamCapture()
self.output_stream_fixture.setUp()
# add the error handler
# catastrophic error messages in a useful way
logging.getLogger().addHandler(error_log)
self.conf = CONF
self.conf.set_override('auth_strategy', 'noauth2')
# Be explicit about all three database connections to avoid
@ -63,6 +83,8 @@ class APIFixture(fixture.GabbiFixture):
def stop_fixture(self):
self.api_db_fixture.cleanup()
self.main_db_fixture.cleanup()
self.output_stream_fixture.cleanUp()
self.standard_logging_fixture.cleanUp()
if self.conf:
self.conf.reset()