From 19a4dc127cf2a4969ba8d9b88bb425024e193826 Mon Sep 17 00:00:00 2001 From: Matthew Farrellee Date: Mon, 17 Feb 2014 13:56:20 -0500 Subject: [PATCH] Expand node-group-template usage validation msg Now that we have a CLI, the error messages returned from validation are presented directly to the user. Currently, node group templates cannot be deleted if they are in use. This change expands the error message to tell the user where the node group templates are in use. Change-Id: I3764aa6730db52f2a313626054c941eb3a9723bc --- .../validations/node_group_templates.py | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/savanna/service/validations/node_group_templates.py b/savanna/service/validations/node_group_templates.py index c5704b62..720bc489 100644 --- a/savanna/service/validations/node_group_templates.py +++ b/savanna/service/validations/node_group_templates.py @@ -90,17 +90,25 @@ def check_node_group_template_create(data, **kwargs): def check_node_group_template_usage(node_group_template_id, **kwargs): - node_groups = [] + cluster_users = [] + template_users = [] for cluster in api.get_clusters(): - node_groups += cluster.node_groups + if (node_group_template_id in + [node_group.node_group_template_id + for node_group in cluster.node_groups]): + cluster_users += [cluster.name] for cluster_template in api.get_cluster_templates(): - node_groups += cluster_template.node_groups + if (node_group_template_id in + [node_group.node_group_template_id + for node_group in cluster_template.node_groups]): + template_users += [cluster_template.name] - node_group_template_ids = set([node_group.node_group_template_id - for node_group in node_groups]) - - if node_group_template_id in node_group_template_ids: + if cluster_users or template_users: raise ex.InvalidException( - "Node group template %s in use" % node_group_template_id) + "Node group template %s is in use by " + "cluster templates: %s; and clusters: %s" % + (node_group_template_id, + template_users and ', '.join(template_users) or 'N/A', + cluster_users and ', '.join(cluster_users) or 'N/A'))