createrepo: Add extra modulemd files to the repo

This is a workaround for modularity design issues and DNF bugs. If there
were gaps in contexts, DNF has trouble handling the upgrades. Thus we
may need to add module metadata for older versions of previously
released module streams and add the missing contexts.

JIRA: RHELCMP-982
Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
Lubomír Sedlář 2020-06-08 14:52:57 +02:00
parent 6ac12af343
commit 3bb1e3df11
5 changed files with 138 additions and 0 deletions

20
tests/fixtures/fake-modulemd.yaml vendored Normal file
View file

@ -0,0 +1,20 @@
---
document: modulemd
version: 2
data:
name: mymodule
stream: master
version: 1
context: cafe
arch: x86_64
summary: Dummy module
description: Dummy module
license:
module:
- Beerware
content:
- Beerware
artifacts:
rpms:
- foobar-0:1.0-1.noarch
...

View file

@ -128,6 +128,22 @@ class TestCreaterepoPhase(PungiTestCase):
],
)
@mock.patch("pungi.phases.createrepo.get_dir_from_scm")
@mock.patch("pungi.phases.createrepo.ThreadPool")
def test_clones_extra_modulemd(self, ThreadPoolCls, get_dir_from_scm):
scm = mock.Mock()
compose = DummyCompose(
self.topdir, {"createrepo_extra_modulemd": {"Server": scm}}
)
phase = CreaterepoPhase(compose)
phase.run()
self.assertEqual(
get_dir_from_scm.call_args_list,
[mock.call(scm, os.path.join(compose.topdir, "work/global/tmp-Server"))],
)
def make_mocked_modifyrepo_cmd(tc, module_artifacts):
def mocked_modifyrepo_cmd(repodir, mmd_path, **kwargs):
@ -1190,6 +1206,56 @@ class TestCreateVariantRepo(PungiTestCase):
[mock.call(repodata_dir, mock.ANY, compress_type="gz", mdtype="modules")],
)
@unittest.skipUnless(Modulemd is not None, "Skipped test, no module support.")
@mock.patch("pungi.phases.createrepo.find_file_in_repodata")
@mock.patch("pungi.phases.createrepo.run")
@mock.patch("pungi.phases.createrepo.CreaterepoWrapper")
def test_variant_repo_extra_modulemd(
self, CreaterepoWrapperCls, run, modulemd_filename
):
compose = DummyCompose(
self.topdir, {"createrepo_extra_modulemd": {"Server": mock.Mock()}}
)
compose.has_comps = False
variant = compose.variants["Server"]
variant.arch_mmds["x86_64"] = {}
variant.module_uid_to_koji_tag = {}
repo = CreaterepoWrapperCls.return_value
copy_fixture("server-rpms.json", compose.paths.compose.metadata("rpms.json"))
copy_fixture(
"fake-modulemd.yaml",
os.path.join(compose.topdir, "work/global/tmp-Server/x86_64/*.yaml"),
)
repodata_dir = os.path.join(
compose.paths.compose.os_tree("x86_64", compose.variants["Server"]),
"repodata",
)
modules_metadata = ModulesMetadata(compose)
modulemd_filename.return_value = "Server/x86_64/os/repodata/3511d16a723e1bd69826e591508f07e377d2212769b59178a9-modules.yaml.gz" # noqa: E501
create_variant_repo(
compose,
"x86_64",
compose.variants["Server"],
"rpm",
self.pkgset,
modules_metadata,
)
self.assertEqual(
repo.get_modifyrepo_cmd.mock_calls,
[mock.call(repodata_dir, mock.ANY, compress_type="gz", mdtype="modules")],
)
self.assertEqual(
list(modules_metadata.productmd_modules_metadata["Server"]["x86_64"]),
["mymodule:master:1:cafe"],
)
class TestGetProductIds(PungiTestCase):
def mock_get(self, filenames):