From ec584361c0f2057e8a7b71ce9b5cd3cd199c0367 Mon Sep 17 00:00:00 2001 From: mrMoZ1 Date: Fri, 20 Aug 2021 13:25:06 +0300 Subject: [PATCH] [draft]vkd-heartbeat: Add execution API to vdk heartbeat Recently we added a new execution api to the control service. This change aims to include the new api functionality in the vdk-heartbeat tests. This change adds the new functionality of the execute API to the VDK heartbeat tests. We now have functionality to check if a data job has a running data jobexecution and start a data job execution through job_controller.py The new test flow disables the data job deployment after all other tests have passed and then checks for a runnig execution. When there are none we start a new data job execution through the execution API, and checks that the data job execution has started. Since the deployment was disabled the only data job execution that could start is a manual one through the execution api. Once that execution finishes the test concludes and execution resources get cleaned up as normal. Testing: CI/CD Signed-off-by: Momchil Zhivkov --- .../src/taurus/vdk/heartbeat/hearbeat.py | 6 +++ .../taurus/vdk/heartbeat/job_controller.py | 50 +++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/projects/vdk-heartbeat/src/taurus/vdk/heartbeat/hearbeat.py b/projects/vdk-heartbeat/src/taurus/vdk/heartbeat/hearbeat.py index 73cc03a61a..e46bd21034 100644 --- a/projects/vdk-heartbeat/src/taurus/vdk/heartbeat/hearbeat.py +++ b/projects/vdk-heartbeat/src/taurus/vdk/heartbeat/hearbeat.py @@ -44,6 +44,12 @@ def run(self): run_test.execute_test() + job_controller.disable_deployment() + + job_controller.check_job_execution_finished() + job_controller.start_job_execution() + job_controller.check_job_execution_finished() + self.clean(run_test, job_controller) log.info("Heartbeat has finished successfully.") except: diff --git a/projects/vdk-heartbeat/src/taurus/vdk/heartbeat/job_controller.py b/projects/vdk-heartbeat/src/taurus/vdk/heartbeat/job_controller.py index a569d6afc9..2eb63016f0 100644 --- a/projects/vdk-heartbeat/src/taurus/vdk/heartbeat/job_controller.py +++ b/projects/vdk-heartbeat/src/taurus/vdk/heartbeat/job_controller.py @@ -148,6 +148,56 @@ def deploy_job(self): "-t", self.config.job_team, "-p", heartbeat_job_dir, "-r", "Updating heartbeat data job"]) + + @LogDecorator(log) + def start_job_execution(self): + log.info("Starting data job execution through API.") + job_execution = self._execute(["execute", + "--start", + "-t", self.config.job_team, + "-n", self.config.job_name, + "-o", "json", + "-u", self.config.control_api_url]) + + job_execution_id = json.loads(job_execution)["execution_id"] + + response = self._execute(["execute", + "--show", + "-t", self.config.job_team, + "-n", self.config.job_name, + "-o", "json", + "-u", self.config.control_api_url, + "--execution-id", str(job_execution_id)]) + execution_response = json.loads(response) + + assert str(job_execution_id) in str(execution_response), "Failed to start data job execution." + log.info("Execution started successfully.") + + @LogDecorator(log) + def check_job_execution_finished(self): + log.info("Checking if data job execution is still running.") + job_execution_running = True + start = time.time() + + while job_execution_running and time.time() - start < self.config.RUN_TEST_TIMEOUT_SECONDS: + response = self._execute(["execute", + "--list", + "-t", self.config.job_team, + "-n", self.config.job_name, + "-o" "json", + "-u", self.config.control_api_url]) + execution_list = json.loads(response) + + job_execution_running = False + for execution in execution_list: + if str(execution["status"]) == "running": + job_execution_running = True + log.info(f"Data job execution is in state {execution['status']}. Will wait 10 seconds and check again.") + break + time.sleep(10) + log.info(f"Data job is running : {job_execution_running}") + assert not job_execution_running, (f"VDK-heartbeat timed out. Job execution {self.config.job_name} " + + f"did not finish in {self.config.RUN_TEST_TIMEOUT_SECONDS}.") def _update_config_ini(self, heartbeat_job_dir): config_ini = configparser.ConfigParser()