Skip to content

Commit

Permalink
backend: fix tests for zst compression on F39+
Browse files Browse the repository at this point in the history
Fix fedora-copr#2832

Since F39 we are using zst compression for repodata instead of gz.
https://fedoraproject.org/wiki/Changes/createrepo_c_1.0.0
  • Loading branch information
FrostyX committed Aug 8, 2023
1 parent 030dd32 commit f0bdefe
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
1 change: 1 addition & 0 deletions backend/copr-backend.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions backend/tests/test_modifyrepo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
22 changes: 20 additions & 2 deletions backend/tests/testlib/repodata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand All @@ -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))

0 comments on commit f0bdefe

Please sign in to comment.