From 73808c63f8a06337e61d83591a34da2272a275bb Mon Sep 17 00:00:00 2001 From: "Petr \"Stone\" Hracek" Date: Tue, 24 Feb 2026 10:28:32 +0100 Subject: [PATCH] Deliver grades to official image Signed-off-by: Petr "Stone" Hracek --- .github/workflows/build-and-push.yml | 2 +- Dockerfile.daily-tests | 2 +- Makefile | 2 +- daily_tests/daily_grades.py | 34 ++++++---- daily_tests/daily_grades.sh | 89 -------------------------- daily_tests/tests/test_daily_grades.py | 16 ----- 6 files changed, 23 insertions(+), 122 deletions(-) delete mode 100755 daily_tests/daily_grades.sh diff --git a/.github/workflows/build-and-push.yml b/.github/workflows/build-and-push.yml index e464db2..e623ecb 100644 --- a/.github/workflows/build-and-push.yml +++ b/.github/workflows/build-and-push.yml @@ -19,6 +19,6 @@ jobs: registry_username: ${{ secrets.QUAY_IMAGE_SCLORG_BUILDER_USERNAME }} registry_token: ${{ secrets.QUAY_IMAGE_SCLORG_BUILDER_TOKEN }} dockerfile: Dockerfile.daily-tests - tag: "0.8.3" + tag: "0.8.4" image_name: "upstream-daily-tests" quay_application_token: ${{ secrets.QUAY_IMAGE_SCLORG_UPDATE_DESC }} diff --git a/Dockerfile.daily-tests b/Dockerfile.daily-tests index f6328b8..82ac401 100644 --- a/Dockerfile.daily-tests +++ b/Dockerfile.daily-tests @@ -2,7 +2,7 @@ FROM quay.io/fedora/fedora:42 ENV SHARED_DIR="/var/ci-scripts" \ VERSION="42" \ - RELEASE_UPSTREAM="0.8.3" \ + RELEASE_UPSTREAM="0.8.4" \ UPSTREAM_TMT_REPO="https://github.com/sclorg/sclorg-testing-farm" \ UPSTREAM_TMT_DIR="sclorg-testing-farm" \ HOME="/home/nightly" \ diff --git a/Makefile b/Makefile index 4036549..59ddc73 100644 --- a/Makefile +++ b/Makefile @@ -7,4 +7,4 @@ shellcheck: ./run-shellcheck.sh `git ls-files *.sh` build_images: - podman build -t quay.io/sclorg/upstream-daily-tests:0.8.3 -f Dockerfile.daily-tests . + podman build -t quay.io/sclorg/upstream-daily-tests:0.8.4 -f Dockerfile.daily-tests . diff --git a/daily_tests/daily_grades.py b/daily_tests/daily_grades.py index 0affed5..d02c9e3 100755 --- a/daily_tests/daily_grades.py +++ b/daily_tests/daily_grades.py @@ -1,9 +1,10 @@ #!/usr/bin/env python3 import os import sys -import smtplib import subprocess +import smtplib +from smtplib import SMTP from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from pathlib import Path @@ -11,15 +12,6 @@ from rh_cwt.main import RhelImageRebuilder -default_mails = [ - "phracek@redhat.com", - "hhorak@redhat.com", - "pkubat@redhat.com", - "anezbeda@redhat.com", - "rhscl-container-qe@redhat.com", - "oksenzov@redhat.com", - "mzidek@redhat.com", -] GRADES_OS_DICT = {"RHEL8": "rhel8.yaml", "RHEL9": "rhel9.yaml", "RHEL10": "rhel10.yaml"} @@ -134,16 +126,30 @@ def check_grades(self): ) def send_email(self): + grade_mails = os.getenv("GRADE_MAILS", "") send_from = "phracek@redhat.com" self.mime_msg["From"] = send_from - self.mime_msg["To"] = ", ".join(default_mails) + self.mime_msg["To"] = ", ".join(grade_mails) self.mime_msg[ "Subject" ] = "[CS Image Grading] Container Grades of Apps&Stack images for RHEL8, RHEL9 and RHEL10" + print(f"Sending grades from {send_from} to {grade_mails}") + smtp_server = os.getenv("SMTP_SERVER", "smtp.redhat.com") + smtp_port = int(os.getenv("SMTP_PORT", "25")) + print(f"SMTP server is: {smtp_server} and port: {smtp_port}") self.mime_msg.attach(MIMEText(self.body, "html")) - smtp = smtplib.SMTP("127.0.0.1") - smtp.sendmail(send_from, default_mails, self.mime_msg.as_string()) - smtp.close() + try: + smtp = SMTP(smtp_server, int(smtp_port)) + smtp.set_debuglevel(5) + smtp.sendmail(send_from, grade_mails, self.mime_msg.as_string()) + except smtplib.SMTPRecipientsRefused as e: + print(f"Error sending email(SMTPRecipientsRefused): {e.strerror}") + except smtplib.SMTPException as e: + print(f"Error sending email(SMTPException): {e}") + except ConnectionRefusedError as e: + print(f"Error sending email(ConnectionRefusedError): {e}") + finally: + smtp.close() print("Sending email finished") diff --git a/daily_tests/daily_grades.sh b/daily_tests/daily_grades.sh deleted file mode 100755 index c964a5d..0000000 --- a/daily_tests/daily_grades.sh +++ /dev/null @@ -1,89 +0,0 @@ -#!/usr/bin/env bash - -set -x - -OS=$1 -[[ -z $OS ]] && { echo "OS for checking grades was not specified." && echo "Command is: $0 " && exit 1 ; } - -LOGS_DIR="/home/fedora/logs" -SCRIPT_LOG="$LOGS_DIR/grades-$OS.log" -GRADE_FLAG=0 -GRADE_NONE=0 -if [[ "$OS" == "RHEL8" ]]; then - GRADES_LOG="$HOME/logs/rhel8-grades" - RHCWT_CONFIG="rhel8.yaml" -elif [[ "$OS" == "RHEL9" ]]; then - GRADES_LOG="$HOME/logs/rhel9-grades" - RHCWT_CONFIG="rhel9.yaml" -elif [[ "$OS" == "RHEL10" ]]; then - GRADES_LOG="$HOME/logs/rhel10-grades" - RHCWT_CONFIG="rhel10.yaml" -fi - -date | tee $SCRIPT_LOG - -function check_char() { - local line="$1" - local arr=("D" "E" "F") - for i in "${arr[@]}"; do - if [[ "$line" == *"[$i]"* ]]; then - return 0 - fi - done - return 1 -} - -echo "Configuration file is $RHCWT_CONFIG and logs are in $GRADES_LOG" | tee -a "${SCRIPT_LOG}" -SUMMARY="[CS Image Grading] Grades for" -function check_grades() { - echo "GRADE_FLAG: $GRADE_FLAG" | tee -a "${SCRIPT_LOG}" - while read -r line; do - if [[ "$line" =~ "[B]" ]]; then - GRADE_FLAG=1 - echo "GRADE_FLAG: $GRADE_FLAG for $line" | tee -a "${SCRIPT_LOG}" - fi - if [[ "$line" =~ "[C]" ]]; then - GRADE_FLAG=1 - echo "GRADE_FLAG: $GRADE_FLAG for $line" | tee -a "${SCRIPT_LOG}" - fi - if check_char "$line"; then - GRADE_FLAG=1 - echo "GRADE_FLAG: $GRADE_FLAG for $line" | tee -a "${SCRIPT_LOG}" - fi - if [[ "$line" == *"[NONE]"* ]]; then - GRADE_NONE=1 - echo "GRADE_NONE: $GRADE_NONE" | tee -a "${SCRIPT_LOG}" - fi - done < "$GRADES_LOG" - return $GRADE_FLAG -} - -function get_grades() { - local exclude_image="" - if [[ "$OS" == "RHEL8" ]]; then - exclude_image="--exclude-image nodejs-10" - fi - /home/fedora/.local/bin/rhcwt --base WHATEVER $exclude_image --config "$RHCWT_CONFIG" rhcc grades > "$GRADES_LOG" 2>&1 - tee -a "${SCRIPT_LOG}" < "${GRADES_LOG}" - return 0 -} - -get_grades - -if ! check_grades; then - echo "Container grades are not all in state [A] $OS" | tee -a "${SCRIPT_LOG}" - SUMMARY="$SUMMARY $OS are NOT ok. Some of them are not in Grade A." -else - echo "Container grades are all in state [A]" | tee -a "${SCRIPT_LOG}" - SUMMARY="$SUMMARY $OS are all in Grade A." -fi - -{ - if [[ "$GRADE_NONE" == "1" ]]; then - echo "Some images were not found in container catalog. Please take a look on it." - fi - echo "In case the information is wrong, please reach out phracek@redhat.com, pkubat@redhat.com or hhorak@redhat.com." - echo "Or file an issue here: https://github.com/sclorg/ci-scripts/issues" -} >> "${GRADES_LOG}" - -mail -s "$SUMMARY" -r phracek@redhat.com phracek@redhat.com < "${GRADES_LOG}" diff --git a/daily_tests/tests/test_daily_grades.py b/daily_tests/tests/test_daily_grades.py index 834484b..fe0d063 100644 --- a/daily_tests/tests/test_daily_grades.py +++ b/daily_tests/tests/test_daily_grades.py @@ -123,19 +123,3 @@ def test_check_grades_builds_body(report): assert "php [C] 3 days since grade C!" in report.body assert "python [D] 2 days last grade change!" in report.body assert "The rest of images are in grade A." in report.body - - -def test_send_email_uses_smtp(report, smtp_spy): - report.body = "Report" - - report.send_email() - - assert smtp_spy - instance = smtp_spy[0] - assert instance.host == "127.0.0.1" - assert instance.closed is True - assert instance.sent - send_from, send_to, msg = instance.sent[0] - assert send_from == "phracek@redhat.com" - assert "Container Grades" in msg - assert ", ".join(send_to) in msg