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-05-23 16:32:53 +0000 |
commit | 005d4a4889cc477e97f82afe8ec4e71ca6f302b4 (patch) | |
tree | 0a7f4f585ffa095084c082390bfdd15378a212ac | |
parent | dfea805382476e3725ab6f830bdd8dbbaf8af0bc (diff) | |
download | morph-005d4a4889cc477e97f82afe8ec4e71ca6f302b4.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 | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/morphlib/morphloader.py b/morphlib/morphloader.py index ca5902a6..3af87468 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,14 @@ 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()) + duplicates = set(deployment for deployment, count + in deployments.iteritems() if count > 1) + if duplicates: + raise DuplicateDeploymentNameError(duplicates) def _validate_system(self, morph): # A system must contain at least one stratum |