Enforce that the mmd can't define a different module name, stream, or version

This commit is contained in:
Matt Prahl
2017-02-24 10:37:40 -05:00
parent 8b83e78394
commit 56d6d90ece
7 changed files with 171 additions and 17 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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')