From f0bdefe38e6b27e39ddc2ca34e7f8cfe1046775c 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 | 5 +++-- backend/tests/testlib/repodata.py | 22 ++++++++++++++++++++-- 3 files changed, 24 insertions(+), 4 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..8b9b465fd 100644 --- a/backend/tests/test_modifyrepo.py +++ b/backend/tests/test_modifyrepo.py @@ -547,9 +547,10 @@ 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")) - assert os.path.exists(name[0]) + name = glob.glob(os.path.join(chrootdir, "repodata", "*-comps.xml.*")) + assert os.path.exists(name[0]) + assert name[0].endswith((".zst", ".gz")) @skip("Works locally and in Copr but fails in Koji") @mock.patch("copr_prune_results.LOG", logging.getLogger()) diff --git a/backend/tests/testlib/repodata.py b/backend/tests/testlib/repodata.py index b150d7a66..292a90f3d 100644 --- a/backend/tests/testlib/repodata.py +++ b/backend/tests/testlib/repodata.py @@ -7,6 +7,14 @@ import gzip from xml.dom import minidom +try: + # This import tracebacks on F37 but we need it only on F39+ + # pylint: disable=import-outside-toplevel + from zstandard import ZstdDecompressor +except ImportError: + pass + + def load_primary_xml(dirname): ''' Parse priary.xml from the given repodata directory path, and return @@ -16,8 +24,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 +43,14 @@ def load_primary_xml(dirname): 'hrefs': hrefs, 'names': names, } + +def extract(path): + if path.endswith(".zst"): + 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))