From b5979372862dbcb0ec4250b1a9419f6865ba555f Mon Sep 17 00:00:00 2001 From: Vladimir Domnich Date: Tue, 9 Aug 2022 00:17:56 +0300 Subject: [PATCH] Fix container filtering by name in devenv Signed-off-by: Vladimir Domnich --- pytest_tests/helpers/service_helper.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pytest_tests/helpers/service_helper.py b/pytest_tests/helpers/service_helper.py index dd2a4882..daae786b 100644 --- a/pytest_tests/helpers/service_helper.py +++ b/pytest_tests/helpers/service_helper.py @@ -208,9 +208,12 @@ class RemoteDevEnvStorageServiceHelper: def _get_container_by_name(self, node_name: str, container_name: str) -> dict: with _create_ssh_client(node_name) as ssh_client: output = ssh_client.exec('docker ps -a --format "{{json .}}"').stdout - containers = json.loads(output) - for container in containers: + # output contains each container as separate JSON structure, so we find each JSON structure + # by curly brackets (works because JSON is not nested), parse it and find container by name + json_blocks = re.findall(r'\{.*?\}', output, re.DOTALL) + for json_block in json_blocks: + container = json.loads(json_block) # unlike docker.API in docker ps output Names seems to be a string, so we check by equality if container["Names"] == container_name: return container