diff --git a/module_build_service/utils.py b/module_build_service/utils.py index 5fc1ffc2..94d9e407 100644 --- a/module_build_service/utils.py +++ b/module_build_service/utils.py @@ -337,16 +337,31 @@ def _fetch_mmd(url, allow_local_url = False): mmd = load_mmd(yaml) - # If undefined, set the name field to VCS repo name. - if not mmd.name and scm: + # If the name was set in the modulemd, make sure it matches what the scmurl + # says it should be + if mmd.name and mmd.name != scm.name: + raise ValidationError('The name "{0}" that is stored in the modulemd ' + 'is not valid'.format(mmd.name)) + else: mmd.name = scm.name - # If undefined, set the stream field to the VCS branch name. - if not mmd.stream and scm: + # If the stream was set in the modulemd, make sure it matches what the repo + # branch is + if mmd.stream and mmd.stream != scm.branch: + raise ValidationError('The stream "{0}" that is stored in the modulemd ' + 'does not match the branch "{1}"'.format( + mmd.stream, scm.branch)) + else: mmd.stream = scm.branch - # If undefined, set the version field to int represenation of VCS commit. - if not mmd.version and scm: + # If the version is in the modulemd, throw an exception since the version + # is generated by pdc-updater + if mmd.version: + raise ValidationError('The version "{0}" is already defined in the ' + 'modulemd but it shouldn\'t be since the version ' + 'is generated based on the commit time'.format( + mmd.version)) + else: mmd.version = int(scm.version) return mmd, scm, yaml diff --git a/tests/staged_data/fakemodule.yaml b/tests/staged_data/fakemodule.yaml index b6fd102e..63401dce 100644 --- a/tests/staged_data/fakemodule.yaml +++ b/tests/staged_data/fakemodule.yaml @@ -1,8 +1,6 @@ document: modulemd version: 1 data: - name: fakemodule - version: 5 summary: A fake module containing the bash shell description: > A fake module used for testing diff --git a/tests/staged_data/includedmodules.yaml b/tests/staged_data/includedmodules.yaml index 3d3c79d9..5c0cc43e 100644 --- a/tests/staged_data/includedmodules.yaml +++ b/tests/staged_data/includedmodules.yaml @@ -1,9 +1,6 @@ document: modulemd version: 1 data: - name: fakemodule - stream: "4.3.44" - version: 5 summary: A fake module containing the bash shell description: > A fake module used for testing diff --git a/tests/staged_data/testmodule-version-set.yaml b/tests/staged_data/testmodule-version-set.yaml new file mode 100644 index 00000000..246f6911 --- /dev/null +++ b/tests/staged_data/testmodule-version-set.yaml @@ -0,0 +1,37 @@ +document: modulemd +version: 1 +data: + summary: A test module in all its beauty + description: This module demonstrates how to write simple modulemd files And can be used for testing the build and release pipeline. + version: 0123456789 + license: + module: [ MIT ] + dependencies: + buildrequires: + base-runtime: master + requires: + base-runtime: master + references: + community: https://fedoraproject.org/wiki/Modularity + documentation: https://fedoraproject.org/wiki/Fedora_Packaging_Guidelines_for_Modules + tracker: https://taiga.fedorainfracloud.org/project/modularity + profiles: + default: + rpms: + - tangerine + api: + rpms: + - perl-Tangerine + - tangerine + components: + rpms: + perl-List-Compare: + rationale: A dependency of tangerine. + ref: f25 + perl-Tangerine: + rationale: Provides API for this module and is a dependency of tangerine. + ref: f25 + tangerine: + rationale: Provides API for this module. + buildorder: 10 + ref: f25 diff --git a/tests/staged_data/testmodule-wrong-name.yaml b/tests/staged_data/testmodule-wrong-name.yaml new file mode 100644 index 00000000..abdb9094 --- /dev/null +++ b/tests/staged_data/testmodule-wrong-name.yaml @@ -0,0 +1,37 @@ +document: modulemd +version: 1 +data: + name: wrong_name + summary: A test module in all its beauty + description: This module demonstrates how to write simple modulemd files And can be used for testing the build and release pipeline. + license: + module: [ MIT ] + dependencies: + buildrequires: + base-runtime: master + requires: + base-runtime: master + references: + community: https://fedoraproject.org/wiki/Modularity + documentation: https://fedoraproject.org/wiki/Fedora_Packaging_Guidelines_for_Modules + tracker: https://taiga.fedorainfracloud.org/project/modularity + profiles: + default: + rpms: + - tangerine + api: + rpms: + - perl-Tangerine + - tangerine + components: + rpms: + perl-List-Compare: + rationale: A dependency of tangerine. + ref: f25 + perl-Tangerine: + rationale: Provides API for this module and is a dependency of tangerine. + ref: f25 + tangerine: + rationale: Provides API for this module. + buildorder: 10 + ref: f25 diff --git a/tests/staged_data/testmodule-wrong-stream.yaml b/tests/staged_data/testmodule-wrong-stream.yaml new file mode 100644 index 00000000..87705aa2 --- /dev/null +++ b/tests/staged_data/testmodule-wrong-stream.yaml @@ -0,0 +1,37 @@ +document: modulemd +version: 1 +data: + stream: wrong_stream + summary: A test module in all its beauty + description: This module demonstrates how to write simple modulemd files And can be used for testing the build and release pipeline. + license: + module: [ MIT ] + dependencies: + buildrequires: + base-runtime: master + requires: + base-runtime: master + references: + community: https://fedoraproject.org/wiki/Modularity + documentation: https://fedoraproject.org/wiki/Fedora_Packaging_Guidelines_for_Modules + tracker: https://taiga.fedorainfracloud.org/project/modularity + profiles: + default: + rpms: + - tangerine + api: + rpms: + - perl-Tangerine + - tangerine + components: + rpms: + perl-List-Compare: + rationale: A dependency of tangerine. + ref: f25 + perl-Tangerine: + rationale: Provides API for this module and is a dependency of tangerine. + ref: f25 + tangerine: + rationale: Provides API for this module. + buildorder: 10 + ref: f25 diff --git a/tests/test_views/test_views.py b/tests/test_views/test_views.py index 204d6118..e90cabba 100644 --- a/tests/test_views/test_views.py +++ b/tests/test_views/test_views.py @@ -267,10 +267,9 @@ class TestViews(unittest.TestCase): self.assertEquals(data['scmurl'], ('git://pkgs.stg.fedoraproject.org/modules/testmodule' '.git?#68931c90de214d9d13feefbd35246a81b6cb8d49')) - self.assertEquals(data['version'], '5') + self.assertEquals(data['version'], '1') self.assertTrue(data['time_submitted'] is not None) self.assertTrue(data['time_modified'] is not None) - self.assertEquals(data['version'], '5') self.assertEquals(data['time_completed'], None) self.assertEquals(data['stream'], 'master') self.assertEquals(data['owner'], 'Homer J. Simpson') @@ -395,16 +394,15 @@ class TestViews(unittest.TestCase): assert 'component_builds' in data, data self.assertEquals(data['component_builds'], [61, 62, 63, 64]) - self.assertEquals(data['name'], 'fakemodule') + self.assertEquals(data['name'], 'includedmodules') self.assertEquals(data['scmurl'], ('git://pkgs.stg.fedoraproject.org/modules/testmodule' '.git?#68931c90de214d9d13feefbd35246a81b6cb8d49')) - self.assertEquals(data['version'], '5') + self.assertEquals(data['version'], '1') self.assertTrue(data['time_submitted'] is not None) self.assertTrue(data['time_modified'] is not None) - self.assertEquals(data['version'], '5') self.assertEquals(data['time_completed'], None) - self.assertEquals(data['stream'], '4.3.44') + self.assertEquals(data['stream'], 'master') self.assertEquals(data['owner'], 'Homer J. Simpson') self.assertEquals(data['id'], 31) self.assertEquals(data['state_name'], 'wait') @@ -474,3 +472,38 @@ class TestViews(unittest.TestCase): ) self.assertEquals(data['status'], 401) self.assertEquals(data['error'], 'Unauthorized') + + @patch('module_build_service.auth.get_user', return_value=user) + @patch('module_build_service.scm.SCM') + def test_submit_build_version_set_error(self, mocked_scm, mocked_get_user): + MockedSCM(mocked_scm, 'testmodule', 'testmodule-version-set.yaml', + '620ec77321b2ea7b0d67d82992dda3e1d67055b4') + + rv = self.client.post('/module-build-service/1/module-builds/', data=json.dumps( + {'scmurl': 'git://pkgs.stg.fedoraproject.org/modules/' + 'testmodule.git?#68931c90de214d9d13feefbd35246a81b6cb8d49'})) + data = json.loads(rv.data) + self.assertEquals(data['status'], 400) + self.assertEquals( + data['message'], + 'The version "123456789" is already defined in the modulemd but ' + 'it shouldn\'t be since the version is generated based on the ' + 'commit time') + self.assertEquals(data['error'], 'Bad Request') + + @patch('module_build_service.auth.get_user', return_value=user) + @patch('module_build_service.scm.SCM') + def test_submit_build_wrong_stream(self, mocked_scm, mocked_get_user): + MockedSCM(mocked_scm, 'testmodule', 'testmodule-wrong-stream.yaml', + '620ec77321b2ea7b0d67d82992dda3e1d67055b4') + + rv = self.client.post('/module-build-service/1/module-builds/', data=json.dumps( + {'scmurl': 'git://pkgs.stg.fedoraproject.org/modules/' + 'testmodule.git?#68931c90de214d9d13feefbd35246a81b6cb8d49'})) + data = json.loads(rv.data) + self.assertEquals(data['status'], 400) + self.assertEquals( + data['message'], + 'The stream "wrong_stream" that is stored in the modulemd does not ' + 'match the branch "master"') + self.assertEquals(data['error'], 'Bad Request')