Skip to content

Commit

Permalink
Improved traceability on site startup errors
Browse files Browse the repository at this point in the history
On any "Site was not running completely" errors, the output of
"omd status" will now be printed. Additionally, all log files
are copied just like it is done after a regular test run.

This should simplify debugging failed jobs in Jenkins.

Change-Id: Iace1bad8c7430435fb1a6aa81aeded49cb178303
  • Loading branch information
rene-slowenski-checkmk committed Nov 2, 2023
1 parent 10a7b83 commit 84a5f27
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions tests/testlib/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -1029,10 +1029,22 @@ def exists(self) -> bool:

def ensure_running(self) -> None:
if not self.is_running():
stdout = subprocess.check_output(["ps", "-ef"], text=True)
omd_status_output = self.execute(
["omd", "status"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT
).communicate()[0]
ps_output_file = os.path.join(self.result_dir(), "processes.out")
self.write_text_file(
ps_output_file,
self.execute(
["ps", "-ef"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT
).communicate()[0],
)
self.save_results()

pytest.exit(
"Site was not running completely while it should. Enforcing stop. "
f"Output of ps -ef:\n{stdout}"
"Site was not running completely while it should be! Enforcing stop.\n\n"
f"Output of omd status:\n{omd_status_output}\n\n"
f'See "{ps_output_file}" for full "ps -ef" output!',
)

def is_running(self) -> bool:
Expand Down Expand Up @@ -1198,8 +1210,7 @@ def save_results(self) -> None:
logger.info("Not containerized: not copying results")
return
logger.info("Saving to %s", self.result_dir())

os.makedirs(self.result_dir(), exist_ok=True)
self.makedirs(self.result_dir())

with suppress(FileNotFoundError):
shutil.copy(self.path("junit.xml"), self.result_dir())
Expand Down

0 comments on commit 84a5f27

Please sign in to comment.