From 079454c5028fbd9940b8e3a7a1dbf8934065848b Mon Sep 17 00:00:00 2001 From: Martin Curlej Date: Tue, 20 Jun 2017 16:26:30 +0200 Subject: [PATCH] pkgset: Use release number of a module Signed-off-by: Martin Curlej updated regex, added comment, pep8 fix --- pungi/phases/pkgset/sources/source_koji.py | 27 ++++++++++++++++++---- tests/test_pkgset_source_koji.py | 24 +++++++++++++++++++ 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/pungi/phases/pkgset/sources/source_koji.py b/pungi/phases/pkgset/sources/source_koji.py index a399e908..bf87ef2a 100644 --- a/pungi/phases/pkgset/sources/source_koji.py +++ b/pungi/phases/pkgset/sources/source_koji.py @@ -17,6 +17,7 @@ import os import cPickle as pickle import json +import re import pungi.wrappers.kojiwrapper import pungi.phases.pkgset.pkgsets @@ -52,11 +53,29 @@ def get_pdc_client_session(compose): def variant_dict_from_str(module_str): - module_info = {} + """ + Method which parses module NVR string, defined in a variants file and returns + a module info dictionary instead. - release_start = module_str.rfind('-') - module_info['variant_version'] = module_str[release_start+1:] - module_info['variant_id'] = module_str[:release_start] + Attributes: + module_str: string, the NV(R) of module defined in a variants file. + """ + + module_info = {} + # The regex is matching a string which should represent the release number + # of a module. The release number is in format: "%Y%m%d%H%M%S" + release_regex = re.compile("^(\d){14}$") + + section_start = module_str.rfind('-') + module_str_first_part = module_str[section_start+1:] + if release_regex.match(module_str_first_part): + module_info['variant_release'] = module_str_first_part + module_str = module_str[:section_start] + section_start = module_str.rfind('-') + module_info['variant_version'] = module_str[section_start+1:] + else: + module_info['variant_version'] = module_str_first_part + module_info['variant_id'] = module_str[:section_start] module_info['variant_type'] = 'module' return module_info diff --git a/tests/test_pkgset_source_koji.py b/tests/test_pkgset_source_koji.py index ab01b00c..d2b43516 100644 --- a/tests/test_pkgset_source_koji.py +++ b/tests/test_pkgset_source_koji.py @@ -6,6 +6,7 @@ import os import sys import unittest import json +import re sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..")) @@ -198,5 +199,28 @@ class TestSourceKoji(helpers.PungiTestCase): [mock.call('koji')]) +class TestCorrectNVR(helpers.PungiTestCase): + + def setUp(self): + super(TestCorrectNVR, self).setUp() + self.nv = "base-runtime-f26" + self.nvr = "base-runtime-f26-20170502134116" + self.release_regex = re.compile("^(\d){14}$") + + def test_nv(self): + module_info = source_koji.variant_dict_from_str(self.nv) + expectedKeys = ["variant_version", "variant_id", "variant_type"] + self.assertItemsEqual(module_info.keys(), expectedKeys) + + def test_nvr(self): + module_info = source_koji.variant_dict_from_str(self.nvr) + expectedKeys = ["variant_version", "variant_id", "variant_type", "variant_release"] + self.assertItemsEqual(module_info.keys(), expectedKeys) + + def test_correct_release(self): + module_info = source_koji.variant_dict_from_str(self.nvr) + self.assertIsNotNone(self.release_regex.match(module_info["variant_release"])) + + if __name__ == "__main__": unittest.main()