2016-04-22 09:15:06 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2022-11-07 21:38:38 +00:00
|
|
|
import ddt
|
2022-11-11 13:32:00 +00:00
|
|
|
from unittest import mock
|
2016-04-22 09:15:06 +00:00
|
|
|
import os
|
2019-10-04 12:45:03 +00:00
|
|
|
import six
|
2020-01-22 10:02:22 +00:00
|
|
|
|
2016-05-25 11:39:02 +00:00
|
|
|
try:
|
|
|
|
import unittest2 as unittest
|
|
|
|
except ImportError:
|
|
|
|
import unittest
|
2016-04-22 09:15:06 +00:00
|
|
|
import json
|
2016-04-26 12:55:46 +00:00
|
|
|
import tempfile
|
2018-01-02 20:06:08 +00:00
|
|
|
import re
|
2018-08-15 07:20:40 +00:00
|
|
|
from dogpile.cache import make_region
|
2016-04-22 09:15:06 +00:00
|
|
|
|
|
|
|
from pungi.phases.pkgset import pkgsets
|
|
|
|
from tests import helpers
|
|
|
|
|
|
|
|
|
|
|
|
class MockPathInfo(object):
|
|
|
|
def __init__(self, topdir):
|
|
|
|
self.topdir = topdir
|
|
|
|
|
|
|
|
def build(self, build_info):
|
|
|
|
return self.topdir
|
|
|
|
|
|
|
|
def get_filename(self, rpm_info):
|
2020-01-22 10:02:22 +00:00
|
|
|
return "{name}@{version}@{release}@{arch}".format(**rpm_info)
|
2016-04-22 09:15:06 +00:00
|
|
|
|
|
|
|
def signed(self, rpm_info, sigkey):
|
2020-01-22 10:02:22 +00:00
|
|
|
return os.path.join("signed", sigkey, self.get_filename(rpm_info))
|
2016-04-22 09:15:06 +00:00
|
|
|
|
|
|
|
def rpm(self, rpm_info):
|
2020-01-22 10:02:22 +00:00
|
|
|
return os.path.join("rpms", self.get_filename(rpm_info))
|
2016-04-22 09:15:06 +00:00
|
|
|
|
2020-06-08 06:00:41 +00:00
|
|
|
def work(self):
|
|
|
|
return "work"
|
|
|
|
|
2016-04-22 09:15:06 +00:00
|
|
|
|
|
|
|
class MockFile(object):
|
|
|
|
def __init__(self, path):
|
2020-01-22 10:02:22 +00:00
|
|
|
if path.startswith("/tmp"):
|
2016-04-22 09:15:06 +00:00
|
|
|
# Drop /tmp/something/ from path
|
2020-01-22 10:02:22 +00:00
|
|
|
path = path.split("/", 3)[-1]
|
2016-04-22 12:05:38 +00:00
|
|
|
self.file_path = path
|
2016-04-22 09:15:06 +00:00
|
|
|
self.file_name = os.path.basename(path)
|
2020-01-22 10:02:22 +00:00
|
|
|
self.name, self.version, self.release, self.arch = self.file_name.split("@")
|
|
|
|
self.sourcerpm = "{0.name}-{0.version}-{0.release}.{0.arch}".format(self)
|
2016-04-22 12:05:38 +00:00
|
|
|
self.exclusivearch = []
|
|
|
|
self.excludearch = []
|
2016-04-22 09:15:06 +00:00
|
|
|
|
|
|
|
def __hash__(self):
|
2016-04-22 12:05:38 +00:00
|
|
|
return hash(self.file_path)
|
2016-04-22 09:15:06 +00:00
|
|
|
|
|
|
|
def __repr__(self):
|
2016-04-22 12:05:38 +00:00
|
|
|
return self.file_path
|
2016-04-22 09:15:06 +00:00
|
|
|
|
|
|
|
def __eq__(self, other):
|
|
|
|
try:
|
2016-04-22 12:05:38 +00:00
|
|
|
return self.file_path == other.file_path
|
2016-04-22 09:15:06 +00:00
|
|
|
except AttributeError:
|
2016-04-22 12:05:38 +00:00
|
|
|
return self.file_path == other
|
2016-04-22 09:15:06 +00:00
|
|
|
|
|
|
|
def __le__(self, other):
|
|
|
|
try:
|
2016-04-22 12:05:38 +00:00
|
|
|
return self.file_path < other.file_path
|
2016-04-22 09:15:06 +00:00
|
|
|
except AttributeError:
|
2016-04-22 12:05:38 +00:00
|
|
|
return self.file_path < other
|
2016-04-22 09:15:06 +00:00
|
|
|
|
2016-05-25 11:27:57 +00:00
|
|
|
def __lt__(self, other):
|
|
|
|
return self <= other and self != other
|
|
|
|
|
|
|
|
def __ge__(self, other):
|
|
|
|
return not (self <= other) or self == other
|
|
|
|
|
|
|
|
def __gt__(self, other):
|
|
|
|
return not (self <= other)
|
|
|
|
|
2016-04-22 09:15:06 +00:00
|
|
|
|
|
|
|
class MockFileCache(dict):
|
|
|
|
"""Mock for kobo.pkgset.FileCache.
|
|
|
|
It gets data from filename and does not touch filesystem.
|
|
|
|
"""
|
2020-01-22 10:02:22 +00:00
|
|
|
|
2016-04-22 09:15:06 +00:00
|
|
|
def __init__(self, _wrapper):
|
|
|
|
super(MockFileCache, self).__init__()
|
2016-04-28 07:05:03 +00:00
|
|
|
self.file_cache = self
|
2016-04-22 09:15:06 +00:00
|
|
|
|
|
|
|
def add(self, file_path):
|
|
|
|
obj = MockFile(file_path)
|
|
|
|
self[file_path] = obj
|
|
|
|
return obj
|
|
|
|
|
|
|
|
|
|
|
|
class FakePool(object):
|
|
|
|
"""This class will be substituted for ReaderPool.
|
|
|
|
It implements the same interface, but uses only the last added worker to
|
|
|
|
process all tasks sequentially.
|
|
|
|
"""
|
2020-01-22 10:02:22 +00:00
|
|
|
|
2016-04-22 09:15:06 +00:00
|
|
|
def __init__(self, package_set, logger=None):
|
|
|
|
self.queue = []
|
|
|
|
self.worker = None
|
|
|
|
self.package_set = package_set
|
|
|
|
|
|
|
|
def log_warning(self, *args, **kwargs):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@property
|
|
|
|
def queue_total(self):
|
|
|
|
return len(self.queue)
|
|
|
|
|
|
|
|
def queue_put(self, item):
|
|
|
|
self.queue.append(item)
|
|
|
|
|
|
|
|
def add(self, worker):
|
|
|
|
self.worker = worker
|
|
|
|
|
|
|
|
def start(self):
|
|
|
|
for i, item in enumerate(self.queue):
|
|
|
|
self.worker.process(item, i)
|
|
|
|
|
|
|
|
def stop(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2016-04-22 12:05:38 +00:00
|
|
|
class PkgsetCompareMixin(object):
|
|
|
|
def assertPkgsetEqual(self, actual, expected):
|
2017-09-05 08:01:21 +00:00
|
|
|
for k, v1 in expected.items():
|
2016-04-22 12:05:38 +00:00
|
|
|
self.assertIn(k, actual)
|
|
|
|
v2 = actual.pop(k)
|
2019-10-04 12:45:03 +00:00
|
|
|
six.assertCountEqual(self, v1, v2)
|
2016-04-22 12:05:38 +00:00
|
|
|
self.assertEqual({}, actual)
|
|
|
|
|
|
|
|
|
2023-07-19 10:16:29 +00:00
|
|
|
class DummySystem(object):
|
|
|
|
def __init__(self):
|
|
|
|
self.methods = ["_listapi", "Dummy", "getRPM", "getRPMChecksums"]
|
|
|
|
|
|
|
|
def listMethods(self):
|
|
|
|
return self.methods
|
|
|
|
|
|
|
|
|
2022-11-07 17:24:39 +00:00
|
|
|
@ddt.ddt
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi.phases.pkgset.pkgsets.ReaderPool", new=FakePool)
|
|
|
|
@mock.patch("kobo.pkgset.FileCache", new=MockFileCache)
|
2016-04-22 12:05:38 +00:00
|
|
|
class TestKojiPkgset(PkgsetCompareMixin, helpers.PungiTestCase):
|
2022-11-07 20:15:16 +00:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls) -> None:
|
|
|
|
|
|
|
|
cls.patcher = mock.patch.object(
|
|
|
|
pkgsets.KojiMockPackageSet,
|
|
|
|
'_is_rpm_signed',
|
|
|
|
return_value=True,
|
|
|
|
)
|
|
|
|
cls.patcher.start()
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def tearDownClass(cls) -> None:
|
|
|
|
cls.patcher.stop()
|
|
|
|
|
2016-04-22 09:15:06 +00:00
|
|
|
def setUp(self):
|
|
|
|
super(TestKojiPkgset, self).setUp()
|
2020-01-22 10:02:22 +00:00
|
|
|
with open(os.path.join(helpers.FIXTURE_DIR, "tagged-rpms.json")) as f:
|
2016-04-22 09:15:06 +00:00
|
|
|
self.tagged_rpms = json.load(f)
|
|
|
|
|
|
|
|
self.path_info = MockPathInfo(self.topdir)
|
2023-07-19 10:16:29 +00:00
|
|
|
self.koji_downloader = helpers.FSKojiDownloader()
|
2016-04-22 09:15:06 +00:00
|
|
|
self.koji_wrapper = mock.Mock()
|
|
|
|
self.koji_wrapper.koji_proxy.listTaggedRPMS.return_value = self.tagged_rpms
|
2023-07-19 10:16:29 +00:00
|
|
|
self.koji_wrapper.koji_proxy.system = DummySystem()
|
2016-04-22 09:15:06 +00:00
|
|
|
self.koji_wrapper.koji_module.pathinfo = self.path_info
|
|
|
|
|
|
|
|
def _touch_files(self, filenames):
|
|
|
|
for filename in filenames:
|
|
|
|
helpers.touch(os.path.join(self.topdir, filename))
|
|
|
|
|
|
|
|
def assertPkgsetEqual(self, actual, expected):
|
2017-09-05 08:01:21 +00:00
|
|
|
for k, v1 in expected.items():
|
2016-04-22 09:15:06 +00:00
|
|
|
self.assertIn(k, actual)
|
|
|
|
v2 = actual.pop(k)
|
2019-10-04 12:45:03 +00:00
|
|
|
six.assertCountEqual(self, v1, v2)
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertEqual({}, actual, msg="Some architectures were missing")
|
2016-04-22 09:15:06 +00:00
|
|
|
|
2022-11-07 17:24:39 +00:00
|
|
|
@ddt.data(
|
|
|
|
pkgsets.KojiMockPackageSet,
|
|
|
|
pkgsets.KojiPackageSet,
|
|
|
|
)
|
|
|
|
def test_all_arches(self, package_set):
|
2020-01-22 10:02:22 +00:00
|
|
|
self._touch_files(
|
|
|
|
[
|
|
|
|
"rpms/pungi@4.1.3@3.fc25@noarch",
|
|
|
|
"rpms/pungi@4.1.3@3.fc25@src",
|
|
|
|
"rpms/bash@4.3.42@4.fc24@i686",
|
|
|
|
"rpms/bash@4.3.42@4.fc24@x86_64",
|
|
|
|
"rpms/bash@4.3.42@4.fc24@src",
|
|
|
|
"rpms/bash-debuginfo@4.3.42@4.fc24@i686",
|
|
|
|
"rpms/bash-debuginfo@4.3.42@4.fc24@x86_64",
|
|
|
|
]
|
|
|
|
)
|
2016-04-22 09:15:06 +00:00
|
|
|
|
2023-07-19 10:16:29 +00:00
|
|
|
pkgset = package_set(
|
|
|
|
"pkgset", self.koji_wrapper, [None], downloader=self.koji_downloader
|
|
|
|
)
|
2016-04-22 09:15:06 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
result = pkgset.populate("f25")
|
2016-04-22 09:15:06 +00:00
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
self.koji_wrapper.koji_proxy.mock_calls,
|
2020-01-22 10:02:22 +00:00
|
|
|
[mock.call.listTaggedRPMS("f25", event=None, inherit=True, latest=True)],
|
|
|
|
)
|
2016-04-22 09:15:06 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertPkgsetEqual(
|
|
|
|
result,
|
|
|
|
{
|
|
|
|
"src": ["rpms/pungi@4.1.3@3.fc25@src", "rpms/bash@4.3.42@4.fc24@src"],
|
|
|
|
"noarch": ["rpms/pungi@4.1.3@3.fc25@noarch"],
|
|
|
|
"i686": [
|
|
|
|
"rpms/bash@4.3.42@4.fc24@i686",
|
|
|
|
"rpms/bash-debuginfo@4.3.42@4.fc24@i686",
|
|
|
|
],
|
|
|
|
"x86_64": [
|
|
|
|
"rpms/bash@4.3.42@4.fc24@x86_64",
|
|
|
|
"rpms/bash-debuginfo@4.3.42@4.fc24@x86_64",
|
|
|
|
],
|
|
|
|
},
|
|
|
|
)
|
2016-04-22 09:15:06 +00:00
|
|
|
|
2022-11-07 17:24:39 +00:00
|
|
|
@ddt.data(
|
|
|
|
pkgsets.KojiPackageSet,
|
|
|
|
pkgsets.KojiMockPackageSet,
|
|
|
|
)
|
|
|
|
def test_only_one_arch(self, package_set):
|
2020-01-22 10:02:22 +00:00
|
|
|
self._touch_files(
|
|
|
|
[
|
|
|
|
"rpms/bash@4.3.42@4.fc24@x86_64",
|
|
|
|
"rpms/bash-debuginfo@4.3.42@4.fc24@x86_64",
|
|
|
|
]
|
|
|
|
)
|
2016-04-22 09:15:06 +00:00
|
|
|
|
2022-11-07 17:24:39 +00:00
|
|
|
pkgset = package_set(
|
2023-07-19 10:16:29 +00:00
|
|
|
"pkgset",
|
|
|
|
self.koji_wrapper,
|
|
|
|
[None],
|
|
|
|
arches=["x86_64"],
|
|
|
|
downloader=self.koji_downloader,
|
2019-07-25 13:35:02 +00:00
|
|
|
)
|
2016-04-22 09:15:06 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
result = pkgset.populate("f25")
|
2016-04-22 09:15:06 +00:00
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
self.koji_wrapper.koji_proxy.mock_calls,
|
2020-01-22 10:02:22 +00:00
|
|
|
[mock.call.listTaggedRPMS("f25", event=None, inherit=True, latest=True)],
|
|
|
|
)
|
2016-04-22 09:15:06 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertPkgsetEqual(
|
|
|
|
result,
|
|
|
|
{
|
|
|
|
"x86_64": [
|
|
|
|
"rpms/bash-debuginfo@4.3.42@4.fc24@x86_64",
|
|
|
|
"rpms/bash@4.3.42@4.fc24@x86_64",
|
|
|
|
]
|
|
|
|
},
|
|
|
|
)
|
2016-04-22 09:15:06 +00:00
|
|
|
|
|
|
|
def test_find_signed_with_preference(self):
|
2020-01-22 10:02:22 +00:00
|
|
|
self._touch_files(
|
|
|
|
[
|
|
|
|
"signed/cafebabe/bash@4.3.42@4.fc24@x86_64",
|
|
|
|
"signed/deadbeef/bash@4.3.42@4.fc24@x86_64",
|
|
|
|
"signed/deadbeef/bash-debuginfo@4.3.42@4.fc24@x86_64",
|
|
|
|
]
|
|
|
|
)
|
2016-04-22 09:15:06 +00:00
|
|
|
|
2019-07-25 13:35:02 +00:00
|
|
|
pkgset = pkgsets.KojiPackageSet(
|
2023-07-19 10:16:29 +00:00
|
|
|
"pkgset",
|
|
|
|
self.koji_wrapper,
|
|
|
|
["cafebabe", "deadbeef"],
|
|
|
|
arches=["x86_64"],
|
|
|
|
downloader=self.koji_downloader,
|
2019-07-25 13:35:02 +00:00
|
|
|
)
|
2016-04-22 09:15:06 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
result = pkgset.populate("f25")
|
2016-04-22 09:15:06 +00:00
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
self.koji_wrapper.koji_proxy.mock_calls,
|
2020-01-22 10:02:22 +00:00
|
|
|
[mock.call.listTaggedRPMS("f25", event=None, inherit=True, latest=True)],
|
|
|
|
)
|
2016-04-22 09:15:06 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertPkgsetEqual(
|
|
|
|
result,
|
|
|
|
{
|
|
|
|
"x86_64": [
|
|
|
|
"signed/cafebabe/bash@4.3.42@4.fc24@x86_64",
|
|
|
|
"signed/deadbeef/bash-debuginfo@4.3.42@4.fc24@x86_64",
|
|
|
|
]
|
|
|
|
},
|
|
|
|
)
|
2016-04-22 09:15:06 +00:00
|
|
|
|
|
|
|
def test_find_signed_fallback_unsigned(self):
|
2020-01-22 10:02:22 +00:00
|
|
|
self._touch_files(
|
|
|
|
[
|
|
|
|
"signed/cafebabe/bash@4.3.42@4.fc24@x86_64",
|
|
|
|
"rpms/bash-debuginfo@4.3.42@4.fc24@x86_64",
|
|
|
|
]
|
|
|
|
)
|
2016-04-22 09:15:06 +00:00
|
|
|
|
2019-07-25 13:35:02 +00:00
|
|
|
pkgset = pkgsets.KojiPackageSet(
|
2023-07-19 10:16:29 +00:00
|
|
|
"pkgset",
|
|
|
|
self.koji_wrapper,
|
|
|
|
["cafebabe", None],
|
|
|
|
arches=["x86_64"],
|
|
|
|
downloader=self.koji_downloader,
|
2019-07-25 13:35:02 +00:00
|
|
|
)
|
2016-04-22 09:15:06 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
result = pkgset.populate("f25")
|
2016-04-22 09:15:06 +00:00
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
self.koji_wrapper.koji_proxy.mock_calls,
|
2020-01-22 10:02:22 +00:00
|
|
|
[mock.call.listTaggedRPMS("f25", event=None, inherit=True, latest=True)],
|
|
|
|
)
|
2016-04-22 09:15:06 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertPkgsetEqual(
|
|
|
|
result,
|
|
|
|
{
|
|
|
|
"x86_64": [
|
|
|
|
"rpms/bash-debuginfo@4.3.42@4.fc24@x86_64",
|
|
|
|
"signed/cafebabe/bash@4.3.42@4.fc24@x86_64",
|
|
|
|
]
|
|
|
|
},
|
|
|
|
)
|
2016-04-22 09:15:06 +00:00
|
|
|
|
2016-04-26 12:41:39 +00:00
|
|
|
def test_can_not_find_signed_package(self):
|
2019-07-25 13:35:02 +00:00
|
|
|
pkgset = pkgsets.KojiPackageSet(
|
2023-07-19 10:16:29 +00:00
|
|
|
"pkgset",
|
|
|
|
self.koji_wrapper,
|
|
|
|
["cafebabe"],
|
|
|
|
arches=["x86_64"],
|
|
|
|
downloader=self.koji_downloader,
|
2019-07-25 13:35:02 +00:00
|
|
|
)
|
2016-04-26 12:41:39 +00:00
|
|
|
|
|
|
|
with self.assertRaises(RuntimeError) as ctx:
|
2020-01-22 10:02:22 +00:00
|
|
|
pkgset.populate("f25")
|
2016-04-26 12:41:39 +00:00
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
self.koji_wrapper.koji_proxy.mock_calls,
|
2020-01-22 10:02:22 +00:00
|
|
|
[mock.call.listTaggedRPMS("f25", event=None, inherit=True, latest=True)],
|
|
|
|
)
|
2016-04-26 12:41:39 +00:00
|
|
|
|
2018-01-02 20:06:08 +00:00
|
|
|
figure = re.compile(
|
2023-03-30 11:05:47 +00:00
|
|
|
r"^RPM\(s\) not found for sigs: .+Check log for details.+bash-4\.3\.42-4\.fc24\.x86_64.+bash-debuginfo-4\.3\.42-4\.fc24\.x86_64$", # noqa: E501
|
2020-01-22 10:02:22 +00:00
|
|
|
re.DOTALL,
|
|
|
|
)
|
2020-07-28 01:23:53 +00:00
|
|
|
self.assertRegex(str(ctx.exception), figure)
|
2016-04-26 12:41:39 +00:00
|
|
|
|
2021-02-11 14:22:18 +00:00
|
|
|
@mock.patch("os.path.isfile")
|
|
|
|
@mock.patch("time.sleep")
|
2022-11-08 10:47:14 +00:00
|
|
|
def test_find_signed_after_wait(self, sleep, isfile):
|
2021-02-11 14:22:18 +00:00
|
|
|
checked_files = set()
|
|
|
|
|
|
|
|
def check_file(path):
|
|
|
|
"""First check for any path will fail, second and further will succeed."""
|
|
|
|
if path in checked_files:
|
|
|
|
return True
|
|
|
|
checked_files.add(path)
|
|
|
|
return False
|
|
|
|
|
|
|
|
isfile.side_effect = check_file
|
|
|
|
|
|
|
|
fst_key, snd_key = ["cafebabe", "deadbeef"]
|
2022-11-08 10:47:14 +00:00
|
|
|
pkgset = pkgsets.KojiPackageSet(
|
2021-02-11 14:22:18 +00:00
|
|
|
"pkgset",
|
|
|
|
self.koji_wrapper,
|
|
|
|
[fst_key, snd_key],
|
|
|
|
arches=["x86_64"],
|
2021-02-23 12:52:15 +00:00
|
|
|
signed_packages_retries=2,
|
2021-02-11 14:22:18 +00:00
|
|
|
signed_packages_wait=5,
|
2023-07-19 10:16:29 +00:00
|
|
|
downloader=self.koji_downloader,
|
2021-02-11 14:22:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
result = pkgset.populate("f25")
|
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
self.koji_wrapper.koji_proxy.mock_calls,
|
|
|
|
[mock.call.listTaggedRPMS("f25", event=None, inherit=True, latest=True)],
|
|
|
|
)
|
|
|
|
|
|
|
|
fst_pkg = "signed/%s/bash-debuginfo@4.3.42@4.fc24@x86_64"
|
|
|
|
snd_pkg = "signed/%s/bash@4.3.42@4.fc24@x86_64"
|
|
|
|
|
|
|
|
self.assertPkgsetEqual(
|
|
|
|
result, {"x86_64": [fst_pkg % "cafebabe", snd_pkg % "cafebabe"]}
|
|
|
|
)
|
|
|
|
# Wait once for each of the two packages
|
|
|
|
self.assertEqual(sleep.call_args_list, [mock.call(5)] * 2)
|
|
|
|
# Each file will be checked three times
|
|
|
|
self.assertEqual(
|
|
|
|
isfile.call_args_list,
|
|
|
|
[
|
|
|
|
mock.call(os.path.join(self.topdir, fst_pkg % fst_key)),
|
|
|
|
mock.call(os.path.join(self.topdir, fst_pkg % snd_key)),
|
|
|
|
mock.call(os.path.join(self.topdir, fst_pkg % fst_key)),
|
|
|
|
mock.call(os.path.join(self.topdir, snd_pkg % fst_key)),
|
|
|
|
mock.call(os.path.join(self.topdir, snd_pkg % snd_key)),
|
|
|
|
mock.call(os.path.join(self.topdir, snd_pkg % fst_key)),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
2018-02-12 07:02:45 +00:00
|
|
|
def test_can_not_find_signed_package_allow_invalid_sigkeys(self):
|
2019-07-25 13:35:02 +00:00
|
|
|
pkgset = pkgsets.KojiPackageSet(
|
|
|
|
"pkgset",
|
|
|
|
self.koji_wrapper,
|
2020-01-22 10:02:22 +00:00
|
|
|
["cafebabe"],
|
|
|
|
arches=["x86_64"],
|
2019-07-25 13:35:02 +00:00
|
|
|
allow_invalid_sigkeys=True,
|
2023-07-19 10:16:29 +00:00
|
|
|
downloader=self.koji_downloader,
|
2019-07-25 13:35:02 +00:00
|
|
|
)
|
2018-02-12 07:02:45 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
pkgset.populate("f25")
|
2018-02-12 07:02:45 +00:00
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
self.koji_wrapper.koji_proxy.mock_calls,
|
2020-01-22 10:02:22 +00:00
|
|
|
[mock.call.listTaggedRPMS("f25", event=None, inherit=True, latest=True)],
|
|
|
|
)
|
2018-02-12 07:02:45 +00:00
|
|
|
|
|
|
|
with self.assertRaises(RuntimeError) as ctx:
|
2018-02-12 12:21:07 +00:00
|
|
|
pkgset.raise_invalid_sigkeys_exception(pkgset.invalid_sigkey_rpms)
|
2018-02-12 07:02:45 +00:00
|
|
|
|
|
|
|
figure = re.compile(
|
2023-03-30 11:05:47 +00:00
|
|
|
r"^RPM\(s\) not found for sigs: .+Check log for details.+bash-4\.3\.42-4\.fc24\.x86_64.+bash-debuginfo-4\.3\.42-4\.fc24\.x86_64$", # noqa: E501
|
2020-01-22 10:02:22 +00:00
|
|
|
re.DOTALL,
|
|
|
|
)
|
2020-07-28 01:23:53 +00:00
|
|
|
self.assertRegex(str(ctx.exception), figure)
|
2018-02-12 07:02:45 +00:00
|
|
|
|
2016-04-26 12:41:39 +00:00
|
|
|
def test_can_not_find_any_package(self):
|
2019-07-25 13:35:02 +00:00
|
|
|
pkgset = pkgsets.KojiPackageSet(
|
2023-07-19 10:16:29 +00:00
|
|
|
"pkgset",
|
|
|
|
self.koji_wrapper,
|
|
|
|
["cafebabe", None],
|
|
|
|
arches=["x86_64"],
|
|
|
|
downloader=self.koji_downloader,
|
2019-07-25 13:35:02 +00:00
|
|
|
)
|
2016-04-26 12:41:39 +00:00
|
|
|
|
|
|
|
with self.assertRaises(RuntimeError) as ctx:
|
2020-01-22 10:02:22 +00:00
|
|
|
pkgset.populate("f25")
|
2016-04-26 12:41:39 +00:00
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
self.koji_wrapper.koji_proxy.mock_calls,
|
2020-01-22 10:02:22 +00:00
|
|
|
[mock.call.listTaggedRPMS("f25", event=None, inherit=True, latest=True)],
|
|
|
|
)
|
2016-04-26 12:41:39 +00:00
|
|
|
|
2020-07-28 01:23:53 +00:00
|
|
|
self.assertRegex(
|
2017-10-30 08:16:18 +00:00
|
|
|
str(ctx.exception),
|
2020-01-22 10:02:22 +00:00
|
|
|
r"^RPM\(s\) not found for sigs: .+Check log for details.+",
|
|
|
|
)
|
2016-04-26 12:41:39 +00:00
|
|
|
|
2021-02-11 14:22:18 +00:00
|
|
|
@mock.patch("time.sleep")
|
2022-11-08 10:47:14 +00:00
|
|
|
def test_can_not_find_signed_package_with_retries(self, time):
|
|
|
|
pkgset = pkgsets.KojiPackageSet(
|
2021-02-11 14:22:18 +00:00
|
|
|
"pkgset",
|
|
|
|
self.koji_wrapper,
|
|
|
|
["cafebabe"],
|
|
|
|
arches=["x86_64"],
|
2021-02-23 12:52:15 +00:00
|
|
|
signed_packages_retries=2,
|
2021-02-11 14:22:18 +00:00
|
|
|
signed_packages_wait=5,
|
2023-07-19 10:16:29 +00:00
|
|
|
downloader=self.koji_downloader,
|
2021-02-11 14:22:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
with self.assertRaises(RuntimeError) as ctx:
|
|
|
|
pkgset.populate("f25")
|
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
self.koji_wrapper.koji_proxy.mock_calls,
|
|
|
|
[mock.call.listTaggedRPMS("f25", event=None, inherit=True, latest=True)],
|
|
|
|
)
|
|
|
|
|
|
|
|
self.assertRegex(
|
|
|
|
str(ctx.exception),
|
|
|
|
r"^RPM\(s\) not found for sigs: .+Check log for details.+",
|
|
|
|
)
|
|
|
|
# Two packages making three attempts each, so two waits per package.
|
|
|
|
self.assertEqual(time.call_args_list, [mock.call(5)] * 4)
|
|
|
|
|
2022-11-07 17:24:39 +00:00
|
|
|
@ddt.data(
|
|
|
|
pkgsets.KojiPackageSet,
|
|
|
|
pkgsets.KojiMockPackageSet,
|
|
|
|
)
|
|
|
|
def test_packages_attribute(self, package_set):
|
2020-01-22 10:02:22 +00:00
|
|
|
self._touch_files(
|
|
|
|
[
|
|
|
|
"rpms/pungi@4.1.3@3.fc25@noarch",
|
|
|
|
"rpms/pungi@4.1.3@3.fc25@src",
|
|
|
|
"rpms/bash@4.3.42@4.fc24@i686",
|
|
|
|
"rpms/bash@4.3.42@4.fc24@x86_64",
|
|
|
|
"rpms/bash@4.3.42@4.fc24@src",
|
|
|
|
"rpms/bash-debuginfo@4.3.42@4.fc24@i686",
|
|
|
|
"rpms/bash-debuginfo@4.3.42@4.fc24@x86_64",
|
|
|
|
]
|
|
|
|
)
|
2017-10-16 12:20:37 +00:00
|
|
|
|
2022-11-07 17:24:39 +00:00
|
|
|
pkgset = package_set(
|
2019-07-25 13:35:02 +00:00
|
|
|
"pkgset",
|
|
|
|
self.koji_wrapper,
|
|
|
|
[None],
|
|
|
|
packages=["bash"],
|
|
|
|
populate_only_packages=True,
|
2023-07-19 10:16:29 +00:00
|
|
|
downloader=self.koji_downloader,
|
2019-07-25 13:35:02 +00:00
|
|
|
)
|
2017-10-16 12:20:37 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
result = pkgset.populate("f25")
|
2017-10-16 12:20:37 +00:00
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
self.koji_wrapper.koji_proxy.mock_calls,
|
2020-01-22 10:02:22 +00:00
|
|
|
[mock.call.listTaggedRPMS("f25", event=None, inherit=True, latest=True)],
|
|
|
|
)
|
2017-10-16 12:20:37 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertPkgsetEqual(
|
|
|
|
result,
|
|
|
|
{
|
|
|
|
"src": ["rpms/bash@4.3.42@4.fc24@src"],
|
|
|
|
"i686": ["rpms/bash@4.3.42@4.fc24@i686"],
|
|
|
|
"x86_64": ["rpms/bash@4.3.42@4.fc24@x86_64"],
|
|
|
|
},
|
|
|
|
)
|
2017-10-16 12:20:37 +00:00
|
|
|
|
2022-11-07 17:24:39 +00:00
|
|
|
@ddt.data(
|
|
|
|
pkgsets.KojiPackageSet,
|
|
|
|
pkgsets.KojiMockPackageSet,
|
|
|
|
)
|
|
|
|
def test_get_extra_rpms_from_tasks(self, package_set):
|
|
|
|
pkgset = package_set(
|
2020-06-08 06:00:41 +00:00
|
|
|
"pkgset",
|
|
|
|
self.koji_wrapper,
|
|
|
|
[None],
|
|
|
|
arches=["x86_64"],
|
|
|
|
extra_tasks=["123", "456"],
|
|
|
|
)
|
|
|
|
children_tasks = [[{"id": 1}, {"id": 2}], [{"id": 3}, {"id": 4}]]
|
|
|
|
task_results = [
|
|
|
|
{
|
|
|
|
"logs": [
|
|
|
|
"tasks/root.log",
|
|
|
|
"tasks/hw_info.log",
|
|
|
|
"tasks/state.log",
|
|
|
|
"tasks/build.log",
|
|
|
|
"tasks/mock_output.log",
|
|
|
|
"tasks/noarch_rpmdiff.json",
|
|
|
|
],
|
|
|
|
"rpms": ["tasks/pungi-4.1.39-5.f30.noarch.rpm"],
|
|
|
|
"srpms": ["tasks/pungi-4.1.39-5.f30.src.rpm"],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"logs": [
|
|
|
|
"tasks/5478/29155478/root.log",
|
|
|
|
"tasks/5478/29155478/hw_info.log",
|
|
|
|
"tasks/5478/29155478/state.log",
|
|
|
|
"tasks/5478/29155478/build.log",
|
|
|
|
],
|
|
|
|
"source": {
|
|
|
|
"source": "pungi-4.1.39-5.f30.src.rpm",
|
|
|
|
"url": "pungi-4.1.39-5.f30.src.rpm",
|
|
|
|
},
|
|
|
|
"srpm": "tasks/5478/29155478/pungi-4.1.39-5.f30.src.rpm",
|
|
|
|
},
|
|
|
|
]
|
|
|
|
self.koji_wrapper.retrying_multicall_map.side_effect = [
|
|
|
|
children_tasks,
|
|
|
|
task_results,
|
|
|
|
]
|
|
|
|
|
|
|
|
expected_rpms = [
|
|
|
|
{
|
|
|
|
"arch": "noarch",
|
|
|
|
"build_id": None,
|
|
|
|
"epoch": "",
|
|
|
|
"name": "pungi",
|
|
|
|
"path_from_task": "work/tasks/pungi-4.1.39-5.f30.noarch.rpm",
|
|
|
|
"release": "5.f30",
|
|
|
|
"src": False,
|
|
|
|
"version": "4.1.39",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"arch": "src",
|
|
|
|
"build_id": None,
|
|
|
|
"epoch": "",
|
|
|
|
"name": "pungi",
|
|
|
|
"path_from_task": "work/tasks/pungi-4.1.39-5.f30.src.rpm",
|
|
|
|
"release": "5.f30",
|
|
|
|
"src": True,
|
|
|
|
"version": "4.1.39",
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
|
|
|
rpms = pkgset.get_extra_rpms_from_tasks()
|
|
|
|
self.assertEqual(rpms, expected_rpms)
|
|
|
|
|
2022-11-07 17:24:39 +00:00
|
|
|
@ddt.data(
|
|
|
|
pkgsets.KojiMockPackageSet,
|
|
|
|
pkgsets.KojiPackageSet,
|
|
|
|
)
|
|
|
|
def test_get_latest_rpms_cache(self, package_set):
|
2020-01-22 10:02:22 +00:00
|
|
|
self._touch_files(
|
|
|
|
[
|
|
|
|
"rpms/bash@4.3.42@4.fc24@x86_64",
|
|
|
|
"rpms/bash-debuginfo@4.3.42@4.fc24@x86_64",
|
|
|
|
]
|
|
|
|
)
|
2018-08-15 07:20:40 +00:00
|
|
|
|
|
|
|
cache_region = make_region().configure("dogpile.cache.memory")
|
2022-11-07 17:24:39 +00:00
|
|
|
pkgset = package_set(
|
2019-07-25 13:35:02 +00:00
|
|
|
"pkgset",
|
|
|
|
self.koji_wrapper,
|
|
|
|
[None],
|
2020-01-22 10:02:22 +00:00
|
|
|
arches=["x86_64"],
|
2019-07-25 13:35:02 +00:00
|
|
|
cache_region=cache_region,
|
2023-07-19 10:16:29 +00:00
|
|
|
downloader=self.koji_downloader,
|
2019-07-25 13:35:02 +00:00
|
|
|
)
|
2018-08-15 07:20:40 +00:00
|
|
|
|
|
|
|
# Try calling the populate twice, but expect just single listTaggedRPMs
|
|
|
|
# call - that means the caching worked.
|
|
|
|
for i in range(2):
|
2020-01-22 10:02:22 +00:00
|
|
|
result = pkgset.populate("f25")
|
2018-08-15 07:20:40 +00:00
|
|
|
self.assertEqual(
|
|
|
|
self.koji_wrapper.koji_proxy.mock_calls,
|
2020-01-22 10:02:22 +00:00
|
|
|
[
|
|
|
|
mock.call.listTaggedRPMS(
|
|
|
|
"f25", event=None, inherit=True, latest=True
|
|
|
|
)
|
|
|
|
],
|
|
|
|
)
|
2018-08-15 07:20:40 +00:00
|
|
|
self.assertPkgsetEqual(
|
|
|
|
result,
|
2020-01-22 10:02:22 +00:00
|
|
|
{
|
|
|
|
"x86_64": [
|
|
|
|
"rpms/bash-debuginfo@4.3.42@4.fc24@x86_64",
|
|
|
|
"rpms/bash@4.3.42@4.fc24@x86_64",
|
|
|
|
]
|
|
|
|
},
|
|
|
|
)
|
2018-08-15 07:20:40 +00:00
|
|
|
|
2022-11-07 17:24:39 +00:00
|
|
|
@ddt.data(
|
|
|
|
pkgsets.KojiMockPackageSet,
|
|
|
|
pkgsets.KojiPackageSet,
|
|
|
|
)
|
|
|
|
def test_get_latest_rpms_cache_different_id(self, package_set):
|
2020-01-22 10:02:22 +00:00
|
|
|
self._touch_files(
|
|
|
|
[
|
|
|
|
"rpms/bash@4.3.42@4.fc24@x86_64",
|
|
|
|
"rpms/bash-debuginfo@4.3.42@4.fc24@x86_64",
|
|
|
|
]
|
|
|
|
)
|
2018-08-15 07:20:40 +00:00
|
|
|
|
|
|
|
cache_region = make_region().configure("dogpile.cache.memory")
|
2022-11-07 17:24:39 +00:00
|
|
|
pkgset = package_set(
|
2019-07-25 13:35:02 +00:00
|
|
|
"pkgset",
|
|
|
|
self.koji_wrapper,
|
|
|
|
[None],
|
2020-01-22 10:02:22 +00:00
|
|
|
arches=["x86_64"],
|
2019-07-25 13:35:02 +00:00
|
|
|
cache_region=cache_region,
|
2023-07-19 10:16:29 +00:00
|
|
|
downloader=self.koji_downloader,
|
2019-07-25 13:35:02 +00:00
|
|
|
)
|
2018-08-15 07:20:40 +00:00
|
|
|
|
|
|
|
# Try calling the populate twice with different event id. It must not
|
|
|
|
# cache anything.
|
|
|
|
expected_calls = []
|
|
|
|
for i in range(2):
|
|
|
|
expected_calls.append(
|
2020-01-22 10:02:22 +00:00
|
|
|
mock.call.listTaggedRPMS("f25", event=i, inherit=True, latest=True)
|
|
|
|
)
|
|
|
|
result = pkgset.populate("f25", event={"id": i})
|
|
|
|
self.assertEqual(self.koji_wrapper.koji_proxy.mock_calls, expected_calls)
|
2018-08-15 07:20:40 +00:00
|
|
|
self.assertPkgsetEqual(
|
|
|
|
result,
|
2020-01-22 10:02:22 +00:00
|
|
|
{
|
|
|
|
"x86_64": [
|
|
|
|
"rpms/bash-debuginfo@4.3.42@4.fc24@x86_64",
|
|
|
|
"rpms/bash@4.3.42@4.fc24@x86_64",
|
|
|
|
]
|
|
|
|
},
|
|
|
|
)
|
2016-04-22 09:15:06 +00:00
|
|
|
|
2022-11-07 17:24:39 +00:00
|
|
|
@ddt.data(
|
|
|
|
pkgsets.KojiMockPackageSet,
|
|
|
|
pkgsets.KojiPackageSet,
|
|
|
|
)
|
|
|
|
def test_extra_builds_attribute(self, package_set):
|
2020-01-22 10:02:22 +00:00
|
|
|
self._touch_files(
|
|
|
|
[
|
|
|
|
"rpms/pungi@4.1.3@3.fc25@noarch",
|
|
|
|
"rpms/pungi@4.1.3@3.fc25@src",
|
|
|
|
"rpms/bash@4.3.42@4.fc24@i686",
|
|
|
|
"rpms/bash@4.3.42@4.fc24@x86_64",
|
|
|
|
"rpms/bash@4.3.42@4.fc24@src",
|
|
|
|
"rpms/bash-debuginfo@4.3.42@4.fc24@i686",
|
|
|
|
"rpms/bash-debuginfo@4.3.42@4.fc24@x86_64",
|
|
|
|
]
|
|
|
|
)
|
2018-09-14 08:59:53 +00:00
|
|
|
|
|
|
|
# Return "pungi" RPMs and builds using "get_latest_rpms" which gets
|
|
|
|
# them from Koji multiCall.
|
2020-01-22 10:02:22 +00:00
|
|
|
extra_rpms = [rpm for rpm in self.tagged_rpms[0] if rpm["name"] == "pungi"]
|
|
|
|
extra_builds = [
|
|
|
|
build for build in self.tagged_rpms[1] if build["package_name"] == "pungi"
|
|
|
|
]
|
2018-09-14 08:59:53 +00:00
|
|
|
self.koji_wrapper.retrying_multicall_map.side_effect = [
|
2020-01-22 10:02:22 +00:00
|
|
|
extra_builds,
|
|
|
|
[extra_rpms],
|
|
|
|
]
|
2018-09-14 08:59:53 +00:00
|
|
|
|
|
|
|
# Do not return "pungi" RPMs and builds using the listTaggedRPMs, so
|
|
|
|
# we can be sure "pungi" gets into compose using the `extra_builds`.
|
|
|
|
self.koji_wrapper.koji_proxy.listTaggedRPMS.return_value = [
|
|
|
|
[rpm for rpm in self.tagged_rpms[0] if rpm["name"] != "pungi"],
|
2020-01-22 10:02:22 +00:00
|
|
|
[b for b in self.tagged_rpms[1] if b["package_name"] != "pungi"],
|
|
|
|
]
|
2018-09-14 08:59:53 +00:00
|
|
|
|
2022-11-07 17:24:39 +00:00
|
|
|
pkgset = package_set(
|
2023-07-19 10:16:29 +00:00
|
|
|
"pkgset",
|
|
|
|
self.koji_wrapper,
|
|
|
|
[None],
|
|
|
|
extra_builds=["pungi-4.1.3-3.fc25"],
|
|
|
|
downloader=self.koji_downloader,
|
2019-07-25 13:35:02 +00:00
|
|
|
)
|
2018-09-14 08:59:53 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
result = pkgset.populate("f25")
|
2018-09-14 08:59:53 +00:00
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
self.koji_wrapper.koji_proxy.mock_calls,
|
2020-01-22 10:02:22 +00:00
|
|
|
[mock.call.listTaggedRPMS("f25", event=None, inherit=True, latest=True)],
|
|
|
|
)
|
2018-09-14 08:59:53 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertPkgsetEqual(
|
|
|
|
result,
|
|
|
|
{
|
|
|
|
"src": ["rpms/pungi@4.1.3@3.fc25@src", "rpms/bash@4.3.42@4.fc24@src"],
|
|
|
|
"noarch": ["rpms/pungi@4.1.3@3.fc25@noarch"],
|
|
|
|
"i686": [
|
|
|
|
"rpms/bash@4.3.42@4.fc24@i686",
|
|
|
|
"rpms/bash-debuginfo@4.3.42@4.fc24@i686",
|
|
|
|
],
|
|
|
|
"x86_64": [
|
|
|
|
"rpms/bash@4.3.42@4.fc24@x86_64",
|
|
|
|
"rpms/bash-debuginfo@4.3.42@4.fc24@x86_64",
|
|
|
|
],
|
|
|
|
},
|
|
|
|
)
|
2018-09-14 08:59:53 +00:00
|
|
|
|
|
|
|
|
2020-02-25 03:02:39 +00:00
|
|
|
class TestReuseKojiPkgset(helpers.PungiTestCase):
|
|
|
|
def setUp(self):
|
|
|
|
super(TestReuseKojiPkgset, self).setUp()
|
|
|
|
self.old_compose_dir = tempfile.mkdtemp()
|
|
|
|
self.old_compose = helpers.DummyCompose(self.old_compose_dir, {})
|
|
|
|
self.compose = helpers.DummyCompose(
|
|
|
|
self.topdir, {"old_composes": os.path.dirname(self.old_compose_dir)}
|
|
|
|
)
|
|
|
|
|
|
|
|
self.koji_wrapper = mock.Mock()
|
|
|
|
|
|
|
|
self.tag = "test-tag"
|
|
|
|
self.inherited_tag = "inherited-test-tag"
|
|
|
|
self.pkgset = pkgsets.KojiPackageSet(
|
|
|
|
self.tag, self.koji_wrapper, [None], arches=["x86_64"]
|
|
|
|
)
|
|
|
|
self.pkgset.log_debug = mock.Mock()
|
|
|
|
self.pkgset.log_info = mock.Mock()
|
|
|
|
|
|
|
|
def assert_not_reuse(self):
|
|
|
|
self.assertIsNone(getattr(self.pkgset, "reuse", None))
|
|
|
|
|
|
|
|
def test_resue_no_old_compose_found(self):
|
|
|
|
self.pkgset.try_to_reuse(self.compose, self.tag)
|
|
|
|
self.pkgset.log_info.assert_called_once_with(
|
|
|
|
"Trying to reuse pkgset data of old compose"
|
|
|
|
)
|
|
|
|
self.pkgset.log_debug.assert_called_once_with(
|
|
|
|
"No old compose found. Nothing to reuse."
|
|
|
|
)
|
|
|
|
self.assert_not_reuse()
|
|
|
|
|
|
|
|
@mock.patch.object(helpers.paths.Paths, "get_old_compose_topdir")
|
|
|
|
def test_reuse_read_koji_event_file_failed(self, mock_old_topdir):
|
|
|
|
mock_old_topdir.return_value = self.old_compose_dir
|
|
|
|
self.pkgset._get_koji_event_from_file = mock.Mock(
|
|
|
|
side_effect=Exception("unknown error")
|
|
|
|
)
|
2022-11-07 17:24:39 +00:00
|
|
|
self.pkgset.try_to_reuse(self.compose, self.tag)
|
|
|
|
self.pkgset.log_debug.assert_called_once_with(
|
|
|
|
"Can't read koji event from file: unknown error"
|
|
|
|
)
|
|
|
|
self.assert_not_reuse()
|
|
|
|
|
|
|
|
@mock.patch.object(helpers.paths.Paths, "get_old_compose_topdir")
|
|
|
|
def test_reuse_build_under_tag_changed(self, mock_old_topdir):
|
|
|
|
mock_old_topdir.return_value = self.old_compose_dir
|
|
|
|
self.pkgset._get_koji_event_from_file = mock.Mock(side_effect=[3, 1])
|
|
|
|
self.koji_wrapper.koji_proxy.queryHistory.return_value = {"tag_listing": [{}]}
|
|
|
|
|
|
|
|
self.pkgset.try_to_reuse(self.compose, self.tag)
|
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
self.pkgset.log_debug.mock_calls,
|
|
|
|
[
|
|
|
|
mock.call(
|
|
|
|
"Koji event doesn't match, querying changes between event 1 and 3"
|
|
|
|
),
|
|
|
|
mock.call("Builds under tag %s changed. Can't reuse." % self.tag),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
self.assert_not_reuse()
|
|
|
|
|
|
|
|
@mock.patch.object(helpers.paths.Paths, "get_old_compose_topdir")
|
|
|
|
def test_reuse_build_under_inherited_tag_changed(self, mock_old_topdir):
|
|
|
|
mock_old_topdir.return_value = self.old_compose_dir
|
|
|
|
self.pkgset._get_koji_event_from_file = mock.Mock(side_effect=[3, 1])
|
|
|
|
self.koji_wrapper.koji_proxy.queryHistory.side_effect = [
|
2022-11-08 10:47:14 +00:00
|
|
|
{"tag_listing": [], "tag_inheritance": []},
|
|
|
|
{"tag_listing": [{}], "tag_inheritance": []},
|
2022-11-07 17:24:39 +00:00
|
|
|
]
|
|
|
|
self.koji_wrapper.koji_proxy.getFullInheritance.return_value = [
|
|
|
|
{"name": self.inherited_tag}
|
|
|
|
]
|
|
|
|
|
|
|
|
self.pkgset.try_to_reuse(self.compose, self.tag)
|
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
self.pkgset.log_debug.mock_calls,
|
|
|
|
[
|
|
|
|
mock.call(
|
|
|
|
"Koji event doesn't match, querying changes between event 1 and 3"
|
|
|
|
),
|
|
|
|
mock.call(
|
|
|
|
"Builds under inherited tag %s changed. Can't reuse."
|
|
|
|
% self.inherited_tag
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
self.assert_not_reuse()
|
|
|
|
|
|
|
|
@mock.patch("pungi.paths.os.path.exists", return_value=True)
|
|
|
|
@mock.patch.object(helpers.paths.Paths, "get_old_compose_topdir")
|
|
|
|
def test_reuse_failed_load_reuse_file(self, mock_old_topdir, mock_exists):
|
|
|
|
mock_old_topdir.return_value = self.old_compose_dir
|
|
|
|
self.pkgset._get_koji_event_from_file = mock.Mock(side_effect=[3, 1])
|
2022-11-08 10:47:14 +00:00
|
|
|
self.koji_wrapper.koji_proxy.queryHistory.return_value = {
|
|
|
|
"tag_listing": [], "tag_inheritance": []
|
|
|
|
}
|
2022-11-07 17:24:39 +00:00
|
|
|
self.koji_wrapper.koji_proxy.getFullInheritance.return_value = []
|
|
|
|
self.pkgset.load_old_file_cache = mock.Mock(
|
|
|
|
side_effect=Exception("unknown error")
|
|
|
|
)
|
|
|
|
|
|
|
|
self.pkgset.try_to_reuse(self.compose, self.tag)
|
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
self.pkgset.log_debug.mock_calls,
|
|
|
|
[
|
|
|
|
mock.call(
|
|
|
|
"Koji event doesn't match, querying changes between event 1 and 3"
|
|
|
|
),
|
|
|
|
mock.call(
|
|
|
|
"Loading reuse file: %s"
|
|
|
|
% os.path.join(
|
|
|
|
self.old_compose_dir,
|
|
|
|
"work/global",
|
|
|
|
"pkgset_%s_reuse.pickle" % self.tag,
|
|
|
|
)
|
|
|
|
),
|
|
|
|
mock.call("Failed to load reuse file: unknown error"),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
self.assert_not_reuse()
|
|
|
|
|
|
|
|
@mock.patch("pungi.paths.os.path.exists", return_value=True)
|
|
|
|
@mock.patch.object(helpers.paths.Paths, "get_old_compose_topdir")
|
|
|
|
def test_reuse_criteria_not_match(self, mock_old_topdir, mock_exists):
|
|
|
|
mock_old_topdir.return_value = self.old_compose_dir
|
|
|
|
self.pkgset._get_koji_event_from_file = mock.Mock(side_effect=[3, 1])
|
2022-11-08 10:47:14 +00:00
|
|
|
self.koji_wrapper.koji_proxy.queryHistory.return_value = {
|
|
|
|
"tag_listing": [], "tag_inheritance": []
|
|
|
|
}
|
2022-11-07 17:24:39 +00:00
|
|
|
self.koji_wrapper.koji_proxy.getFullInheritance.return_value = []
|
|
|
|
self.pkgset.load_old_file_cache = mock.Mock(
|
|
|
|
return_value={"allow_invalid_sigkeys": True}
|
|
|
|
)
|
|
|
|
|
|
|
|
self.pkgset.try_to_reuse(self.compose, self.tag)
|
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
self.pkgset.log_debug.mock_calls,
|
|
|
|
[
|
|
|
|
mock.call(
|
|
|
|
"Koji event doesn't match, querying changes between event 1 and 3"
|
|
|
|
),
|
|
|
|
mock.call(
|
|
|
|
"Loading reuse file: %s"
|
|
|
|
% os.path.join(
|
|
|
|
self.old_compose_dir,
|
|
|
|
"work/global",
|
|
|
|
"pkgset_%s_reuse.pickle" % self.tag,
|
|
|
|
)
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
self.pkgset.log_info.mock_calls,
|
|
|
|
[
|
|
|
|
mock.call("Trying to reuse pkgset data of old compose"),
|
|
|
|
mock.call("Criteria does not match. Nothing to reuse."),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
self.assert_not_reuse()
|
|
|
|
|
|
|
|
@mock.patch("pungi.phases.pkgset.pkgsets.copy_all")
|
|
|
|
@mock.patch("pungi.paths.os.path.exists", return_value=True)
|
|
|
|
@mock.patch.object(helpers.paths.Paths, "get_old_compose_topdir")
|
|
|
|
def test_reuse_pkgset(self, mock_old_topdir, mock_exists, mock_copy_all):
|
|
|
|
mock_old_topdir.return_value = self.old_compose_dir
|
|
|
|
self.pkgset._get_koji_event_from_file = mock.Mock(side_effect=[3, 1])
|
2022-11-08 10:47:14 +00:00
|
|
|
self.koji_wrapper.koji_proxy.queryHistory.return_value = {
|
|
|
|
"tag_listing": [], "tag_inheritance": []
|
|
|
|
}
|
2022-11-07 17:24:39 +00:00
|
|
|
self.koji_wrapper.koji_proxy.getFullInheritance.return_value = []
|
|
|
|
self.pkgset.load_old_file_cache = mock.Mock(
|
|
|
|
return_value={
|
|
|
|
"allow_invalid_sigkeys": self.pkgset._allow_invalid_sigkeys,
|
|
|
|
"packages": self.pkgset.packages,
|
|
|
|
"populate_only_packages": self.pkgset.populate_only_packages,
|
|
|
|
"extra_builds": self.pkgset.extra_builds,
|
|
|
|
"sigkeys": self.pkgset.sigkey_ordering,
|
|
|
|
"include_packages": None,
|
|
|
|
"rpms_by_arch": mock.Mock(),
|
|
|
|
"srpms_by_name": mock.Mock(),
|
2023-11-10 16:08:03 +00:00
|
|
|
"inherit_to_noarch": True,
|
|
|
|
"exclusive_noarch": True,
|
2022-11-07 17:24:39 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
self.pkgset.old_file_cache = mock.Mock()
|
|
|
|
|
|
|
|
self.pkgset.try_to_reuse(self.compose, self.tag)
|
|
|
|
|
|
|
|
old_repo_dir = os.path.join(self.old_compose_dir, "work/global/repo", self.tag)
|
|
|
|
self.assertEqual(
|
|
|
|
self.pkgset.log_info.mock_calls,
|
|
|
|
[
|
|
|
|
mock.call("Trying to reuse pkgset data of old compose"),
|
|
|
|
mock.call("Copying repo data for reuse: %s" % old_repo_dir),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
self.assertEqual(old_repo_dir, self.pkgset.reuse)
|
|
|
|
self.assertEqual(self.pkgset.file_cache, self.pkgset.old_file_cache)
|
|
|
|
|
|
|
|
|
|
|
|
class TestReuseKojiMockPkgset(helpers.PungiTestCase):
|
|
|
|
def setUp(self):
|
|
|
|
super(TestReuseKojiMockPkgset, self).setUp()
|
|
|
|
self.old_compose_dir = tempfile.mkdtemp()
|
|
|
|
self.old_compose = helpers.DummyCompose(self.old_compose_dir, {})
|
|
|
|
self.compose = helpers.DummyCompose(
|
|
|
|
self.topdir, {"old_composes": os.path.dirname(self.old_compose_dir)}
|
|
|
|
)
|
|
|
|
|
|
|
|
self.koji_wrapper = mock.Mock()
|
|
|
|
|
|
|
|
self.tag = "test-tag"
|
|
|
|
self.inherited_tag = "inherited-test-tag"
|
|
|
|
self.pkgset = pkgsets.KojiMockPackageSet(
|
|
|
|
self.tag, self.koji_wrapper, [None], arches=["x86_64"]
|
|
|
|
)
|
|
|
|
self.pkgset.log_debug = mock.Mock()
|
|
|
|
self.pkgset.log_info = mock.Mock()
|
|
|
|
|
|
|
|
def assert_not_reuse(self):
|
|
|
|
self.assertIsNone(getattr(self.pkgset, "reuse", None))
|
|
|
|
|
|
|
|
def test_resue_no_old_compose_found(self):
|
|
|
|
self.pkgset.try_to_reuse(self.compose, self.tag)
|
|
|
|
self.pkgset.log_info.assert_called_once_with(
|
|
|
|
"Trying to reuse pkgset data of old compose"
|
|
|
|
)
|
|
|
|
self.pkgset.log_debug.assert_called_once_with(
|
|
|
|
"No old compose found. Nothing to reuse."
|
|
|
|
)
|
|
|
|
self.assert_not_reuse()
|
|
|
|
|
|
|
|
@mock.patch.object(helpers.paths.Paths, "get_old_compose_topdir")
|
|
|
|
def test_reuse_read_koji_event_file_failed(self, mock_old_topdir):
|
|
|
|
mock_old_topdir.return_value = self.old_compose_dir
|
|
|
|
self.pkgset._get_koji_event_from_file = mock.Mock(
|
|
|
|
side_effect=Exception("unknown error")
|
|
|
|
)
|
2020-02-25 03:02:39 +00:00
|
|
|
self.pkgset.try_to_reuse(self.compose, self.tag)
|
|
|
|
self.pkgset.log_debug.assert_called_once_with(
|
|
|
|
"Can't read koji event from file: unknown error"
|
|
|
|
)
|
|
|
|
self.assert_not_reuse()
|
|
|
|
|
|
|
|
@mock.patch.object(helpers.paths.Paths, "get_old_compose_topdir")
|
|
|
|
def test_reuse_build_under_tag_changed(self, mock_old_topdir):
|
|
|
|
mock_old_topdir.return_value = self.old_compose_dir
|
|
|
|
self.pkgset._get_koji_event_from_file = mock.Mock(side_effect=[3, 1])
|
2021-01-29 04:00:54 +00:00
|
|
|
self.koji_wrapper.koji_proxy.queryHistory.return_value = {
|
|
|
|
"tag_listing": [{}],
|
|
|
|
"tag_inheritance": [],
|
|
|
|
}
|
2020-02-25 03:02:39 +00:00
|
|
|
|
|
|
|
self.pkgset.try_to_reuse(self.compose, self.tag)
|
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
self.pkgset.log_debug.mock_calls,
|
|
|
|
[
|
|
|
|
mock.call(
|
|
|
|
"Koji event doesn't match, querying changes between event 1 and 3"
|
|
|
|
),
|
|
|
|
mock.call("Builds under tag %s changed. Can't reuse." % self.tag),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
self.assert_not_reuse()
|
|
|
|
|
|
|
|
@mock.patch.object(helpers.paths.Paths, "get_old_compose_topdir")
|
|
|
|
def test_reuse_build_under_inherited_tag_changed(self, mock_old_topdir):
|
|
|
|
mock_old_topdir.return_value = self.old_compose_dir
|
|
|
|
self.pkgset._get_koji_event_from_file = mock.Mock(side_effect=[3, 1])
|
|
|
|
self.koji_wrapper.koji_proxy.queryHistory.side_effect = [
|
2021-01-29 04:00:54 +00:00
|
|
|
{"tag_listing": [], "tag_inheritance": []},
|
|
|
|
{"tag_listing": [{}], "tag_inheritance": []},
|
2020-02-25 03:02:39 +00:00
|
|
|
]
|
|
|
|
self.koji_wrapper.koji_proxy.getFullInheritance.return_value = [
|
|
|
|
{"name": self.inherited_tag}
|
|
|
|
]
|
|
|
|
|
|
|
|
self.pkgset.try_to_reuse(self.compose, self.tag)
|
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
self.pkgset.log_debug.mock_calls,
|
|
|
|
[
|
|
|
|
mock.call(
|
|
|
|
"Koji event doesn't match, querying changes between event 1 and 3"
|
|
|
|
),
|
|
|
|
mock.call(
|
|
|
|
"Builds under inherited tag %s changed. Can't reuse."
|
|
|
|
% self.inherited_tag
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
self.assert_not_reuse()
|
|
|
|
|
|
|
|
@mock.patch("pungi.paths.os.path.exists", return_value=True)
|
|
|
|
@mock.patch.object(helpers.paths.Paths, "get_old_compose_topdir")
|
|
|
|
def test_reuse_failed_load_reuse_file(self, mock_old_topdir, mock_exists):
|
|
|
|
mock_old_topdir.return_value = self.old_compose_dir
|
|
|
|
self.pkgset._get_koji_event_from_file = mock.Mock(side_effect=[3, 1])
|
2021-01-29 04:00:54 +00:00
|
|
|
self.koji_wrapper.koji_proxy.queryHistory.return_value = {
|
|
|
|
"tag_listing": [],
|
|
|
|
"tag_inheritance": [],
|
|
|
|
}
|
2020-02-25 03:02:39 +00:00
|
|
|
self.koji_wrapper.koji_proxy.getFullInheritance.return_value = []
|
|
|
|
self.pkgset.load_old_file_cache = mock.Mock(
|
|
|
|
side_effect=Exception("unknown error")
|
|
|
|
)
|
|
|
|
|
|
|
|
self.pkgset.try_to_reuse(self.compose, self.tag)
|
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
self.pkgset.log_debug.mock_calls,
|
|
|
|
[
|
|
|
|
mock.call(
|
|
|
|
"Koji event doesn't match, querying changes between event 1 and 3"
|
|
|
|
),
|
|
|
|
mock.call(
|
|
|
|
"Loading reuse file: %s"
|
|
|
|
% os.path.join(
|
|
|
|
self.old_compose_dir,
|
|
|
|
"work/global",
|
|
|
|
"pkgset_%s_reuse.pickle" % self.tag,
|
|
|
|
)
|
|
|
|
),
|
|
|
|
mock.call("Failed to load reuse file: unknown error"),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
self.assert_not_reuse()
|
|
|
|
|
|
|
|
@mock.patch("pungi.paths.os.path.exists", return_value=True)
|
|
|
|
@mock.patch.object(helpers.paths.Paths, "get_old_compose_topdir")
|
|
|
|
def test_reuse_criteria_not_match(self, mock_old_topdir, mock_exists):
|
|
|
|
mock_old_topdir.return_value = self.old_compose_dir
|
|
|
|
self.pkgset._get_koji_event_from_file = mock.Mock(side_effect=[3, 1])
|
2021-01-29 04:00:54 +00:00
|
|
|
self.koji_wrapper.koji_proxy.queryHistory.return_value = {
|
|
|
|
"tag_listing": [],
|
|
|
|
"tag_inheritance": [],
|
|
|
|
}
|
2020-02-25 03:02:39 +00:00
|
|
|
self.koji_wrapper.koji_proxy.getFullInheritance.return_value = []
|
|
|
|
self.pkgset.load_old_file_cache = mock.Mock(
|
|
|
|
return_value={"allow_invalid_sigkeys": True}
|
|
|
|
)
|
|
|
|
|
|
|
|
self.pkgset.try_to_reuse(self.compose, self.tag)
|
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
self.pkgset.log_debug.mock_calls,
|
|
|
|
[
|
|
|
|
mock.call(
|
|
|
|
"Koji event doesn't match, querying changes between event 1 and 3"
|
|
|
|
),
|
|
|
|
mock.call(
|
|
|
|
"Loading reuse file: %s"
|
|
|
|
% os.path.join(
|
|
|
|
self.old_compose_dir,
|
|
|
|
"work/global",
|
|
|
|
"pkgset_%s_reuse.pickle" % self.tag,
|
|
|
|
)
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
self.pkgset.log_info.mock_calls,
|
|
|
|
[
|
|
|
|
mock.call("Trying to reuse pkgset data of old compose"),
|
|
|
|
mock.call("Criteria does not match. Nothing to reuse."),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
self.assert_not_reuse()
|
|
|
|
|
|
|
|
@mock.patch("pungi.phases.pkgset.pkgsets.copy_all")
|
|
|
|
@mock.patch("pungi.paths.os.path.exists", return_value=True)
|
|
|
|
@mock.patch.object(helpers.paths.Paths, "get_old_compose_topdir")
|
|
|
|
def test_reuse_pkgset(self, mock_old_topdir, mock_exists, mock_copy_all):
|
|
|
|
mock_old_topdir.return_value = self.old_compose_dir
|
|
|
|
self.pkgset._get_koji_event_from_file = mock.Mock(side_effect=[3, 1])
|
2021-01-29 04:00:54 +00:00
|
|
|
self.koji_wrapper.koji_proxy.queryHistory.return_value = {
|
|
|
|
"tag_listing": [],
|
|
|
|
"tag_inheritance": [],
|
|
|
|
}
|
2020-02-25 03:02:39 +00:00
|
|
|
self.koji_wrapper.koji_proxy.getFullInheritance.return_value = []
|
|
|
|
self.pkgset.load_old_file_cache = mock.Mock(
|
|
|
|
return_value={
|
|
|
|
"allow_invalid_sigkeys": self.pkgset._allow_invalid_sigkeys,
|
|
|
|
"packages": self.pkgset.packages,
|
|
|
|
"populate_only_packages": self.pkgset.populate_only_packages,
|
|
|
|
"extra_builds": self.pkgset.extra_builds,
|
|
|
|
"sigkeys": self.pkgset.sigkey_ordering,
|
|
|
|
"include_packages": None,
|
|
|
|
"rpms_by_arch": mock.Mock(),
|
|
|
|
"srpms_by_name": mock.Mock(),
|
2022-09-23 08:14:12 +00:00
|
|
|
"exclusive_noarch": True,
|
|
|
|
"inherit_to_noarch": True,
|
2020-02-25 03:02:39 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
self.pkgset.old_file_cache = mock.Mock()
|
|
|
|
|
|
|
|
self.pkgset.try_to_reuse(self.compose, self.tag)
|
|
|
|
|
|
|
|
old_repo_dir = os.path.join(self.old_compose_dir, "work/global/repo", self.tag)
|
|
|
|
self.assertEqual(
|
|
|
|
self.pkgset.log_info.mock_calls,
|
|
|
|
[
|
|
|
|
mock.call("Trying to reuse pkgset data of old compose"),
|
|
|
|
mock.call("Copying repo data for reuse: %s" % old_repo_dir),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
self.assertEqual(old_repo_dir, self.pkgset.reuse)
|
|
|
|
self.assertEqual(self.pkgset.file_cache, self.pkgset.old_file_cache)
|
|
|
|
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("kobo.pkgset.FileCache", new=MockFileCache)
|
2016-04-22 12:05:38 +00:00
|
|
|
class TestMergePackageSets(PkgsetCompareMixin, unittest.TestCase):
|
|
|
|
def test_merge_in_another_arch(self):
|
2019-07-25 13:35:02 +00:00
|
|
|
first = pkgsets.PackageSetBase("first", [None])
|
|
|
|
second = pkgsets.PackageSetBase("second", [None])
|
2016-04-22 12:05:38 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
for name in ["rpms/pungi@4.1.3@3.fc25@noarch", "rpms/pungi@4.1.3@3.fc25@src"]:
|
2016-04-22 12:05:38 +00:00
|
|
|
pkg = first.file_cache.add(name)
|
|
|
|
first.rpms_by_arch.setdefault(pkg.arch, []).append(pkg)
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
for name in ["rpms/bash@4.3.42@4.fc24@i686"]:
|
2016-04-22 12:05:38 +00:00
|
|
|
pkg = second.file_cache.add(name)
|
|
|
|
second.rpms_by_arch.setdefault(pkg.arch, []).append(pkg)
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
first.merge(second, "i386", ["i686"])
|
2016-04-22 12:05:38 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertPkgsetEqual(
|
|
|
|
first.rpms_by_arch,
|
|
|
|
{
|
|
|
|
"src": ["rpms/pungi@4.1.3@3.fc25@src"],
|
|
|
|
"noarch": ["rpms/pungi@4.1.3@3.fc25@noarch"],
|
|
|
|
"i686": ["rpms/bash@4.3.42@4.fc24@i686"],
|
|
|
|
},
|
|
|
|
)
|
2016-04-22 12:05:38 +00:00
|
|
|
|
|
|
|
def test_merge_includes_noarch_with_different_exclude_arch(self):
|
2019-07-25 13:35:02 +00:00
|
|
|
first = pkgsets.PackageSetBase("first", [None])
|
|
|
|
second = pkgsets.PackageSetBase("second", [None])
|
2016-04-22 12:05:38 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
pkg = first.file_cache.add("rpms/bash@4.3.42@4.fc24@i686")
|
2016-04-22 12:05:38 +00:00
|
|
|
first.rpms_by_arch.setdefault(pkg.arch, []).append(pkg)
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
pkg = second.file_cache.add("rpms/pungi@4.1.3@3.fc25@noarch")
|
|
|
|
pkg.excludearch = ["x86_64"]
|
2016-04-22 12:05:38 +00:00
|
|
|
second.rpms_by_arch.setdefault(pkg.arch, []).append(pkg)
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
first.merge(second, "i386", ["i686", "noarch"])
|
2016-04-22 12:05:38 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertPkgsetEqual(
|
|
|
|
first.rpms_by_arch,
|
|
|
|
{
|
|
|
|
"i686": ["rpms/bash@4.3.42@4.fc24@i686"],
|
|
|
|
"noarch": ["rpms/pungi@4.1.3@3.fc25@noarch"],
|
|
|
|
},
|
|
|
|
)
|
2016-04-22 12:05:38 +00:00
|
|
|
|
|
|
|
def test_merge_excludes_noarch_exclude_arch(self):
|
2019-07-25 13:35:02 +00:00
|
|
|
first = pkgsets.PackageSetBase("first", [None])
|
|
|
|
second = pkgsets.PackageSetBase("second", [None])
|
2016-04-22 12:05:38 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
pkg = first.file_cache.add("rpms/bash@4.3.42@4.fc24@i686")
|
2016-04-22 12:05:38 +00:00
|
|
|
first.rpms_by_arch.setdefault(pkg.arch, []).append(pkg)
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
pkg = second.file_cache.add("rpms/pungi@4.1.3@3.fc25@noarch")
|
|
|
|
pkg.excludearch = ["i686"]
|
2016-04-22 12:05:38 +00:00
|
|
|
second.rpms_by_arch.setdefault(pkg.arch, []).append(pkg)
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
first.merge(second, "i386", ["i686", "noarch"])
|
2016-04-22 12:05:38 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertPkgsetEqual(
|
|
|
|
first.rpms_by_arch, {"i686": ["rpms/bash@4.3.42@4.fc24@i686"], "noarch": []}
|
|
|
|
)
|
2016-04-22 12:05:38 +00:00
|
|
|
|
2022-09-22 14:17:53 +00:00
|
|
|
def test_merge_doesnt_exclude_noarch_exclude_arch_when_configured(self):
|
|
|
|
first = pkgsets.PackageSetBase("first", [None])
|
|
|
|
second = pkgsets.PackageSetBase("second", [None])
|
|
|
|
|
|
|
|
pkg = first.file_cache.add("rpms/bash@4.3.42@4.fc24@i686")
|
|
|
|
first.rpms_by_arch.setdefault(pkg.arch, []).append(pkg)
|
|
|
|
|
|
|
|
pkg = second.file_cache.add("rpms/pungi@4.1.3@3.fc25@noarch")
|
|
|
|
pkg.excludearch = ["i686"]
|
|
|
|
second.rpms_by_arch.setdefault(pkg.arch, []).append(pkg)
|
|
|
|
|
|
|
|
first.merge(second, "i386", ["i686", "noarch"], inherit_to_noarch=False)
|
|
|
|
|
|
|
|
print(first.rpms_by_arch)
|
|
|
|
self.assertPkgsetEqual(
|
|
|
|
first.rpms_by_arch,
|
|
|
|
{
|
|
|
|
"i686": ["rpms/bash@4.3.42@4.fc24@i686"],
|
|
|
|
"noarch": ["rpms/pungi@4.1.3@3.fc25@noarch"],
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
2016-04-22 12:05:38 +00:00
|
|
|
def test_merge_excludes_noarch_exclusive_arch(self):
|
2019-07-25 13:35:02 +00:00
|
|
|
first = pkgsets.PackageSetBase("first", [None])
|
|
|
|
second = pkgsets.PackageSetBase("second", [None])
|
2016-04-22 12:05:38 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
pkg = first.file_cache.add("rpms/bash@4.3.42@4.fc24@i686")
|
2016-04-22 12:05:38 +00:00
|
|
|
first.rpms_by_arch.setdefault(pkg.arch, []).append(pkg)
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
pkg = second.file_cache.add("rpms/pungi@4.1.3@3.fc25@noarch")
|
|
|
|
pkg.exclusivearch = ["x86_64"]
|
2016-04-22 12:05:38 +00:00
|
|
|
second.rpms_by_arch.setdefault(pkg.arch, []).append(pkg)
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
first.merge(second, "i386", ["i686", "noarch"])
|
2016-04-22 12:05:38 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertPkgsetEqual(
|
|
|
|
first.rpms_by_arch, {"i686": ["rpms/bash@4.3.42@4.fc24@i686"], "noarch": []}
|
|
|
|
)
|
2016-04-22 12:05:38 +00:00
|
|
|
|
|
|
|
def test_merge_includes_noarch_with_same_exclusive_arch(self):
|
2019-07-25 13:35:02 +00:00
|
|
|
first = pkgsets.PackageSetBase("first", [None])
|
|
|
|
second = pkgsets.PackageSetBase("second", [None])
|
2016-04-22 12:05:38 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
pkg = first.file_cache.add("rpms/bash@4.3.42@4.fc24@i686")
|
2016-04-22 12:05:38 +00:00
|
|
|
first.rpms_by_arch.setdefault(pkg.arch, []).append(pkg)
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
pkg = second.file_cache.add("rpms/pungi@4.1.3@3.fc25@noarch")
|
|
|
|
pkg.exclusivearch = ["i686"]
|
2016-04-22 12:05:38 +00:00
|
|
|
second.rpms_by_arch.setdefault(pkg.arch, []).append(pkg)
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
first.merge(second, "i386", ["i686", "noarch"])
|
2016-04-22 12:05:38 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertPkgsetEqual(
|
|
|
|
first.rpms_by_arch,
|
|
|
|
{
|
|
|
|
"i686": ["rpms/bash@4.3.42@4.fc24@i686"],
|
|
|
|
"noarch": ["rpms/pungi@4.1.3@3.fc25@noarch"],
|
|
|
|
},
|
|
|
|
)
|
2016-04-22 12:05:38 +00:00
|
|
|
|
|
|
|
def test_merge_skips_package_in_cache(self):
|
2019-07-25 13:35:02 +00:00
|
|
|
first = pkgsets.PackageSetBase("first", [None])
|
|
|
|
second = pkgsets.PackageSetBase("second", [None])
|
2016-04-22 12:05:38 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
pkg = first.file_cache.add("rpms/bash@4.3.42@4.fc24@i686")
|
2016-04-22 12:05:38 +00:00
|
|
|
first.rpms_by_arch.setdefault(pkg.arch, []).append(pkg)
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
pkg = second.file_cache.add("rpms/bash@4.3.42@4.fc24@i686")
|
2016-04-22 12:05:38 +00:00
|
|
|
second.rpms_by_arch.setdefault(pkg.arch, []).append(pkg)
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
first.merge(second, "i386", ["i686"])
|
2016-04-22 12:05:38 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertPkgsetEqual(
|
|
|
|
first.rpms_by_arch, {"i686": ["rpms/bash@4.3.42@4.fc24@i686"]}
|
|
|
|
)
|
2016-04-22 12:05:38 +00:00
|
|
|
|
|
|
|
def test_merge_skips_src_without_binary(self):
|
2019-07-25 13:35:02 +00:00
|
|
|
first = pkgsets.PackageSetBase("first", [None])
|
|
|
|
second = pkgsets.PackageSetBase("second", [None])
|
2016-04-22 12:05:38 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
pkg = first.file_cache.add("rpms/bash@4.3.42@4.fc24@i686")
|
2016-04-22 12:05:38 +00:00
|
|
|
first.rpms_by_arch.setdefault(pkg.arch, []).append(pkg)
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
pkg = second.file_cache.add("rpms/pungi@4.1.3@3.fc25@src")
|
2016-04-22 12:05:38 +00:00
|
|
|
second.rpms_by_arch.setdefault(pkg.arch, []).append(pkg)
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
first.merge(second, "i386", ["i686", "src"])
|
2016-04-22 12:05:38 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertPkgsetEqual(
|
|
|
|
first.rpms_by_arch,
|
|
|
|
{"i686": ["rpms/bash@4.3.42@4.fc24@i686"], "src": [], "nosrc": []},
|
|
|
|
)
|
2016-04-22 12:05:38 +00:00
|
|
|
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("kobo.pkgset.FileCache", new=MockFileCache)
|
2016-04-26 12:55:46 +00:00
|
|
|
class TestSaveFileList(unittest.TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
fd, self.tmpfile = tempfile.mkstemp()
|
|
|
|
os.close(fd)
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
os.unlink(self.tmpfile)
|
|
|
|
|
|
|
|
def test_save_arches_alphabetically(self):
|
2019-07-25 13:35:02 +00:00
|
|
|
pkgset = pkgsets.PackageSetBase("pkgset", [None])
|
2020-01-22 10:02:22 +00:00
|
|
|
for name in [
|
|
|
|
"rpms/pungi@4.1.3@3.fc25@x86_64",
|
|
|
|
"rpms/pungi@4.1.3@3.fc25@src",
|
|
|
|
"rpms/pungi@4.1.3@3.fc25@ppc64",
|
|
|
|
]:
|
2016-04-26 12:55:46 +00:00
|
|
|
pkg = pkgset.file_cache.add(name)
|
|
|
|
pkgset.rpms_by_arch.setdefault(pkg.arch, []).append(pkg)
|
|
|
|
|
|
|
|
pkgset.save_file_list(self.tmpfile)
|
|
|
|
|
|
|
|
with open(self.tmpfile) as f:
|
2020-01-22 10:02:22 +00:00
|
|
|
rpms = f.read().strip().split("\n")
|
|
|
|
self.assertEqual(
|
|
|
|
rpms,
|
|
|
|
[
|
|
|
|
"rpms/pungi@4.1.3@3.fc25@ppc64",
|
|
|
|
"rpms/pungi@4.1.3@3.fc25@src",
|
|
|
|
"rpms/pungi@4.1.3@3.fc25@x86_64",
|
|
|
|
],
|
|
|
|
)
|
2016-04-26 12:55:46 +00:00
|
|
|
|
|
|
|
def test_save_strip_prefix(self):
|
2019-07-25 13:35:02 +00:00
|
|
|
pkgset = pkgsets.PackageSetBase("pkgset", [None])
|
2020-01-22 10:02:22 +00:00
|
|
|
for name in ["rpms/pungi@4.1.3@3.fc25@noarch", "rpms/pungi@4.1.3@3.fc25@src"]:
|
2016-04-26 12:55:46 +00:00
|
|
|
pkg = pkgset.file_cache.add(name)
|
|
|
|
pkgset.rpms_by_arch.setdefault(pkg.arch, []).append(pkg)
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
pkgset.save_file_list(self.tmpfile, remove_path_prefix="rpms/")
|
2016-04-26 12:55:46 +00:00
|
|
|
|
|
|
|
with open(self.tmpfile) as f:
|
2020-01-22 10:02:22 +00:00
|
|
|
rpms = f.read().strip().split("\n")
|
2019-10-04 12:45:03 +00:00
|
|
|
six.assertCountEqual(
|
|
|
|
self, rpms, ["pungi@4.1.3@3.fc25@noarch", "pungi@4.1.3@3.fc25@src"]
|
|
|
|
)
|