2016-04-21 10:20:31 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2018-04-06 13:28:33 +00:00
|
|
|
import json
|
2021-04-23 10:03:05 +00:00
|
|
|
|
2016-04-21 10:20:31 +00:00
|
|
|
import os
|
2017-06-20 14:26:30 +00:00
|
|
|
import re
|
2019-10-04 12:45:03 +00:00
|
|
|
import six
|
2021-04-23 10:03:05 +00:00
|
|
|
from ddt import ddt, data, unpack
|
|
|
|
from typing import AnyStr, List, Set, Dict, Tuple
|
2020-01-22 10:02:22 +00:00
|
|
|
|
2018-04-06 13:28:33 +00:00
|
|
|
try:
|
|
|
|
import unittest2 as unittest
|
2021-04-23 10:03:05 +00:00
|
|
|
from unittest2 import mock
|
2018-04-06 13:28:33 +00:00
|
|
|
except ImportError:
|
|
|
|
import unittest
|
2021-04-23 10:03:05 +00:00
|
|
|
from unittest import mock
|
2016-04-21 10:20:31 +00:00
|
|
|
|
2022-11-07 17:24:39 +00:00
|
|
|
from pungi.phases.pkgset.sources import source_koji, source_kojimock
|
2016-04-21 10:20:31 +00:00
|
|
|
from tests import helpers
|
2019-10-02 07:40:18 +00:00
|
|
|
from pungi.module_util import Modulemd
|
2016-04-21 10:20:31 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
EVENT_INFO = {"id": 15681980, "ts": 1460956382.81936}
|
2016-04-21 10:20:31 +00:00
|
|
|
TAG_INFO = {
|
|
|
|
"maven_support": False,
|
|
|
|
"locked": False,
|
|
|
|
"name": "f25",
|
2020-01-22 10:02:22 +00:00
|
|
|
"extra": {"mock.package_manager": "dnf"},
|
2016-04-21 10:20:31 +00:00
|
|
|
"perm": None,
|
|
|
|
"id": 335,
|
|
|
|
"arches": None,
|
|
|
|
"maven_include_all": None,
|
2020-01-22 10:02:22 +00:00
|
|
|
"perm_id": None,
|
2016-04-21 10:20:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class TestGetKojiEvent(helpers.PungiTestCase):
|
|
|
|
def setUp(self):
|
|
|
|
super(TestGetKojiEvent, self).setUp()
|
|
|
|
self.compose = helpers.DummyCompose(self.topdir, {})
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.event_file = self.topdir + "/work/global/koji-event"
|
2016-04-21 10:20:31 +00:00
|
|
|
|
|
|
|
def test_use_preconfigured_event(self):
|
|
|
|
koji_wrapper = mock.Mock()
|
|
|
|
self.compose.koji_event = 123456
|
|
|
|
|
|
|
|
koji_wrapper.koji_proxy.getEvent.return_value = EVENT_INFO
|
|
|
|
|
|
|
|
event = source_koji.get_koji_event_info(self.compose, koji_wrapper)
|
|
|
|
|
|
|
|
self.assertEqual(event, EVENT_INFO)
|
2019-10-04 12:45:03 +00:00
|
|
|
six.assertCountEqual(
|
2020-01-22 10:02:22 +00:00
|
|
|
self, koji_wrapper.mock_calls, [mock.call.koji_proxy.getEvent(123456)]
|
|
|
|
)
|
2016-04-21 10:20:31 +00:00
|
|
|
with open(self.event_file) as f:
|
|
|
|
self.assertEqual(json.load(f), EVENT_INFO)
|
|
|
|
|
|
|
|
def test_gets_last_event(self):
|
|
|
|
self.compose.koji_event = None
|
|
|
|
koji_wrapper = mock.Mock()
|
|
|
|
|
|
|
|
koji_wrapper.koji_proxy.getLastEvent.return_value = EVENT_INFO
|
|
|
|
|
|
|
|
event = source_koji.get_koji_event_info(self.compose, koji_wrapper)
|
|
|
|
|
|
|
|
self.assertEqual(event, EVENT_INFO)
|
2019-10-04 12:45:03 +00:00
|
|
|
six.assertCountEqual(
|
2020-01-22 10:02:22 +00:00
|
|
|
self, koji_wrapper.mock_calls, [mock.call.koji_proxy.getLastEvent()]
|
|
|
|
)
|
2016-04-21 10:20:31 +00:00
|
|
|
with open(self.event_file) as f:
|
|
|
|
self.assertEqual(json.load(f), EVENT_INFO)
|
|
|
|
|
2017-06-14 12:04:54 +00:00
|
|
|
|
2016-04-21 10:20:31 +00:00
|
|
|
class TestPopulateGlobalPkgset(helpers.PungiTestCase):
|
|
|
|
def setUp(self):
|
|
|
|
super(TestPopulateGlobalPkgset, self).setUp()
|
2020-01-22 10:02:22 +00:00
|
|
|
self.compose = helpers.DummyCompose(
|
|
|
|
self.topdir, {"pkgset_koji_tag": "f25", "sigkeys": ["foo", "bar"]}
|
|
|
|
)
|
2016-04-21 10:20:31 +00:00
|
|
|
self.koji_wrapper = mock.Mock()
|
2020-01-22 10:02:22 +00:00
|
|
|
self.pkgset_path = os.path.join(
|
|
|
|
self.topdir, "work", "global", "pkgset_global.pickle"
|
|
|
|
)
|
|
|
|
self.koji_module_path = os.path.join(
|
|
|
|
self.topdir, "work", "global", "koji-module-Server.yaml"
|
|
|
|
)
|
2016-04-21 10:20:31 +00:00
|
|
|
|
2019-08-01 09:19:51 +00:00
|
|
|
@mock.patch("pungi.phases.pkgset.sources.source_koji.MaterializedPackageSet.create")
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi.phases.pkgset.pkgsets.KojiPackageSet")
|
2019-08-01 09:19:51 +00:00
|
|
|
def test_populate(self, KojiPackageSet, materialize):
|
|
|
|
materialize.side_effect = self.mock_materialize
|
2016-04-21 10:20:31 +00:00
|
|
|
|
2020-02-25 03:02:39 +00:00
|
|
|
KojiPackageSet.return_value.reuse = None
|
2016-04-21 10:20:31 +00:00
|
|
|
orig_pkgset = KojiPackageSet.return_value
|
|
|
|
|
2019-08-01 09:19:51 +00:00
|
|
|
pkgsets = source_koji.populate_global_pkgset(
|
|
|
|
self.compose, self.koji_wrapper, "/prefix", 123456
|
|
|
|
)
|
2016-04-21 10:20:31 +00:00
|
|
|
|
2019-08-01 09:19:51 +00:00
|
|
|
self.assertEqual(len(pkgsets), 1)
|
|
|
|
self.assertIs(pkgsets[0], orig_pkgset)
|
|
|
|
pkgsets[0].assert_has_calls(
|
|
|
|
[mock.call.populate("f25", 123456, inherit=True, include_packages=set())],
|
2018-06-25 12:35:32 +00:00
|
|
|
)
|
2016-04-21 10:20:31 +00:00
|
|
|
|
2019-08-01 09:19:51 +00:00
|
|
|
def mock_materialize(self, compose, pkgset, prefix, mmd):
|
|
|
|
self.assertEqual(prefix, "/prefix")
|
|
|
|
self.assertEqual(compose, self.compose)
|
|
|
|
return pkgset
|
|
|
|
|
|
|
|
@mock.patch("pungi.phases.pkgset.sources.source_koji.MaterializedPackageSet.create")
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi.phases.pkgset.pkgsets.KojiPackageSet")
|
|
|
|
def test_populate_with_multiple_koji_tags(self, KojiPackageSet, materialize):
|
|
|
|
self.compose = helpers.DummyCompose(
|
|
|
|
self.topdir,
|
|
|
|
{"pkgset_koji_tag": ["f25", "f25-extra"], "sigkeys": ["foo", "bar"]},
|
|
|
|
)
|
2017-06-27 11:48:02 +00:00
|
|
|
|
2019-08-01 09:19:51 +00:00
|
|
|
materialize.side_effect = self.mock_materialize
|
2017-06-27 11:48:02 +00:00
|
|
|
|
2020-02-25 03:02:39 +00:00
|
|
|
KojiPackageSet.return_value.reuse = None
|
|
|
|
|
2019-08-01 09:19:51 +00:00
|
|
|
pkgsets = source_koji.populate_global_pkgset(
|
|
|
|
self.compose, self.koji_wrapper, "/prefix", 123456
|
|
|
|
)
|
2017-06-27 11:48:02 +00:00
|
|
|
|
2019-08-01 09:19:51 +00:00
|
|
|
self.assertEqual(len(pkgsets), 2)
|
|
|
|
init_calls = KojiPackageSet.call_args_list
|
2020-01-22 10:02:22 +00:00
|
|
|
six.assertCountEqual(
|
|
|
|
self, [call[0][0] for call in init_calls], ["f25", "f25-extra"]
|
|
|
|
)
|
2019-10-04 12:45:03 +00:00
|
|
|
six.assertCountEqual(
|
|
|
|
self, [call[0][1] for call in init_calls], [self.koji_wrapper] * 2
|
2019-08-01 09:19:51 +00:00
|
|
|
)
|
2019-10-04 12:45:03 +00:00
|
|
|
six.assertCountEqual(
|
|
|
|
self, [call[0][2] for call in init_calls], [["foo", "bar"]] * 2
|
2019-08-01 09:19:51 +00:00
|
|
|
)
|
2017-06-27 11:48:02 +00:00
|
|
|
|
2019-08-01 09:19:51 +00:00
|
|
|
pkgsets[0].assert_has_calls(
|
|
|
|
[mock.call.populate("f25", 123456, inherit=True, include_packages=set())]
|
2018-06-25 12:35:32 +00:00
|
|
|
)
|
2019-08-01 09:19:51 +00:00
|
|
|
pkgsets[1].assert_has_calls(
|
2018-06-25 12:35:32 +00:00
|
|
|
[
|
|
|
|
mock.call.populate(
|
2019-08-01 09:19:51 +00:00
|
|
|
"f25-extra", 123456, inherit=True, include_packages=set()
|
2018-06-25 12:35:32 +00:00
|
|
|
),
|
|
|
|
]
|
|
|
|
)
|
2019-08-01 09:19:51 +00:00
|
|
|
|
|
|
|
@mock.patch("pungi.phases.pkgset.sources.source_koji.MaterializedPackageSet.create")
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi.phases.pkgset.pkgsets.KojiPackageSet.populate")
|
|
|
|
@mock.patch("pungi.phases.pkgset.pkgsets.KojiPackageSet.save_file_list")
|
2019-08-01 09:19:51 +00:00
|
|
|
def test_populate_packages_to_gather(self, save_file_list, popuplate, materialize):
|
2020-01-22 10:02:22 +00:00
|
|
|
self.compose = helpers.DummyCompose(
|
|
|
|
self.topdir,
|
|
|
|
{
|
|
|
|
"gather_method": "nodeps",
|
|
|
|
"pkgset_koji_tag": "f25",
|
|
|
|
"sigkeys": ["foo", "bar"],
|
|
|
|
"additional_packages": [(".*", {"*": ["pkg", "foo.x86_64"]})],
|
|
|
|
},
|
|
|
|
)
|
2019-08-01 09:19:51 +00:00
|
|
|
|
|
|
|
materialize.side_effect = self.mock_materialize
|
2017-10-16 12:20:37 +00:00
|
|
|
|
2019-07-26 14:06:53 +00:00
|
|
|
pkgsets = source_koji.populate_global_pkgset(
|
2020-01-22 10:02:22 +00:00
|
|
|
self.compose, self.koji_wrapper, "/prefix", 123456
|
|
|
|
)
|
2019-07-26 14:06:53 +00:00
|
|
|
self.assertEqual(len(pkgsets), 1)
|
2019-10-04 12:45:03 +00:00
|
|
|
six.assertCountEqual(self, pkgsets[0].packages, ["pkg", "foo"])
|
2017-10-16 12:20:37 +00:00
|
|
|
|
2016-04-21 10:20:31 +00:00
|
|
|
|
|
|
|
class TestGetPackageSetFromKoji(helpers.PungiTestCase):
|
|
|
|
def setUp(self):
|
|
|
|
super(TestGetPackageSetFromKoji, self).setUp()
|
2020-01-22 10:02:22 +00:00
|
|
|
self.compose = helpers.DummyCompose(self.topdir, {"pkgset_koji_tag": "f25"})
|
2016-04-21 10:20:31 +00:00
|
|
|
self.compose.koji_event = None
|
|
|
|
self.koji_wrapper = mock.Mock()
|
|
|
|
self.koji_wrapper.koji_proxy.getLastEvent.return_value = EVENT_INFO
|
|
|
|
self.koji_wrapper.koji_proxy.getTag.return_value = TAG_INFO
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi.phases.pkgset.sources.source_koji.populate_global_pkgset")
|
2019-08-01 09:19:51 +00:00
|
|
|
def test_get_package_sets(self, pgp):
|
|
|
|
pkgsets = source_koji.get_pkgset_from_koji(
|
|
|
|
self.compose, self.koji_wrapper, "/prefix"
|
|
|
|
)
|
2016-04-21 10:20:31 +00:00
|
|
|
|
2019-10-04 12:45:03 +00:00
|
|
|
six.assertCountEqual(
|
2020-01-22 10:02:22 +00:00
|
|
|
self, self.koji_wrapper.koji_proxy.mock_calls, [mock.call.getLastEvent()]
|
2016-04-21 10:20:31 +00:00
|
|
|
)
|
2019-08-01 09:19:51 +00:00
|
|
|
self.assertEqual(pkgsets, pgp.return_value)
|
2017-02-28 13:03:36 +00:00
|
|
|
|
2019-07-26 11:19:39 +00:00
|
|
|
self.assertEqual(
|
2019-08-01 09:19:51 +00:00
|
|
|
pgp.call_args_list,
|
2020-01-22 10:02:22 +00:00
|
|
|
[mock.call(self.compose, self.koji_wrapper, "/prefix", EVENT_INFO)],
|
2019-07-26 11:19:39 +00:00
|
|
|
)
|
2016-04-21 10:20:31 +00:00
|
|
|
|
2018-06-15 07:26:38 +00:00
|
|
|
def test_get_koji_modules(self):
|
2020-01-22 10:02:22 +00:00
|
|
|
mock_build_ids = [
|
|
|
|
{"id": 1065873, "name": "testmodule2-master_dash-20180406051653.96c371af"}
|
|
|
|
]
|
2018-06-15 07:26:38 +00:00
|
|
|
mock_extra = {
|
2020-01-22 10:02:22 +00:00
|
|
|
"typeinfo": {
|
|
|
|
"module": {
|
|
|
|
"content_koji_tag": "module-b62270b82443edde",
|
|
|
|
"modulemd_str": mock.Mock(),
|
|
|
|
"name": "testmodule2",
|
|
|
|
"stream": "master",
|
|
|
|
"version": "20180406051653",
|
|
|
|
"context": "96c371af",
|
2018-10-23 13:10:29 +00:00
|
|
|
}
|
2018-06-15 07:26:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
mock_build_md = [
|
|
|
|
{
|
2020-01-22 10:02:22 +00:00
|
|
|
"id": 1065873,
|
|
|
|
"epoch": None,
|
|
|
|
"extra": mock_extra,
|
|
|
|
"name": "testmodule2",
|
|
|
|
"nvr": "testmodule2-master_dash-20180406051653.2e6f5e0a",
|
|
|
|
"release": "20180406051653.2e6f5e0a",
|
|
|
|
"state": 1,
|
|
|
|
"version": "master_dash",
|
|
|
|
"completion_ts": 1433473124.0,
|
2018-06-15 07:26:38 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
self.koji_wrapper.koji_proxy.search.return_value = mock_build_ids
|
|
|
|
self.koji_wrapper.koji_proxy.getBuild.return_value = mock_build_md[0]
|
2018-08-29 11:02:29 +00:00
|
|
|
event = {"id": 12345, "ts": 1533473124.0}
|
2018-06-15 07:26:38 +00:00
|
|
|
|
2018-07-18 08:22:33 +00:00
|
|
|
module_info_str = "testmodule2:master-dash:20180406051653:96c371af"
|
2018-08-29 11:02:29 +00:00
|
|
|
result = source_koji.get_koji_modules(
|
|
|
|
self.compose, self.koji_wrapper, event, module_info_str
|
|
|
|
)
|
2018-06-15 07:26:38 +00:00
|
|
|
|
|
|
|
assert type(result) is list
|
|
|
|
assert len(result) == 1
|
|
|
|
module = result[0]
|
|
|
|
assert type(module) is dict
|
2019-04-30 10:22:13 +00:00
|
|
|
self.assertIn("module_stream", module)
|
|
|
|
self.assertIn("module_version", module)
|
|
|
|
self.assertIn("module_context", module)
|
|
|
|
self.assertIn("tag", module)
|
2018-06-15 07:26:38 +00:00
|
|
|
|
2018-07-18 08:22:33 +00:00
|
|
|
expected_query = "testmodule2-master_dash-20180406051653.96c371af"
|
2020-01-22 10:02:22 +00:00
|
|
|
self.koji_wrapper.koji_proxy.search.assert_called_once_with(
|
|
|
|
expected_query, "build", "glob"
|
|
|
|
)
|
|
|
|
self.koji_wrapper.koji_proxy.getBuild.assert_called_once_with(
|
|
|
|
mock_build_ids[0]["id"]
|
|
|
|
)
|
2018-06-15 07:26:38 +00:00
|
|
|
|
2018-08-29 11:02:29 +00:00
|
|
|
def test_get_koji_modules_filter_by_event(self):
|
|
|
|
mock_build_ids = [
|
|
|
|
{"id": 1065873, "name": "testmodule2-master_dash-20180406051653.96c371af"}
|
|
|
|
]
|
|
|
|
mock_extra = {
|
|
|
|
"typeinfo": {
|
|
|
|
"module": {
|
|
|
|
"content_koji_tag": "module-b62270b82443edde",
|
2020-01-22 10:02:22 +00:00
|
|
|
"modulemd_str": mock.Mock(),
|
|
|
|
}
|
2018-08-29 11:02:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
mock_build_md = [
|
|
|
|
{
|
|
|
|
"id": 1065873,
|
|
|
|
"epoch": None,
|
|
|
|
"extra": mock_extra,
|
|
|
|
"name": "testmodule2",
|
|
|
|
"nvr": "testmodule2-master_dash-20180406051653.2e6f5e0a",
|
|
|
|
"release": "20180406051653.2e6f5e0a",
|
|
|
|
"state": 1,
|
|
|
|
"version": "master_dash",
|
|
|
|
"completion_ts": 1633473124.0,
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
self.koji_wrapper.koji_proxy.search.return_value = mock_build_ids
|
|
|
|
self.koji_wrapper.koji_proxy.getBuild.return_value = mock_build_md[0]
|
|
|
|
event = {"id": 12345, "ts": 1533473124.0}
|
|
|
|
|
|
|
|
with self.assertRaises(ValueError) as ctx:
|
|
|
|
source_koji.get_koji_modules(
|
|
|
|
self.compose, self.koji_wrapper, event, "testmodule2:master-dash"
|
|
|
|
)
|
|
|
|
|
|
|
|
self.assertIn("No module build found", str(ctx.exception))
|
|
|
|
|
|
|
|
self.koji_wrapper.koji_proxy.search.assert_called_once_with(
|
|
|
|
"testmodule2-master_dash-*", "build", "glob"
|
|
|
|
)
|
2020-01-22 10:02:22 +00:00
|
|
|
self.koji_wrapper.koji_proxy.getBuild.assert_called_once_with(
|
|
|
|
mock_build_ids[0]["id"]
|
|
|
|
)
|
2018-08-29 11:02:29 +00:00
|
|
|
self.koji_wrapper.koji_proxy.listArchives.assert_not_called()
|
|
|
|
self.koji_wrapper.koji_proxy.listRPMs.assert_not_called()
|
|
|
|
|
2018-06-15 07:26:38 +00:00
|
|
|
def test_get_koji_modules_no_version(self):
|
|
|
|
mock_build_ids = [
|
2020-01-22 10:02:22 +00:00
|
|
|
{"id": 1065873, "name": "testmodule2-master-20180406051653.2e6f5e0a"},
|
|
|
|
{"id": 1065874, "name": "testmodule2-master-20180406051653.96c371af"},
|
2018-06-15 07:26:38 +00:00
|
|
|
]
|
|
|
|
mock_extra = [
|
|
|
|
{
|
2020-01-22 10:02:22 +00:00
|
|
|
"typeinfo": {
|
|
|
|
"module": {
|
|
|
|
"content_koji_tag": "module-b62270b82443edde",
|
|
|
|
"modulemd_str": mock.Mock(),
|
|
|
|
"name": "testmodule2",
|
|
|
|
"stream": "master",
|
|
|
|
"version": "20180406051653",
|
|
|
|
"context": "2e6f5e0a",
|
2018-10-23 13:10:29 +00:00
|
|
|
}
|
2018-06-15 07:26:38 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2020-01-22 10:02:22 +00:00
|
|
|
"typeinfo": {
|
|
|
|
"module": {
|
|
|
|
"content_koji_tag": "module-52e40b9cdd3c0f7d",
|
|
|
|
"modulemd_str": mock.Mock(),
|
|
|
|
"name": "testmodule2",
|
|
|
|
"stream": "master",
|
|
|
|
"version": "20180406051653",
|
|
|
|
"context": "96c371af",
|
2018-10-23 13:10:29 +00:00
|
|
|
}
|
2018-06-15 07:26:38 +00:00
|
|
|
}
|
2020-01-22 10:02:22 +00:00
|
|
|
},
|
2018-06-15 07:26:38 +00:00
|
|
|
]
|
|
|
|
mock_build_md = [
|
|
|
|
{
|
2020-01-22 10:02:22 +00:00
|
|
|
"id": 1065873,
|
|
|
|
"epoch": None,
|
|
|
|
"extra": mock_extra[0],
|
|
|
|
"name": "testmodule2",
|
|
|
|
"nvr": "testmodule2-master-20180406051653.2e6f5e0a",
|
|
|
|
"release": "20180406051653.2e6f5e0a",
|
|
|
|
"state": 1,
|
|
|
|
"version": "master",
|
|
|
|
"completion_ts": 1433473124.0,
|
2018-06-15 07:26:38 +00:00
|
|
|
},
|
|
|
|
{
|
2020-01-22 10:02:22 +00:00
|
|
|
"id": 1065874,
|
|
|
|
"epoch": None,
|
|
|
|
"extra": mock_extra[1],
|
|
|
|
"name": "testmodule2",
|
|
|
|
"nvr": "testmodule2-master-20180406051653.96c371af",
|
|
|
|
"release": "20180406051653.96c371af",
|
|
|
|
"state": 1,
|
|
|
|
"version": "master",
|
|
|
|
"completion_ts": 1433473124.0,
|
|
|
|
},
|
2018-06-15 07:26:38 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
self.koji_wrapper.koji_proxy.search.return_value = mock_build_ids
|
|
|
|
self.koji_wrapper.koji_proxy.getBuild.side_effect = mock_build_md
|
|
|
|
|
2018-08-29 11:02:29 +00:00
|
|
|
event = {"id": 12345, "ts": 1533473124.0}
|
|
|
|
|
2018-06-15 07:26:38 +00:00
|
|
|
module_info_str = "testmodule2:master"
|
2018-08-29 11:02:29 +00:00
|
|
|
result = source_koji.get_koji_modules(
|
|
|
|
self.compose, self.koji_wrapper, event, module_info_str
|
|
|
|
)
|
2018-06-15 07:26:38 +00:00
|
|
|
|
|
|
|
assert type(result) is list
|
|
|
|
assert len(result) == 2
|
|
|
|
module = result[0]
|
|
|
|
for module in result:
|
|
|
|
assert type(module) is dict
|
2019-04-30 10:22:13 +00:00
|
|
|
self.assertIn("module_stream", module)
|
|
|
|
self.assertIn("module_version", module)
|
|
|
|
self.assertIn("module_context", module)
|
2018-06-15 07:26:38 +00:00
|
|
|
|
|
|
|
expected_query = "testmodule2-master-*"
|
2020-01-22 10:02:22 +00:00
|
|
|
self.koji_wrapper.koji_proxy.search.assert_called_once_with(
|
|
|
|
expected_query, "build", "glob"
|
|
|
|
)
|
2018-06-15 07:26:38 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
expected_calls = [
|
|
|
|
mock.call(mock_build_ids[0]["id"]),
|
|
|
|
mock.call(mock_build_ids[1]["id"]),
|
|
|
|
]
|
2018-06-15 07:26:38 +00:00
|
|
|
self.koji_wrapper.koji_proxy.getBuild.mock_calls == expected_calls
|
|
|
|
|
2020-01-14 08:23:55 +00:00
|
|
|
def test_get_koji_modules_ignore_deleted(self):
|
|
|
|
mock_build_ids = [
|
|
|
|
{"id": 1065873, "name": "testmodule2-master_dash-20180406051653.96c371af"}
|
|
|
|
]
|
|
|
|
mock_extra = {
|
|
|
|
"typeinfo": {
|
|
|
|
"module": {
|
|
|
|
"content_koji_tag": "module-b62270b82443edde",
|
|
|
|
"modulemd_str": mock.Mock(),
|
|
|
|
"name": "testmodule2",
|
|
|
|
"stream": "master",
|
|
|
|
"version": "20180406051653",
|
|
|
|
"context": "96c371af",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mock_build_md = [
|
|
|
|
{
|
|
|
|
"id": 1065873,
|
|
|
|
"epoch": None,
|
|
|
|
"extra": mock_extra,
|
|
|
|
"name": "testmodule2",
|
|
|
|
"nvr": "testmodule2-master_dash-20180406051653.96c371af",
|
|
|
|
"release": "20180406051653.96c371af",
|
|
|
|
"state": 2,
|
|
|
|
"version": "master_dash",
|
|
|
|
"completion_ts": 1433473124.0,
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
self.koji_wrapper.koji_proxy.search.return_value = mock_build_ids
|
|
|
|
self.koji_wrapper.koji_proxy.getBuild.return_value = mock_build_md[0]
|
|
|
|
event = {"id": 12345, "ts": 1533473124.0}
|
|
|
|
|
|
|
|
with self.assertRaises(ValueError) as ctx:
|
|
|
|
source_koji.get_koji_modules(
|
|
|
|
self.compose, self.koji_wrapper, event, "testmodule2:master-dash"
|
|
|
|
)
|
|
|
|
|
|
|
|
self.compose.log_debug.assert_called_once_with(
|
|
|
|
"Module build %s has been deleted, ignoring it." % mock_build_ids[0]["name"]
|
|
|
|
)
|
|
|
|
|
|
|
|
self.assertIn("No module build found", str(ctx.exception))
|
|
|
|
|
|
|
|
self.koji_wrapper.koji_proxy.search.assert_called_once_with(
|
|
|
|
"testmodule2-master_dash-*", "build", "glob"
|
|
|
|
)
|
2020-01-22 10:02:22 +00:00
|
|
|
self.koji_wrapper.koji_proxy.getBuild.assert_called_once_with(
|
|
|
|
mock_build_ids[0]["id"]
|
|
|
|
)
|
2020-01-14 08:23:55 +00:00
|
|
|
self.koji_wrapper.koji_proxy.listArchives.assert_not_called()
|
|
|
|
self.koji_wrapper.koji_proxy.listRPMs.assert_not_called()
|
|
|
|
|
2016-04-21 10:20:31 +00:00
|
|
|
|
|
|
|
class TestSourceKoji(helpers.PungiTestCase):
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi.phases.pkgset.sources.source_koji.get_pkgset_from_koji")
|
|
|
|
@mock.patch("pungi.wrappers.kojiwrapper.KojiWrapper")
|
2016-04-21 10:20:31 +00:00
|
|
|
def test_run(self, KojiWrapper, gpfk):
|
2020-01-22 10:02:22 +00:00
|
|
|
compose = helpers.DummyCompose(self.topdir, {"koji_profile": "koji"})
|
|
|
|
KojiWrapper.return_value.koji_module.config.topdir = "/prefix"
|
2016-04-21 10:20:31 +00:00
|
|
|
|
|
|
|
phase = source_koji.PkgsetSourceKoji(compose)
|
|
|
|
pkgsets, path_prefix = phase()
|
|
|
|
|
|
|
|
self.assertEqual(pkgsets, gpfk.return_value)
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertEqual(path_prefix, "/prefix/")
|
|
|
|
self.assertEqual(KojiWrapper.mock_calls, [mock.call("koji")])
|
2016-04-21 10:20:31 +00:00
|
|
|
|
|
|
|
|
2017-06-20 14:26:30 +00:00
|
|
|
class TestCorrectNVR(helpers.PungiTestCase):
|
|
|
|
def setUp(self):
|
|
|
|
super(TestCorrectNVR, self).setUp()
|
2017-10-20 08:41:30 +00:00
|
|
|
self.compose = helpers.DummyCompose(self.topdir, {})
|
2017-06-20 14:26:30 +00:00
|
|
|
self.nv = "base-runtime-f26"
|
|
|
|
self.nvr = "base-runtime-f26-20170502134116"
|
2019-05-15 13:47:44 +00:00
|
|
|
self.release_regex = re.compile(r"^(\d){14}$")
|
2017-10-20 08:41:30 +00:00
|
|
|
self.new_nv = "base-runtime:f26"
|
|
|
|
self.new_nvr = "base-runtime:f26:20170502134116"
|
|
|
|
self.new_nvrc = "base-runtime:f26:20170502134116:0123abcd"
|
2017-06-20 14:26:30 +00:00
|
|
|
|
|
|
|
def test_nv(self):
|
2017-10-20 08:41:30 +00:00
|
|
|
module_info = source_koji.variant_dict_from_str(self.compose, self.nv)
|
2018-04-16 12:47:49 +00:00
|
|
|
expectedKeys = ["stream", "name"]
|
2019-10-04 12:45:03 +00:00
|
|
|
six.assertCountEqual(self, module_info.keys(), expectedKeys)
|
2017-06-20 14:26:30 +00:00
|
|
|
|
|
|
|
def test_nvr(self):
|
2017-10-20 08:41:30 +00:00
|
|
|
module_info = source_koji.variant_dict_from_str(self.compose, self.nvr)
|
2018-04-16 12:47:49 +00:00
|
|
|
expectedKeys = ["stream", "name", "version"]
|
2019-10-04 12:45:03 +00:00
|
|
|
six.assertCountEqual(self, module_info.keys(), expectedKeys)
|
2017-06-20 14:26:30 +00:00
|
|
|
|
|
|
|
def test_correct_release(self):
|
2017-10-20 08:41:30 +00:00
|
|
|
module_info = source_koji.variant_dict_from_str(self.compose, self.nvr)
|
2018-04-16 12:47:49 +00:00
|
|
|
self.assertIsNotNone(self.release_regex.match(module_info["version"]))
|
2017-06-20 14:26:30 +00:00
|
|
|
|
2017-10-20 08:41:30 +00:00
|
|
|
def test_new_nv(self):
|
|
|
|
module_info = source_koji.variant_dict_from_str(self.compose, self.new_nv)
|
2020-01-22 10:02:22 +00:00
|
|
|
expected = {"name": "base-runtime", "stream": "f26"}
|
2017-10-20 08:41:30 +00:00
|
|
|
|
|
|
|
self.assertEqual(module_info, expected)
|
|
|
|
|
|
|
|
def test_new_nvr(self):
|
|
|
|
module_info = source_koji.variant_dict_from_str(self.compose, self.new_nvr)
|
|
|
|
expected = {
|
2020-01-22 10:02:22 +00:00
|
|
|
"name": "base-runtime",
|
|
|
|
"stream": "f26",
|
|
|
|
"version": "20170502134116",
|
|
|
|
}
|
2017-10-20 08:41:30 +00:00
|
|
|
self.assertEqual(module_info, expected)
|
|
|
|
|
|
|
|
def test_new_nvrc(self):
|
2018-04-26 07:01:13 +00:00
|
|
|
module_info = source_koji.variant_dict_from_str(self.compose, self.new_nvrc)
|
|
|
|
expected = {
|
2020-01-22 10:02:22 +00:00
|
|
|
"name": "base-runtime",
|
|
|
|
"stream": "f26",
|
|
|
|
"version": "20170502134116",
|
|
|
|
"context": "0123abcd",
|
|
|
|
}
|
2018-04-26 07:01:13 +00:00
|
|
|
self.assertEqual(module_info, expected)
|
|
|
|
|
|
|
|
def test_new_garbage_value(self):
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertRaises(
|
|
|
|
ValueError,
|
|
|
|
source_koji.variant_dict_from_str,
|
|
|
|
self.compose,
|
|
|
|
"foo:bar:baz:quux:qaar",
|
|
|
|
)
|
2017-06-20 14:26:30 +00:00
|
|
|
|
2018-04-16 12:47:49 +00:00
|
|
|
|
2018-08-30 09:12:58 +00:00
|
|
|
class TestFilterInherited(unittest.TestCase):
|
|
|
|
def test_empty_module_list(self):
|
|
|
|
event = {"id": 123456}
|
|
|
|
koji_proxy = mock.Mock()
|
|
|
|
module_builds = []
|
|
|
|
top_tag = "top-tag"
|
|
|
|
|
|
|
|
koji_proxy.getFullInheritance.return_value = [
|
2020-01-22 10:02:22 +00:00
|
|
|
{"name": "middle-tag"},
|
|
|
|
{"name": "bottom-tag"},
|
2018-08-30 09:12:58 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
result = source_koji.filter_inherited(koji_proxy, event, module_builds, top_tag)
|
|
|
|
|
2019-10-04 12:45:03 +00:00
|
|
|
self.assertEqual(result, [])
|
2018-08-30 09:12:58 +00:00
|
|
|
self.assertEqual(
|
|
|
|
koji_proxy.mock_calls,
|
|
|
|
[mock.call.getFullInheritance("top-tag", event=123456)],
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_exclude_middle_and_bottom_tag(self):
|
|
|
|
event = {"id": 123456}
|
|
|
|
koji_proxy = mock.Mock()
|
|
|
|
top_tag = "top-tag"
|
|
|
|
|
|
|
|
koji_proxy.getFullInheritance.return_value = [
|
2020-01-22 10:02:22 +00:00
|
|
|
{"name": "middle-tag"},
|
|
|
|
{"name": "bottom-tag"},
|
2018-08-30 09:12:58 +00:00
|
|
|
]
|
|
|
|
module_builds = [
|
|
|
|
{"name": "foo", "version": "1", "release": "1", "tag_name": "top-tag"},
|
|
|
|
{"name": "foo", "version": "1", "release": "2", "tag_name": "bottom-tag"},
|
|
|
|
{"name": "foo", "version": "1", "release": "3", "tag_name": "middle-tag"},
|
|
|
|
]
|
|
|
|
|
|
|
|
result = source_koji.filter_inherited(koji_proxy, event, module_builds, top_tag)
|
|
|
|
|
2019-10-04 12:45:03 +00:00
|
|
|
six.assertCountEqual(
|
|
|
|
self,
|
2018-08-30 09:12:58 +00:00
|
|
|
result,
|
|
|
|
[{"name": "foo", "version": "1", "release": "1", "tag_name": "top-tag"}],
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
koji_proxy.mock_calls,
|
|
|
|
[mock.call.getFullInheritance("top-tag", event=123456)],
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_missing_from_top_tag(self):
|
|
|
|
event = {"id": 123456}
|
|
|
|
koji_proxy = mock.Mock()
|
|
|
|
top_tag = "top-tag"
|
|
|
|
|
|
|
|
koji_proxy.getFullInheritance.return_value = [
|
2020-01-22 10:02:22 +00:00
|
|
|
{"name": "middle-tag"},
|
|
|
|
{"name": "bottom-tag"},
|
2018-08-30 09:12:58 +00:00
|
|
|
]
|
|
|
|
module_builds = [
|
|
|
|
{"name": "foo", "version": "1", "release": "2", "tag_name": "bottom-tag"},
|
|
|
|
{"name": "foo", "version": "1", "release": "3", "tag_name": "middle-tag"},
|
|
|
|
]
|
|
|
|
|
|
|
|
result = source_koji.filter_inherited(koji_proxy, event, module_builds, top_tag)
|
|
|
|
|
2019-10-04 12:45:03 +00:00
|
|
|
six.assertCountEqual(
|
|
|
|
self,
|
2018-08-30 09:12:58 +00:00
|
|
|
result,
|
|
|
|
[{"name": "foo", "version": "1", "release": "3", "tag_name": "middle-tag"}],
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
koji_proxy.mock_calls,
|
|
|
|
[mock.call.getFullInheritance("top-tag", event=123456)],
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class TestFilterByWhitelist(unittest.TestCase):
|
2019-05-03 12:44:16 +00:00
|
|
|
def _build(self, n, s, v, c):
|
|
|
|
s = s.replace("-", "_")
|
|
|
|
return {
|
|
|
|
"nvr": "%s-%s-%s.%s" % (n, s, v, c),
|
|
|
|
"name": n,
|
|
|
|
"version": s,
|
|
|
|
"release": "%s.%s" % (v, c),
|
|
|
|
}
|
|
|
|
|
2018-08-30 09:12:58 +00:00
|
|
|
def test_no_modules(self):
|
|
|
|
compose = mock.Mock()
|
|
|
|
module_builds = []
|
|
|
|
input_modules = [{"name": "foo:1"}]
|
2019-06-13 08:10:30 +00:00
|
|
|
expected = set(["foo:1"])
|
2018-08-30 09:12:58 +00:00
|
|
|
|
2019-06-13 08:10:30 +00:00
|
|
|
source_koji.filter_by_whitelist(compose, module_builds, input_modules, expected)
|
2018-08-30 09:12:58 +00:00
|
|
|
|
2019-06-13 08:10:30 +00:00
|
|
|
self.assertEqual(expected, set(["foo:1"]))
|
2018-08-30 09:12:58 +00:00
|
|
|
|
|
|
|
def test_filter_by_NS(self):
|
|
|
|
compose = mock.Mock()
|
|
|
|
module_builds = [
|
2019-05-03 12:44:16 +00:00
|
|
|
self._build("foo", "1", "201809031048", "cafebabe"),
|
|
|
|
self._build("foo", "1", "201809031047", "deadbeef"),
|
|
|
|
self._build("foo", "2", "201809031047", "deadbeef"),
|
2018-08-30 09:12:58 +00:00
|
|
|
]
|
|
|
|
input_modules = [{"name": "foo:1"}]
|
2019-06-13 08:10:30 +00:00
|
|
|
expected = set(["foo:1"])
|
2018-08-30 09:12:58 +00:00
|
|
|
|
2019-06-13 08:10:30 +00:00
|
|
|
result = source_koji.filter_by_whitelist(
|
|
|
|
compose, module_builds, input_modules, expected
|
|
|
|
)
|
2018-08-30 09:12:58 +00:00
|
|
|
|
2019-10-04 12:45:03 +00:00
|
|
|
six.assertCountEqual(self, result, [module_builds[0], module_builds[1]])
|
2019-06-13 08:10:30 +00:00
|
|
|
self.assertEqual(expected, set())
|
2018-08-30 09:12:58 +00:00
|
|
|
|
|
|
|
def test_filter_by_NSV(self):
|
|
|
|
compose = mock.Mock()
|
|
|
|
module_builds = [
|
2019-05-03 12:44:16 +00:00
|
|
|
self._build("foo", "1", "201809031048", "cafebabe"),
|
|
|
|
self._build("foo", "1", "201809031047", "deadbeef"),
|
|
|
|
self._build("foo", "2", "201809031047", "deadbeef"),
|
2018-08-30 09:12:58 +00:00
|
|
|
]
|
|
|
|
input_modules = [{"name": "foo:1:201809031047"}]
|
2019-06-13 08:10:30 +00:00
|
|
|
expected = set(["foo:1:201809031047"])
|
2018-08-30 09:12:58 +00:00
|
|
|
|
2019-06-13 08:10:30 +00:00
|
|
|
result = source_koji.filter_by_whitelist(
|
|
|
|
compose, module_builds, input_modules, expected
|
|
|
|
)
|
2018-08-30 09:12:58 +00:00
|
|
|
|
2019-10-04 12:45:03 +00:00
|
|
|
self.assertEqual(result, [module_builds[1]])
|
2019-06-13 08:10:30 +00:00
|
|
|
self.assertEqual(expected, set())
|
2018-08-30 09:12:58 +00:00
|
|
|
|
|
|
|
def test_filter_by_NSVC(self):
|
|
|
|
compose = mock.Mock()
|
|
|
|
module_builds = [
|
2019-05-03 12:44:16 +00:00
|
|
|
self._build("foo", "1", "201809031048", "cafebabe"),
|
|
|
|
self._build("foo", "1", "201809031047", "deadbeef"),
|
|
|
|
self._build("foo", "1", "201809031047", "cafebabe"),
|
|
|
|
self._build("foo", "2", "201809031047", "deadbeef"),
|
2018-08-30 09:12:58 +00:00
|
|
|
]
|
|
|
|
input_modules = [{"name": "foo:1:201809031047:deadbeef"}]
|
2019-06-13 08:10:30 +00:00
|
|
|
expected = set()
|
2018-08-30 09:12:58 +00:00
|
|
|
|
2019-06-13 08:10:30 +00:00
|
|
|
result = source_koji.filter_by_whitelist(
|
|
|
|
compose, module_builds, input_modules, expected
|
|
|
|
)
|
2018-08-30 09:12:58 +00:00
|
|
|
|
2019-10-04 12:45:03 +00:00
|
|
|
self.assertEqual(result, [module_builds[1]])
|
2019-06-13 08:10:30 +00:00
|
|
|
self.assertEqual(expected, set())
|
2018-08-30 09:12:58 +00:00
|
|
|
|
2019-02-07 12:58:08 +00:00
|
|
|
def test_filter_by_wildcard(self):
|
|
|
|
compose = mock.Mock()
|
|
|
|
module_builds = [
|
2019-05-03 12:44:16 +00:00
|
|
|
self._build("foo", "1", "201809031048", "cafebabe"),
|
|
|
|
self._build("foo", "1", "201809031047", "deadbeef"),
|
|
|
|
self._build("foo", "2", "201809031047", "deadbeef"),
|
2019-02-07 12:58:08 +00:00
|
|
|
]
|
|
|
|
input_modules = [{"name": "*"}]
|
2019-06-13 08:10:30 +00:00
|
|
|
expected = set(["*"])
|
2019-02-07 12:58:08 +00:00
|
|
|
|
2019-06-13 08:10:30 +00:00
|
|
|
result = source_koji.filter_by_whitelist(
|
|
|
|
compose, module_builds, input_modules, expected
|
|
|
|
)
|
2019-02-07 12:58:08 +00:00
|
|
|
|
2019-10-04 12:45:03 +00:00
|
|
|
six.assertCountEqual(self, result, module_builds)
|
2019-06-13 08:10:30 +00:00
|
|
|
self.assertEqual(expected, set())
|
2019-02-07 12:58:08 +00:00
|
|
|
|
2018-08-30 09:12:58 +00:00
|
|
|
|
2019-03-14 14:28:22 +00:00
|
|
|
class MockModule(object):
|
2019-07-01 10:11:39 +00:00
|
|
|
def __init__(self, path, strict=True):
|
2019-03-14 14:28:22 +00:00
|
|
|
self.path = path
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return "MockModule(%r)" % self.path
|
|
|
|
|
|
|
|
def __eq__(self, other):
|
|
|
|
return self.path == other.path
|
|
|
|
|
|
|
|
|
2019-10-02 07:40:18 +00:00
|
|
|
@mock.patch("pungi.module_util.Modulemd.ModuleStream.read_file", new=MockModule)
|
2019-03-25 09:16:43 +00:00
|
|
|
@unittest.skipIf(Modulemd is None, "Skipping tests, no module support")
|
2019-09-23 12:31:57 +00:00
|
|
|
class TestAddModuleToVariant(helpers.PungiTestCase):
|
2022-11-07 17:24:39 +00:00
|
|
|
def setUp(self):
|
|
|
|
super(TestAddModuleToVariant, self).setUp()
|
|
|
|
self.koji = mock.Mock()
|
|
|
|
self.koji.koji_module.pathinfo.typedir.return_value = "/koji"
|
|
|
|
files = ["modulemd.x86_64.txt", "modulemd.armv7hl.txt", "modulemd.txt"]
|
|
|
|
self.koji.koji_proxy.listArchives.return_value = [
|
|
|
|
{"btype": "module", "filename": fname} for fname in files
|
|
|
|
] + [{"btype": "foo"}]
|
|
|
|
self.buildinfo = {
|
|
|
|
"id": 1234,
|
|
|
|
"extra": {
|
|
|
|
"typeinfo": {
|
|
|
|
"module": {
|
|
|
|
"name": "module",
|
|
|
|
"stream": "master",
|
|
|
|
"version": "20190318",
|
|
|
|
"context": "abcdef",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
def test_adding_module(self):
|
|
|
|
variant = mock.Mock(arches=["armhfp", "x86_64"], arch_mmds={}, modules=[])
|
|
|
|
|
|
|
|
source_koji._add_module_to_variant(self.koji, variant, self.buildinfo)
|
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
variant.arch_mmds,
|
|
|
|
{
|
|
|
|
"armhfp": {
|
|
|
|
"module:master:20190318:abcdef": MockModule(
|
|
|
|
"/koji/modulemd.armv7hl.txt"
|
|
|
|
),
|
|
|
|
},
|
|
|
|
"x86_64": {
|
|
|
|
"module:master:20190318:abcdef": MockModule(
|
|
|
|
"/koji/modulemd.x86_64.txt"
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
self.assertEqual(variant.modules, [])
|
|
|
|
|
|
|
|
def test_adding_module_to_existing(self):
|
|
|
|
variant = mock.Mock(
|
|
|
|
arches=["armhfp", "x86_64"],
|
|
|
|
arch_mmds={
|
|
|
|
"x86_64": {"m1:latest:20190101:cafe": MockModule("/koji/m1.x86_64.txt")}
|
|
|
|
},
|
|
|
|
modules=[{"name": "m1:latest-20190101:cafe", "glob": False}],
|
|
|
|
)
|
|
|
|
|
|
|
|
source_koji._add_module_to_variant(self.koji, variant, self.buildinfo)
|
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
variant.arch_mmds,
|
|
|
|
{
|
|
|
|
"armhfp": {
|
|
|
|
"module:master:20190318:abcdef": MockModule(
|
|
|
|
"/koji/modulemd.armv7hl.txt"
|
|
|
|
),
|
|
|
|
},
|
|
|
|
"x86_64": {
|
|
|
|
"module:master:20190318:abcdef": MockModule(
|
|
|
|
"/koji/modulemd.x86_64.txt"
|
|
|
|
),
|
|
|
|
"m1:latest:20190101:cafe": MockModule("/koji/m1.x86_64.txt"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
variant.modules, [{"name": "m1:latest-20190101:cafe", "glob": False}]
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_adding_module_with_add_module(self):
|
|
|
|
variant = mock.Mock(arches=["armhfp", "x86_64"], arch_mmds={}, modules=[])
|
|
|
|
|
|
|
|
source_koji._add_module_to_variant(
|
|
|
|
self.koji, variant, self.buildinfo, add_to_variant_modules=True
|
|
|
|
)
|
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
variant.arch_mmds,
|
|
|
|
{
|
|
|
|
"armhfp": {
|
|
|
|
"module:master:20190318:abcdef": MockModule(
|
|
|
|
"/koji/modulemd.armv7hl.txt"
|
|
|
|
),
|
|
|
|
},
|
|
|
|
"x86_64": {
|
|
|
|
"module:master:20190318:abcdef": MockModule(
|
|
|
|
"/koji/modulemd.x86_64.txt"
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
variant.modules, [{"name": "module:master:20190318:abcdef", "glob": False}]
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_adding_module_to_existing_with_add_module(self):
|
|
|
|
variant = mock.Mock(
|
|
|
|
arches=["armhfp", "x86_64"],
|
|
|
|
arch_mmds={
|
|
|
|
"x86_64": {"m1:latest:20190101:cafe": MockModule("/koji/m1.x86_64.txt")}
|
|
|
|
},
|
|
|
|
modules=[{"name": "m1:latest-20190101:cafe", "glob": False}],
|
|
|
|
)
|
|
|
|
|
|
|
|
source_koji._add_module_to_variant(
|
|
|
|
self.koji, variant, self.buildinfo, add_to_variant_modules=True
|
|
|
|
)
|
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
variant.arch_mmds,
|
|
|
|
{
|
|
|
|
"armhfp": {
|
|
|
|
"module:master:20190318:abcdef": MockModule(
|
|
|
|
"/koji/modulemd.armv7hl.txt"
|
|
|
|
),
|
|
|
|
},
|
|
|
|
"x86_64": {
|
|
|
|
"module:master:20190318:abcdef": MockModule(
|
|
|
|
"/koji/modulemd.x86_64.txt"
|
|
|
|
),
|
|
|
|
"m1:latest:20190101:cafe": MockModule("/koji/m1.x86_64.txt"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
variant.modules,
|
|
|
|
[
|
|
|
|
{"name": "m1:latest-20190101:cafe", "glob": False},
|
|
|
|
{"name": "module:master:20190318:abcdef", "glob": False},
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_adding_module_but_filtered(self):
|
|
|
|
compose = helpers.DummyCompose(
|
|
|
|
self.topdir, {"filter_modules": [(".*", {"*": ["module:*"]})]}
|
|
|
|
)
|
|
|
|
variant = mock.Mock(
|
|
|
|
arches=["armhfp", "x86_64"], arch_mmds={}, modules=[], uid="Variant"
|
|
|
|
)
|
|
|
|
|
|
|
|
nsvc = source_koji._add_module_to_variant(
|
|
|
|
self.koji,
|
|
|
|
variant,
|
|
|
|
self.buildinfo,
|
|
|
|
add_to_variant_modules=True,
|
|
|
|
compose=compose,
|
|
|
|
)
|
|
|
|
|
|
|
|
self.assertIsNone(nsvc)
|
|
|
|
self.assertEqual(variant.arch_mmds, {})
|
|
|
|
self.assertEqual(variant.modules, [])
|
|
|
|
|
|
|
|
|
|
|
|
@mock.patch("pungi.module_util.Modulemd.ModuleStream.read_file", new=MockModule)
|
|
|
|
@unittest.skipIf(Modulemd is None, "Skipping tests, no module support")
|
|
|
|
class TestAddModuleToVariantForKojiMock(helpers.PungiTestCase):
|
2019-03-14 14:28:22 +00:00
|
|
|
def setUp(self):
|
2022-11-07 18:03:59 +00:00
|
|
|
super(TestAddModuleToVariantForKojiMock, self).setUp()
|
2019-03-14 14:28:22 +00:00
|
|
|
self.koji = mock.Mock()
|
|
|
|
self.koji.koji_module.pathinfo.typedir.return_value = "/koji"
|
2020-12-29 10:45:45 +00:00
|
|
|
self.koji.koji_module.pathinfo.topdir = "/mnt/koji"
|
2019-03-14 14:28:22 +00:00
|
|
|
files = ["modulemd.x86_64.txt", "modulemd.armv7hl.txt", "modulemd.txt"]
|
|
|
|
self.koji.koji_proxy.listArchives.return_value = [
|
|
|
|
{"btype": "module", "filename": fname} for fname in files
|
|
|
|
] + [{"btype": "foo"}]
|
2019-06-28 06:42:50 +00:00
|
|
|
self.buildinfo = {
|
|
|
|
"id": 1234,
|
2021-05-12 15:14:49 +00:00
|
|
|
"arch": "fake_arch",
|
2019-06-28 06:42:50 +00:00
|
|
|
"extra": {
|
|
|
|
"typeinfo": {
|
|
|
|
"module": {
|
|
|
|
"name": "module",
|
|
|
|
"stream": "master",
|
|
|
|
"version": "20190318",
|
|
|
|
"context": "abcdef",
|
2020-12-29 10:45:45 +00:00
|
|
|
'content_koji_tag': 'module:master-20190318-abcdef'
|
2019-06-28 06:42:50 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2019-03-14 14:28:22 +00:00
|
|
|
|
|
|
|
def test_adding_module(self):
|
2020-12-29 10:45:45 +00:00
|
|
|
variant = mock.Mock(arches=[
|
|
|
|
"x86_64"
|
|
|
|
], arch_mmds={}, modules=[])
|
2019-03-14 14:28:22 +00:00
|
|
|
|
2022-11-07 18:16:53 +00:00
|
|
|
source_kojimock._add_module_to_variant(self.koji, variant, self.buildinfo)
|
2019-03-14 14:28:22 +00:00
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
variant.arch_mmds,
|
|
|
|
{
|
|
|
|
"x86_64": {
|
2020-01-22 10:02:22 +00:00
|
|
|
"module:master:20190318:abcdef": MockModule(
|
2021-05-12 15:14:49 +00:00
|
|
|
"/mnt/koji/modules/fake_arch/module:master-20190318-abcdef"
|
2020-01-22 10:02:22 +00:00
|
|
|
),
|
2019-03-14 14:28:22 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
self.assertEqual(variant.modules, [])
|
|
|
|
|
|
|
|
def test_adding_module_to_existing(self):
|
|
|
|
variant = mock.Mock(
|
2020-12-29 10:45:45 +00:00
|
|
|
arches=[
|
|
|
|
"x86_64"
|
|
|
|
],
|
2019-03-14 14:28:22 +00:00
|
|
|
arch_mmds={
|
2021-05-12 15:14:49 +00:00
|
|
|
"x86_64": {"m1:latest:20190101:cafe": MockModule("/mnt/koji/modules/fake_arch/m1:latest:20190101:cafe")}
|
2019-03-14 14:28:22 +00:00
|
|
|
},
|
2019-08-05 08:56:44 +00:00
|
|
|
modules=[{"name": "m1:latest-20190101:cafe", "glob": False}],
|
2019-03-14 14:28:22 +00:00
|
|
|
)
|
|
|
|
|
2022-11-07 18:16:53 +00:00
|
|
|
source_kojimock._add_module_to_variant(self.koji, variant, self.buildinfo)
|
2019-03-14 14:28:22 +00:00
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
variant.arch_mmds,
|
|
|
|
{
|
|
|
|
"x86_64": {
|
2020-01-22 10:02:22 +00:00
|
|
|
"module:master:20190318:abcdef": MockModule(
|
2021-05-12 15:14:49 +00:00
|
|
|
"/mnt/koji/modules/fake_arch/module:master-20190318-abcdef"
|
2020-01-22 10:02:22 +00:00
|
|
|
),
|
2021-05-12 15:14:49 +00:00
|
|
|
"m1:latest:20190101:cafe": MockModule("/mnt/koji/modules/fake_arch/m1:latest:20190101:cafe"),
|
2019-03-14 14:28:22 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
2019-08-05 08:56:44 +00:00
|
|
|
self.assertEqual(
|
|
|
|
variant.modules, [{"name": "m1:latest-20190101:cafe", "glob": False}]
|
|
|
|
)
|
2019-03-14 14:28:22 +00:00
|
|
|
|
|
|
|
def test_adding_module_with_add_module(self):
|
2020-12-29 10:45:45 +00:00
|
|
|
variant = mock.Mock(arches=[
|
|
|
|
"x86_64"
|
|
|
|
], arch_mmds={}, modules=[])
|
2019-03-14 14:28:22 +00:00
|
|
|
|
2022-11-07 18:16:53 +00:00
|
|
|
source_kojimock._add_module_to_variant(
|
2019-06-28 06:42:50 +00:00
|
|
|
self.koji, variant, self.buildinfo, add_to_variant_modules=True
|
2019-03-14 14:28:22 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
variant.arch_mmds,
|
|
|
|
{
|
|
|
|
"x86_64": {
|
2020-01-22 10:02:22 +00:00
|
|
|
"module:master:20190318:abcdef": MockModule(
|
2021-05-12 15:14:49 +00:00
|
|
|
"/mnt/koji/modules/fake_arch/module:master-20190318-abcdef"
|
2020-12-29 10:45:45 +00:00
|
|
|
)
|
2019-03-14 14:28:22 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
2019-08-05 08:56:44 +00:00
|
|
|
self.assertEqual(
|
|
|
|
variant.modules, [{"name": "module:master:20190318:abcdef", "glob": False}]
|
|
|
|
)
|
2019-03-14 14:28:22 +00:00
|
|
|
|
|
|
|
def test_adding_module_to_existing_with_add_module(self):
|
|
|
|
variant = mock.Mock(
|
2020-12-29 10:45:45 +00:00
|
|
|
arches=[
|
|
|
|
"x86_64"
|
|
|
|
],
|
2019-03-14 14:28:22 +00:00
|
|
|
arch_mmds={
|
2021-05-12 15:14:49 +00:00
|
|
|
"x86_64": {"m1:latest:20190101:cafe": MockModule("/mnt/koji/modules/fake_arch/m1:latest:20190101:cafe")}
|
2019-03-14 14:28:22 +00:00
|
|
|
},
|
2019-08-05 08:56:44 +00:00
|
|
|
modules=[{"name": "m1:latest-20190101:cafe", "glob": False}],
|
2019-03-14 14:28:22 +00:00
|
|
|
)
|
|
|
|
|
2022-11-07 18:16:53 +00:00
|
|
|
source_kojimock._add_module_to_variant(
|
2019-06-28 06:42:50 +00:00
|
|
|
self.koji, variant, self.buildinfo, add_to_variant_modules=True
|
2019-03-14 14:28:22 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
variant.arch_mmds,
|
|
|
|
{
|
|
|
|
"x86_64": {
|
2020-01-22 10:02:22 +00:00
|
|
|
"module:master:20190318:abcdef": MockModule(
|
2021-05-12 15:14:49 +00:00
|
|
|
"/mnt/koji/modules/fake_arch/module:master-20190318-abcdef"
|
2020-01-22 10:02:22 +00:00
|
|
|
),
|
2021-05-12 15:14:49 +00:00
|
|
|
"m1:latest:20190101:cafe": MockModule("/mnt/koji/modules/fake_arch/m1:latest:20190101:cafe"),
|
2019-03-14 14:28:22 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
variant.modules,
|
2019-08-05 08:56:44 +00:00
|
|
|
[
|
|
|
|
{"name": "m1:latest-20190101:cafe", "glob": False},
|
|
|
|
{"name": "module:master:20190318:abcdef", "glob": False},
|
|
|
|
],
|
2019-03-14 14:28:22 +00:00
|
|
|
)
|
2019-09-23 12:31:57 +00:00
|
|
|
|
|
|
|
def test_adding_module_but_filtered(self):
|
|
|
|
compose = helpers.DummyCompose(
|
|
|
|
self.topdir, {"filter_modules": [(".*", {"*": ["module:*"]})]}
|
|
|
|
)
|
|
|
|
variant = mock.Mock(
|
2020-12-29 10:45:45 +00:00
|
|
|
arches=[
|
|
|
|
"x86_64"
|
|
|
|
], arch_mmds={}, modules=[], uid="Variant"
|
2019-09-23 12:31:57 +00:00
|
|
|
)
|
|
|
|
|
2022-11-07 18:16:53 +00:00
|
|
|
nsvc = source_kojimock._add_module_to_variant(
|
2019-09-23 12:31:57 +00:00
|
|
|
self.koji,
|
|
|
|
variant,
|
|
|
|
self.buildinfo,
|
|
|
|
add_to_variant_modules=True,
|
|
|
|
compose=compose,
|
|
|
|
)
|
|
|
|
|
|
|
|
self.assertIsNone(nsvc)
|
|
|
|
self.assertEqual(variant.arch_mmds, {})
|
|
|
|
self.assertEqual(variant.modules, [])
|
|
|
|
|
|
|
|
|
|
|
|
class TestIsModuleFiltered(helpers.PungiTestCase):
|
|
|
|
def assertIsFiltered(self, name, stream):
|
|
|
|
self.assertTrue(
|
|
|
|
source_koji._is_filtered_out(
|
|
|
|
self.compose, self.compose.variants["Server"], "x86_64", name, stream
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
def assertIsNotFiltered(self, name, stream):
|
|
|
|
self.assertFalse(
|
|
|
|
source_koji._is_filtered_out(
|
|
|
|
self.compose, self.compose.variants["Server"], "x86_64", name, stream
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_no_filters(self):
|
|
|
|
self.compose = helpers.DummyCompose(self.topdir, {})
|
|
|
|
|
|
|
|
self.assertIsNotFiltered("foo", "master")
|
|
|
|
|
|
|
|
def test_filter_by_name(self):
|
|
|
|
self.compose = helpers.DummyCompose(
|
|
|
|
self.topdir, {"filter_modules": [(".*", {"*": ["foo"]})]}
|
|
|
|
)
|
|
|
|
|
|
|
|
self.assertIsFiltered("foo", "master")
|
|
|
|
self.assertIsNotFiltered("bar", "master")
|
|
|
|
|
|
|
|
def test_filter_by_stream(self):
|
|
|
|
self.compose = helpers.DummyCompose(
|
|
|
|
self.topdir, {"filter_modules": [(".*", {"*": ["foo:master"]})]}
|
|
|
|
)
|
|
|
|
|
|
|
|
self.assertIsFiltered("foo", "master")
|
|
|
|
self.assertIsNotFiltered("bar", "master")
|
|
|
|
self.assertIsNotFiltered("foo", "stable")
|
2020-07-06 03:02:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
class MockMBS(object):
|
|
|
|
def __init__(self, api_url):
|
|
|
|
self.api_url = api_url
|
|
|
|
|
|
|
|
def get_module_build_by_nsvc(self, nsvc):
|
|
|
|
return {"id": 1, "koji_tag": "scratch-module-tag", "name": "scratch-module"}
|
|
|
|
|
|
|
|
def final_modulemd(self, module_build_id):
|
|
|
|
return {"x86_64": ""}
|
|
|
|
|
|
|
|
|
|
|
|
class MockMmd(object):
|
|
|
|
def __init__(self, mmd, strict=True):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
@mock.patch("pungi.phases.pkgset.sources.source_koji.MBSWrapper", new=MockMBS)
|
|
|
|
@unittest.skipIf(Modulemd is None, "Skipping tests, no module support")
|
|
|
|
class TestAddScratchModuleToVariant(helpers.PungiTestCase):
|
|
|
|
def setUp(self):
|
|
|
|
super(TestAddScratchModuleToVariant, self).setUp()
|
|
|
|
self.compose = helpers.DummyCompose(
|
|
|
|
self.topdir, {"mbs_api_url": "http://mbs.local/module-build-service/2"}
|
|
|
|
)
|
|
|
|
self.nsvc = "scratch-module:master:20200710:abcdef"
|
|
|
|
|
|
|
|
@mock.patch(
|
|
|
|
"pungi.phases.pkgset.sources.source_koji.Modulemd.ModuleStream.read_string"
|
|
|
|
)
|
|
|
|
def test_adding_scratch_module(self, mock_mmd):
|
|
|
|
variant = mock.Mock(
|
2020-12-29 10:45:45 +00:00
|
|
|
arches=[
|
|
|
|
# "armhfp",
|
|
|
|
"x86_64"
|
|
|
|
],
|
2020-07-06 03:02:55 +00:00
|
|
|
arch_mmds={},
|
|
|
|
modules=[],
|
|
|
|
module_uid_to_koji_tag={},
|
|
|
|
)
|
|
|
|
variant_tags = {variant: []}
|
|
|
|
tag_to_mmd = {}
|
|
|
|
scratch_modules = [self.nsvc]
|
|
|
|
|
|
|
|
source_koji._add_scratch_modules_to_variant(
|
|
|
|
self.compose, variant, scratch_modules, variant_tags, tag_to_mmd
|
|
|
|
)
|
|
|
|
self.assertEqual(variant_tags, {variant: ["scratch-module-tag"]})
|
|
|
|
self.assertEqual(
|
|
|
|
variant.arch_mmds, {"x86_64": {self.nsvc: mock_mmd.return_value}}
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
2020-08-18 01:24:00 +00:00
|
|
|
tag_to_mmd, {"scratch-module-tag": {"x86_64": set([mock_mmd.return_value])}}
|
2020-07-06 03:02:55 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
self.assertEqual(variant.modules, [])
|
|
|
|
|
|
|
|
def test_adding_scratch_module_nontest_compose(self):
|
|
|
|
self.compose.compose_type = "production"
|
|
|
|
scratch_modules = [self.nsvc]
|
|
|
|
|
|
|
|
source_koji._add_scratch_modules_to_variant(
|
|
|
|
self.compose, mock.Mock(), scratch_modules, {}, {}
|
|
|
|
)
|
|
|
|
self.compose.log_warning.assert_called_once_with(
|
|
|
|
"Only test composes could include scratch module builds"
|
|
|
|
)
|
2021-04-23 10:03:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
@ddt
|
|
|
|
class TestSourceKoji(unittest.TestCase):
|
|
|
|
|
|
|
|
@unpack
|
|
|
|
@data(
|
|
|
|
(
|
|
|
|
'AppStream',
|
|
|
|
[
|
|
|
|
'x86_64',
|
|
|
|
'i386'
|
|
|
|
],
|
|
|
|
{
|
|
|
|
'python39-devel:3.9',
|
|
|
|
'python39:3.9',
|
|
|
|
},
|
|
|
|
[
|
|
|
|
(
|
|
|
|
'^(BaseOS|AppStream|PowerTools)$',
|
|
|
|
{
|
|
|
|
'x86_64': [
|
|
|
|
'python39:3.9',
|
|
|
|
],
|
|
|
|
'aarch64': [
|
|
|
|
'python39-devel:3.9',
|
|
|
|
]
|
|
|
|
}
|
|
|
|
)
|
|
|
|
],
|
|
|
|
{
|
|
|
|
'python39-devel:3.9',
|
|
|
|
}
|
|
|
|
),
|
|
|
|
(
|
|
|
|
'AppStream',
|
|
|
|
[
|
|
|
|
'x86_64',
|
|
|
|
'i386'
|
|
|
|
],
|
|
|
|
{
|
|
|
|
'python39-devel:3.9',
|
|
|
|
'python39:3.9',
|
|
|
|
'python38-devel:3.8',
|
|
|
|
'python38:3.8',
|
|
|
|
},
|
|
|
|
[
|
|
|
|
(
|
|
|
|
'^(BaseOS|AppStream|PowerTools)$',
|
|
|
|
{
|
|
|
|
'x86_64': [
|
|
|
|
'python39:3.9',
|
|
|
|
],
|
|
|
|
'*': [
|
|
|
|
'python38-devel:3.8',
|
|
|
|
]
|
|
|
|
}
|
|
|
|
)
|
|
|
|
],
|
|
|
|
{
|
|
|
|
'python39-devel:3.9',
|
|
|
|
'python38:3.8',
|
|
|
|
}
|
|
|
|
),
|
|
|
|
(
|
|
|
|
'AppStream',
|
|
|
|
[
|
|
|
|
'x86_64',
|
|
|
|
'i386'
|
|
|
|
],
|
|
|
|
{
|
|
|
|
'python39-devel:3.9',
|
|
|
|
'python39:3.9',
|
|
|
|
'python38-devel:3.8',
|
|
|
|
'python38:3.8',
|
|
|
|
},
|
|
|
|
[
|
|
|
|
(
|
|
|
|
'^(BaseOS|AppStream|PowerTools)$',
|
|
|
|
{
|
|
|
|
'x86_64': [
|
|
|
|
'python39:3.9',
|
|
|
|
],
|
|
|
|
'aarch64': [
|
|
|
|
'python38-devel:3.8',
|
|
|
|
]
|
|
|
|
}
|
|
|
|
),
|
|
|
|
(
|
|
|
|
'*',
|
|
|
|
{
|
|
|
|
'*': [
|
|
|
|
'python38-devel:3.8',
|
|
|
|
]
|
|
|
|
}
|
|
|
|
),
|
|
|
|
],
|
|
|
|
{
|
|
|
|
'python39-devel:3.9',
|
|
|
|
'python38:3.8',
|
|
|
|
}
|
|
|
|
),
|
|
|
|
)
|
|
|
|
def test__filter_expected_modules(
|
|
|
|
self,
|
|
|
|
variant_name: AnyStr,
|
|
|
|
variant_arches: List[AnyStr],
|
|
|
|
expected_modules: Set[AnyStr],
|
|
|
|
filtered_modules: List[Tuple[AnyStr, Dict[AnyStr, List[AnyStr]]]],
|
|
|
|
expected_result: Set[AnyStr],
|
|
|
|
) -> None:
|
2022-11-07 17:24:39 +00:00
|
|
|
real_result = source_kojimock._filter_expected_modules(
|
2021-04-23 10:03:05 +00:00
|
|
|
variant_name=variant_name,
|
|
|
|
variant_arches=variant_arches,
|
|
|
|
expected_modules=expected_modules,
|
|
|
|
filtered_modules=filtered_modules,
|
|
|
|
)
|
|
|
|
self.assertSetEqual(
|
|
|
|
real_result,
|
|
|
|
expected_result,
|
|
|
|
)
|