diff options
author | Tiago Gomes <tiago.gomes@codethink.co.uk> | 2013-08-16 08:56:00 +0000 |
---|---|---|
committer | Tiago Gomes <tiago.gomes@codethink.co.uk> | 2013-08-16 13:05:18 +0000 |
commit | 10a788b3642608de1c0ecc7a41055f950c0652dd (patch) | |
tree | 587e3438b5acd5e2566b00102cec29369efb0ba2 /morphlib | |
parent | 2514eb9717ab6f8161d1fb403ca2bfff9e1169ea (diff) | |
download | morph-10a788b3642608de1c0ecc7a41055f950c0652dd.tar.gz |
Add support for a `cluster` type of morphology.
Add the necessary tests to keep CoverageTestRunner happy.
Diffstat (limited to 'morphlib')
-rw-r--r-- | morphlib/morph2.py | 38 | ||||
-rw-r--r-- | morphlib/morph2_tests.py | 58 | ||||
-rw-r--r-- | morphlib/plugins/branch_and_merge_plugin.py | 9 |
3 files changed, 103 insertions, 2 deletions
diff --git a/morphlib/morph2.py b/morphlib/morph2.py index d949c696..a733ce77 100644 --- a/morphlib/morph2.py +++ b/morphlib/morph2.py @@ -60,7 +60,8 @@ class Morphology(object): ('arch', None), ('system-kind', None), ('configuration-extensions', []), - ] + ], + 'cluster': [] } @staticmethod @@ -129,6 +130,27 @@ class Morphology(object): if name in names: raise ValueError('Duplicate chunk "%s"' % name) names.add(name) + elif self['kind'] == 'cluster': + if not 'systems' in self: + raise KeyError('"systems" not found') + if not self['systems']: + raise ValueError('"systems" is empty') + for system in self['systems']: + if 'morph' not in system: + raise KeyError('"morph" not found') + if 'deploy-defaults' in system: + if not isinstance(system['deploy-defaults'], dict): + raise ValueError('deploy defaults for morph "%s" ' + 'are not a mapping: %r' + % (system['morph'], + system['deploy-defaults'])) + if 'deploy' in system: + for system_id, deploy_params in system['deploy'].items(): + if not isinstance(deploy_params, dict): + raise ValueError('deployment parameters for ' + 'system "%s" are not a mapping:' + ' %r' + % (system_id, deploy_params)) def _set_default_value(self, target_dict, key, value): '''Change a value in the in-memory representation of the morphology @@ -157,6 +179,8 @@ class Morphology(object): if self['kind'] == 'stratum': self._set_stratum_defaults() + elif self['kind'] == 'cluster': + self._set_cluster_defaults() def _set_stratum_defaults(self): for source in self['chunks']: @@ -171,6 +195,18 @@ class Morphology(object): if 'prefix' not in source: self._set_default_value(source, 'prefix', '/usr') + def _set_cluster_defaults(self): + if 'systems' in self and self['systems']: + for system in self['systems']: + if 'deploy-defaults' not in system: + self._set_default_value(system, + 'deploy-defaults', + dict()) + if 'deploy' not in system: + self._set_default_value(system, + 'deploy', + dict()) + def _parse_size(self, size): if isinstance(size, basestring): size = size.lower() diff --git a/morphlib/morph2_tests.py b/morphlib/morph2_tests.py index 9de23e56..bf32d3c2 100644 --- a/morphlib/morph2_tests.py +++ b/morphlib/morph2_tests.py @@ -379,3 +379,61 @@ class MorphologyTests(unittest.TestCase): ''') cmds = m.get_commands('build-commands') self.assertEqual(cmds, []) + + ## Cluster morphologies tests + + def test_parses_simple_cluster_morph(self): + m = Morphology(''' + name: foo + kind: cluster + systems: + - morph: bar + ''') + self.assertEqual(m['name'], 'foo') + self.assertEqual(m['kind'], 'cluster') + self.assertEqual(m['systems'][0]['morph'], 'bar') + + def test_fails_without_systems(self): + text = ''' + name: foo + kind: cluster + ''' + self.assertRaises(KeyError, Morphology, text) + + def test_fails_with_empty_systems(self): + text = ''' + name: foo + kind: cluster + systems: + ''' + self.assertRaises(ValueError, Morphology, text) + + def test_fails_without_morph(self): + text = ''' + name: foo + kind: cluster + systems: + - deploy: + ''' + self.assertRaises(KeyError, Morphology, text) + + def test_fails_with_invalid_deploy_defaults(self): + text = ''' + name: foo + kind: cluster + systems: + - morph: bar + deploy-defaults: ooops_i_am_not_a_mapping + ''' + self.assertRaises(ValueError, Morphology, text) + + def test_fails_with_invalid_deployment_params(self): + text = ''' + name: foo + kind: cluster + systems: + - morph: bar + deploy: + qux: ooops_i_am_not_a_mapping + ''' + self.assertRaises(ValueError, Morphology, text) diff --git a/morphlib/plugins/branch_and_merge_plugin.py b/morphlib/plugins/branch_and_merge_plugin.py index 38b882a0..85e74501 100644 --- a/morphlib/plugins/branch_and_merge_plugin.py +++ b/morphlib/plugins/branch_and_merge_plugin.py @@ -349,7 +349,11 @@ class BranchAndMergePlugin(cliapp.Plugin): ], 'chunk': [ 'name', - ] + ], + 'cluster': [ + 'name', + 'systems', + ], } also_known = { @@ -376,6 +380,9 @@ class BranchAndMergePlugin(cliapp.Plugin): 'max-jobs', 'chunks', 'devices', + ], + 'cluster': [ + 'kind' ] } |