From 9b02605370f6b1d159f0bb4911daec53c2c96bc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Kadl=C4=8D=C3=ADk?= Date: Mon, 27 Feb 2017 21:03:20 +0100 Subject: [PATCH 1/5] Fix format_mmd function for empty scmurl --- module_build_service/utils.py | 28 ++++++++++++++-------------- tests/test_utils/test_utils.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 14 deletions(-) diff --git a/module_build_service/utils.py b/module_build_service/utils.py index aae2b7f7..51c2fb0a 100644 --- a/module_build_service/utils.py +++ b/module_build_service/utils.py @@ -444,23 +444,23 @@ def format_mmd(mmd, scmurl): # them because of dep-chain. from module_build_service.scm import SCM - mmd.xmd['mbs'] = {'scmurl': scmurl} + mmd.xmd['mbs'] = {'scmurl': scmurl, 'commit': None} - scm = SCM(scmurl) - # If a commit hash is provided, add that information to the modulemd - if scm.commit: - # We want to make sure we have the full commit hash for consistency - if SCM.is_full_commit_hash(scm.scheme, scm.commit): - full_scm_hash = scm.commit - else: - full_scm_hash = scm.get_full_commit_hash() - - mmd.xmd['mbs']['commit'] = full_scm_hash - # If a commit hash wasn't provided then just get the latest from master - else: + # If module build was submitted via yaml file, there is no scmurl + if scmurl: scm = SCM(scmurl) - mmd.xmd['mbs']['commit'] = scm.get_latest() + # If a commit hash is provided, add that information to the modulemd + if scm.commit: + # We want to make sure we have the full commit hash for consistency + if SCM.is_full_commit_hash(scm.scheme, scm.commit): + full_scm_hash = scm.commit + else: + full_scm_hash = scm.get_full_commit_hash() + mmd.xmd['mbs']['commit'] = full_scm_hash + # If a commit hash wasn't provided then just get the latest from master + else: + mmd.xmd['mbs']['commit'] = scm.get_latest() # If the modulemd yaml specifies module buildrequires, replace the streams # with commit hashes diff --git a/tests/test_utils/test_utils.py b/tests/test_utils/test_utils.py index 3337d6ed..8cd37fd6 100644 --- a/tests/test_utils/test_utils.py +++ b/tests/test_utils/test_utils.py @@ -115,6 +115,35 @@ class TestUtils(unittest.TestCase): } self.assertEqual(mmd.xmd, xmd) + @vcr.use_cassette( + path.join(CASSETTES_DIR, 'tests.test_utils.TestUtils.test_format_mmd')) + @patch('module_build_service.scm.SCM') + def test_format_mmd_empty_scmurl(self, mocked_scm): + # For all the RPMs in testmodule, get_latest is called + mocked_scm.return_value.get_latest.side_effect = [ + '4ceea43add2366d8b8c5a622a2fb563b625b9abf', + 'fbed359411a1baa08d4a88e0d12d426fbf8f602c', + '76f9d8c8e87eed0aab91034b01d3d5ff6bd5b4cb'] + + mmd = modulemd.ModuleMetadata() + with open(path.join(BASE_DIR, '..', 'staged_data', 'testmodule.yaml')) \ + as mmd_file: + mmd.loads(mmd_file) + + module_build_service.utils.format_mmd(mmd, scmurl=None) + xmd = { + 'mbs': { + 'commit': None, + 'buildrequires': { + 'base-runtime': { + 'ref': 'ae993ba84f4bce554471382ccba917ef16265f11', + 'stream': 'master', + 'version': '3'}}, + 'scmurl': None, + } + } + self.assertEqual(mmd.xmd, xmd) + def test_get_reusable_component_same(self): test_reuse_component_init_data() new_module = models.ModuleBuild.query.filter_by(id=2).one() From 95dee6c46351f271d45166147dc342a3646d6f70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Kadl=C4=8D=C3=ADk?= Date: Fri, 17 Mar 2017 11:29:25 +0100 Subject: [PATCH 2/5] Not fail when 'ref' is missing --- module_build_service/utils.py | 5 +++-- tests/test_utils/test_utils.py | 13 +++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/module_build_service/utils.py b/module_build_service/utils.py index 51c2fb0a..1bac207a 100644 --- a/module_build_service/utils.py +++ b/module_build_service/utils.py @@ -767,8 +767,9 @@ def get_reusable_component(session, module, component_name): # Assumes that the streams have been replaced with commit hashes, so we # can compare to see if they have changed. Since a build is unique to # a commit hash, this is a safe test. - if br_module['ref'] != \ - old_mmd.xmd['mbs']['buildrequires'][br_module_name]['ref']: + ref1 = br_module.get('ref') + ref2 = old_mmd.xmd['mbs']['buildrequires'][br_module_name].get('ref') + if not (ref1 and ref2) or ref1 != ref2: return None # At this point we've determined that both module builds depend(ed) on the diff --git a/tests/test_utils/test_utils.py b/tests/test_utils/test_utils.py index 8cd37fd6..6dbc9817 100644 --- a/tests/test_utils/test_utils.py +++ b/tests/test_utils/test_utils.py @@ -151,6 +151,19 @@ class TestUtils(unittest.TestCase): db.session, new_module, 'tangerine') self.assertEqual(rv.package, 'tangerine') + def test_get_reusable_component_empty_scmurl(self): + test_reuse_component_init_data() + + new_module = models.ModuleBuild.query.filter_by(id=2).one() + mmd = new_module.mmd() + mmd.xmd['mbs']['buildrequires'] = {'base-runtime': {}} + new_module.modulemd = mmd.dumps() + db.session.commit() + + rv = module_build_service.utils.get_reusable_component( + db.session, new_module, 'tangerine') + self.assertEqual(rv, None) + def test_get_reusable_component_different_perl_tangerine(self): test_reuse_component_init_data() second_module_build = models.ModuleBuild.query.filter_by(id=2).one() From d13adc81df8d83cd2536dc2af3bdaaad6c82bd56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Kadl=C4=8D=C3=ADk?= Date: Mon, 20 Mar 2017 19:51:50 +0100 Subject: [PATCH 3/5] Filter only module builds with scmurl --- module_build_service/utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/module_build_service/utils.py b/module_build_service/utils.py index 1bac207a..59f87377 100644 --- a/module_build_service/utils.py +++ b/module_build_service/utils.py @@ -729,6 +729,7 @@ def get_reusable_component(session, module, component_name): previous_module_build = session.query(models.ModuleBuild)\ .filter_by(name=mmd.name)\ .filter(models.ModuleBuild.state.in_([3, 5]))\ + .filter(models.ModuleBuild.scmurl.isnot(None))\ .order_by(models.ModuleBuild.time_completed.desc())\ .first() # The component can't be reused if there isn't a previous build in the done From 81ff98cfedbc7313ee6ca0e4738e3fd5c2f4ab59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Kadl=C4=8D=C3=ADk?= Date: Tue, 21 Mar 2017 11:29:27 +0100 Subject: [PATCH 4/5] Not fail when there is no scmurl --- module_build_service/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module_build_service/utils.py b/module_build_service/utils.py index 59f87377..6e7c8a5c 100644 --- a/module_build_service/utils.py +++ b/module_build_service/utils.py @@ -475,7 +475,7 @@ def format_mmd(mmd, scmurl): 'version': module_stream} commit_hash, version = get_module_commit_hash_and_version( pdc, module_info) - if commit_hash and version: + if version and (commit_hash or not scmurl): mmd.xmd['mbs']['buildrequires'][module_name] = { 'ref': commit_hash, 'stream': mmd.buildrequires[module_name], From 2c3e47d1d589851d11078a89edfe4a64019054f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Kadl=C4=8D=C3=ADk?= Date: Tue, 28 Mar 2017 16:01:48 +0200 Subject: [PATCH 5/5] Update version and ref for base-runtime --- tests/test_utils/test_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_utils/test_utils.py b/tests/test_utils/test_utils.py index 6dbc9817..52cd3baa 100644 --- a/tests/test_utils/test_utils.py +++ b/tests/test_utils/test_utils.py @@ -136,9 +136,9 @@ class TestUtils(unittest.TestCase): 'commit': None, 'buildrequires': { 'base-runtime': { - 'ref': 'ae993ba84f4bce554471382ccba917ef16265f11', + 'ref': 'abffed45ca33d7fe94fff8253b5bfe1d87e786b2', 'stream': 'master', - 'version': '3'}}, + 'version': '20170315134803'}}, 'scmurl': None, } }