Validation checks improvements

* Check if cluster template exists
* Check if image is registered

Fixes: bug #1199975

Change-Id: I9665958ef9ffcd4fbdb7fd70722b52de43db5ad2
This commit is contained in:
Alexander Ignatov 2013-07-10 23:51:06 +04:00
parent ede0f4a57a
commit 3b17811a75
3 changed files with 15 additions and 10 deletions

View File

@ -46,12 +46,9 @@ def check_plugin_supports_version(p_name, version):
" version '%s'" % (p_name, version))
def check_image_exists(image_id):
try:
# TODO(aignatov): Check supported images by plugin instead of it
api.get_image(id=image_id)
except nova_ex.NotFound:
raise ex.InvalidException("Requested image '%s' not found"
def check_image_registered(image_id):
if image_id not in [i.id for i in nova.client().images.list_registered()]:
raise ex.InvalidException("Requested image '%s' is not registered"
% image_id)
@ -104,7 +101,7 @@ def check_node_group_basic_fields(plugin_name, hadoop_version, ng,
check_node_processes(plugin_name, hadoop_version, ng['node_processes'])
if ng.get('image_id'):
check_image_exists(ng['image_id'])
check_image_registered(ng['image_id'])
def check_flavor_exists(flavor_id):
@ -151,7 +148,7 @@ def check_keypair_exists(keypair):
raise ex.InvalidException("Requested keypair '%s' not found" % keypair)
## Cluster templates creation related checks
## Cluster templates related checks
def check_cluster_template_unique_name(name):
if name in [t.name for t in api.get_cluster_templates()]:
@ -159,6 +156,12 @@ def check_cluster_template_unique_name(name):
" already exists" % name)
def check_cluster_template_exists(cluster_template_id):
if not api.get_cluster_templates(id=cluster_template_id):
raise ex.InvalidException("Cluster template with id '%s'"
" doesn't exist" % cluster_template_id)
## NodeGroup templates related checks
def check_node_group_template_unique_name(name):

View File

@ -103,7 +103,7 @@ def check_cluster_template_create(data, **kwargs):
data['hadoop_version'])
if data.get('default_image_id'):
b.check_image_exists(data['default_image_id'])
b.check_image_registered(data['default_image_id'])
b.check_all_configurations(data)

View File

@ -41,12 +41,14 @@ def check_cluster_create(data, **kwargs):
b.check_plugin_name_exists(data['plugin_name'])
b.check_plugin_supports_version(data['plugin_name'],
data['hadoop_version'])
if data.get('cluster_template_id'):
b.check_cluster_template_exists(data['cluster_template_id'])
if data.get('user_keypair_id'):
b.check_keypair_exists(data['user_keypair_id'])
if data.get('default_image_id'):
b.check_image_exists(data['default_image_id'])
b.check_image_registered(data['default_image_id'])
b.check_all_configurations(data)