diff options
author | Adam Coldrick <adam.coldrick@codethink.co.uk> | 2014-05-22 15:28:06 +0000 |
---|---|---|
committer | Adam Coldrick <adam.coldrick@codethink.co.uk> | 2014-06-18 14:46:58 +0000 |
commit | 6b1bf6c586ed2304c39f6d8572f08f62c1743368 (patch) | |
tree | 91948108b8b0d53916bcca273fdc16088eafb3fc /morphlib | |
parent | 5bf3a96bd125548f058907001904b552f952e279 (diff) | |
download | morph-6b1bf6c586ed2304c39f6d8572f08f62c1743368.tar.gz |
Validate cluster morphologies
The names of deployments in cluster morphologies will need to be unique
in order for the deployment of selected systems to work.
Diffstat (limited to 'morphlib')
-rw-r--r-- | morphlib/morphloader.py | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/morphlib/morphloader.py b/morphlib/morphloader.py index ca5902a6..b5c8168d 100644 --- a/morphlib/morphloader.py +++ b/morphlib/morphloader.py @@ -205,6 +205,15 @@ class MultipleValidationErrors(morphlib.Error): self.msg += ('\t' + str(error)) +class DuplicateDeploymentNameError(morphlib.Error): + + def __init__(self, duplicates): + self.duplicates = duplicates + morphlib.Error.__init__( + self, 'Cluster morphology contains the following non-unique ' + 'deployment names:\n%s' % '\n '.join(duplicates)) + + class OrderedDumper(yaml.SafeDumper): keyorder = ( 'name', @@ -412,7 +421,23 @@ class MorphologyLoader(object): getattr(self, '_validate_%s' % kind)(morph) def _validate_cluster(self, morph): - pass + # Deployment names must be unique within a cluster + deployments = collections.Counter() + for system in morph['systems']: + deployments.update(system['deploy'].iterkeys()) + if 'subsystems' in system: + deployments.update(self._get_subsystem_names(system)) + duplicates = set(deployment for deployment, count + in deployments.iteritems() if count > 1) + if duplicates: + raise DuplicateDeploymentNameError(duplicates) + + def _get_subsystem_names(self, system): # pragma: no cover + for subsystem in system.get('subsystems', []): + for name in subsystem['deploy'].iterkeys(): + yield name + for name in self._get_subsystem_names(subsystem): + yield name def _validate_system(self, morph): # A system must contain at least one stratum |