From dbdc4fecb6ba7a9db7c65363fdf2025c0f09e4dc Mon Sep 17 00:00:00 2001 From: Jakub Kadlcik Date: Tue, 8 Aug 2023 04:06:24 +0200 Subject: [PATCH] backend: fix tests for zst compression on F39+ Fix #2832 Since F39 we are using zst compression for repodata instead of gz. https://fedoraproject.org/wiki/Changes/createrepo_c_1.0.0 --- backend/copr-backend.spec | 1 + backend/tests/test_modifyrepo.py | 6 +++++- backend/tests/testlib/repodata.py | 17 +++++++++++++++-- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/backend/copr-backend.spec b/backend/copr-backend.spec index a75ba78f6..0379ea647 100644 --- a/backend/copr-backend.spec +++ b/backend/copr-backend.spec @@ -56,6 +56,7 @@ BuildRequires: python3-retask BuildRequires: python3-setproctitle BuildRequires: python3-sphinx BuildRequires: python3-tabulate +BuildRequires: python3-zstandard BuildRequires: modulemd-tools >= 0.6 BuildRequires: prunerepo >= %prunerepo_version BuildRequires: dnf diff --git a/backend/tests/test_modifyrepo.py b/backend/tests/test_modifyrepo.py index b6215aaca..16e50b0e9 100644 --- a/backend/tests/test_modifyrepo.py +++ b/backend/tests/test_modifyrepo.py @@ -547,7 +547,11 @@ def test_comps_present(self, f_third_build): pass assert call_copr_repo(chrootdir) - name = glob.glob(os.path.join(chrootdir, "repodata", "*-comps.xml.gz")) + + f39 = distro.id() == "fedora" and int(distro.version()) >= 39 + compression = "zst" if f39 else "gz" + pattern = "*-comps.xml.{0}".format(compression) + name = glob.glob(os.path.join(chrootdir, "repodata", pattern)) assert os.path.exists(name[0]) diff --git a/backend/tests/testlib/repodata.py b/backend/tests/testlib/repodata.py index b150d7a66..b91d8bffc 100644 --- a/backend/tests/testlib/repodata.py +++ b/backend/tests/testlib/repodata.py @@ -16,8 +16,7 @@ def load_primary_xml(dirname): hrefs = set() names = set() primary = glob.glob(os.path.join(dirname, '*primary*xml*'))[0] - with gzip.open(primary) as fprimary: - xml_content = fprimary.read() + xml_content = extract(primary) dom = minidom.parseString(xml_content) @@ -36,3 +35,17 @@ def load_primary_xml(dirname): 'hrefs': hrefs, 'names': names, } + +def extract(path): + if path.endswith(".zst"): + # This import tracebacks on F37 but we need it only on F39+ + # pylint: disable=import-outside-toplevel + from zstandard import ZstdDecompressor + with open(path, "rb") as fp: + decompressor = ZstdDecompressor() + return decompressor.stream_reader(fp).read() + + if path.endswith(".gz"): + with gzip.open(path) as fp: + return fp.read() + raise ValueError("Unexpected extension: {0}".format(path))