From f245bddbe335a0f24b625c4e78b8c6e684aae5b5 Mon Sep 17 00:00:00 2001 From: kooomix Date: Thu, 9 Jan 2025 14:30:27 +0200 Subject: [PATCH] refactor cleanup methods in workflows to improve error handling and code organization --- tests_scripts/workflows/teams_workflows.py | 6 +++++- tests_scripts/workflows/workflows.py | 15 +++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/tests_scripts/workflows/teams_workflows.py b/tests_scripts/workflows/teams_workflows.py index 4df5ce68..f596ba1e 100644 --- a/tests_scripts/workflows/teams_workflows.py +++ b/tests_scripts/workflows/teams_workflows.py @@ -133,8 +133,12 @@ def start(self): def cleanup(self, **kwargs): + super().cleanup_workflows() if self.webhook_name: - self.delete_channel_by_guid(self.get_channel_guid_by_name(self.webhook_name)) + try: + self.delete_channel_by_guid(self.get_channel_guid_by_name(self.webhook_name)) + except Exception as e: + Logger.logger.error(f"Failed to delete channel with name {self.webhook_name}, got exception {e}") if self.fw_name: self.wait_for_report(report_type=self.backend.delete_custom_framework, framework_name=self.fw_name) return super().cleanup(**kwargs) diff --git a/tests_scripts/workflows/workflows.py b/tests_scripts/workflows/workflows.py index 1d558b05..0de48a0d 100644 --- a/tests_scripts/workflows/workflows.py +++ b/tests_scripts/workflows/workflows.py @@ -15,12 +15,7 @@ def __init__(self, test_obj=None, backend=None, test_driver=None, kubernetes_obj def cleanup(self, **kwargs): - for guid in self.test_workflows_guids: - try: - self.delete_and_assert_workflow(guid) - except Exception as e: - Logger.logger.error(f"Failed to delete workflow with guid {guid}, got exception {e}") - self.test_workflows_guids = [] + self.cleanup_workflows() return super().cleanup(**kwargs) def active_workflow(self): @@ -39,6 +34,14 @@ def install_kubescape(self, helm_kwargs: dict = None): self.add_and_upgrade_armo_to_repo() self.install_armo_helm_chart(helm_kwargs=helm_kwargs) self.verify_running_pods(namespace=statics.CA_NAMESPACE_FROM_HELM_NAME) + + def cleanup_workflows(self): + for guid in self.test_workflows_guids: + try: + self.delete_and_assert_workflow(guid) + except Exception as e: + Logger.logger.error(f"Failed to delete workflow with guid {guid}, got exception {e}") + self.test_workflows_guids = [] def create_and_assert_workflow(self, workflow_body, expected_response, update=False): if update: