Skip to content

Commit

Permalink
Fix unittests that relied on checksum being at the end of solvfiles
Browse files Browse the repository at this point in the history
  • Loading branch information
kontura authored and lukash committed Mar 23, 2022
1 parent b4926be commit 71e435f
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions tests/test_fill_sack_from_repos_in_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@


class FillSackFromReposInCacheTest(unittest.TestCase):
def _create_cache_for_repo(self, repopath, tmpdir):
def _create_cache_for_repo(self, repopath, tmpdir, repo_name=TEST_REPO_NAME):
conf = dnf.conf.MainConf()
conf.cachedir = os.path.join(tmpdir, "cache")
conf.installroot = tmpdir
Expand All @@ -49,7 +49,7 @@ def _create_cache_for_repo(self, repopath, tmpdir):

base = dnf.Base(conf=conf)

repoconf = dnf.repo.Repo(TEST_REPO_NAME, base.conf)
repoconf = dnf.repo.Repo(repo_name, base.conf)
repoconf.baseurl = repopath
repoconf.enable()

Expand Down Expand Up @@ -194,33 +194,35 @@ def test_exception_with_just_repomd(self):

def test_exception_with_checksum_mismatch_and_only_repomd(self):
self._setUp_from_repo_path(os.path.join(os.path.abspath(os.path.dirname(__file__)), "repos/rpm"))
self._create_cache_for_repo(os.path.join(os.path.abspath(os.path.dirname(__file__)), "repos/drpm"),
self.tmpdir, "drpm-repo")

# Remove xml metadata except repomd
# repomd.xml is not compressed and doesn't end with .gz
repodata_without_repomd = glob.glob(os.path.join(self.tmpdir, "cache/test-repo-*/repodata/*.gz"))
for f in repodata_without_repomd:
os.remove(f)

# Modify checksum of solv file so it doesn't match with repomd
solv = glob.glob(os.path.join(self.tmpdir, "cache/*.solv"))[0]
with open(solv, "a") as opensolv:
opensolv.write("appended text to change checksum")
# Replace solvfile of test-repo with solvfile from drpm-repo which has different data (different checksum)
shutil.move(os.path.join(self.tmpdir, "cache/drpm-repo.solv"),
os.path.join(self.tmpdir, "cache/test-repo.solv"))

# Now we only have cache with solvx, modified solv file and just repomd
# Now we only have cache with solvx, mismatching solv file and just repomd
# Since we don't have original xml metadata we cannot regenerate solv -> fail (exception)

self.assertRaises(dnf.exceptions.RepoError,
self.test_base.fill_sack_from_repos_in_cache, load_system_repo=False)

def test_checksum_mistmatch_regenerates_solv(self):
self._setUp_from_repo_path(os.path.join(os.path.abspath(os.path.dirname(__file__)), "repos/rpm"))
self._create_cache_for_repo(os.path.join(os.path.abspath(os.path.dirname(__file__)), "repos/drpm"),
self.tmpdir, "drpm-repo")

# Modify checksum of solv file so it doesn't match with repomd
solv = glob.glob(os.path.join(self.tmpdir, "cache/*.solv"))[0]
with open(solv, "a") as opensolv:
opensolv.write("appended text to change checksum")
# Replace solvfile of test-repo with solvfile from drpm-repo which has different data (different checksum)
shutil.move(os.path.join(self.tmpdir, "cache/drpm-repo.solv"),
os.path.join(self.tmpdir, "cache/test-repo.solv"))

# Now we only have cache with solvx, modified solv file and xml metadata.
# Now we only have cache with solvx, mismatching solv file and xml metadata.
# Checksum mistmatch causes regeneration of solv file and repo works.

self.test_base.fill_sack_from_repos_in_cache(load_system_repo=False)
Expand Down

0 comments on commit 71e435f

Please sign in to comment.