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 d358fe5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 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
6 changes: 5 additions & 1 deletion backend/tests/test_modifyrepo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])


Expand Down
15 changes: 13 additions & 2 deletions backend/tests/testlib/repodata.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import glob
import gzip
from xml.dom import minidom
from zstandard import ZstdDecompressor

def load_primary_xml(dirname):
'''
Expand All @@ -16,8 +17,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 +36,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 d358fe5

Please sign in to comment.