diff --git a/src/environment_provider/environment.py b/src/environment_provider/environment.py index 306f4ef..d16c198 100644 --- a/src/environment_provider/environment.py +++ b/src/environment_provider/environment.py @@ -17,6 +17,7 @@ import json import time import traceback +import re from typing import Optional, Union from etos_lib import ETOS @@ -34,6 +35,8 @@ TRACER = trace.get_tracer(__name__) +# REGEX for matching /testrun/tercc-id/suite/main-suite-id/subsuite/subsuite-id/suite. +SUBSUITE_REGEX = r"/testrun/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/suite/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/subsuite/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/suite" # pylint:disable=line-too-long def checkin_provider( @@ -129,14 +132,17 @@ def release_full_environment(etos: ETOS, jsontas: JsonTas, suite_id: str) -> tup # references to the last log files created. This is to ensure that # etos-client has enough time to find and download them. time.sleep(30) - for suite, metadata in registry.testrun.join("suite").read_all(): - suite = json.loads(suite) - for sub_suite in suite.get("sub_suites", []): - try: - failure = release_environment(etos, jsontas, registry, sub_suite) - except json.JSONDecodeError as exception: - failure = exception - ETCDPath(metadata.get("key")).delete() + # Iterating over all keys "below" the suite key to find all sub suites. + for value, metadata in registry.testrun.join("suite").read_all(): + key = metadata.get("key", b"").decode() + if re.match(SUBSUITE_REGEX, key) is None: + continue + try: + sub_suite = json.loads(value) + failure = release_environment(etos, jsontas, registry, sub_suite) + except json.JSONDecodeError as exception: + failure = exception + ETCDPath(key).delete() registry.testrun.delete_all() if failure: