Log PDC communications and info for modular composes

Fixes: https://pagure.io/pungi/issue/664
Merges: https://pagure.io/pungi/pull-request/723
Signed-off-by: Dong Wang <dowang@redhat.com>
This commit is contained in:
Dong Wang 2017-08-30 16:21:41 +08:00 committed by Lubomír Sedlář
parent 4ff3190935
commit 463fb961bc
4 changed files with 33 additions and 2 deletions

1
.gitignore vendored
View File

@ -11,3 +11,4 @@ tests/data/repo-krb5-lookaside
tests/_composes tests/_composes
htmlcov/ htmlcov/
.coverage .coverage
.idea/

View File

@ -219,12 +219,15 @@ def populate_global_pkgset(compose, koji_wrapper, path_prefix, event_id):
koji_wrapper, compose.conf["sigkeys"], logger=compose._logger, koji_wrapper, compose.conf["sigkeys"], logger=compose._logger,
arches=all_arches) arches=all_arches)
variant_tags[variant] = [] variant_tags[variant] = []
pdc_module_file = os.path.join(compose.paths.work.topdir(arch="global"),
"pdc-module-%s.json" % variant.uid)
pdc_modules = []
# Find out all modules in every variant and add their compose tags # Find out all modules in every variant and add their compose tags
# to compose_tags list. # to compose_tags list.
if session: if session:
for module in variant.get_modules(): for module in variant.get_modules():
pdc_module = get_module(compose, session, module["name"]) pdc_module = get_module(compose, session, module["name"])
pdc_modules.append(pdc_module)
mmd = modulemd.ModuleMetadata() mmd = modulemd.ModuleMetadata()
mmd.loads(pdc_module["modulemd"]) mmd.loads(pdc_module["modulemd"])
@ -248,7 +251,9 @@ def populate_global_pkgset(compose, koji_wrapper, path_prefix, event_id):
variant_tags[variant].append(tag) variant_tags[variant].append(tag)
if tag not in compose_tags: if tag not in compose_tags:
compose_tags.append(tag) compose_tags.append(tag)
if pdc_modules:
with open(pdc_module_file, 'w') as f:
json.dump(pdc_modules, f)
if not variant_tags[variant]: if not variant_tags[variant]:
variant_tags[variant].extend(force_list(compose.conf["pkgset_koji_tag"])) variant_tags[variant].extend(force_list(compose.conf["pkgset_koji_tag"]))

View File

@ -46,6 +46,9 @@ class MockVariant(mock.Mock):
return [v for v in list(self.variants.values()) return [v for v in list(self.variants.values())
if (not arch or arch in v.arches) and (not types or v.type in types)] if (not arch or arch in v.arches) and (not types or v.type in types)]
def get_modules(self, arch=None, types=None):
return []
class IterableMock(mock.Mock): class IterableMock(mock.Mock):
def __iter__(self): def __iter__(self):

View File

@ -93,6 +93,7 @@ class TestPopulateGlobalPkgset(helpers.PungiTestCase):
self.compose.DEBUG = False self.compose.DEBUG = False
self.koji_wrapper = mock.Mock() self.koji_wrapper = mock.Mock()
self.pkgset_path = os.path.join(self.topdir, 'work', 'global', 'pkgset_global.pickle') self.pkgset_path = os.path.join(self.topdir, 'work', 'global', 'pkgset_global.pickle')
self.pdc_module_path = os.path.join(self.topdir, 'work', 'global', 'pdc-module-Server.json')
@mock.patch('six.moves.cPickle.dumps') @mock.patch('six.moves.cPickle.dumps')
@mock.patch('pungi.phases.pkgset.pkgsets.KojiPackageSet') @mock.patch('pungi.phases.pkgset.pkgsets.KojiPackageSet')
@ -117,6 +118,27 @@ class TestPopulateGlobalPkgset(helpers.PungiTestCase):
with open(self.pkgset_path) as f: with open(self.pkgset_path) as f:
self.assertEqual(f.read(), 'DATA') self.assertEqual(f.read(), 'DATA')
@mock.patch('six.moves.cPickle.dumps')
@mock.patch('pungi.phases.pkgset.pkgsets.KojiPackageSet')
@mock.patch('pungi.phases.pkgset.sources.source_koji.get_module')
@mock.patch('pungi.phases.pkgset.sources.source_koji.get_pdc_client_session')
@mock.patch('pungi.phases.pkgset.sources.source_koji.modulemd')
def test_pdc_log(self, modulemd, get_pdc_client_session, get_module, KojiPackageSet, pickle_dumps):
pickle_dumps.return_value = b'DATA'
get_module.return_value = {'abc': 'def', 'modulemd': 'sth', 'rpms': ['dummy'], 'koji_tag': 'taggg'}
for name, variant in self.compose.variants.items():
variant.get_modules = mock.MagicMock()
if name == 'Server':
variant.get_modules.return_value = [{'name': 'a'}]
source_koji.populate_global_pkgset(
self.compose, self.koji_wrapper, '/prefix', 123456)
with open(self.pdc_module_path, 'r') as pdc_f:
self.assertEqual(json.load(pdc_f),
[{"rpms": ["dummy"], "abc": "def", "koji_tag": "taggg", "modulemd": "sth"}])
@mock.patch('six.moves.cPickle.dumps') @mock.patch('six.moves.cPickle.dumps')
@mock.patch('pungi.phases.pkgset.pkgsets.KojiPackageSet') @mock.patch('pungi.phases.pkgset.pkgsets.KojiPackageSet')
def test_populate_with_multiple_koji_tags(self, KojiPackageSet, pickle_dumps): def test_populate_with_multiple_koji_tags(self, KojiPackageSet, pickle_dumps):