Move node group template schema definition to its own file

Moving the schema definition to another file allows it to be
imported without unnecessary dependencies.

Partial-implements: blueprint default-templates
Change-Id: Ic2b8fcb94b51be854edcd52f22bb2aa2a8af2ff2
This commit is contained in:
Trevor McKay 2015-03-12 10:06:29 -04:00
parent 3814c2796e
commit f88a627f49
6 changed files with 114 additions and 98 deletions

View File

@ -22,6 +22,7 @@ from sahara.service.validations import cluster_templates as v_ct
from sahara.service.validations import clusters as v_c
from sahara.service.validations import clusters_scaling as v_c_s
from sahara.service.validations import images as v_images
from sahara.service.validations import node_group_template_schema as ngt_schema
from sahara.service.validations import node_group_templates as v_ngt
from sahara.service.validations import plugins as v_p
import sahara.utils.api as u
@ -131,7 +132,7 @@ def node_group_templates_list():
@rest.post('/node-group-templates')
@acl.enforce("node-group-templates:create")
@v.validate(v_ngt.NODE_GROUP_TEMPLATE_SCHEMA,
@v.validate(ngt_schema.NODE_GROUP_TEMPLATE_SCHEMA,
v_ngt.check_node_group_template_create)
def node_group_templates_create(data):
return u.render(api.create_node_group_template(data).to_wrapped_dict())
@ -148,7 +149,7 @@ def node_group_templates_get(node_group_template_id):
@rest.put('/node-group-templates/<node_group_template_id>')
@acl.enforce("node-group-templates:modify")
@v.check_exists(api.get_node_group_template, 'node_group_template_id')
@v.validate(v_ngt.NODE_GROUP_TEMPLATE_UPDATE_SCHEMA,
@v.validate(ngt_schema.NODE_GROUP_TEMPLATE_UPDATE_SCHEMA,
v_ngt.check_node_group_template_update)
def node_group_templates_update(node_group_template_id, data):
return u.render(

View File

@ -19,11 +19,11 @@ from sahara import exceptions as ex
from sahara.i18n import _
from sahara.service import api
import sahara.service.validations.base as b
import sahara.service.validations.node_group_templates as ng_tml
import sahara.service.validations.node_group_template_schema as ngt_schema
def _build_ng_schema_for_cluster_tmpl():
cl_tmpl_ng_schema = copy.deepcopy(ng_tml.NODE_GROUP_TEMPLATE_SCHEMA)
cl_tmpl_ng_schema = copy.deepcopy(ngt_schema.NODE_GROUP_TEMPLATE_SCHEMA)
cl_tmpl_ng_schema['properties'].update({"count": {"type": "integer"}})
cl_tmpl_ng_schema["required"] = ['name', 'flavor_id',
'node_processes', 'count']

View File

@ -0,0 +1,106 @@
# Copyright (c) 2013 Mirantis Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import copy
NODE_GROUP_TEMPLATE_SCHEMA = {
"type": "object",
"properties": {
"name": {
"type": "string",
"minLength": 1,
"maxLength": 50,
"format": "valid_name_hostname",
},
"flavor_id": {
'type': 'flavor',
},
"plugin_name": {
"type": "string",
},
"hadoop_version": {
"type": "string",
},
"node_processes": {
"type": "array",
"items": {
"type": "string",
},
"minItems": 1
},
"image_id": {
"type": "string",
"format": "uuid",
},
"node_configs": {
"type": "configs",
},
"volumes_per_node": {
"type": "integer",
"minimum": 0,
},
"volumes_size": {
"type": "integer",
"minimum": 1,
},
"volume_type": {
"type": "string"
},
"volumes_availability_zone": {
"type": "string",
},
"volume_mount_prefix": {
"type": "string",
"format": "posix_path",
},
"description": {
"type": "string",
},
"floating_ip_pool": {
"type": "string",
},
"security_groups": {
"type": "array",
"items": {
"type": "string",
},
},
"auto_security_group": {
"type": "boolean"
},
"availability_zone": {
"type": "string",
},
"is_proxy_gateway": {
"type": "boolean"
},
"volume_local_to_instance": {
"type": "boolean"
},
},
"additionalProperties": False,
"required": [
"name",
"flavor_id",
"plugin_name",
"hadoop_version",
"node_processes",
]
}
# For an update we do not require any fields but we want the given
# fields to be validated
NODE_GROUP_TEMPLATE_UPDATE_SCHEMA = copy.copy(NODE_GROUP_TEMPLATE_SCHEMA)
NODE_GROUP_TEMPLATE_UPDATE_SCHEMA["required"] = []

View File

@ -13,7 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import copy
from sahara import exceptions as ex
from sahara.i18n import _
@ -21,97 +20,6 @@ from sahara.service import api
import sahara.service.validations.base as b
NODE_GROUP_TEMPLATE_SCHEMA = {
"type": "object",
"properties": {
"name": {
"type": "string",
"minLength": 1,
"maxLength": 50,
"format": "valid_name_hostname",
},
"flavor_id": {
'type': 'flavor',
},
"plugin_name": {
"type": "string",
},
"hadoop_version": {
"type": "string",
},
"node_processes": {
"type": "array",
"items": {
"type": "string",
},
"minItems": 1
},
"image_id": {
"type": "string",
"format": "uuid",
},
"node_configs": {
"type": "configs",
},
"volumes_per_node": {
"type": "integer",
"minimum": 0,
},
"volumes_size": {
"type": "integer",
"minimum": 1,
},
"volume_type": {
"type": "string"
},
"volumes_availability_zone": {
"type": "string",
},
"volume_mount_prefix": {
"type": "string",
"format": "posix_path",
},
"description": {
"type": "string",
},
"floating_ip_pool": {
"type": "string",
},
"security_groups": {
"type": "array",
"items": {
"type": "string",
},
},
"auto_security_group": {
"type": "boolean"
},
"availability_zone": {
"type": "string",
},
"is_proxy_gateway": {
"type": "boolean"
},
"volume_local_to_instance": {
"type": "boolean"
},
},
"additionalProperties": False,
"required": [
"name",
"flavor_id",
"plugin_name",
"hadoop_version",
"node_processes",
]
}
# For an update we do not require any fields but we want the given
# fields to be validated
NODE_GROUP_TEMPLATE_UPDATE_SCHEMA = copy.copy(NODE_GROUP_TEMPLATE_SCHEMA)
NODE_GROUP_TEMPLATE_UPDATE_SCHEMA["required"] = []
def check_node_group_template_create(data, **kwargs):
b.check_node_group_template_unique_name(data['name'])
b.check_plugin_name_exists(data['plugin_name'])

View File

@ -14,6 +14,7 @@
# limitations under the License.
from sahara.service import api
from sahara.service.validations import node_group_template_schema as ngt_schema
from sahara.service.validations import node_group_templates as nt
from sahara.tests.unit.service.validation import utils as u
@ -22,7 +23,7 @@ class TestNGTemplateCreateValidation(u.ValidationTestCase):
def setUp(self):
super(TestNGTemplateCreateValidation, self).setUp()
self._create_object_fun = nt.check_node_group_template_create
self.scheme = nt.NODE_GROUP_TEMPLATE_SCHEMA
self.scheme = ngt_schema.NODE_GROUP_TEMPLATE_SCHEMA
api.plugin_base.setup_plugins()
def test_node_groups_create_required(self):

View File

@ -16,7 +16,7 @@
import copy
from sahara.service import api
from sahara.service.validations import node_group_templates as nt
from sahara.service.validations import node_group_template_schema as nt
from sahara.tests.unit.service.validation import utils as u