Skip to content

Commit c1db293

Browse files
authored
ETR to wait for environment (#69)
Allow the passing of suite URL instead of environment ID
1 parent 311ee74 commit c1db293

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-12
lines changed

src/etos_test_runner/etr.py

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,26 @@
1717
# -*- coding: utf-8 -*-
1818
"""ETOS test runner module."""
1919

20-
import sys
20+
import importlib
2121
import logging
2222
import os
23-
import signal
24-
import importlib
2523
import pkgutil
26-
from typing import Optional, Union
27-
from pprint import pprint
24+
import signal
25+
import sys
2826
from collections import OrderedDict
27+
from pprint import pprint
28+
from typing import Optional, Union
2929

3030
from etos_lib import ETOS
31+
from etos_lib.lib.http import Http
3132
from etos_lib.logging.logger import FORMAT_CONFIG
3233
from jsontas.jsontas import JsonTas
34+
from urllib3.util import Retry
3335

34-
from etos_test_runner.lib.testrunner import TestRunner
35-
from etos_test_runner.lib.iut import Iut
3636
from etos_test_runner.lib.custom_dataset import CustomDataset
3737
from etos_test_runner.lib.decrypt import Decrypt, decrypt
38+
from etos_test_runner.lib.iut import Iut
39+
from etos_test_runner.lib.testrunner import TestRunner
3840

3941
# Remove spam from pika.
4042
logging.getLogger("pika").setLevel(logging.WARNING)
@@ -64,6 +66,7 @@ def __init__(self) -> None:
6466

6567
self.etos.start_publisher()
6668
self.environment_id = os.getenv("ENVIRONMENT_ID")
69+
self.environment_url = os.getenv("ENVIRONMENT_URL")
6770

6871
signal.signal(signal.SIGTERM, self.graceful_shutdown)
6972

@@ -77,7 +80,19 @@ def download_and_load(self, sub_suite_url: str) -> None:
7780
7881
:param sub_suite_url: URL to where the sub suite information exists.
7982
"""
80-
response = self.etos.http.get(sub_suite_url)
83+
codes = [*Retry.RETRY_AFTER_STATUS_CODES, 404]
84+
retry = Retry(
85+
total=None,
86+
read=0,
87+
connect=10, # With 1 as backoff_factor, will retry for 1023s
88+
status=10, # With 1 as backoff_factor, will retry for 1023s
89+
backoff_factor=1,
90+
other=0,
91+
status_forcelist=codes, # 413, 429, 503
92+
)
93+
http_client = Http(retry=retry)
94+
95+
response = http_client.get(sub_suite_url)
8196
json_config = response.json(object_pairs_hook=OrderedDict)
8297
dataset = CustomDataset()
8398
dataset.add("decrypt", Decrypt)
@@ -162,11 +177,13 @@ def run_etr(self) -> Union[int, dict]:
162177
:return: Result of testrunner execution.
163178
"""
164179
_LOGGER.info("Starting ETR.")
165-
sub_suite_url = self.get_sub_suite_url(self.environment_id)
180+
sub_suite_url = self.environment_url
166181
if sub_suite_url is None:
167-
raise TimeoutError(
168-
f"Could not get sub suite environment event with id {self.environment_id!r}"
169-
)
182+
sub_suite_url = self.get_sub_suite_url(self.environment_id)
183+
if sub_suite_url is None:
184+
raise TimeoutError(
185+
f"Could not get sub suite environment event with id {self.environment_id!r}"
186+
)
170187
self.download_and_load(sub_suite_url)
171188
FORMAT_CONFIG.identifier = self.etos.config.get("suite_id")
172189
self.load_plugins()

0 commit comments

Comments
 (0)