Skip to content

Commit

Permalink
Disable logging when pulling on python integration tests (#20397) (#2…
Browse files Browse the repository at this point in the history
…0445)

Docker compose library is quite verbose, and it prints many messages
when logging is enabled. On integration tests we make a pull before
trying to build the images in case the image is already pre-built. If
this pull doesn't work, the image is built, so we ignore errors on this
pull. But, even when ignoring errors, these errors are logged, and when
investigating problems with tests this may lead to think that the
problem is with the unavailability of some image. Disable logging on the
compose logger while this previous pull is being done.

(cherry picked from commit 6d8acd0)
  • Loading branch information
jsoriano committed Aug 6, 2020
1 parent 7bd908c commit e4d22bc
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions libbeat/tests/system/beat/compose.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import io
import logging
import os
import sys
import tarfile
import time
import io

from contextlib import contextmanager


INTEGRATION_TESTS = os.environ.get('INTEGRATION_TESTS', False)
Expand Down Expand Up @@ -54,9 +57,12 @@ def is_healthy(container):
return container.inspect()['State']['Health']['Status'] == 'healthy'

project = cls.compose_project()
project.pull(
ignore_pull_failures=True,
service_names=cls.COMPOSE_SERVICES)

with disabled_logger('compose.service'):
project.pull(
ignore_pull_failures=True,
service_names=cls.COMPOSE_SERVICES)

project.up(
strategy=ConvergenceStrategy.always,
service_names=cls.COMPOSE_SERVICES,
Expand Down Expand Up @@ -231,3 +237,14 @@ def service_log_contains(cls, service, msg):
if line.find(msg.encode("utf-8")) >= 0:
counter += 1
return counter > 0


@contextmanager
def disabled_logger(name):
logger = logging.getLogger(name)
old_level = logger.getEffectiveLevel()
logger.setLevel(logging.CRITICAL)
try:
yield logger
finally:
logger.setLevel(old_level)

0 comments on commit e4d22bc

Please sign in to comment.