From 7d5804051531147298085d4db1b81ffd4b3c10c6 Mon Sep 17 00:00:00 2001 From: Tiago Gomes Date: Mon, 7 Dec 2015 10:36:28 +0000 Subject: morphloader: remove unset functions Change-Id: I2a9177245e8cd4eac54ef8a2079eaed2e98e88e7 --- morphlib/morphloader.py | 50 --------------------- morphlib/morphloader_tests.py | 100 ------------------------------------------ 2 files changed, 150 deletions(-) diff --git a/morphlib/morphloader.py b/morphlib/morphloader.py index fef56ca3..05ffd0b8 100644 --- a/morphlib/morphloader.py +++ b/morphlib/morphloader.py @@ -685,21 +685,6 @@ class MorphologyLoader(object): getattr(self, '_set_%s_defaults' % kind)(morphology) - def unset_defaults(self, morphology): - '''If a field is equal to its default, delete it. - - The morphology is assumed to be valid. - - ''' - - kind = morphology['kind'] - defaults = self._static_defaults[kind] - for key in defaults: - if key in morphology and morphology[key] == defaults[key]: - del morphology[key] - - getattr(self, '_unset_%s_defaults' % kind)(morphology) - def _set_cluster_defaults(self, morph): for system in morph.get('systems', []): if 'deploy-defaults' not in system: @@ -707,19 +692,9 @@ class MorphologyLoader(object): if 'deploy' not in system: system['deploy'] = {} - def _unset_cluster_defaults(self, morph): - for system in morph.get('systems', []): - if 'deploy-defaults' in system and system['deploy-defaults'] == {}: - del system['deploy-defaults'] - if 'deploy' in system and system['deploy'] == {}: - del system['deploy'] - def _set_system_defaults(self, morph): pass - def _unset_system_defaults(self, morph): - pass - def _set_stratum_defaults(self, morph): for spec in morph['chunks']: if 'repo' not in spec: @@ -731,35 +706,10 @@ class MorphologyLoader(object): spec['prefix'] = \ self._static_defaults['chunk']['prefix'] - def _unset_stratum_defaults(self, morph): - for spec in morph['chunks']: - if 'repo' in spec and spec['repo'] == spec['name']: - del spec['repo'] - if 'build-mode' in spec and spec['build-mode'] == \ - self._static_defaults['chunk']['build-mode']: - del spec['build-mode'] - if 'prefix' in spec and spec['prefix'] == \ - self._static_defaults['chunk']['prefix']: - del spec['prefix'] - def _set_chunk_defaults(self, morph): if morph['max-jobs'] is not None: morph['max-jobs'] = int(morph['max-jobs']) - def _unset_chunk_defaults(self, morph): # pragma: no cover - # This is only used by the deprecated branch-and-merge plugin, and - # probably doesn't work correctly for definitions V7 and newer. - default_bs = self._static_defaults['chunk']['build-system'] - bs_name = morph.get('build-system', default_bs) - bs = self.lookup_build_system(bs_name) - for key in self._static_defaults['chunk']: - if key not in morph: continue - if 'commands' not in key: continue - attr = key.replace('-', '_') - default_value = getattr(bs, attr) - if morph[key] == default_value: - del morph[key] - def lookup_build_system(self, name): return self._predefined_build_systems[name] diff --git a/morphlib/morphloader_tests.py b/morphlib/morphloader_tests.py index 4500a563..3d9e5fbb 100644 --- a/morphlib/morphloader_tests.py +++ b/morphlib/morphloader_tests.py @@ -574,20 +574,6 @@ build-system: manual 'prefix': '/usr', }) - def test_unsets_defaults_for_chunks(self): - m = morphlib.morphology.Morphology({ - 'kind': 'chunk', - 'name': 'foo', - 'build-system': 'manual', - }) - self.loader.unset_defaults(m) - self.assertEqual( - dict(m), - { - 'kind': 'chunk', - 'name': 'foo', - }) - def test_sets_defaults_for_strata(self): m = morphlib.morphology.Morphology({ 'kind': 'stratum', @@ -626,28 +612,6 @@ build-system: manual 'products': [], }) - def test_unsets_defaults_for_strata(self): - test_dict = { - 'kind': 'stratum', - 'name': 'foo', - 'chunks': [ - { - 'name': 'bar', - "ref": "bar", - 'build-mode': 'staging', - 'build-depends': [], - 'prefix': '/usr', - }, - ], - } - test_dict_with_build_depends = dict(test_dict) - test_dict_with_build_depends["build-depends"] = [] - m = morphlib.morphology.Morphology(test_dict_with_build_depends) - self.loader.unset_defaults(m) - self.assertEqual( - dict(m), - test_dict) - def test_sets_defaults_for_system(self): m = morphlib.morphology.Morphology( kind='system', @@ -674,32 +638,6 @@ build-system: manual }, dict(m)) - def test_unsets_defaults_for_system(self): - m = morphlib.morphology.Morphology( - { - 'description': '', - 'kind': 'system', - 'name': 'foo', - 'arch': 'testarch', - 'strata': [ - { - 'morph': 'bar', - }, - ], - 'configuration-extensions': [], - }) - self.loader.unset_defaults(m) - self.assertEqual( - dict(m), - { - 'kind': 'system', - 'name': 'foo', - 'arch': 'testarch', - 'strata': [ - {'morph': 'bar'}, - ], - }) - def test_sets_defaults_for_cluster(self): m = morphlib.morphology.Morphology( name='foo', @@ -717,24 +655,6 @@ build-system: manual 'deploy-defaults': {}, 'deploy': {}}]) - def test_unsets_defaults_for_cluster(self): - m = morphlib.morphology.Morphology( - name='foo', - kind='cluster', - description='', - systems=[ - {'morph': 'foo', - 'deploy-defaults': {}, - 'deploy': {}}, - {'morph': 'bar', - 'deploy-defaults': {}, - 'deploy': {}}]) - self.loader.unset_defaults(m) - self.assertNotIn('description', m) - self.assertEqual(m['systems'], - [{'morph': 'foo'}, - {'morph': 'bar'}]) - def test_sets_stratum_chunks_repo_from_name(self): m = morphlib.morphology.Morphology( { @@ -754,26 +674,6 @@ build-system: manual self.loader.validate(m) self.assertEqual(m['chunks'][0]['repo'], 'le-chunk') - def test_collapses_stratum_chunks_repo_from_name(self): - m = morphlib.morphology.Morphology( - { - "name": "foo", - "kind": "stratum", - "chunks": [ - { - "name": "le-chunk", - "repo": "le-chunk", - "morph": "le-chunk", - "ref": "ref", - "build-system": "manual", - "build-depends": [], - } - ] - }) - - self.loader.unset_defaults(m) - self.assertTrue('repo' not in m['chunks'][0]) - def test_convertes_max_jobs_to_an_integer(self): m = morphlib.morphology.Morphology( { -- cgit v1.2.1