Skip to content

Commit 1d36b92

Browse files
committed
Implemented configuration for enabling/disabling container information logging
1 parent f4c99ba commit 1d36b92

File tree

3 files changed

+51
-37
lines changed

3 files changed

+51
-37
lines changed

app/container_manager/container_manager.py

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
docker_rm_command,
3333
docker_run_command,
3434
)
35+
from app.core.config import settings
3536
from app.singleton import Singleton
3637
from app.test_engine.logger import test_engine_logger as logger
3738

@@ -49,20 +50,23 @@ async def create_container(
4950
) -> Container:
5051
container = self.__run_new_container(docker_image_tag, parameters)
5152
await self.__container_ready(container)
52-
logger.info("Container running for " + docker_image_tag)
53+
if settings.ENABLE_CONTAINER_LOGS:
54+
logger.info("Container running for " + docker_image_tag)
5355

5456
return container
5557

5658
def destroy(self, container: Container) -> None:
5759
if self.is_running(container):
5860
# Log equivalent shell command for kill
59-
shell_cmd = docker_kill_command(container.name)
60-
logger.info(f"{SHELL_CMD_LOG_PREFIX}{shell_cmd}")
61+
if settings.ENABLE_CONTAINER_LOGS:
62+
shell_cmd = docker_kill_command(container.name)
63+
logger.info(f"{SHELL_CMD_LOG_PREFIX}{shell_cmd}")
6164
container.kill()
6265

6366
# Log equivalent shell command for remove
64-
shell_cmd = docker_rm_command(container.name, force=True)
65-
logger.info(f"{SHELL_CMD_LOG_PREFIX}{shell_cmd}")
67+
if settings.ENABLE_CONTAINER_LOGS:
68+
shell_cmd = docker_rm_command(container.name, force=True)
69+
logger.info(f"{SHELL_CMD_LOG_PREFIX}{shell_cmd}")
6670
container.remove(force=True)
6771

6872
def get_container(self, id_or_name: str) -> Optional[Container]:
@@ -109,8 +113,9 @@ def __run_new_container(self, docker_image_tag: str, parameters: Dict) -> Contai
109113
# Create containers
110114
try:
111115
# Log equivalent shell command
112-
shell_cmd = docker_run_command(docker_image_tag, parameters)
113-
logger.info(f"{SHELL_CMD_LOG_PREFIX}{shell_cmd}")
116+
if settings.ENABLE_CONTAINER_LOGS:
117+
shell_cmd = docker_run_command(docker_image_tag, parameters)
118+
logger.info(f"{SHELL_CMD_LOG_PREFIX}{shell_cmd}")
114119

115120
return self.__client.containers.run(docker_image_tag, **parameters)
116121
except DockerException as error:
@@ -151,20 +156,22 @@ def copy_file_from_container(
151156
destination_file_name: str,
152157
) -> None:
153158
try:
154-
logger.info(
155-
"### File Copy: CONTAINER->HOST"
156-
f" From Container Path: {str(container_file_path)}"
157-
f" To Host Path: {str(destination_path)}/{destination_file_name}"
158-
f" Container Name: {str(container.name)}"
159-
)
159+
if settings.ENABLE_CONTAINER_LOGS:
160+
logger.info(
161+
"### File Copy: CONTAINER->HOST"
162+
f" From Container Path: {str(container_file_path)}"
163+
f" To Host Path: {str(destination_path)}/{destination_file_name}"
164+
f" Container Name: {str(container.name)}"
165+
)
160166

161167
# Log equivalent shell command
162-
shell_cmd = docker_cp_from_container_command(
163-
container.name,
164-
container_file_path,
165-
destination_path / destination_file_name,
166-
)
167-
logger.info(f"{SHELL_CMD_LOG_PREFIX}{shell_cmd}")
168+
if settings.ENABLE_CONTAINER_LOGS:
169+
shell_cmd = docker_cp_from_container_command(
170+
container.name,
171+
container_file_path,
172+
destination_path / destination_file_name,
173+
)
174+
logger.info(f"{SHELL_CMD_LOG_PREFIX}{shell_cmd}")
168175

169176
stream, _ = container.get_archive(str(container_file_path))
170177
with open(
@@ -187,18 +194,20 @@ def copy_file_to_container(
187194
destination_container_path: Path,
188195
) -> None:
189196
try:
190-
logger.info(
191-
"### File Copy: HOST->CONTAINER"
192-
f" From Host Path: {str(host_file_path)}"
193-
f" To Container Path: {destination_container_path}"
194-
f" Container Name: {str(container.name)}"
195-
)
197+
if settings.ENABLE_CONTAINER_LOGS:
198+
logger.info(
199+
"### File Copy: HOST->CONTAINER"
200+
f" From Host Path: {str(host_file_path)}"
201+
f" To Container Path: {destination_container_path}"
202+
f" Container Name: {str(container.name)}"
203+
)
196204

197205
# Log equivalent shell command
198-
shell_cmd = docker_cp_to_container_command(
199-
container.name, host_file_path, destination_container_path
200-
)
201-
logger.info(f"{SHELL_CMD_LOG_PREFIX}{shell_cmd}")
206+
if settings.ENABLE_CONTAINER_LOGS:
207+
shell_cmd = docker_cp_to_container_command(
208+
container.name, host_file_path, destination_container_path
209+
)
210+
logger.info(f"{SHELL_CMD_LOG_PREFIX}{shell_cmd}")
202211

203212
tar_stream = io.BytesIO()
204213
with tarfile.open(f"{host_file_path}", mode="r") as tar_in:

app/core/config.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2023 Project CHIP Authors
2+
# Copyright (c) 2026 Project CHIP Authors
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -110,6 +110,9 @@ def get_emails_enabled(cls, v: bool, values: Dict[str, Any]) -> bool:
110110
# Python Test Logging
111111
ENABLE_REALTIME_PYTHON_TEST_LOGS: bool = False
112112

113+
# Container Logging
114+
ENABLE_CONTAINER_LOGS: bool = False
115+
113116
class Config:
114117
case_sensitive = True
115118

test_collections/matter/sdk_tests/support/sdk_container.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
SHELL_CMD_LOG_PREFIX,
2727
docker_exec_command,
2828
)
29+
from app.core.config import settings
2930
from app.schemas.pics import PICS, PICSError
3031
from app.singleton import Singleton
3132
from app.test_engine.logger import test_engine_logger as logger
@@ -239,13 +240,14 @@ def send_command(
239240
self.logger.info("Sending command to SDK container: " + full_cmd_str)
240241

241242
# Log equivalent shell command
242-
shell_cmd = docker_exec_command(
243-
self.container_name,
244-
full_cmd_str,
245-
stdin=True,
246-
detach=is_detach,
247-
)
248-
self.logger.info(f"{SHELL_CMD_LOG_PREFIX}{shell_cmd}")
243+
if settings.ENABLE_CONTAINER_LOGS:
244+
shell_cmd = docker_exec_command(
245+
self.container_name,
246+
full_cmd_str,
247+
stdin=True,
248+
detach=is_detach,
249+
)
250+
self.logger.info(f"{SHELL_CMD_LOG_PREFIX}{shell_cmd}")
249251

250252
result = exec_run_in_container(
251253
self.__container,

0 commit comments

Comments
 (0)