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/common/statuses.py b/framework/python/src/common/statuses.py index c7487868a..967e98981 100644 --- a/framework/python/src/common/statuses.py +++ b/framework/python/src/common/statuses.py @@ -15,7 +15,9 @@ class TestrunStatus: + """Enum for all possible Testrun statuses""" IDLE = "Idle" + STARTING = "Starting" WAITING_FOR_DEVICE = "Waiting for Device" MONITORING = "Monitoring" IN_PROGRESS = "In Progress" @@ -27,6 +29,7 @@ class TestrunStatus: class TestResult: + """Enum for all possible test results""" IN_PROGRESS = "In Progress" COMPLIANT = "Compliant" NON_COMPLIANT = "Non-Compliant" diff --git a/framework/python/src/core/session.py b/framework/python/src/core/session.py index 3c2662ae3..144b333f4 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 61c4812be..f4ce62c0f 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 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 83a70ac72..f328d7885 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"