Skip to content

Commit

Permalink
If amd64 tag fails creenshot test, mark CI run a "FAIL".
Browse files Browse the repository at this point in the history
  • Loading branch information
GilbN committed Aug 27, 2024
1 parent e929867 commit 9f80277
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions ci/ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,11 @@ def container_test(self, tag: str) -> None:
return

# Screenshot the web interface and check connectivity
self.take_screenshot(container, tag)
screenshot: bool = self.take_screenshot(container, tag)
if not screenshot and self.get_platform(tag) == "amd64": # Allow ARM tags to fail the screenshot test
self.logger.error("Test of %s FAILED after %.2f seconds", tag, time.time() - start_time)
self._endtest(container, tag, build_info, sbom, False, start_time)
return

self._endtest(container, tag, build_info, sbom, True, start_time)
self.logger.success("Test of %s PASSED after %.2f seconds", tag, time.time() - start_time)
Expand Down Expand Up @@ -723,17 +727,20 @@ def _add_test_result(self, tag:str, test:str, status:str, message:str, start_tim
"message":message,
"runtime": runtime}.items())))

def take_screenshot(self, container: Container, tag:str) -> None:
def take_screenshot(self, container: Container, tag:str) -> bool:
"""Take a screenshot and save it to self.outdir if self.screenshot is True
Takes a screenshot using a ChromiumDriver instance.
Args:
container (Container): Container object
tag (str): The container tag we are testing.
Returns:
bool: Return True if the screenshot was successful, otherwise False.
"""
if not self.screenshot:
return
return True
proto: Literal["https", "http"] = "https" if self.ssl.upper() == "TRUE" else "http"
screenshot_timeout = time.time() + self.screenshot_timeout
test = "Get screenshot"
Expand All @@ -757,7 +764,7 @@ def take_screenshot(self, container: Container, tag:str) -> None:
raise FileNotFoundError(f"Screenshot '{self.outdir}/{tag}.png' not found")
self._add_test_result(tag, test, "PASS", "-", start_time)
self.logger.success("Screenshot %s: PASSED after %.2f seconds", tag, time.time() - start_time)
return
return True
except Exception as error:
logger.debug("Failed to take screenshot of %s at %s, trying again in 3 seconds", tag, endpoint, exc_info=error)
time.sleep(3)
Expand All @@ -768,12 +775,18 @@ def take_screenshot(self, container: Container, tag:str) -> None:
except (requests.Timeout, requests.ConnectionError, KeyError) as error:
self._add_test_result(tag, test, "FAIL", f"CONNECTION ERROR: {str(error)}", start_time)
self.logger.exception("Screenshot %s FAIL CONNECTION ERROR", tag)
self.report_status = "FAIL"
return False
except TimeoutException as error:
self._add_test_result(tag, test, "FAIL", f"TIMEOUT: {str(error)}", start_time)
self.logger.exception("Screenshot %s FAIL TIMEOUT", tag)
self.report_status = "FAIL"
return False
except (WebDriverException, Exception) as error:
self._add_test_result(tag, test, "FAIL", f"UNKNOWN: {str(error)}", start_time)
self.logger.exception("Screenshot %s FAIL UNKNOWN", tag)
self.report_status = "FAIL"
return False
finally:
try:
driver.quit()
Expand Down

0 comments on commit 9f80277

Please sign in to comment.