From b8555b786922af1302f331a39a5dd2d38b7fbf09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Thu, 26 Apr 2018 09:01:13 +0200 Subject: [PATCH] modules: Allow context in variants XML MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit JIRA: COMPOSE-2508 Signed-off-by: Lubomír Sedlář --- pungi/phases/pkgset/sources/source_koji.py | 13 ++++++++----- tests/test_pkgset_source_koji.py | 11 ++++++++++- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/pungi/phases/pkgset/sources/source_koji.py b/pungi/phases/pkgset/sources/source_koji.py index 806e5a4a..51985304 100644 --- a/pungi/phases/pkgset/sources/source_koji.py +++ b/pungi/phases/pkgset/sources/source_koji.py @@ -65,8 +65,7 @@ def variant_dict_from_str(compose, module_str): https://pagure.io/modularity/blob/master/f/source/development/ building-modules/naming-policy.rst - Pungi supports only N:S and N:S:V, because other combinations do not - have sense for variant files. + Pungi supports N:S, N:S:V and N:S:V:C. Attributes: compose: compose for which the variant_dict is generated @@ -81,10 +80,12 @@ def variant_dict_from_str(compose, module_str): module_info = {} nsv = module_str.split(":") - if len(nsv) > 3: + if len(nsv) > 4: raise ValueError( - "Module string \"%s\" is not allowed. " - "Only NAME:STREAM or NAME:STREAM:VERSION is allowed.") + "Module string \"%s\" is not recognized. " + "Only NAME:STREAM[:VERSION[:CONTEXT]] is allowed.") + if len(nsv) > 3: + module_info["context"] = nsv[3] if len(nsv) > 2: module_info["version"] = nsv[2] if len(nsv) > 1: @@ -135,6 +136,8 @@ def get_module(compose, session, module_info): ) if module_info.get('version'): query['version'] = module_info['version'] + if module_info.get('context'): + query['context'] = module_info['context'] retval = session['modules'](page_size=-1, **query) diff --git a/tests/test_pkgset_source_koji.py b/tests/test_pkgset_source_koji.py index ae7d114c..f75a0fbc 100644 --- a/tests/test_pkgset_source_koji.py +++ b/tests/test_pkgset_source_koji.py @@ -344,8 +344,17 @@ class TestCorrectNVR(helpers.PungiTestCase): self.assertEqual(module_info, expected) def test_new_nvrc(self): + module_info = source_koji.variant_dict_from_str(self.compose, self.new_nvrc) + expected = { + 'name': 'base-runtime', + 'stream': 'f26', + 'version': '20170502134116', + 'context': '0123abcd'} + self.assertEqual(module_info, expected) + + def test_new_garbage_value(self): self.assertRaises(ValueError, source_koji.variant_dict_from_str, - self.compose, self.new_nvrc) + self.compose, 'foo:bar:baz:quux:qaar') if __name__ == "__main__":