Skip to content

Commit 6d8acd0

Browse files
authored
Disable logging when pulling on python integration tests (#20397)
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.
1 parent 3cc97ff commit 6d8acd0

1 file changed

Lines changed: 21 additions & 4 deletions

File tree

libbeat/tests/system/beat/compose.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import io
2+
import logging
13
import os
24
import sys
35
import tarfile
46
import time
5-
import io
7+
8+
from contextlib import contextmanager
69

710

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

5659
project = cls.compose_project()
57-
project.pull(
58-
ignore_pull_failures=True,
59-
service_names=cls.COMPOSE_SERVICES)
60+
61+
with disabled_logger('compose.service'):
62+
project.pull(
63+
ignore_pull_failures=True,
64+
service_names=cls.COMPOSE_SERVICES)
65+
6066
project.up(
6167
strategy=ConvergenceStrategy.always,
6268
service_names=cls.COMPOSE_SERVICES,
@@ -231,3 +237,14 @@ def service_log_contains(cls, service, msg):
231237
if line.find(msg.encode("utf-8")) >= 0:
232238
counter += 1
233239
return counter > 0
240+
241+
242+
@contextmanager
243+
def disabled_logger(name):
244+
logger = logging.getLogger(name)
245+
old_level = logger.getEffectiveLevel()
246+
logger.setLevel(logging.CRITICAL)
247+
try:
248+
yield logger
249+
finally:
250+
logger.setLevel(old_level)

0 commit comments

Comments
 (0)