From 7cebadae6e95c4ee4dc05c9d268f928c96f838b5 Mon Sep 17 00:00:00 2001 From: Maja Massarini Date: Tue, 13 Feb 2024 15:14:27 +0100 Subject: [PATCH 1/4] Copr project name depends on namespace and packit instance --- src/validation/testcase/gitlab.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/validation/testcase/gitlab.py b/src/validation/testcase/gitlab.py index 971c6a6..4f669e7 100644 --- a/src/validation/testcase/gitlab.py +++ b/src/validation/testcase/gitlab.py @@ -20,7 +20,7 @@ def get_status_name(self, status: CommitFlag) -> str: return status.context def construct_copr_project_name(self) -> str: - return f"gitlab.com-packit-service-hello-world-{self.pr.id}" + return f"{self.project.service.hostname}-{self.project.namespace}-hello-world-{self.pr.id}" def create_file_in_new_branch(self, branch: str): self.pr_branch_ref = self.project.gitlab_repo.branches.create( From c272ce2818c16f3dcc10677728e012de5b6f33c0 Mon Sep 17 00:00:00 2001 From: Maja Massarini Date: Tue, 13 Feb 2024 15:17:17 +0100 Subject: [PATCH 2/4] Log failing validation test --- src/validation/testcase/base.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/validation/testcase/base.py b/src/validation/testcase/base.py index e23e2c5..d78984a 100644 --- a/src/validation/testcase/base.py +++ b/src/validation/testcase/base.py @@ -52,15 +52,18 @@ def run_test(self): opening PR close it. :return: """ - self.run_checks() - if self.failure_msg: - message = f"{self.pr.title} ({self.pr.url}) failed: {self.failure_msg}" + try: + self.run_checks() + if self.failure_msg: + message = f"{self.pr.title} ({self.pr.url}) failed: {self.failure_msg}" - log_failure(message) + log_failure(message) - if self.trigger == Trigger.pr_opened: - self.pr.close() - self.pr_branch_ref.delete() + if self.trigger == Trigger.pr_opened: + self.pr.close() + self.pr_branch_ref.delete() + except Exception as e: + logging.error(f"Validation test {self.pr.title} ({self.pr.url}) failed: {e}") def trigger_build(self): """ @@ -210,9 +213,9 @@ def check_build_submitted(self): self.deployment.copr_user, self.copr_project_name, ) - except Exception: + except Exception as e: # project does not exist yet - logging.info("Copr project doesn't exist yet") + logging.warning(f"Copr project doesn't exist yet: {e}") continue if len(new_builds) >= old_build_len + 1: From 47650d14246781928663d08f24d517360c84fcc8 Mon Sep 17 00:00:00 2001 From: Maja Massarini Date: Tue, 13 Feb 2024 15:18:44 +0100 Subject: [PATCH 3/4] Check for test existence If PR change their name chance is that we do not realize it and we don't execute the tests... --- src/validation/tests/base.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/validation/tests/base.py b/src/validation/tests/base.py index 5c0f4ea..ee7bca2 100644 --- a/src/validation/tests/base.py +++ b/src/validation/tests/base.py @@ -15,10 +15,15 @@ class Tests: test_case_kls: type def run(self): - logging.info("Run testcases where the build is triggered by a ‹vm-image-build› comment") prs_for_comment = [ pr for pr in self.project.get_pr_list() if pr.title.startswith("Test VM Image builds") ] + if prs_for_comment: + logging.info("Run testcases where the build is triggered by a ‹vm-image-build› comment") + else: + logging.warning( + "No testcases found where the build is triggered by a ‹vm-image-build› comment", + ) for pr in prs_for_comment: self.test_case_kls( project=self.project, @@ -28,10 +33,13 @@ def run(self): comment=DEPLOYMENT.pr_comment_vm_image_build, ).run_test() - logging.info("Run testcases where the build is triggered by a ‹build› comment") prs_for_comment = [ pr for pr in self.project.get_pr_list() if pr.title.startswith("Basic test case:") ] + if prs_for_comment: + logging.info("Run testcases where the build is triggered by a ‹build› comment") + else: + logging.warning("No testcases found where the build is triggered by a ‹build› comment") for pr in prs_for_comment: self.test_case_kls( project=self.project, @@ -40,12 +48,15 @@ def run(self): deployment=DEPLOYMENT, ).run_test() - logging.info("Run testcase where the build is triggered by push") pr_for_push = [ pr for pr in self.project.get_pr_list() if pr.title.startswith(DEPLOYMENT.push_trigger_tests_prefix) ] + if pr_for_push: + logging.info("Run testcase where the build is triggered by push") + else: + logging.warning("No testcase found where the build is triggered by push") if pr_for_push: self.test_case_kls( project=self.project, From 99e6e9153f5be6016b7b3e661a8e52ac3a205945 Mon Sep 17 00:00:00 2001 From: Maja Massarini Date: Tue, 13 Feb 2024 15:33:45 +0100 Subject: [PATCH 4/4] Do not use f-strings in logs --- src/validation/testcase/base.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/validation/testcase/base.py b/src/validation/testcase/base.py index d78984a..70f8b14 100644 --- a/src/validation/testcase/base.py +++ b/src/validation/testcase/base.py @@ -63,7 +63,8 @@ def run_test(self): self.pr.close() self.pr_branch_ref.delete() except Exception as e: - logging.error(f"Validation test {self.pr.title} ({self.pr.url}) failed: {e}") + msg = f"Validation test {self.pr.title} ({self.pr.url}) failed: {e}" + logging.error(msg) def trigger_build(self): """ @@ -215,7 +216,8 @@ def check_build_submitted(self): ) except Exception as e: # project does not exist yet - logging.warning(f"Copr project doesn't exist yet: {e}") + msg = f"Copr project doesn't exist yet: {e}" + logging.warning(msg) continue if len(new_builds) >= old_build_len + 1: