Added first Savanna Controller level validation

* It checks if user configs has wrong applicable targtes and config names

Change-Id: Ie8979103e888696e2f16654abd910ffdd281d7d8
NOTE: This is just for simplifying testing purposes and maybe changed soon
This commit is contained in:
Alexander Ignatov
2013-06-14 10:40:47 -07:00
parent 56513f6895
commit 1a446b3081

View File

@@ -34,6 +34,7 @@ def create_cluster(values):
plugin = plugin_base.PLUGINS.get_plugin(cluster.plugin_name)
# TODO(slukjanov): validate configs and etc.
_validate(cluster, plugin)
# validating cluster
cluster.status = 'Validating'
@@ -119,3 +120,25 @@ def convert_to_cluster_template(plugin_name, version, config_file):
raise RuntimeError("Plugin doesn't convert config file")
return s.persist_cluster_template(cluster_template)
def _validate(cluster, plugin):
# Validate that user configs are not included in plugin configs set
pl_confs = {}
for config in plugin.get_configs(cluster.hadoop_version):
if pl_confs.get(config.applicable_target):
pl_confs[config.applicable_target].append(config.name)
else:
pl_confs[config.applicable_target] = [config.name]
for ng in cluster.node_groups:
for app_target, configs in ng.configuration.items():
if app_target not in pl_confs:
raise RuntimeError("Plugin doesn't contain applicable "
"target '%s'" % app_target)
for name, values in configs.items():
if name not in pl_confs[app_target]:
raise RuntimeError("Plugin's applicable target '%s' "
"doesn't contain config with name '%s'"
% (app_target, name))