Skip to content
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
4 changes: 2 additions & 2 deletions .github/workflows/build-and-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
registry_username: ${{ secrets.QUAY_IMAGE_SCLORG_BUILDER_USERNAME }}
registry_token: ${{ secrets.QUAY_IMAGE_SCLORG_BUILDER_TOKEN }}
dockerfile: Dockerfile.daily-tests
tag: "0.10.3"
tag: "0.10.4"
image_name: "upstream-daily-tests"
quay_application_token: ${{ secrets.QUAY_IMAGE_SCLORG_UPDATE_DESC }}

Expand All @@ -31,6 +31,6 @@ jobs:
registry_username: ${{ secrets.QUAY_IMAGE_SCLORG_BUILDER_USERNAME }}
registry_token: ${{ secrets.QUAY_IMAGE_SCLORG_BUILDER_TOKEN }}
dockerfile: Dockerfile.eol-checker
tag: "0.10.3"
tag: "0.10.4"
image_name: "upstream-eol-checker"
quay_application_token: ${{ secrets.QUAY_IMAGE_SCLORG_UPDATE_DESC }}
2 changes: 1 addition & 1 deletion Dockerfile.daily-tests
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM quay.io/fedora/fedora:42

ENV SHARED_DIR="/var/ci-scripts" \
VERSION="42" \
RELEASE_UPSTREAM="0.10.3" \
RELEASE_UPSTREAM="0.10.4" \
UPSTREAM_TMT_REPO="https://github.com/sclorg/sclorg-testing-farm" \
UPSTREAM_TMT_DIR="sclorg-testing-farm" \
HOME="/home/nightly" \
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.eol-checker
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM quay.io/fedora/fedora:42

ENV VERSION="42" \
RELEASE_UPSTREAM="0.10.3" \
RELEASE_UPSTREAM="0.10.4" \
HOME="/home/eol-checker" \
SUMMARY="EOL checker for SCL org projects" \
DESCRIPTION="This image is used to run EOL checker for SCL org projects in CI." \
Expand Down
12 changes: 8 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
.PHONY: run_daily_tests shellcheck build_images
.PHONY: run_daily_tests shellcheck build_images daily_tests eol_checker

run_daily_tests:
bash daily_tests/daily_scl_tests.sh

shellcheck:
./run-shellcheck.sh `git ls-files *.sh`

build_images:
podman build -t quay.io/sclorg/upstream-daily-tests:0.10.3 -f Dockerfile.daily-tests .
podman build -t quay.io/sclorg/upstream-eol-checker:0.10.3 -f Dockerfile.eol-checker .
build_images: daily_tests eol_checker

daily_tests:
podman build -t quay.io/sclorg/upstream-daily-tests:0.10.4 -f Dockerfile.daily-tests .

eol_checker:
podman build -t quay.io/sclorg/upstream-eol-checker:0.10.4 -f Dockerfile.eol-checker .
1 change: 0 additions & 1 deletion eol-checker/eol_checker/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ def __init__(self, debug: bool = False, send_email: bool = False):
self.bold_line_end = "</b>" if self.send_email else ""
self.mime_msg = MIMEMultipart()
self.body = ""
self.debug = bool(os.getenv("DEBUG", "False"))

def _setup_logger(self, debug: bool = False):
"""
Expand Down
34 changes: 20 additions & 14 deletions eol-checker/eol_checker/jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,18 @@ def __init__(self):
@property
def jira(self) -> Jira:
if self._jira_api is None:
username = os.getenv("JIRA_USERNAME", "")
password = os.getenv("JIRA_PASSWORD", "")
if username == "" or password == "":
logger.error("JIRA_USERNAME and/or JIRA_PASSWORD are not set")
jira_token = os.getenv("JIRA_TOKEN", "")
jira_username = os.getenv("JIRA_USERNAME", "")
if not all((jira_token, jira_username)):
logger.error("JIRA_TOKEN and/or JIRA_USERNAME are not set")
return None
self._jira_api = Jira(
url=self.jira_url, username=username, password=password
url=self.jira_url,
username=jira_username,
password=jira_token,
cloud=True,
)
self._jira_api.http_status_code_handler(self._jira_api.http_status_code)
if self._jira_api.http_status_code != 200:
logger.error(
"Failed to get JIRA details: %s", self._jira_api.http_status_code
)
return None
logger.debug("JIRA API initialized with URL: '%s'", self.jira_url)
return self._jira_api

def get_jira_deprecation_details(self):
Expand All @@ -46,9 +44,17 @@ def get_jira_deprecation_details(self):
Returns:
The JIRA details.
"""
issue = self.jira.issue(self.jira_deprecation_ticket)
if "fields" in issue and "issuelinks" in issue["fields"]:
self.jira_details = issue["fields"]["issuelinks"]
logger.debug("JIRA deprecation ticket details: '%s'", self.jira_deprecation_ticket)
if self.jira is None:
logger.error("JIRA API is not initialized")
return
try:
issue = self.jira.issue(self.jira_deprecation_ticket)
if "fields" in issue and "issuelinks" in issue["fields"]:
self.jira_details = issue["fields"]["issuelinks"]
except HTTPError as e:
logger.error("Error occurred while fetching JIRA issue: %s", e)
Comment thread
phracek marked this conversation as resolved.
self.jira_details = None

def is_jira_filled_for_container(self, stream_name: str) -> str:
jira_id = ""
Expand Down
61 changes: 25 additions & 36 deletions eol-checker/tests/test_jira.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import pytest
from flexmock import flexmock

Expand All @@ -11,10 +12,9 @@ def fetcher():
return JiraFetcher()


def test_init_uses_defaults_when_env_unset(monkeypatch):
monkeypatch.delenv("JIRA_DEPRECATION_TICKET", raising=False)
monkeypatch.delenv("JIRA_URL", raising=False)

def test_init_uses_defaults_when_env_unset():
os.environ["JIRA_DEPRECATION_TICKET"] = JIRA_DEPRECATION_TICKET
os.environ["JIRA_URL"] = JIRA_URL
instance = JiraFetcher()

assert instance.jira_deprecation_ticket == JIRA_DEPRECATION_TICKET
Expand All @@ -23,52 +23,43 @@ def test_init_uses_defaults_when_env_unset(monkeypatch):
assert instance.jira_deprecated_opened_issues == []


def test_init_uses_env_overrides(monkeypatch):
monkeypatch.setenv("JIRA_DEPRECATION_TICKET", "CUSTOM-1")
monkeypatch.setenv("JIRA_URL", "https://jira.example.com")
def test_init_uses_env_overrides():
os.environ["JIRA_DEPRECATION_TICKET"] = "CUSTOM-1"
os.environ["JIRA_URL"] = "https://jira.example.com"

instance = JiraFetcher()

assert instance.jira_deprecation_ticket == "CUSTOM-1"
assert instance.jira_url == "https://jira.example.com"


def test_jira_property_returns_none_without_credentials(monkeypatch, fetcher):
monkeypatch.delenv("JIRA_USERNAME", raising=False)
monkeypatch.delenv("JIRA_PASSWORD", raising=False)
def test_jira_property_returns_none_without_credentials(fetcher):
os.environ["JIRA_TOKEN"] = ""
os.environ["JIRA_USERNAME"] = ""
flexmock(jira_module).should_receive("Jira").never()

assert fetcher.jira is None


def test_jira_property_returns_none_when_http_status_not_ok(monkeypatch, fetcher):
monkeypatch.setenv("JIRA_USERNAME", "user@redhat.com")
monkeypatch.setenv("JIRA_PASSWORD", "secret")
mock_client = flexmock(http_status_code=403)
mock_client.should_receive("http_status_code_handler").with_args(403).once()
flexmock(jira_module).should_receive("Jira").and_return(mock_client)

assert fetcher.jira is None


def test_jira_property_creates_client_once(monkeypatch, fetcher):
monkeypatch.setenv("JIRA_USERNAME", "user@redhat.com")
monkeypatch.setenv("JIRA_PASSWORD", "secret")
mock_client = flexmock(http_status_code=200)
mock_client.should_receive("http_status_code_handler").with_args(200).once()
def test_jira_property_creates_client_once(fetcher):
os.environ["JIRA_TOKEN"] = "secret"
os.environ["JIRA_USERNAME"] = "user@redhat.com"
mock_client = flexmock()
flexmock(jira_module).should_receive("Jira").with_args(
url=fetcher.jira_url, username="user@redhat.com", password="secret"
url=fetcher.jira_url,
username="user@redhat.com",
password="secret",
cloud=True,
).once().and_return(mock_client)

assert fetcher.jira is mock_client
assert fetcher.jira is mock_client


def test_get_jira_deprecation_details_stores_issuelinks(fetcher):
mock_client = flexmock()
mock_client.should_receive("issue").with_args(
fetcher.jira_deprecation_ticket
).and_return({"fields": {"issuelinks": [{"inwardIssue": {"key": "CLONE-1"}}]}})
mock_client.should_receive("issue").with_args(fetcher.jira_deprecation_ticket).and_return(
{"fields": {"issuelinks": [{"inwardIssue": {"key": "CLONE-1"}}]}}
)
fetcher._jira_api = mock_client

fetcher.get_jira_deprecation_details()
Expand All @@ -78,9 +69,9 @@ def test_get_jira_deprecation_details_stores_issuelinks(fetcher):

def test_get_jira_deprecation_details_skips_when_no_issuelinks(fetcher):
mock_client = flexmock()
mock_client.should_receive("issue").with_args(
fetcher.jira_deprecation_ticket
).and_return({"fields": {}})
mock_client.should_receive("issue").with_args(fetcher.jira_deprecation_ticket).and_return(
{"fields": {}}
)
fetcher._jira_api = mock_client

fetcher.get_jira_deprecation_details()
Expand All @@ -90,9 +81,7 @@ def test_get_jira_deprecation_details_skips_when_no_issuelinks(fetcher):

def test_get_jira_deprecation_details_skips_when_fields_missing(fetcher):
mock_client = flexmock()
mock_client.should_receive("issue").with_args(
fetcher.jira_deprecation_ticket
).and_return({})
mock_client.should_receive("issue").with_args(fetcher.jira_deprecation_ticket).and_return({})
fetcher._jira_api = mock_client

fetcher.get_jira_deprecation_details()
Expand Down
Loading