diff options
author | Richard Maw <richard.maw@codethink.co.uk> | 2013-08-07 12:14:41 +0000 |
---|---|---|
committer | Richard Maw <richard.maw@codethink.co.uk> | 2013-08-07 13:41:40 +0100 |
commit | edc50cf457a92575a22e202e648d64b0ef1a3527 (patch) | |
tree | ab32524630bf0b3480761ef2c3a338b054ce29f8 /morphlib | |
parent | 131d8744eb68c75deb491fb3ce39c83851c64ae3 (diff) | |
download | morph-edc50cf457a92575a22e202e648d64b0ef1a3527.tar.gz |
morphologyfactory: validate stratum build-depends
A stratum morphology must either have stratum build-depends, or
have some bootstrap chunks, otherwise there's no way to have the
required set of commands to be able to build chunks.
A concession has been made to also allow strata that contain chunks
built in test mode, but this opens a reproducibility hole.
Unit tests for these failures have been added, and the stratum
used by other unit tests has been fixed.
Diffstat (limited to 'morphlib')
-rw-r--r-- | morphlib/morphologyfactory.py | 12 | ||||
-rw-r--r-- | morphlib/morphologyfactory_tests.py | 43 |
2 files changed, 55 insertions, 0 deletions
diff --git a/morphlib/morphologyfactory.py b/morphlib/morphologyfactory.py index fa71e820..ae5a4332 100644 --- a/morphlib/morphologyfactory.py +++ b/morphlib/morphologyfactory.py @@ -54,6 +54,13 @@ class EmptyStratumError(StratumError): "Stratum %s is empty (has no dependencies)" % stratum) +class NoStratumBuildDependsError(StratumError): + def __init__(self, stratum): + StratumError.__init__( + self, 'Stratum %s has no build-dependencies listed ' + 'and has no bootstrap chunks.' % stratum) + + class MorphologyFactory(object): '''An way of creating morphologies which will provide a default''' @@ -162,6 +169,11 @@ class MorphologyFactory(object): name = source.get('name', source.get('repo', 'unknown')) raise NoChunkBuildDependsError(filename, name) + if (len(morphology['build-depends'] or []) == 0 and + not any(c.get('build-mode') in ('bootstrap', 'test') + for c in morphology['chunks'])): + raise NoStratumBuildDependsError(filename) + morphology.builds_artifacts = [morphology['name']] morphology.needs_artifact_metadata_cached = True diff --git a/morphlib/morphologyfactory_tests.py b/morphlib/morphologyfactory_tests.py index de1be017..06489085 100644 --- a/morphlib/morphologyfactory_tests.py +++ b/morphlib/morphologyfactory_tests.py @@ -63,6 +63,7 @@ class FakeLocalRepo(object): "name": "chunk", "repo": "test:repo", "ref": "sha1", + "build-mode": "bootstrap", "build-depends": [] } ] @@ -79,6 +80,37 @@ class FakeLocalRepo(object): } ] }''', + 'stratum-no-bdeps-no-bootstrap.morph': '''{ + "name": "stratum-no-bdeps-no-bootstrap", + "kind": "stratum", + "chunks": [ + { + "name": "chunk", + "repo": "test:repo", + "ref": "sha1", + "build-depends": [] + } + ] + }''', + 'stratum-bdeps-no-bootstrap.morph': '''{ + "name": "stratum-bdeps-no-bootstrap", + "kind": "stratum", + "build-depends": [ + { + "repo": "test:repo", + "ref": "sha1", + "morph": "stratum" + } + ], + "chunks": [ + { + "name": "chunk", + "repo": "test:repo", + "ref": "sha1", + "build-depends": [] + } + ] + }''', 'stratum-empty.morph': '''{ "name": "stratum-empty", "kind": "stratum" @@ -290,6 +322,17 @@ class MorphologyFactoryTests(unittest.TestCase): self.mf.get_morphology, 'reponame', 'sha1', 'stratum-no-chunk-bdeps.morph') + def test_fails_on_no_bdeps_or_bootstrap(self): + self.assertRaises( + morphlib.morphologyfactory.NoStratumBuildDependsError, + self.mf.get_morphology, 'reponame', 'sha1', + 'stratum-no-bdeps-no-bootstrap.morph') + + def test_succeeds_on_bdeps_no_bootstrap(self): + self.mf.get_morphology( + 'reponame', 'sha1', + 'stratum-bdeps-no-bootstrap.morph') + def test_fails_on_empty_stratum(self): self.assertRaises( morphlib.morphologyfactory.EmptyStratumError, |