Skip to content

Add support for sending logs to pastebin #161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 37 additions & 21 deletions daily_tests/daily_nightly_tests_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]"
"[email protected]",
],
}

Expand Down Expand Up @@ -99,6 +99,8 @@

# The default directory used for nightly build
RESULTS_DIR = "/var/tmp/daily_reports_dir"
# The default directory used for running build
SCLORG_DIR = "/var/tmp/daily_scl_tests"


class NightlyTestsReport(object):
Expand Down Expand Up @@ -154,6 +156,16 @@ def prepare(self) -> bool:
self.log_dir = self.args.log_dir
return True

def get_pastebin_url(self, log_name: str) -> str:
with open(log_name, "r") as f:
lines = f.read()

for line in lines.split("\n"):
if not line.startswith("Link:"):
continue
return line.replace("Link:", "").strip()
return ""

def collect_data(self):
# Collect data to class dictionary
# self.data_dict['tmt'] item is used for Testing Farm errors per each OS and test case
Expand All @@ -171,10 +183,19 @@ def collect_data(self):
path_dir = Path(RESULTS_DIR) / test_case
if not path_dir.is_dir():
print(f"The test case {path_dir} does not exists that is weird")
self.data_dict["tmt"]["msg"].append(
self.data_dict["tmt"]["logs"].append(
f"Nightly build tests for {test_case} is not finished or did not run. "
f"Check nightly build machine for logs."
)
for sclorg in ["S2I", "NOS2I"]:
name = f"{test_case}-{sclorg}"
self.data_dict["tmt"]["logs"].append(
(
name,
Path(SCLORG_DIR) / f"{test_case}-{sclorg}" / "log.txt",
f"{name}.txt",
)
)
failed_tests = True
continue
# It looks like TMT is still running for long time
Expand Down Expand Up @@ -227,17 +248,10 @@ def collect_data(self):
continue
print(f"Failed containers are for {test_case} are: {failed_containers}")
failed_tests = True
for cont in failed_containers:
mime_name = f"{test_case}-{cont.name}"
attach = MIMEApplication(open(cont, "r").read(), Name=mime_name)
attach.add_header(
"Content-Disposition", 'attachment; filename="{}"'.format(mime_name)
)
self.mime_msg.attach(attach)

self.data_dict[test_case] = [
(str(f), str(f.name)) for f in failed_containers
]
print(failed_tests)
if not failed_tests:
self.full_success = True
print(f"collect data: {self.data_dict}")
Expand All @@ -252,13 +266,11 @@ def generate_email_body(self):
body_failure = "<b>Nightly builds Testing Farm failures:</b><br>"
body_success = "<b>These nightly builds were completely successful:</b><br>"
# Function for generation mail body
if self.data_dict["tmt"]["msg"]:
tmt_failures = "<br>".join(self.data_dict["tmt"]["msg"])
if self.data_dict["tmt"]["logs"]:
self.body += (
f"{body_failure}\n"
f"Tests were not successful because Testing Farm failures. "
f"Please contact [email protected] to analyse it.<br><br>"
f"{tmt_failures}<br><br>"
)
self.generate_tmt_logs_containers()
if self.data_dict["SUCCESS"]:
Expand All @@ -281,10 +293,15 @@ def generate_failed_containers(self):
for test_case, plan, msg in self.available_test_case:
if test_case not in self.data_dict:
continue
print(f"generate_email_body: {self.data_dict[test_case]}")
print(
f"generate_email_body_for_failed_containers: {self.data_dict[test_case]}"
)
self.body += f"<br><b>{msg}</b><br>List of failed containers:<br>"
for _, name in self.data_dict[test_case]:
self.body += f"{name}<br>"
for full_log_name, name in self.data_dict[test_case]:
self.body += (
f"<a href='{self.get_pastebin_url(log_name=full_log_name)}'>{name}</a>"
f"<br>"
)

def generate_success_containers(self):
for test_case, cont_path, log_name in self.data_dict["SUCCESS_DATA"]:
Expand All @@ -298,13 +315,12 @@ def generate_success_containers(self):

def generate_tmt_logs_containers(self):
for test_case, cont_path, log_name in self.data_dict["tmt"]["logs"]:
mime_name = f"{test_case}-{log_name}"
print(cont_path, log_name)
if os.path.exists(cont_path):
attach = MIMEApplication(open(cont_path, "r").read(), Name=mime_name)
attach.add_header(
"Content-Disposition", 'attachment; filename="{}"'.format(mime_name)
self.body += (
f"<a href='{self.get_pastebin_url(log_name=cont_path)}'>{test_case}</a>"
f"<br><br>"
)
self.mime_msg.attach(attach)

def generate_emails(self):
for test_case, plan, _ in self.available_test_case:
Expand Down
4 changes: 3 additions & 1 deletion daily_tests/daily_scl_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ TMP_DIR="${TMT_PLAN_DATA}"
RESULT_DIR="${TMP_DIR}/results/"
KUBECONFIG=/root/.kube/config
KUBEPASSWD=/root/.kube/ocp-kube
PBINCLI=/usr/local/bin/pbincli
PBINCLI_OPTS="--server https://privatebin.corp.redhat.com --expire 1week --no-insecure-warning --no-check-certificate --format plaintext"

mkdir -p "${RESULT_DIR}"

Expand Down Expand Up @@ -94,7 +96,7 @@ function iterate_over_all_containers() {
make "${TESTS}" TARGET="${TARGET}" > "${log_name}" 2>&1
if [[ $? -ne 0 ]]; then
echo "Tests for container $repo has failed."
cp "${log_name}" "${RESULT_DIR}/"
$PBINCLI send $PBINCLI_OPTS < "${log_name}" > "${RESULT_DIR}/${log_name}.txt" 2>&1
echo "Show the last 100 lines from file: ${RESULT_DIR}/${repo}.log"
tail -100 "${RESULT_DIR}/${repo}.log"
fi
Expand Down