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-11 12:49:25 +0000 |
commit | 01c350a1b33e2eb40f2241d5b98ae17da96d598a (patch) | |
tree | 10cf8d1b786e731254bfe0aabe3173d4738ccc59 | |
parent | 6513aaa1202602873ad00f0b13ed341e21ca8f25 (diff) | |
download | morph-01c350a1b33e2eb40f2241d5b98ae17da96d598a.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.
-rw-r--r-- | morphlib/morphloader.py | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/morphlib/morphloader.py b/morphlib/morphloader.py index ca5902a6..1f8a18de 100644 --- a/morphlib/morphloader.py +++ b/morphlib/morphloader.py @@ -205,6 +205,14 @@ class MultipleValidationErrors(morphlib.Error): self.msg += ('\t' + str(error)) +class DuplicateDeploymentNameError(morphlib.Error): + + def __init__(self, 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 +420,22 @@ 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 system.get('subsystems'): + self._get_subsystem_names(system, deployments) + duplicates = set(deployment for deployment, count + in deployments.iteritems() if count > 1) + if duplicates: + raise DuplicateDeploymentNameError(duplicates) + + def _get_subsystem_names(self, system, names): # pragma: no cover + for subsystem in system.get('subsystems', []): + names.update(subsystem['deploy'].iterkeys()) + if subsystem.get('subsystems'): + self._get_subsystem_names(subsystem, names) def _validate_system(self, morph): # A system must contain at least one stratum |