pkgset: Use modules PDC API
Instead of the deprecated and confusing unreleasedvariants. JIRA: COMPOSE-2363 Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
parent
527394707d
commit
267ff86f04
@ -79,7 +79,6 @@ def variant_dict_from_str(compose, module_str):
|
|||||||
# naming policy format.
|
# naming policy format.
|
||||||
if module_str.find(":") != -1:
|
if module_str.find(":") != -1:
|
||||||
module_info = {}
|
module_info = {}
|
||||||
module_info['variant_type'] = 'module'
|
|
||||||
|
|
||||||
nsv = module_str.split(":")
|
nsv = module_str.split(":")
|
||||||
if len(nsv) > 3:
|
if len(nsv) > 3:
|
||||||
@ -87,10 +86,10 @@ def variant_dict_from_str(compose, module_str):
|
|||||||
"Module string \"%s\" is not allowed. "
|
"Module string \"%s\" is not allowed. "
|
||||||
"Only NAME:STREAM or NAME:STREAM:VERSION is allowed.")
|
"Only NAME:STREAM or NAME:STREAM:VERSION is allowed.")
|
||||||
if len(nsv) > 2:
|
if len(nsv) > 2:
|
||||||
module_info["variant_release"] = nsv[2]
|
module_info["version"] = nsv[2]
|
||||||
if len(nsv) > 1:
|
if len(nsv) > 1:
|
||||||
module_info["variant_version"] = nsv[1]
|
module_info["stream"] = nsv[1]
|
||||||
module_info["variant_id"] = nsv[0]
|
module_info["name"] = nsv[0]
|
||||||
return module_info
|
return module_info
|
||||||
else:
|
else:
|
||||||
# Fallback to previous old format with '-' delimiter.
|
# Fallback to previous old format with '-' delimiter.
|
||||||
@ -107,14 +106,13 @@ def variant_dict_from_str(compose, module_str):
|
|||||||
section_start = module_str.rfind('-')
|
section_start = module_str.rfind('-')
|
||||||
module_str_first_part = module_str[section_start+1:]
|
module_str_first_part = module_str[section_start+1:]
|
||||||
if release_regex.match(module_str_first_part):
|
if release_regex.match(module_str_first_part):
|
||||||
module_info['variant_release'] = module_str_first_part
|
module_info['version'] = module_str_first_part
|
||||||
module_str = module_str[:section_start]
|
module_str = module_str[:section_start]
|
||||||
section_start = module_str.rfind('-')
|
section_start = module_str.rfind('-')
|
||||||
module_info['variant_version'] = module_str[section_start+1:]
|
module_info['stream'] = module_str[section_start+1:]
|
||||||
else:
|
else:
|
||||||
module_info['variant_version'] = module_str_first_part
|
module_info['stream'] = module_str_first_part
|
||||||
module_info['variant_id'] = module_str[:section_start]
|
module_info['name'] = module_str[:section_start]
|
||||||
module_info['variant_type'] = 'module'
|
|
||||||
|
|
||||||
return module_info
|
return module_info
|
||||||
|
|
||||||
@ -131,30 +129,30 @@ def get_module(compose, session, module_info):
|
|||||||
module_info = variant_dict_from_str(compose, module_info)
|
module_info = variant_dict_from_str(compose, module_info)
|
||||||
|
|
||||||
query = dict(
|
query = dict(
|
||||||
variant_id=module_info['variant_id'],
|
name=module_info['name'],
|
||||||
variant_version=module_info['variant_version'],
|
stream=module_info['stream'],
|
||||||
active=True,
|
active=True,
|
||||||
)
|
)
|
||||||
if module_info.get('variant_release'):
|
if module_info.get('version'):
|
||||||
query['variant_release'] = module_info['variant_release']
|
query['version'] = module_info['version']
|
||||||
|
|
||||||
retval = session['unreleasedvariants'](page_size=-1, **query)
|
retval = session['modules'](page_size=-1, **query)
|
||||||
|
|
||||||
# Error reporting
|
# Error reporting
|
||||||
if not retval:
|
if not retval:
|
||||||
raise ValueError("Failed to find module in PDC %r" % query)
|
raise ValueError("Failed to find module in PDC %r" % query)
|
||||||
|
|
||||||
module = None
|
module = None
|
||||||
# If we specify 'variant_release', we expect only single module to be
|
# If we specify 'version', we expect only single module to be
|
||||||
# returned, but otherwise we have to pick the one with the highest
|
# returned, but otherwise we have to pick the one with the highest
|
||||||
# release ourselves.
|
# release ourselves.
|
||||||
if 'variant_release' in query:
|
if 'version' in query:
|
||||||
assert len(retval) <= 1, "More than one module returned from PDC: %s" % retval
|
assert len(retval) <= 1, "More than one module returned from PDC: %s" % retval
|
||||||
module = retval[0]
|
module = retval[0]
|
||||||
else:
|
else:
|
||||||
module = retval[0]
|
module = retval[0]
|
||||||
for m in retval:
|
for m in retval:
|
||||||
if int(m['variant_release']) > int(module['variant_release']):
|
if int(m['version']) > int(module['version']):
|
||||||
module = m
|
module = m
|
||||||
|
|
||||||
return module
|
return module
|
||||||
@ -261,8 +259,8 @@ def _get_modules_from_pdc(compose, session, variant, variant_tags):
|
|||||||
_log_modulemd(compose, variant, mmd)
|
_log_modulemd(compose, variant, mmd)
|
||||||
|
|
||||||
tag = pdc_module["koji_tag"]
|
tag = pdc_module["koji_tag"]
|
||||||
uid = ':'.join([pdc_module['variant_name'], pdc_module['variant_version'],
|
uid = ':'.join([pdc_module['name'], pdc_module['stream'],
|
||||||
pdc_module['variant_release'], pdc_module['variant_context']])
|
pdc_module['version'], pdc_module['context']])
|
||||||
variant_tags[variant].append(tag)
|
variant_tags[variant].append(tag)
|
||||||
|
|
||||||
# Store mapping module-uid --> koji_tag into variant.
|
# Store mapping module-uid --> koji_tag into variant.
|
||||||
|
@ -145,7 +145,17 @@ data:
|
|||||||
- MIT
|
- MIT
|
||||||
"""
|
"""
|
||||||
|
|
||||||
get_module.return_value = {'abc': 'def', 'modulemd': modulemd, 'rpms': [], 'koji_tag': 'taggg', 'variant_uid': 'modulenamefoo-rhel-1', 'variant_name': 'modulenamefoo', 'variant_version': 'rhel', 'variant_release': '1', 'variant_context': '00000000'}
|
get_module.return_value = {
|
||||||
|
'abc': 'def',
|
||||||
|
'modulemd': modulemd,
|
||||||
|
'rpms': [],
|
||||||
|
'koji_tag': 'taggg',
|
||||||
|
'uid': 'modulenamefoo:rhel:1:00000000',
|
||||||
|
'name': 'modulenamefoo',
|
||||||
|
'stream': 'rhel',
|
||||||
|
'version': '1',
|
||||||
|
'context': '00000000'
|
||||||
|
}
|
||||||
for name, variant in self.compose.variants.items():
|
for name, variant in self.compose.variants.items():
|
||||||
variant.get_modules = mock.MagicMock()
|
variant.get_modules = mock.MagicMock()
|
||||||
if name == 'Server':
|
if name == 'Server':
|
||||||
@ -303,39 +313,38 @@ class TestCorrectNVR(helpers.PungiTestCase):
|
|||||||
|
|
||||||
def test_nv(self):
|
def test_nv(self):
|
||||||
module_info = source_koji.variant_dict_from_str(self.compose, self.nv)
|
module_info = source_koji.variant_dict_from_str(self.compose, self.nv)
|
||||||
expectedKeys = ["variant_version", "variant_id", "variant_type"]
|
expectedKeys = ["stream", "name"]
|
||||||
self.assertItemsEqual(module_info.keys(), expectedKeys)
|
self.assertItemsEqual(module_info.keys(), expectedKeys)
|
||||||
|
|
||||||
def test_nvr(self):
|
def test_nvr(self):
|
||||||
module_info = source_koji.variant_dict_from_str(self.compose, self.nvr)
|
module_info = source_koji.variant_dict_from_str(self.compose, self.nvr)
|
||||||
expectedKeys = ["variant_version", "variant_id", "variant_type", "variant_release"]
|
expectedKeys = ["stream", "name", "version"]
|
||||||
self.assertItemsEqual(module_info.keys(), expectedKeys)
|
self.assertItemsEqual(module_info.keys(), expectedKeys)
|
||||||
|
|
||||||
def test_correct_release(self):
|
def test_correct_release(self):
|
||||||
module_info = source_koji.variant_dict_from_str(self.compose, self.nvr)
|
module_info = source_koji.variant_dict_from_str(self.compose, self.nvr)
|
||||||
self.assertIsNotNone(self.release_regex.match(module_info["variant_release"]))
|
self.assertIsNotNone(self.release_regex.match(module_info["version"]))
|
||||||
|
|
||||||
def test_new_nv(self):
|
def test_new_nv(self):
|
||||||
module_info = source_koji.variant_dict_from_str(self.compose, self.new_nv)
|
module_info = source_koji.variant_dict_from_str(self.compose, self.new_nv)
|
||||||
expected = {
|
expected = {
|
||||||
'variant_id': 'base-runtime',
|
'name': 'base-runtime',
|
||||||
'variant_type': 'module',
|
'stream': 'f26'}
|
||||||
'variant_version': 'f26'}
|
|
||||||
|
|
||||||
self.assertEqual(module_info, expected)
|
self.assertEqual(module_info, expected)
|
||||||
|
|
||||||
def test_new_nvr(self):
|
def test_new_nvr(self):
|
||||||
module_info = source_koji.variant_dict_from_str(self.compose, self.new_nvr)
|
module_info = source_koji.variant_dict_from_str(self.compose, self.new_nvr)
|
||||||
expected = {
|
expected = {
|
||||||
'variant_id': 'base-runtime',
|
'name': 'base-runtime',
|
||||||
'variant_type': 'module',
|
'stream': 'f26',
|
||||||
'variant_version': 'f26',
|
'version': '20170502134116'}
|
||||||
'variant_release': '20170502134116'}
|
|
||||||
self.assertEqual(module_info, expected)
|
self.assertEqual(module_info, expected)
|
||||||
|
|
||||||
def test_new_nvrc(self):
|
def test_new_nvrc(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, self.new_nvrc)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
Reference in New Issue
Block a user