| |
@@ -11,6 +11,19 @@
|
| |
import toddlers.plugins.koji_block_retired as koji_block_retired
|
| |
|
| |
|
| |
+ @pytest.fixture
|
| |
+ def config():
|
| |
+ """Test configuration for toddler fixture."""
|
| |
+ return {
|
| |
+ "dist_git_url": "https://src.fedoraproject.org",
|
| |
+ "koji_url": "https://example.koji.org",
|
| |
+ "principal": "principal",
|
| |
+ "keytab": "keytab",
|
| |
+ "pagure_url": "https://src.fedoraproject.org",
|
| |
+ "pagure_api_key": "pagure_api_key",
|
| |
+ }
|
| |
+
|
| |
+
|
| |
class TestAcceptTopic:
|
| |
"""
|
| |
Test class for `toddler.plugins.koji_block_retired.KojiBlockRetired.accepts_topic`
|
| |
@@ -31,6 +44,9 @@
|
| |
"org.fedoraproject.*.git.receive",
|
| |
"org.fedoraproject.prod.git.receive",
|
| |
"org.fedoraproject.stg.git.receive",
|
| |
+ "org.fedoraproject.prod.toddlers.trigger.koji_block_retired",
|
| |
+ "org.fedoraproject.*.toddlers.trigger.koji_block_retired",
|
| |
+ "org.fedoraproject.stg.toddlers.trigger.koji_block_retired",
|
| |
],
|
| |
)
|
| |
def test_accepts_topic_valid(self, topic, toddler):
|
| |
@@ -57,14 +73,14 @@
|
| |
config = {"key": "value"}
|
| |
message = "Example message"
|
| |
|
| |
- self.toddler_cls.process_block_retired = MagicMock()
|
| |
+ self.toddler_cls.process = MagicMock()
|
| |
self.toddler_cls.process(config, message)
|
| |
- self.toddler_cls.process_block_retired.assert_called_once_with(config, message)
|
| |
+ self.toddler_cls.process.assert_called_once_with(config, message)
|
| |
|
| |
|
| |
class TestProcessBlockRetired:
|
| |
"""
|
| |
- Test class for `toddler.plugins.koji_block_retired.KojiBlockRetired.process_block_retired`
|
| |
+ Test class for `toddler.plugins.koji_block_retired.KojiBlockRetired.process`
|
| |
method.
|
| |
"""
|
| |
|
| |
@@ -73,21 +89,24 @@
|
| |
self.toddler_cls = koji_block_retired.KojiBlockRetired()
|
| |
self.toddler_cls.koji_session = MagicMock()
|
| |
|
| |
- def test_no_dead_package_file(self, caplog):
|
| |
+ @patch("toddlers.plugins.koji_block_retired.KojiBlockRetired._create_session")
|
| |
+ def test_no_dead_package_file(self, mock_session, caplog):
|
| |
"""
|
| |
Assert that if no dead package was added the plugin stops.
|
| |
"""
|
| |
caplog.set_level(logging.INFO)
|
| |
message = MagicMock()
|
| |
message.body = {"commit": {"stats": {"files": {}}}}
|
| |
+ message.topic = "git.receive"
|
| |
config = MagicMock()
|
| |
config = {
|
| |
"koji_url": "https://example.koji.org",
|
| |
"principal": "principal",
|
| |
"keytab": "keytab",
|
| |
}
|
| |
- self.toddler_cls.process_block_retired(config, message)
|
| |
+ self.toddler_cls.process(config, message)
|
| |
assert caplog.records[-1].message == "No dead.package in the commit, bailing"
|
| |
+ self.toddler_cls._create_session.assert_not_called()
|
| |
|
| |
def test_dead_package_not_added(self, caplog):
|
| |
"""
|
| |
@@ -100,24 +119,25 @@
|
| |
"stats": {"files": {"dead.package": {"additions": 0, "deletions": 1}}}
|
| |
}
|
| |
}
|
| |
+ message.topic = "git.receive"
|
| |
config = MagicMock()
|
| |
config = {
|
| |
"koji_url": "https://example.koji.org",
|
| |
"principal": "principal",
|
| |
"keytab": "keytab",
|
| |
}
|
| |
- self.toddler_cls.process_block_retired(config, message)
|
| |
+ self.toddler_cls.process(config, message)
|
| |
assert caplog.records[-1].message == "dead.package file was not added, bailing"
|
| |
|
| |
- @patch("toddlers.plugins.koji_block_retired.KojiBlockRetired._create_session")
|
| |
- @patch("toddlers.plugins.koji_block_retired.KojiBlockRetired.get_tag_from_target")
|
| |
- def test_dead_package_added_to_main_branch(self, mock_get_tag_from_target, caplog):
|
| |
+ @patch("toddlers.plugins.koji_block_retired.pagure.set_pagure")
|
| |
+ def test_dead_package_not_in_distgit(self, mock_pagure, caplog):
|
| |
"""
|
| |
- Assert that that main branch will be changed to rawhide tag
|
| |
+ Assert if dead.package not present in distgit, the plugin stops.
|
| |
"""
|
| |
- mock_get_tag_from_target.return_value = "f41"
|
| |
+ mock_dist_git = MagicMock()
|
| |
+ mock_dist_git.has_dead_package_on_branch.return_value = False
|
| |
+ mock_pagure.return_value = mock_dist_git
|
| |
caplog.set_level(logging.INFO)
|
| |
-
|
| |
message = MagicMock()
|
| |
message.body = {
|
| |
"commit": {
|
| |
@@ -128,27 +148,73 @@
|
| |
"date": "2024-09-16T12:12:46+01:00",
|
| |
}
|
| |
}
|
| |
- message._headers = {"sent-at": "2024-09-16T12:12:46+01:00"}
|
| |
+ message.topic = "git.receive"
|
| |
config = MagicMock()
|
| |
config = {
|
| |
"koji_url": "https://example.koji.org",
|
| |
"principal": "principal",
|
| |
"keytab": "keytab",
|
| |
}
|
| |
+ self.toddler_cls.process(config, message)
|
| |
+ assert (
|
| |
+ caplog.records[-1].message
|
| |
+ == "Package example-repo is not retired on the distgit branch main, "
|
| |
+ "probably new branch creation, bailing"
|
| |
+ )
|
| |
+
|
| |
+ @patch("toddlers.plugins.koji_block_retired.pagure.set_pagure")
|
| |
+ @patch("toddlers.plugins.koji_block_retired.KojiBlockRetired._create_session")
|
| |
+ @patch("toddlers.plugins.koji_block_retired.KojiBlockRetired.get_tag_from_target")
|
| |
+ def test_dead_package_added_to_main_branch(
|
| |
+ self,
|
| |
+ mock_get_tag_from_target,
|
| |
+ mock_session,
|
| |
+ mock_pagure,
|
| |
+ config,
|
| |
+ caplog,
|
| |
+ ):
|
| |
+ """
|
| |
+ Assert that that main branch will be changed to rawhide tag
|
| |
+ """
|
| |
+ mock_get_tag_from_target.return_value = "f41"
|
| |
+ caplog.set_level(logging.INFO)
|
| |
+ mock_dist_git = MagicMock()
|
| |
+ mock_dist_git.has_dead_package_on_branch.return_value = True
|
| |
+ mock_pagure.return_value = mock_dist_git
|
| |
+
|
| |
+ message = MagicMock()
|
| |
+ message.body = {
|
| |
+ "commit": {
|
| |
+ "stats": {"files": {"dead.package": {"additions": 1, "deletions": 0}}},
|
| |
+ "branch": "main",
|
| |
+ "repo": "example-repo",
|
| |
+ "namespace": "example_ns",
|
| |
+ "date": "2024-09-16T12:12:46+01:00",
|
| |
+ }
|
| |
+ }
|
| |
+ message.topic = "git.receive"
|
| |
+ self.toddler_cls.koji_session.packageListBlock.__name__ = "packageListBlock"
|
| |
with patch.object(
|
| |
self.toddler_cls, "get_tag_from_target", MagicMock(return_value="f41")
|
| |
):
|
| |
- self.toddler_cls.process_block_retired(config, message)
|
| |
+ self.toddler_cls.process(config, message)
|
| |
self.toddler_cls.koji_session.packageListBlock.assert_called_once_with(
|
| |
taginfo="f41",
|
| |
pkginfo="example-repo",
|
| |
)
|
| |
|
| |
+ @patch("toddlers.plugins.koji_block_retired.pagure.set_pagure")
|
| |
@patch("toddlers.plugins.koji_block_retired.KojiBlockRetired._create_session")
|
| |
- def test_dead_package_added_to_different_branch(self, mock_session, caplog):
|
| |
+ def test_dead_package_added_to_different_branch(
|
| |
+ self, mock_session, mock_pagure, config, caplog
|
| |
+ ):
|
| |
"""
|
| |
Assert that method will process correctly with different branches.
|
| |
"""
|
| |
+ mock_dist_git = MagicMock()
|
| |
+ mock_dist_git.has_dead_package_on_branch.return_value = True
|
| |
+ mock_pagure.return_value = mock_dist_git
|
| |
+
|
| |
caplog.set_level(logging.INFO)
|
| |
message = MagicMock()
|
| |
message.body = {
|
| |
@@ -160,24 +226,24 @@
|
| |
"date": "2024-09-16T12:12:46+01:00",
|
| |
}
|
| |
}
|
| |
- message._headers = {"sent-at": "2024-09-16T12:12:46+01:00"}
|
| |
- config = MagicMock()
|
| |
- config = {
|
| |
- "koji_url": "https://example.koji.org",
|
| |
- "principal": "principal",
|
| |
- "keytab": "keytab",
|
| |
- }
|
| |
- self.toddler_cls.process_block_retired(config, message)
|
| |
+ message.topic = "git.receive"
|
| |
+ self.toddler_cls.koji_session.packageListBlock.__name__ = "packageListBlock"
|
| |
+ self.toddler_cls.process(config, message)
|
| |
self.toddler_cls.koji_session.packageListBlock.assert_called_once_with(
|
| |
taginfo="f38",
|
| |
pkginfo="example-repo",
|
| |
)
|
| |
|
| |
+ @patch("toddlers.plugins.koji_block_retired.pagure.set_pagure")
|
| |
@patch("toddlers.plugins.koji_block_retired.KojiBlockRetired._create_session")
|
| |
- def test_koji_generic_error_prod(self, mock_session, caplog):
|
| |
+ def test_koji_generic_error_prod(self, mock_session, mock_pagure, config, caplog):
|
| |
"""
|
| |
Assert that Koji generic error will be handled correctly.
|
| |
"""
|
| |
+ mock_dist_git = MagicMock()
|
| |
+ mock_dist_git.has_dead_package_on_branch.return_value = True
|
| |
+ mock_pagure.return_value = mock_dist_git
|
| |
+
|
| |
message = MagicMock()
|
| |
message.body = {
|
| |
"commit": {
|
| |
@@ -188,27 +254,31 @@
|
| |
"date": "2024-09-16T12:12:46+01:00",
|
| |
}
|
| |
}
|
| |
- message._headers = {"sent-at": "2024-09-16T12:12:46+01:00"}
|
| |
- config = MagicMock()
|
| |
- config = {
|
| |
- "koji_url": "https://example.koji.org",
|
| |
- "principal": "principal",
|
| |
- "keytab": "keytab",
|
| |
- }
|
| |
+ message.topic = "git.receive"
|
| |
+ self.toddler_cls.koji_session.packageListBlock.__name__ = "packageListBlock"
|
| |
self.toddler_cls.koji_session.packageListBlock.side_effect = koji.GenericError(
|
| |
"Failed"
|
| |
)
|
| |
- self.toddler_cls.process_block_retired(config, message)
|
| |
+ self.toddler_cls.process(config, message)
|
| |
+ assert (
|
| |
+ caplog.records[-2].message
|
| |
+ == "Unable to create koji ClientSession for call packageListBlock: Failed"
|
| |
+ )
|
| |
assert (
|
| |
caplog.records[-1].message
|
| |
- == "Failed to block retired package example-repo on branch f38: Failed"
|
| |
+ == "Failed, recreating koji_session and trying again"
|
| |
)
|
| |
|
| |
+ @patch("toddlers.plugins.koji_block_retired.pagure.set_pagure")
|
| |
@patch("toddlers.plugins.koji_block_retired.KojiBlockRetired._create_session")
|
| |
- def test_koji_generic_error_stg(self, mock_session, caplog):
|
| |
+ def test_koji_generic_error_stg(self, mock_session, mock_pagure, config, caplog):
|
| |
"""
|
| |
Assert that Koji generic error will be handled correctly.
|
| |
"""
|
| |
+ mock_dist_git = MagicMock()
|
| |
+ mock_dist_git.has_dead_package_on_branch.return_value = True
|
| |
+ mock_pagure.return_value = mock_dist_git
|
| |
+
|
| |
message = MagicMock()
|
| |
message.body = {
|
| |
"commit": {
|
| |
@@ -219,48 +289,57 @@
|
| |
"date": "2024-09-16T12:12:46+01:00",
|
| |
}
|
| |
}
|
| |
- message._headers = {"sent-at": "2024-09-16T12:12:46+01:00"}
|
| |
- config = MagicMock()
|
| |
- config = {
|
| |
- "koji_url": "https://example.koji.org",
|
| |
- "principal": "principal",
|
| |
- "keytab": "keytab",
|
| |
- }
|
| |
+ message.topic = "git.receive"
|
| |
+ self.toddler_cls.koji_session.packageListBlock.__name__ = "packageListBlock"
|
| |
self.toddler_cls.koji_session.packageListBlock.side_effect = koji.GenericError(
|
| |
"Failed"
|
| |
)
|
| |
- self.toddler_cls.process_block_retired(config, message)
|
| |
+ self.toddler_cls.process(config, message)
|
| |
+ assert (
|
| |
+ caplog.records[-2].message
|
| |
+ == "Unable to create koji ClientSession for call packageListBlock: Failed"
|
| |
+ )
|
| |
assert (
|
| |
caplog.records[-1].message
|
| |
- == "Failed to block retired package example-epel-repo on branch f38: Failed"
|
| |
+ == "Failed, recreating koji_session and trying again"
|
| |
)
|
| |
|
| |
- def test_timedelta_of_commit_bigger_than_one_day(self, caplog):
|
| |
+ @patch("toddlers.plugins.koji_block_retired.pagure.set_pagure")
|
| |
+ @patch("toddlers.plugins.koji_block_retired.KojiBlockRetired._create_session")
|
| |
+ def test_koji_generic_error_epel_unblock(
|
| |
+ self, mock_session, mock_pagure, config, caplog
|
| |
+ ):
|
| |
"""
|
| |
- Assert if in commit dead package wasn't added the plugin stops.
|
| |
+ Assert that Koji generic error will be handled correctly.
|
| |
"""
|
| |
- caplog.set_level(logging.INFO)
|
| |
+ mock_dist_git = MagicMock()
|
| |
+ mock_dist_git.has_dead_package_on_branch.return_value = True
|
| |
+ mock_pagure.return_value = mock_dist_git
|
| |
+
|
| |
message = MagicMock()
|
| |
message.body = {
|
| |
"commit": {
|
| |
"stats": {"files": {"dead.package": {"additions": 1, "deletions": 0}}},
|
| |
- "branch": "f38",
|
| |
+ "branch": "epel9",
|
| |
"repo": "example-epel-repo",
|
| |
"namespace": "example_ns",
|
| |
"date": "2024-09-16T12:12:46+01:00",
|
| |
- },
|
| |
- }
|
| |
- message._headers = {"sent-at": "2024-09-18T12:12:46+01:00"}
|
| |
- config = MagicMock()
|
| |
- config = {
|
| |
- "koji_url": "https://example.koji.org",
|
| |
- "principal": "principal",
|
| |
- "keytab": "keytab",
|
| |
+ }
|
| |
}
|
| |
- self.toddler_cls.process_block_retired(config, message)
|
| |
+ message.topic = "git.receive"
|
| |
+ self.toddler_cls.koji_session.packageListUnblock.__name__ = "packageListUnblock"
|
| |
+ self.toddler_cls.koji_session.packageListBlock.__name__ = "packageListBlock"
|
| |
+ self.toddler_cls.koji_session.packageListUnblock.side_effect = (
|
| |
+ koji.GenericError("Failed")
|
| |
+ )
|
| |
+ self.toddler_cls.process(config, message)
|
| |
+ assert (
|
| |
+ caplog.records[-2].message
|
| |
+ == "Unable to create koji ClientSession for call packageListUnblock: Failed"
|
| |
+ )
|
| |
assert (
|
| |
caplog.records[-1].message
|
| |
- == "Commit is older than 1 day, probably new branch creation, bailing."
|
| |
+ == "Failed, recreating koji_session and trying again"
|
| |
)
|
| |
|
| |
@pytest.mark.parametrize(
|
| |
@@ -307,8 +386,13 @@
|
| |
caplog.records[-1].message == f"Failed to get {branch} tag in koji: Failed"
|
| |
)
|
| |
|
| |
+ @patch("toddlers.plugins.koji_block_retired.pagure.set_pagure")
|
| |
@patch("toddlers.plugins.koji_block_retired.KojiBlockRetired._create_session")
|
| |
- def test_branch_with_container(self, mock_session, caplog):
|
| |
+ def test_branch_with_container(self, mock_session, mock_pagure, config, caplog):
|
| |
+ mock_dist_git = MagicMock()
|
| |
+ mock_dist_git.has_dead_package_on_branch.return_value = True
|
| |
+ mock_pagure.return_value = mock_dist_git
|
| |
+
|
| |
caplog.set_level(logging.INFO)
|
| |
message = MagicMock()
|
| |
message.body = {
|
| |
@@ -320,22 +404,25 @@
|
| |
"date": "2024-09-16T12:12:46+01:00",
|
| |
}
|
| |
}
|
| |
- message._headers = {"sent-at": "2024-09-16T12:12:46+01:00"}
|
| |
- config = MagicMock()
|
| |
- config = {
|
| |
- "koji_url": "https://example.koji.org",
|
| |
- "principal": "principal",
|
| |
- "keytab": "keytab",
|
| |
- }
|
| |
- self.toddler_cls.process_block_retired(config, message)
|
| |
+ message.topic = MagicMock()
|
| |
+ message.topic = "git.receive"
|
| |
+ self.toddler_cls.koji_session.packageListBlock.__name__ = "packageListBlock"
|
| |
+ self.toddler_cls.process(config, message)
|
| |
self.toddler_cls.koji_session.packageListBlock.assert_called_once_with(
|
| |
taginfo="f38-container",
|
| |
pkginfo="example-repo",
|
| |
)
|
| |
|
| |
+ @patch("toddlers.plugins.koji_block_retired.pagure.set_pagure")
|
| |
@patch("toddlers.plugins.koji_block_retired.KojiBlockRetired._create_session")
|
| |
@patch("toddlers.plugins.koji_block_retired.KojiBlockRetired.get_tag_from_target")
|
| |
- def test_branch_epel(self, mock_get_tag_from_target, mock_session, caplog):
|
| |
+ def test_branch_epel(
|
| |
+ self, mock_get_tag_from_target, mock_session, mock_pagure, config, caplog
|
| |
+ ):
|
| |
+ mock_dist_git = MagicMock()
|
| |
+ mock_dist_git.has_dead_package_on_branch.return_value = True
|
| |
+ mock_pagure.return_value = mock_dist_git
|
| |
+
|
| |
mock_get_tag_from_target.return_value = "epel10.2"
|
| |
caplog.set_level(logging.INFO)
|
| |
message = MagicMock()
|
| |
@@ -348,16 +435,412 @@
|
| |
"date": "2024-09-16T12:12:46+01:00",
|
| |
}
|
| |
}
|
| |
- message._headers = {"sent-at": "2024-09-16T12:12:46+01:00"}
|
| |
- config = MagicMock()
|
| |
+ message.topic = MagicMock()
|
| |
+ message.topic = "git.receive"
|
| |
|
| |
- config = {
|
| |
- "koji_url": "https://example.koji.org",
|
| |
- "principal": "principal",
|
| |
- "keytab": "keytab",
|
| |
- }
|
| |
- self.toddler_cls.process_block_retired(config, message)
|
| |
+ self.toddler_cls.koji_session.packageListBlock.__name__ = "packageListBlock"
|
| |
+ self.toddler_cls.koji_session.packageListUnblock.__name__ = "packageListUnblock"
|
| |
+ self.toddler_cls.process(config, message)
|
| |
self.toddler_cls.koji_session.packageListBlock.assert_called_once_with(
|
| |
taginfo="epel10.2",
|
| |
pkginfo="example-repo",
|
| |
)
|
| |
+
|
| |
+ def mocked_requests_get(*args, **kwargs):
|
| |
+ class MockResponse:
|
| |
+ def __init__(self, json_data, status_code):
|
| |
+ self.json_data = json_data
|
| |
+ self.status_code = status_code
|
| |
+
|
| |
+ def json(self):
|
| |
+ return self.json_data
|
| |
+
|
| |
+ if args[0] == "https://src.fedoraproject.org/lookaside/retired_in_epel9.json":
|
| |
+ return MockResponse(
|
| |
+ {
|
| |
+ "epel9": [
|
| |
+ "epel_pkg",
|
| |
+ "epel_pkg1",
|
| |
+ "epel_pkg2",
|
| |
+ ]
|
| |
+ },
|
| |
+ 200,
|
| |
+ )
|
| |
+
|
| |
+ return MockResponse(None, 404)
|
| |
+
|
| |
+ @patch("requests.get")
|
| |
+ @patch("toddlers.plugins.koji_block_retired.KojiBlockRetired.get_tag_from_target")
|
| |
+ @patch("toddlers.plugins.koji_block_retired.bodhi.set_bodhi")
|
| |
+ @patch("toddlers.plugins.koji_block_retired.KojiBlockRetired._create_session")
|
| |
+ def test_playtime_call_epel_not_blocked(
|
| |
+ self,
|
| |
+ mock_create_session,
|
| |
+ mock_set_bodhi,
|
| |
+ mock_tag,
|
| |
+ mock_req,
|
| |
+ config,
|
| |
+ caplog,
|
| |
+ ):
|
| |
+ mock_bodhi = MagicMock()
|
| |
+ mock_bodhi.get_active_branches.return_value = [
|
| |
+ "epel9",
|
| |
+ ]
|
| |
+ mock_set_bodhi.return_value = mock_bodhi
|
| |
+ mock_tag.return_value = "epel9"
|
| |
+ caplog.set_level(logging.INFO)
|
| |
+ message = MagicMock()
|
| |
+ message.topic = "toddlers.trigger.koji_block_retired"
|
| |
+ mock_response = MagicMock()
|
| |
+ mock_response.status_code = 200
|
| |
+ mock_response.json.return_value = {
|
| |
+ "epel9": [
|
| |
+ "epel_pkg",
|
| |
+ ]
|
| |
+ }
|
| |
+
|
| |
+ def req(*args, **kwargs):
|
| |
+ if (
|
| |
+ args[0]
|
| |
+ == "https://src.fedoraproject.org/lookaside/retired_in_epel9.json"
|
| |
+ ):
|
| |
+ return mock_response
|
| |
+
|
| |
+ mock_req.side_effect = req
|
| |
+
|
| |
+ self.toddler_cls.koji_session.listPackages.__name__ = "listPackages"
|
| |
+ self.toddler_cls.koji_session.listPackages.return_value = [
|
| |
+ {
|
| |
+ "blocked": False,
|
| |
+ }
|
| |
+ ]
|
| |
+ self.toddler_cls.process(config, message)
|
| |
+ self.toddler_cls.koji_session.listPackages.assert_called_with(
|
| |
+ pkgID="epel_pkg",
|
| |
+ tagID="epel9",
|
| |
+ )
|
| |
+ self.toddler_cls.koji_session.packageListBlock.assert_called_with(
|
| |
+ taginfo="epel9", pkginfo="epel_pkg"
|
| |
+ )
|
| |
+ assert caplog.records[-2].message == "Blocking package epel_pkg, tag: epel9"
|
| |
+ assert (
|
| |
+ caplog.records[-1].message
|
| |
+ == "All packages that should be blocked: {'epel9': ['epel_pkg']}"
|
| |
+ )
|
| |
+
|
| |
+ @patch("requests.get")
|
| |
+ @patch("toddlers.plugins.koji_block_retired.KojiBlockRetired.get_tag_from_target")
|
| |
+ @patch("toddlers.plugins.koji_block_retired.bodhi.set_bodhi")
|
| |
+ @patch("toddlers.plugins.koji_block_retired.KojiBlockRetired._create_session")
|
| |
+ def test_playtime_call_epel_blocked(
|
| |
+ self,
|
| |
+ mock_create_session,
|
| |
+ mock_set_bodhi,
|
| |
+ mock_tag,
|
| |
+ mock_req,
|
| |
+ config,
|
| |
+ caplog,
|
| |
+ ):
|
| |
+ mock_bodhi = MagicMock()
|
| |
+ mock_bodhi.get_active_branches.return_value = [
|
| |
+ "epel9",
|
| |
+ ]
|
| |
+ mock_set_bodhi.return_value = mock_bodhi
|
| |
+ mock_tag.return_value = "epel9"
|
| |
+ caplog.set_level(logging.INFO)
|
| |
+ message = MagicMock()
|
| |
+ message.topic = "toddlers.trigger.koji_block_retired"
|
| |
+ mock_response = MagicMock()
|
| |
+ mock_response.status_code = 200
|
| |
+ mock_response.json.return_value = {
|
| |
+ "epel9": [
|
| |
+ "epel_pkg",
|
| |
+ ]
|
| |
+ }
|
| |
+
|
| |
+ def req(*args, **kwargs):
|
| |
+ if (
|
| |
+ args[0]
|
| |
+ == "https://src.fedoraproject.org/lookaside/retired_in_epel9.json"
|
| |
+ ):
|
| |
+ return mock_response
|
| |
+
|
| |
+ mock_req.side_effect = req
|
| |
+ self.toddler_cls.koji_session.listPackages.__name__ = "listPackages"
|
| |
+ self.toddler_cls.koji_session.packageListBlock.__name__ = "packageListBlock"
|
| |
+ self.toddler_cls.koji_session.listPackages.return_value = [
|
| |
+ {
|
| |
+ "blocked": True,
|
| |
+ }
|
| |
+ ]
|
| |
+ self.toddler_cls.process(config, message)
|
| |
+ self.toddler_cls.koji_session.listPackages.assert_called_once_with(
|
| |
+ pkgID="epel_pkg",
|
| |
+ tagID="epel9",
|
| |
+ )
|
| |
+ self.toddler_cls.koji_session.packageListBlock.assert_not_called()
|
| |
+ assert caplog.records[-1].message == "All packages that should be blocked: {}"
|
| |
+
|
| |
+ @patch("requests.get")
|
| |
+ @patch("toddlers.plugins.koji_block_retired.KojiBlockRetired.get_tag_from_target")
|
| |
+ @patch("toddlers.plugins.koji_block_retired.bodhi.set_bodhi")
|
| |
+ @patch("toddlers.plugins.koji_block_retired.KojiBlockRetired._create_session")
|
| |
+ def test_playtime_call_rawhide_blocked(
|
| |
+ self,
|
| |
+ mock_create_session,
|
| |
+ mock_set_bodhi,
|
| |
+ mock_rawhide,
|
| |
+ mock_req,
|
| |
+ config,
|
| |
+ caplog,
|
| |
+ ):
|
| |
+ mock_bodhi = MagicMock()
|
| |
+ mock_bodhi.get_active_branches.return_value = [
|
| |
+ "rawhide",
|
| |
+ ]
|
| |
+ mock_set_bodhi.return_value = mock_bodhi
|
| |
+ caplog.set_level(logging.INFO)
|
| |
+ message = MagicMock()
|
| |
+ message.topic = "toddlers.trigger.koji_block_retired"
|
| |
+ mock_response = MagicMock()
|
| |
+ mock_response.status_code = 200
|
| |
+ mock_response.json.return_value = {
|
| |
+ "rawhide": [
|
| |
+ "fedora_pkg",
|
| |
+ ]
|
| |
+ }
|
| |
+
|
| |
+ def req(*args, **kwargs):
|
| |
+ if (
|
| |
+ args[0]
|
| |
+ == "https://src.fedoraproject.org/lookaside/retired_in_rawhide.json"
|
| |
+ ):
|
| |
+ return mock_response
|
| |
+
|
| |
+ mock_req.side_effect = req
|
| |
+ mock_rawhide.return_value = "f42"
|
| |
+ self.toddler_cls.koji_session.listPackages.__name__ = "listPackages"
|
| |
+ self.toddler_cls.koji_session.packageListBlock.__name__ = "packageListBlock"
|
| |
+ self.toddler_cls.koji_session.listPackages.return_value = [
|
| |
+ {
|
| |
+ "blocked": True,
|
| |
+ }
|
| |
+ ]
|
| |
+ self.toddler_cls.process(config, message)
|
| |
+ self.toddler_cls.koji_session.listPackages.assert_called_with(
|
| |
+ pkgID="fedora_pkg",
|
| |
+ tagID="f42",
|
| |
+ )
|
| |
+ self.toddler_cls.koji_session.packageListBlock.assert_not_called()
|
| |
+
|
| |
+ @patch("requests.get")
|
| |
+ @patch("toddlers.plugins.koji_block_retired.KojiBlockRetired.get_tag_from_target")
|
| |
+ @patch("toddlers.plugins.koji_block_retired.bodhi.set_bodhi")
|
| |
+ @patch("toddlers.plugins.koji_block_retired.KojiBlockRetired._create_session")
|
| |
+ def test_playtime_call_rawhide_block_pkg_error(
|
| |
+ self,
|
| |
+ mock_create_session,
|
| |
+ mock_set_bodhi,
|
| |
+ mock_rawhide,
|
| |
+ mock_req,
|
| |
+ config,
|
| |
+ caplog,
|
| |
+ ):
|
| |
+ mock_bodhi = MagicMock()
|
| |
+ mock_bodhi.get_active_branches.return_value = [
|
| |
+ "rawhide",
|
| |
+ ]
|
| |
+ mock_set_bodhi.return_value = mock_bodhi
|
| |
+ caplog.set_level(logging.INFO)
|
| |
+ message = MagicMock()
|
| |
+ message.topic = "toddlers.trigger.koji_block_retired"
|
| |
+ mock_response = MagicMock()
|
| |
+ mock_response.status_code = 200
|
| |
+ mock_response.json.return_value = {
|
| |
+ "rawhide": [
|
| |
+ "fedora_pkg",
|
| |
+ ]
|
| |
+ }
|
| |
+
|
| |
+ def req(*args, **kwargs):
|
| |
+ if (
|
| |
+ args[0]
|
| |
+ == "https://src.fedoraproject.org/lookaside/retired_in_rawhide.json"
|
| |
+ ):
|
| |
+ return mock_response
|
| |
+
|
| |
+ mock_req.side_effect = req
|
| |
+ mock_rawhide.return_value = "f42"
|
| |
+ self.toddler_cls.koji_session.listPackages.__name__ = "listPackages"
|
| |
+ self.toddler_cls.koji_session.packageListBlock.__name__ = "packageListBlock"
|
| |
+ self.toddler_cls.koji_session.listPackages.return_value = [
|
| |
+ {
|
| |
+ "blocked": False,
|
| |
+ }
|
| |
+ ]
|
| |
+ self.toddler_cls.koji_session.packageListBlock.side_effect = koji.GenericError(
|
| |
+ "fail"
|
| |
+ )
|
| |
+
|
| |
+ self.toddler_cls.process(config, message)
|
| |
+ self.toddler_cls.koji_session.listPackages.assert_called_with(
|
| |
+ pkgID="fedora_pkg",
|
| |
+ tagID="f42",
|
| |
+ )
|
| |
+ self.toddler_cls.koji_session.packageListBlock.assert_called_with(
|
| |
+ taginfo="f42", pkginfo="fedora_pkg"
|
| |
+ )
|
| |
+ assert (
|
| |
+ caplog.records[-6].message
|
| |
+ == "Checking if package fedora_pkg is blocked in koji for release f42"
|
| |
+ )
|
| |
+ assert caplog.records[-5].message == "Blocking package fedora_pkg, tag: f42"
|
| |
+ assert (
|
| |
+ caplog.records[-4].message
|
| |
+ == "fail, recreating koji_session and trying again"
|
| |
+ )
|
| |
+ assert (
|
| |
+ caplog.records[-3].message
|
| |
+ == "Unable to create koji ClientSession for call packageListBlock: fail"
|
| |
+ )
|
| |
+ assert (
|
| |
+ caplog.records[-2].message
|
| |
+ == "fail, recreating koji_session and trying again"
|
| |
+ )
|
| |
+ assert (
|
| |
+ caplog.records[-1].message
|
| |
+ == "All packages that should be blocked: {'f42': ['fedora_pkg']}"
|
| |
+ )
|
| |
+
|
| |
+ @patch("requests.get")
|
| |
+ @patch("toddlers.plugins.koji_block_retired.KojiBlockRetired.get_tag_from_target")
|
| |
+ @patch("toddlers.plugins.koji_block_retired.bodhi.set_bodhi")
|
| |
+ @patch("toddlers.plugins.koji_block_retired.KojiBlockRetired._create_session")
|
| |
+ def test_playtime_call_rawhide_list_pkg_error(
|
| |
+ self,
|
| |
+ mock_create_session,
|
| |
+ mock_set_bodhi,
|
| |
+ mock_rawhide,
|
| |
+ mock_req,
|
| |
+ config,
|
| |
+ caplog,
|
| |
+ ):
|
| |
+ mock_bodhi = MagicMock()
|
| |
+ mock_bodhi.get_active_branches.return_value = [
|
| |
+ "rawhide",
|
| |
+ ]
|
| |
+ mock_set_bodhi.return_value = mock_bodhi
|
| |
+ caplog.set_level(logging.INFO)
|
| |
+ message = MagicMock()
|
| |
+ message.topic = "toddlers.trigger.koji_block_retired"
|
| |
+ mock_response = MagicMock()
|
| |
+ mock_response.status_code = 200
|
| |
+ mock_response.json.return_value = {
|
| |
+ "rawhide": [
|
| |
+ "fedora_pkg",
|
| |
+ ]
|
| |
+ }
|
| |
+
|
| |
+ def req(*args, **kwargs):
|
| |
+ if (
|
| |
+ args[0]
|
| |
+ == "https://src.fedoraproject.org/lookaside/retired_in_rawhide.json"
|
| |
+ ):
|
| |
+ return mock_response
|
| |
+
|
| |
+ mock_req.side_effect = req
|
| |
+ mock_rawhide.return_value = "f42"
|
| |
+ self.toddler_cls.koji_session.listPackages.__name__ = "listPackages"
|
| |
+ self.toddler_cls.koji_session.packageListBlock.__name__ = "packageListBlock"
|
| |
+ self.toddler_cls.koji_session.listPackages.side_effect = koji.GenericError(
|
| |
+ "fail"
|
| |
+ )
|
| |
+ self.toddler_cls.process(config, message)
|
| |
+ self.toddler_cls.koji_session.listPackages.assert_called_with(
|
| |
+ pkgID="fedora_pkg",
|
| |
+ tagID="f42",
|
| |
+ )
|
| |
+ assert (
|
| |
+ caplog.records[-5].message
|
| |
+ == "Checking if package fedora_pkg is blocked in koji for release f42"
|
| |
+ )
|
| |
+ assert (
|
| |
+ caplog.records[-4].message
|
| |
+ == "fail, recreating koji_session and trying again"
|
| |
+ )
|
| |
+ assert (
|
| |
+ caplog.records[-3].message
|
| |
+ == "Unable to create koji ClientSession for call listPackages: fail"
|
| |
+ )
|
| |
+ assert (
|
| |
+ caplog.records[-2].message
|
| |
+ == "fail, recreating koji_session and trying again"
|
| |
+ )
|
| |
+ assert caplog.records[-1].message == "Not able to get data from koji, bailing."
|
| |
+
|
| |
+ self.toddler_cls.koji_session.packageListBlock.assert_not_called()
|
| |
+
|
| |
+ @patch("requests.get")
|
| |
+ @patch("toddlers.plugins.koji_block_retired.KojiBlockRetired.get_tag_from_target")
|
| |
+ @patch("toddlers.plugins.koji_block_retired.bodhi.set_bodhi")
|
| |
+ @patch("toddlers.plugins.koji_block_retired.KojiBlockRetired._create_session")
|
| |
+ def test_playtime_call_rawhide_not_blocked(
|
| |
+ self,
|
| |
+ mock_create_session,
|
| |
+ mock_set_bodhi,
|
| |
+ mock_rawhide,
|
| |
+ mock_req,
|
| |
+ config,
|
| |
+ caplog,
|
| |
+ ):
|
| |
+ mock_bodhi = MagicMock()
|
| |
+ mock_bodhi.get_active_branches.return_value = [
|
| |
+ "rawhide",
|
| |
+ ]
|
| |
+ mock_set_bodhi.return_value = mock_bodhi
|
| |
+ caplog.set_level(logging.INFO)
|
| |
+ message = MagicMock()
|
| |
+ message.topic = "toddlers.trigger.koji_block_retired"
|
| |
+ mock_response = MagicMock()
|
| |
+ mock_response.status_code = 200
|
| |
+ mock_response.json.return_value = {
|
| |
+ "rawhide": [
|
| |
+ "fedora_pkg",
|
| |
+ ]
|
| |
+ }
|
| |
+
|
| |
+ def req(*args, **kwargs):
|
| |
+ if (
|
| |
+ args[0]
|
| |
+ == "https://src.fedoraproject.org/lookaside/retired_in_rawhide.json"
|
| |
+ ):
|
| |
+ return mock_response
|
| |
+
|
| |
+ mock_req.side_effect = req
|
| |
+ mock_rawhide.return_value = "f42"
|
| |
+ self.toddler_cls.koji_session.listPackages.return_value = [
|
| |
+ {
|
| |
+ "blocked": False,
|
| |
+ }
|
| |
+ ]
|
| |
+ self.toddler_cls.koji_session.listPackages.__name__ = "listPackages"
|
| |
+ self.toddler_cls.koji_session.packageListBlock.__name__ = "packageListBlock"
|
| |
+ self.toddler_cls.process(config, message)
|
| |
+ self.toddler_cls.koji_session.listPackages.assert_called_with(
|
| |
+ pkgID="fedora_pkg",
|
| |
+ tagID="f42",
|
| |
+ )
|
| |
+ self.toddler_cls.koji_session.packageListBlock.assert_called_with(
|
| |
+ taginfo="f42", pkginfo="fedora_pkg"
|
| |
+ )
|
| |
+
|
| |
+ def test_adjust_releases_for_lookaside(self):
|
| |
+ releases = ["epel8", "epel9", "epel10", "f40", "f41", "f42"]
|
| |
+ assert self.toddler_cls.adjust_releases_for_lookaside(releases) == [
|
| |
+ "epel10",
|
| |
+ "epel8",
|
| |
+ "epel9",
|
| |
+ "f40",
|
| |
+ "f41",
|
| |
+ "rawhide",
|
| |
+ ]
|
| |
Signed-off-by: Lenka Segura lsegura@redhat.com