From 87fba30a27472c53ee59f145e06c19b9af851c6b Mon Sep 17 00:00:00 2001 From: Jacob Boddey Date: Mon, 23 Dec 2024 13:42:52 +0000 Subject: [PATCH 1/3] Add starting status --- framework/python/src/common/statuses.py | 1 + framework/python/src/core/session.py | 2 +- framework/python/src/core/testrun.py | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/framework/python/src/common/statuses.py b/framework/python/src/common/statuses.py index c7487868a..ea2eb15ec 100644 --- a/framework/python/src/common/statuses.py +++ b/framework/python/src/common/statuses.py @@ -16,6 +16,7 @@ class TestrunStatus: IDLE = "Idle" + STARTING = "Starting" WAITING_FOR_DEVICE = "Waiting for Device" MONITORING = "Monitoring" IN_PROGRESS = "In Progress" diff --git a/framework/python/src/core/session.py b/framework/python/src/core/session.py index 17d583219..6a8b7749b 100644 --- a/framework/python/src/core/session.py +++ b/framework/python/src/core/session.py @@ -156,7 +156,7 @@ def __init__(self, root_dir): def start(self): self.reset() - self._status = TestrunStatus.WAITING_FOR_DEVICE + self._status = TestrunStatus.STARTING self._started = datetime.datetime.now() def get_started(self): diff --git a/framework/python/src/core/testrun.py b/framework/python/src/core/testrun.py index 5d4e78e9c..e481290aa 100644 --- a/framework/python/src/core/testrun.py +++ b/framework/python/src/core/testrun.py @@ -375,6 +375,7 @@ def start(self): self._device_stable, [NetworkEvent.DEVICE_STABLE]) self.get_net_orc().start_listener() + self.get_session().set_status(TestrunStatus.WAITING_FOR_DEVICE) LOGGER.info('Waiting for devices on the network...') # Keep application running until stopped From 90fa5858c91944dcc6a2d6ea085f038a446b290e Mon Sep 17 00:00:00 2001 From: Jacob Boddey Date: Thu, 2 Jan 2025 10:08:49 +0000 Subject: [PATCH 2/3] Fix pylint issue --- framework/python/src/common/statuses.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/framework/python/src/common/statuses.py b/framework/python/src/common/statuses.py index ea2eb15ec..967e98981 100644 --- a/framework/python/src/common/statuses.py +++ b/framework/python/src/common/statuses.py @@ -15,6 +15,7 @@ class TestrunStatus: + """Enum for all possible Testrun statuses""" IDLE = "Idle" STARTING = "Starting" WAITING_FOR_DEVICE = "Waiting for Device" @@ -28,6 +29,7 @@ class TestrunStatus: class TestResult: + """Enum for all possible test results""" IN_PROGRESS = "In Progress" COMPLIANT = "Compliant" NON_COMPLIANT = "Non-Compliant" From 6cf264465801f7c0b568e047a33e66d01bbcdb27 Mon Sep 17 00:00:00 2001 From: Marius <86727846+MariusBaldovin@users.noreply.github.com> Date: Thu, 2 Jan 2025 14:59:01 +0000 Subject: [PATCH 3/3] fix api tests for new status 'Starting' (#1041) --- framework/python/src/api/api.py | 6 +++-- .../src/net_orc/network_orchestrator.py | 3 ++- testing/api/test_api.py | 27 ++++++++++++++++--- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/framework/python/src/api/api.py b/framework/python/src/api/api.py index 2bba5e62f..5799fd478 100644 --- a/framework/python/src/api/api.py +++ b/framework/python/src/api/api.py @@ -278,7 +278,8 @@ async def start_testrun(self, request: Request, response: Response): TestrunStatus.IN_PROGRESS, TestrunStatus.WAITING_FOR_DEVICE, TestrunStatus.MONITORING, - TestrunStatus.VALIDATING + TestrunStatus.VALIDATING, + TestrunStatus.STARTING ]: LOGGER.debug("Testrun is already running. Cannot start another instance") @@ -341,7 +342,8 @@ async def stop_testrun(self, response: Response): not in [TestrunStatus.IN_PROGRESS, TestrunStatus.WAITING_FOR_DEVICE, TestrunStatus.MONITORING, - TestrunStatus.VALIDATING]): + TestrunStatus.VALIDATING, + TestrunStatus.STARTING]): response.status_code = 404 return self._generate_msg(False, "Testrun is not currently running") diff --git a/framework/python/src/net_orc/network_orchestrator.py b/framework/python/src/net_orc/network_orchestrator.py index 37858c4e1..25e036ef7 100644 --- a/framework/python/src/net_orc/network_orchestrator.py +++ b/framework/python/src/net_orc/network_orchestrator.py @@ -713,7 +713,8 @@ def internet_conn_checker(self, mqtt_client: mqtt.MQTT, topic: str): if self.get_session().get_status() not in [ TestrunStatus.WAITING_FOR_DEVICE, TestrunStatus.MONITORING, - TestrunStatus.IN_PROGRESS + TestrunStatus.IN_PROGRESS, + TestrunStatus.STARTING ]: message['connection'] = None diff --git a/testing/api/test_api.py b/testing/api/test_api.py index e67506a71..dc8861031 100644 --- a/testing/api/test_api.py +++ b/testing/api/test_api.py @@ -728,9 +728,9 @@ def test_sys_status_cancelled(empty_devices_dir, add_devices, # pylint: disable= @pytest.mark.parametrize("add_devices", [ ["device_1"] ],indirect=True) -def test_sys_status_waiting(empty_devices_dir, add_devices, # pylint: disable=W0613 - testrun, start_test): # pylint: disable=W0613 - """ Test for system status 'Waiting for Device' (200) """ +def test_sys_status_starting(empty_devices_dir, add_devices, # pylint: disable=W0613 + testrun, start_test): # pylint: disable=W0613 + """ Test for system status 'Starting' and 'Waiting for Device' (200) """ # Send the get request r = requests.get(f"{API}/system/status", timeout=5) @@ -741,6 +741,27 @@ def test_sys_status_waiting(empty_devices_dir, add_devices, # pylint: disable=W0 # Parse the json response response = r.json() + # Check if system status is 'Starting' + assert response["status"] == "Starting" + + # Add max 60 seconds delay to allow for status to change + max_retries = 60 + + # If status is "Starting" and max_retries didn't reach 0 + while response["status"] == "Starting" and max_retries != 0: + + # Add 1 second delay + time.sleep(1) + + # Subtract 1 from max_retries + max_retries -= 1 + + # Resend the get request + r = requests.get(f"{API}/system/status", timeout=5) + + # Parse the json response + response = r.json() + # Check if system status is 'Waiting for Device' assert response["status"] == "Waiting for Device"