diff --git a/.github/workflows/build-and-push.yml b/.github/workflows/build-and-push.yml index d202bdf..9e05b7f 100644 --- a/.github/workflows/build-and-push.yml +++ b/.github/workflows/build-and-push.yml @@ -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 }} @@ -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 }} diff --git a/Dockerfile.daily-tests b/Dockerfile.daily-tests index 910f755..b77a26e 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.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" \ diff --git a/Dockerfile.eol-checker b/Dockerfile.eol-checker index 2cef298..368e298 100644 --- a/Dockerfile.eol-checker +++ b/Dockerfile.eol-checker @@ -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." \ diff --git a/Makefile b/Makefile index 71701c7..cb15c41 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.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 @@ -6,6 +6,10 @@ run_daily_tests: 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 . diff --git a/eol-checker/eol_checker/checker.py b/eol-checker/eol_checker/checker.py index de1365e..03965e3 100755 --- a/eol-checker/eol_checker/checker.py +++ b/eol-checker/eol_checker/checker.py @@ -89,7 +89,6 @@ def __init__(self, debug: bool = False, send_email: bool = False): self.bold_line_end = "" 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): """ diff --git a/eol-checker/eol_checker/jira.py b/eol-checker/eol_checker/jira.py index b396456..11f6464 100644 --- a/eol-checker/eol_checker/jira.py +++ b/eol-checker/eol_checker/jira.py @@ -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): @@ -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) + self.jira_details = None def is_jira_filled_for_container(self, stream_name: str) -> str: jira_id = "" diff --git a/eol-checker/tests/test_jira.py b/eol-checker/tests/test_jira.py index f894209..f77fe73 100644 --- a/eol-checker/tests/test_jira.py +++ b/eol-checker/tests/test_jira.py @@ -1,3 +1,4 @@ +import os import pytest from flexmock import flexmock @@ -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 @@ -23,9 +23,9 @@ 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() @@ -33,42 +33,33 @@ def test_init_uses_env_overrides(monkeypatch): 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() @@ -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() @@ -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()