modules: Allow context in variants XML

JIRA: COMPOSE-2508
Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
Lubomír Sedlář 2018-04-26 09:01:13 +02:00
parent 8c22236ad4
commit b8555b7869
2 changed files with 18 additions and 6 deletions

View File

@ -65,8 +65,7 @@ def variant_dict_from_str(compose, module_str):
https://pagure.io/modularity/blob/master/f/source/development/ https://pagure.io/modularity/blob/master/f/source/development/
building-modules/naming-policy.rst building-modules/naming-policy.rst
Pungi supports only N:S and N:S:V, because other combinations do not Pungi supports N:S, N:S:V and N:S:V:C.
have sense for variant files.
Attributes: Attributes:
compose: compose for which the variant_dict is generated compose: compose for which the variant_dict is generated
@ -81,10 +80,12 @@ def variant_dict_from_str(compose, module_str):
module_info = {} module_info = {}
nsv = module_str.split(":") nsv = module_str.split(":")
if len(nsv) > 3: if len(nsv) > 4:
raise ValueError( raise ValueError(
"Module string \"%s\" is not allowed. " "Module string \"%s\" is not recognized. "
"Only NAME:STREAM or NAME:STREAM:VERSION is allowed.") "Only NAME:STREAM[:VERSION[:CONTEXT]] is allowed.")
if len(nsv) > 3:
module_info["context"] = nsv[3]
if len(nsv) > 2: if len(nsv) > 2:
module_info["version"] = nsv[2] module_info["version"] = nsv[2]
if len(nsv) > 1: if len(nsv) > 1:
@ -135,6 +136,8 @@ def get_module(compose, session, module_info):
) )
if module_info.get('version'): if module_info.get('version'):
query['version'] = module_info['version'] query['version'] = module_info['version']
if module_info.get('context'):
query['context'] = module_info['context']
retval = session['modules'](page_size=-1, **query) retval = session['modules'](page_size=-1, **query)

View File

@ -344,8 +344,17 @@ class TestCorrectNVR(helpers.PungiTestCase):
self.assertEqual(module_info, expected) self.assertEqual(module_info, expected)
def test_new_nvrc(self): 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.assertRaises(ValueError, source_koji.variant_dict_from_str,
self.compose, self.new_nvrc) self.compose, 'foo:bar:baz:quux:qaar')
if __name__ == "__main__": if __name__ == "__main__":