From 01c350a1b33e2eb40f2241d5b98ae17da96d598a Mon Sep 17 00:00:00 2001 From: Adam Coldrick Date: Thu, 22 May 2014 15:28:06 +0000 Subject: 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. --- morphlib/morphloader.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) 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 -- cgit v1.2.1