655 lines
23 KiB
Python
655 lines
23 KiB
Python
import datetime
|
|
import logging
|
|
from unittest.mock import ANY, call, MagicMock, Mock, patch
|
|
|
|
import fedora_messaging.api
|
|
import pytest
|
|
|
|
import toddlers.plugins.pdc_retired_packages
|
|
|
|
|
|
class TestPDCRetiredPackagesToddler:
|
|
toddler_cls = toddlers.plugins.pdc_retired_packages.PDCRetiredPackages
|
|
|
|
def test_accepts_topic_invalid(self, toddler):
|
|
assert toddler.accepts_topic("foo.bar") is False
|
|
|
|
@pytest.mark.parametrize(
|
|
"topic",
|
|
[
|
|
"org.fedoraproject.*.toddlers.trigger.pdc_retired_packages",
|
|
"org.fedoraproject.prod.toddlers.trigger.pdc_retired_packages",
|
|
"org.fedoraproject.stg.toddlers.trigger.pdc_retired_packages",
|
|
"org.fedoraproject.*.git.receive",
|
|
"org.fedoraproject.prod.git.receive",
|
|
"org.fedoraproject.stg.git.receive",
|
|
],
|
|
)
|
|
def test_accepts_topic_valid(self, toddler, topic):
|
|
assert toddler.accepts_topic(topic)
|
|
|
|
@patch("toddlers.plugins.pdc_retired_packages.PDCRetiredPackages._process_dist_git")
|
|
@patch("toddlers.plugins.pdc_retired_packages.pdc_client_for_config")
|
|
def test_process_full_dist_git(self, pdc, process_dg, toddler):
|
|
client = Mock()
|
|
pdc.return_value = client
|
|
|
|
msg = fedora_messaging.api.Message()
|
|
msg.id = 123
|
|
msg.topic = "org.fedoraproject.prod.toddlers.trigger.pdc_retired_packages"
|
|
msg.body = {}
|
|
|
|
toddler.process({"config": "foobar"}, msg)
|
|
|
|
process_dg.assert_called_once_with({"config": "foobar"}, client)
|
|
|
|
@patch(
|
|
"toddlers.plugins.pdc_retired_packages.PDCRetiredPackages._process_single_package"
|
|
)
|
|
@patch("toddlers.plugins.pdc_retired_packages.pdc_client_for_config")
|
|
def test_process_single_package(self, pdc, process_dg, toddler):
|
|
client = Mock()
|
|
pdc.return_value = client
|
|
|
|
msg = fedora_messaging.api.Message()
|
|
msg.id = 123
|
|
msg.topic = "org.fedoraproject.prod.git.receive"
|
|
msg.body = {}
|
|
|
|
toddler.process({"config": "foobar"}, msg)
|
|
|
|
process_dg.assert_called_once_with({"config": "foobar"}, client, msg)
|
|
|
|
def test_process_dist_git(self, toddler):
|
|
retired_in_dg = toddler._is_retired_in_dist_git = MagicMock()
|
|
page_component_branches = [
|
|
{
|
|
"id": 44,
|
|
"global_component": "0ad",
|
|
"name": "epel7",
|
|
"slas": [
|
|
{"id": 88, "sla": "bug_fixes", "eol": "2024-06-30"},
|
|
{"id": 89, "sla": "security_fixes", "eol": "2024-06-30"},
|
|
{"id": 90, "sla": "stable_api", "eol": "2024-06-30"},
|
|
],
|
|
"type": "rpm",
|
|
"active": True,
|
|
"critical_path": False,
|
|
},
|
|
{
|
|
"id": 39,
|
|
"global_component": "0ad",
|
|
"name": "f16",
|
|
"slas": [
|
|
{"id": 78, "sla": "bug_fixes", "eol": "2013-02-12"},
|
|
{"id": 79, "sla": "security_fixes", "eol": "2013-02-12"},
|
|
],
|
|
"type": "rpm",
|
|
"active": False,
|
|
"critical_path": False,
|
|
},
|
|
{
|
|
"id": 396194,
|
|
"global_component": "0ad",
|
|
"name": "master",
|
|
"slas": [{"id": 789078, "sla": "rawhide", "eol": "2222-01-01"}],
|
|
"type": "rpm",
|
|
"active": True,
|
|
"critical_path": False,
|
|
},
|
|
]
|
|
client = MagicMock()
|
|
client["component-branches"]._ = page_component_branches
|
|
client.get_paged.return_value = client["component-branches"]._
|
|
|
|
msg = fedora_messaging.api.Message()
|
|
msg.id = 123
|
|
msg.topic = "org.fedoraproject.prod.toddlers.trigger.pdc_retired_packages"
|
|
msg.body = {}
|
|
|
|
toddler._process_dist_git({}, client)
|
|
|
|
client.get_paged.assert_has_calls(calls=[call(page_component_branches)])
|
|
retired_in_dg.assert_has_calls(
|
|
calls=[
|
|
call(namespace="rpms", repo="0ad", branch="epel7"),
|
|
call().__bool__(),
|
|
call(namespace="rpms", repo="0ad", branch="f16"),
|
|
call().__bool__(),
|
|
call(namespace="rpms", repo="0ad", branch="master"),
|
|
call().__bool__(),
|
|
]
|
|
)
|
|
|
|
def test_process_dist_git_invalid_pdc_namespace(self, caplog, toddler):
|
|
retired_in_dg = toddler._is_retired_in_dist_git = MagicMock()
|
|
caplog.set_level(logging.DEBUG)
|
|
page_component_branches = [
|
|
{
|
|
"id": 44,
|
|
"global_component": "0ad",
|
|
"name": "epel7",
|
|
"slas": [
|
|
{"id": 88, "sla": "bug_fixes", "eol": "2024-06-30"},
|
|
{"id": 89, "sla": "security_fixes", "eol": "2024-06-30"},
|
|
{"id": 90, "sla": "stable_api", "eol": "2024-06-30"},
|
|
],
|
|
"type": "rpm",
|
|
"active": True,
|
|
"critical_path": False,
|
|
},
|
|
{
|
|
"id": 39,
|
|
"global_component": "0ad",
|
|
"name": "f16",
|
|
"slas": [
|
|
{"id": 78, "sla": "bug_fixes", "eol": "2013-02-12"},
|
|
{"id": 79, "sla": "security_fixes", "eol": "2013-02-12"},
|
|
],
|
|
"type": "rpm",
|
|
"active": False,
|
|
"critical_path": False,
|
|
},
|
|
{
|
|
"id": 396194,
|
|
"global_component": "0ad",
|
|
"name": "master",
|
|
"slas": [{"id": 789078, "sla": "rawhide", "eol": "2222-01-01"}],
|
|
"type": "flatpack",
|
|
"active": True,
|
|
"critical_path": False,
|
|
},
|
|
]
|
|
client = MagicMock()
|
|
client["component-branches"]._ = page_component_branches
|
|
client.get_paged.return_value = client["component-branches"]._
|
|
|
|
msg = fedora_messaging.api.Message()
|
|
msg.id = 123
|
|
msg.topic = "org.fedoraproject.prod.toddlers.trigger.pdc_retired_packages"
|
|
msg.body = {}
|
|
|
|
toddler._process_dist_git({}, client)
|
|
|
|
client.get_paged.assert_has_calls(calls=[call(page_component_branches)])
|
|
retired_in_dg.assert_has_calls(
|
|
calls=[
|
|
call(namespace="rpms", repo="0ad", branch="epel7"),
|
|
call().__bool__(),
|
|
call(namespace="rpms", repo="0ad", branch="f16"),
|
|
call().__bool__(),
|
|
]
|
|
)
|
|
|
|
assert (
|
|
'Ignoring PDC error for: The PDC type "flatpack" is not supported'
|
|
in caplog.text
|
|
)
|
|
|
|
def test_process_dist_git_full_distgit(self, toddler):
|
|
retired_in_dg = toddler._is_retired_in_dist_git = MagicMock()
|
|
retire_branch = toddler._retire_branch = MagicMock()
|
|
page_component_branches = [
|
|
{
|
|
"id": 44,
|
|
"global_component": "0ad",
|
|
"name": "epel7",
|
|
"slas": [
|
|
{"id": 88, "sla": "bug_fixes", "eol": "2024-06-30"},
|
|
{"id": 89, "sla": "security_fixes", "eol": "2024-06-30"},
|
|
{"id": 90, "sla": "stable_api", "eol": "2024-06-30"},
|
|
],
|
|
"type": "rpm",
|
|
"active": True,
|
|
"critical_path": False,
|
|
},
|
|
{
|
|
"id": 39,
|
|
"global_component": "0ad",
|
|
"name": "f16",
|
|
"slas": [
|
|
{"id": 78, "sla": "bug_fixes", "eol": "2013-02-12"},
|
|
{"id": 79, "sla": "security_fixes", "eol": "2013-02-12"},
|
|
],
|
|
"type": "rpm",
|
|
"active": False,
|
|
"critical_path": False,
|
|
},
|
|
{
|
|
"id": 396194,
|
|
"global_component": "0ad",
|
|
"name": "master",
|
|
"slas": [{"id": 789078, "sla": "rawhide", "eol": "2222-01-01"}],
|
|
"type": "rpm",
|
|
"active": True,
|
|
"critical_path": False,
|
|
},
|
|
]
|
|
client = MagicMock()
|
|
client["component-branches"]._ = page_component_branches
|
|
client.get_paged.return_value = client["component-branches"]._
|
|
|
|
msg = fedora_messaging.api.Message()
|
|
msg.id = 123
|
|
msg.topic = "org.fedoraproject.prod.toddlers.trigger.pdc_retired_packages"
|
|
msg.body = {}
|
|
|
|
toddler._process_dist_git({}, client)
|
|
|
|
client.get_paged.assert_has_calls(calls=[call(page_component_branches)])
|
|
retired_in_dg.assert_has_calls(
|
|
calls=[
|
|
call(namespace="rpms", repo="0ad", branch="epel7"),
|
|
call().__bool__(),
|
|
call(namespace="rpms", repo="0ad", branch="f16"),
|
|
call().__bool__(),
|
|
call(namespace="rpms", repo="0ad", branch="master"),
|
|
call().__bool__(),
|
|
]
|
|
)
|
|
retire_branch.assert_has_calls(
|
|
calls=[
|
|
call(
|
|
ANY,
|
|
{
|
|
"id": 44,
|
|
"global_component": "0ad",
|
|
"name": "epel7",
|
|
"slas": [
|
|
{"id": 88, "sla": "bug_fixes", "eol": "2024-06-30"},
|
|
{"id": 89, "sla": "security_fixes", "eol": "2024-06-30"},
|
|
{"id": 90, "sla": "stable_api", "eol": "2024-06-30"},
|
|
],
|
|
"type": "rpm",
|
|
"active": True,
|
|
"critical_path": False,
|
|
},
|
|
),
|
|
call(
|
|
ANY,
|
|
{
|
|
"id": 39,
|
|
"global_component": "0ad",
|
|
"name": "f16",
|
|
"slas": [
|
|
{"id": 78, "sla": "bug_fixes", "eol": "2013-02-12"},
|
|
{"id": 79, "sla": "security_fixes", "eol": "2013-02-12"},
|
|
],
|
|
"type": "rpm",
|
|
"active": False,
|
|
"critical_path": False,
|
|
},
|
|
),
|
|
call(
|
|
ANY,
|
|
{
|
|
"id": 396194,
|
|
"global_component": "0ad",
|
|
"name": "master",
|
|
"slas": [{"id": 789078, "sla": "rawhide", "eol": "2222-01-01"}],
|
|
"type": "rpm",
|
|
"active": True,
|
|
"critical_path": False,
|
|
},
|
|
),
|
|
]
|
|
)
|
|
|
|
def test__process_single_package_regular_commit(self, toddler, caplog):
|
|
caplog.set_level(logging.INFO)
|
|
client = MagicMock()
|
|
|
|
msg = fedora_messaging.api.Message()
|
|
msg.id = 123
|
|
msg.topic = "org.fedoraproject.prod.toddlers.trigger.pdc_retired_packages"
|
|
msg.body = {
|
|
"commit": {
|
|
"stats": {
|
|
"files": {
|
|
"foobar.spec": {"additions": 5, "deletions": 2},
|
|
"sources": {"additions": 1, "deletions": 1},
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
toddler._process_single_package({}, client, msg)
|
|
|
|
assert caplog.records[-1].message == "No dead.package in the commit, bailing"
|
|
|
|
def test__process_single_package_un_retirement(self, toddler, caplog):
|
|
caplog.set_level(logging.INFO)
|
|
client = MagicMock()
|
|
|
|
msg = fedora_messaging.api.Message()
|
|
msg.id = 123
|
|
msg.topic = "org.fedoraproject.prod.toddlers.trigger.pdc_retired_packages"
|
|
msg.body = {
|
|
"commit": {
|
|
"stats": {
|
|
"files": {
|
|
"foobar.spec": {"additions": 70, "deletions": 0},
|
|
"sources": {"additions": 1, "deletions": 0},
|
|
"dead.package": {"additions": 0, "deletions": 3},
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
toddler._process_single_package({}, client, msg)
|
|
|
|
assert caplog.records[-1].message == "dead.package file was not added, bailing"
|
|
|
|
def test__process_single_package_incomplete_config(self, toddler, caplog):
|
|
caplog.set_level(logging.INFO)
|
|
client = MagicMock()
|
|
|
|
msg = fedora_messaging.api.Message()
|
|
msg.id = 123
|
|
msg.topic = "org.fedoraproject.prod.toddlers.trigger.pdc_retired_packages"
|
|
msg.body = {
|
|
"commit": {
|
|
"stats": {
|
|
"files": {
|
|
"foobar.spec": {"additions": 0, "deletions": 120},
|
|
"sources": {"additions": 0, "deletions": 1},
|
|
"dead.package": {"additions": 3, "deletions": 0},
|
|
}
|
|
},
|
|
"branch": "f33",
|
|
"namespace": "rpms",
|
|
"repo": "toddlers",
|
|
}
|
|
}
|
|
|
|
toddler._process_single_package({}, client, msg)
|
|
|
|
assert caplog.records[-1].message == "No check URL configured, ignoring"
|
|
|
|
def test__process_single_package_package_not_in_pdc(self, toddler, caplog):
|
|
caplog.set_level(logging.INFO)
|
|
|
|
page_component_branches = {
|
|
"count": 4,
|
|
}
|
|
client = MagicMock()
|
|
client["component-branches"]._ = Mock(return_value=page_component_branches)
|
|
|
|
msg = fedora_messaging.api.Message()
|
|
msg.id = 123
|
|
msg.topic = "org.fedoraproject.prod.toddlers.trigger.pdc_retired_packages"
|
|
msg.body = {
|
|
"commit": {
|
|
"stats": {
|
|
"files": {
|
|
"foobar.spec": {"additions": 0, "deletions": 120},
|
|
"sources": {"additions": 0, "deletions": 1},
|
|
"dead.package": {"additions": 3, "deletions": 0},
|
|
}
|
|
},
|
|
"branch": "f33",
|
|
"namespace": "rpms",
|
|
"repo": "0ad",
|
|
}
|
|
}
|
|
|
|
toddler._process_single_package(
|
|
{
|
|
"file_check_url": "https://src.fedoraproject.org/"
|
|
"%(namespace)s/%(repo)s/blob/%(branch)s/f/%(file)s",
|
|
},
|
|
client,
|
|
msg,
|
|
)
|
|
|
|
assert caplog.records[-1].message == '"rpms/0ad" was not found in PDC'
|
|
|
|
def test__process_single_package_namespace_not_in_pdc(self, toddler, caplog):
|
|
caplog.set_level(logging.INFO)
|
|
|
|
page_component_branches = {
|
|
"count": 4,
|
|
}
|
|
client = MagicMock()
|
|
client["component-branches"]._ = Mock(return_value=page_component_branches)
|
|
|
|
msg = fedora_messaging.api.Message()
|
|
msg.id = 123
|
|
msg.topic = "org.fedoraproject.prod.toddlers.trigger.pdc_retired_packages"
|
|
msg.body = {
|
|
"commit": {
|
|
"stats": {
|
|
"files": {
|
|
"foobar.spec": {"additions": 0, "deletions": 120},
|
|
"sources": {"additions": 0, "deletions": 1},
|
|
"dead.package": {"additions": 3, "deletions": 0},
|
|
}
|
|
},
|
|
"branch": "f33",
|
|
"namespace": "flatpack",
|
|
"repo": "0ad",
|
|
}
|
|
}
|
|
|
|
toddler._process_single_package(
|
|
{
|
|
"file_check_url": "https://src.fedoraproject.org/"
|
|
"%(namespace)s/%(repo)s/blob/%(branch)s/f/%(file)s",
|
|
},
|
|
client,
|
|
msg,
|
|
)
|
|
|
|
assert (
|
|
caplog.records[-1].message
|
|
== "Ignoring namespace 'flatpack', error: The namespace \"flatpack\" is not supported"
|
|
)
|
|
|
|
def test__process_single_package_package_inactive(self, toddler, caplog):
|
|
caplog.set_level(logging.INFO)
|
|
|
|
page_component_branches = {
|
|
"count": 1,
|
|
"results": [
|
|
{
|
|
"id": 396194,
|
|
"global_component": "0ad",
|
|
"name": "master",
|
|
"slas": [{"id": 789078, "sla": "rawhide", "eol": "2222-01-01"}],
|
|
"type": "rpm",
|
|
"active": False,
|
|
"critical_path": False,
|
|
},
|
|
],
|
|
}
|
|
client = MagicMock()
|
|
client["component-branches"]._ = Mock(return_value=page_component_branches)
|
|
|
|
msg = fedora_messaging.api.Message()
|
|
msg.id = 123
|
|
msg.topic = "org.fedoraproject.prod.toddlers.trigger.pdc_retired_packages"
|
|
msg.body = {
|
|
"commit": {
|
|
"stats": {
|
|
"files": {
|
|
"foobar.spec": {"additions": 0, "deletions": 120},
|
|
"sources": {"additions": 0, "deletions": 1},
|
|
"dead.package": {"additions": 3, "deletions": 0},
|
|
}
|
|
},
|
|
"branch": "f33",
|
|
"namespace": "rpms",
|
|
"repo": "0ad",
|
|
}
|
|
}
|
|
|
|
toddler._process_single_package(
|
|
{
|
|
"file_check_url": "https://src.fedoraproject.org/"
|
|
"%(namespace)s/%(repo)s/blob/%(branch)s/f/%(file)s",
|
|
},
|
|
client,
|
|
msg,
|
|
)
|
|
|
|
assert caplog.records[-1].message == '"rpms/0ad" not active in PDC in master'
|
|
|
|
def test__process_single_package_package_not_retired(self, toddler, caplog):
|
|
caplog.set_level(logging.INFO)
|
|
resp = Mock()
|
|
resp.status_code = 404
|
|
toddler.requests_session.head.return_value = resp
|
|
|
|
page_component_branches = {
|
|
"count": 1,
|
|
"results": [
|
|
{
|
|
"id": 396194,
|
|
"global_component": "0ad",
|
|
"name": "master",
|
|
"slas": [{"id": 789078, "sla": "rawhide", "eol": "2222-01-01"}],
|
|
"type": "rpm",
|
|
"active": True,
|
|
"critical_path": False,
|
|
},
|
|
],
|
|
}
|
|
client = MagicMock()
|
|
client["component-branches"]._ = Mock(return_value=page_component_branches)
|
|
|
|
msg = fedora_messaging.api.Message()
|
|
msg.id = 123
|
|
msg.topic = "org.fedoraproject.prod.toddlers.trigger.pdc_retired_packages"
|
|
msg.body = {
|
|
"commit": {
|
|
"stats": {
|
|
"files": {
|
|
"foobar.spec": {"additions": 0, "deletions": 120},
|
|
"sources": {"additions": 0, "deletions": 1},
|
|
"dead.package": {"additions": 3, "deletions": 0},
|
|
}
|
|
},
|
|
"branch": "f33",
|
|
"namespace": "rpms",
|
|
"repo": "0ad",
|
|
}
|
|
}
|
|
|
|
toddler._process_single_package(
|
|
{
|
|
"file_check_url": "https://src.fedoraproject.org/"
|
|
"%(namespace)s/%(repo)s/blob/%(branch)s/f/%(file)s",
|
|
},
|
|
client,
|
|
msg,
|
|
)
|
|
|
|
assert (
|
|
caplog.records[-1].message
|
|
== "Seems not to actually be retired, possibly a merge commit?"
|
|
)
|
|
|
|
def test__process_single_package(self, toddler, caplog):
|
|
toddler._retire_branch = MagicMock()
|
|
caplog.set_level(logging.INFO)
|
|
resp = Mock()
|
|
resp.status_code = 200
|
|
toddler.requests_session.head.return_value = resp
|
|
|
|
page_component_branches = {
|
|
"count": 1,
|
|
"results": [
|
|
{
|
|
"id": 396194,
|
|
"global_component": "0ad",
|
|
"name": "master",
|
|
"slas": [{"id": 789078, "sla": "rawhide", "eol": "2222-01-01"}],
|
|
"type": "rpm",
|
|
"active": True,
|
|
"critical_path": False,
|
|
},
|
|
],
|
|
}
|
|
client = MagicMock()
|
|
client["component-branches"]._ = Mock(return_value=page_component_branches)
|
|
|
|
msg = fedora_messaging.api.Message()
|
|
msg.id = 123
|
|
msg.topic = "org.fedoraproject.prod.toddlers.trigger.pdc_retired_packages"
|
|
msg.body = {
|
|
"commit": {
|
|
"stats": {
|
|
"files": {
|
|
"foobar.spec": {"additions": 0, "deletions": 120},
|
|
"sources": {"additions": 0, "deletions": 1},
|
|
"dead.package": {"additions": 3, "deletions": 0},
|
|
}
|
|
},
|
|
"branch": "f33",
|
|
"namespace": "rpms",
|
|
"repo": "0ad",
|
|
}
|
|
}
|
|
|
|
toddler._process_single_package(
|
|
{
|
|
"file_check_url": "https://src.fedoraproject.org/"
|
|
"%(namespace)s/%(repo)s/blob/%(branch)s/f/%(file)s",
|
|
},
|
|
client,
|
|
msg,
|
|
)
|
|
|
|
toddler._retire_branch.assert_called_once_with(
|
|
client, page_component_branches["results"][0]
|
|
)
|
|
|
|
def test__is_retired_in_dist_git(self, toddler):
|
|
resp = Mock()
|
|
resp.status_code = 200
|
|
toddler.requests_session.head.return_value = resp
|
|
|
|
assert toddler._is_retired_in_dist_git("rpms", "guake", "f33")
|
|
toddler.requests_session.head.assert_called_once_with(
|
|
"https://src.fedoraproject.org//rpms/guake/raw/f33/f/dead.package"
|
|
)
|
|
|
|
def test__is_retired_in_dist_git_internal_error(self, toddler):
|
|
resp = Mock()
|
|
resp.status_code = 500
|
|
toddler.requests_session.head.return_value = resp
|
|
|
|
with pytest.raises(
|
|
ValueError,
|
|
match=r"The connection to dist_git failed. Retirement status could "
|
|
"not be determined. The status code was: 500. The content was: .*",
|
|
):
|
|
toddler._is_retired_in_dist_git("rpms", "guake", "f33")
|
|
toddler.requests_session.head.assert_called_once_with(
|
|
"https://src.fedoraproject.org//rpms/guake/raw/f33/f/dead.package"
|
|
)
|
|
|
|
def test_retire_branch(self, toddler, caplog):
|
|
caplog.set_level(logging.INFO)
|
|
today = datetime.datetime.utcnow().date()
|
|
eol = (datetime.datetime.utcnow() + datetime.timedelta(days=60)).date()
|
|
pdc = MagicMock()
|
|
branch = {
|
|
"id": 396194,
|
|
"global_component": "0ad",
|
|
"name": "master",
|
|
"slas": [{"id": 789078, "sla": "rawhide", "eol": str(eol)}],
|
|
"type": "rpm",
|
|
"active": True,
|
|
"critical_path": False,
|
|
}
|
|
|
|
toddler._retire_branch(pdc, branch)
|
|
|
|
assert (
|
|
caplog.records[-1].message
|
|
== "Setting eol of branch: {'id': 396194, 'global_component': "
|
|
"'0ad', 'name': 'master', 'slas': [{'id': 789078, 'sla': "
|
|
"'rawhide', 'eol': '%s'}], 'type': 'rpm', 'active': True, "
|
|
"'critical_path': False} to %s" % (eol, today)
|
|
)
|