Move cluster template schema definition to is own file

Moving the schema definition to another file allows it to be
imported without unnecessary dependencies. This allows a
default template CLI tool to use the schema for validation
without extra baggage.

Partial-implements: blueprint default-templates
Change-Id: I2fcd8d3c461f11b8f0d387b2a25d91d5de2419a7
This commit is contained in:
Trevor McKay 2015-03-06 18:10:06 -05:00
parent f88a627f49
commit 594428b57d
7 changed files with 116 additions and 97 deletions

View File

@ -18,6 +18,7 @@ from oslo_log import log as logging
from sahara.api import acl
from sahara.service import api
from sahara.service import validation as v
from sahara.service.validations import cluster_template_schema as ct_schema
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
@ -86,7 +87,8 @@ def cluster_templates_list():
@rest.post('/cluster-templates')
@acl.enforce("cluster-templates:create")
@v.validate(v_ct.CLUSTER_TEMPLATE_SCHEMA, v_ct.check_cluster_template_create)
@v.validate(ct_schema.CLUSTER_TEMPLATE_SCHEMA,
v_ct.check_cluster_template_create)
def cluster_templates_create(data):
return u.render(api.create_cluster_template(data).to_wrapped_dict())
@ -102,7 +104,7 @@ def cluster_templates_get(cluster_template_id):
@rest.put('/cluster-templates/<cluster_template_id>')
@acl.enforce("cluster-templates:modify")
@v.check_exists(api.get_cluster_template, 'cluster_template_id')
@v.validate(v_ct.CLUSTER_TEMPLATE_UPDATE_SCHEMA,
@v.validate(ct_schema.CLUSTER_TEMPLATE_UPDATE_SCHEMA,
v_ct.check_cluster_template_update)
def cluster_templates_update(cluster_template_id, data):
return u.render(

View File

@ -0,0 +1,102 @@
# 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
from sahara.service.validations import node_group_template_schema as ngt_schema
def _build_ng_schema_for_cluster_tmpl():
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']
del cl_tmpl_ng_schema['properties']['hadoop_version']
del cl_tmpl_ng_schema['properties']['plugin_name']
return cl_tmpl_ng_schema
_cluster_tmpl_ng_schema = _build_ng_schema_for_cluster_tmpl()
def _build_ng_tmpl_schema_for_cluster_template():
cl_tmpl_ng_tmpl_schema = copy.deepcopy(_cluster_tmpl_ng_schema)
cl_tmpl_ng_tmpl_schema['properties'].update(
{
"node_group_template_id": {
"type": "string",
"format": "uuid",
}
})
cl_tmpl_ng_tmpl_schema["required"] = ["node_group_template_id",
"name", "count"]
return cl_tmpl_ng_tmpl_schema
_cluster_tmpl_ng_tmpl_schema = _build_ng_tmpl_schema_for_cluster_template()
CLUSTER_TEMPLATE_SCHEMA = {
"type": "object",
"properties": {
"name": {
"type": "string",
"minLength": 1,
"maxLength": 50,
"format": "valid_name_hostname",
},
"plugin_name": {
"type": "string",
},
"hadoop_version": {
"type": "string",
},
"default_image_id": {
"type": "string",
"format": "uuid",
},
"cluster_configs": {
"type": "configs",
},
"node_groups": {
"type": "array",
"items": {
"oneOf": [_cluster_tmpl_ng_tmpl_schema,
_cluster_tmpl_ng_schema]
}
},
"anti_affinity": {
"type": "array",
"items": {
"type": "string",
},
},
"description": {
"type": "string",
},
"neutron_management_network": {
"type": "string",
"format": "uuid"
},
},
"additionalProperties": False,
"required": [
"name",
"plugin_name",
"hadoop_version",
]
}
CLUSTER_TEMPLATE_UPDATE_SCHEMA = copy.copy(CLUSTER_TEMPLATE_SCHEMA)
CLUSTER_TEMPLATE_UPDATE_SCHEMA["required"] = []

View File

@ -13,98 +13,11 @@
# 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 _
from sahara.service import api
import sahara.service.validations.base as b
import sahara.service.validations.node_group_template_schema as ngt_schema
def _build_ng_schema_for_cluster_tmpl():
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']
del cl_tmpl_ng_schema['properties']['hadoop_version']
del cl_tmpl_ng_schema['properties']['plugin_name']
return cl_tmpl_ng_schema
_cluster_tmpl_ng_schema = _build_ng_schema_for_cluster_tmpl()
def _build_ng_tmpl_schema_for_cluster_template():
cl_tmpl_ng_tmpl_schema = copy.deepcopy(_cluster_tmpl_ng_schema)
cl_tmpl_ng_tmpl_schema['properties'].update(
{
"node_group_template_id": {
"type": "string",
"format": "uuid",
}
})
cl_tmpl_ng_tmpl_schema["required"] = ["node_group_template_id",
"name", "count"]
return cl_tmpl_ng_tmpl_schema
_cluster_tmpl_ng_tmpl_schema = _build_ng_tmpl_schema_for_cluster_template()
CLUSTER_TEMPLATE_SCHEMA = {
"type": "object",
"properties": {
"name": {
"type": "string",
"minLength": 1,
"maxLength": 50,
"format": "valid_name_hostname",
},
"plugin_name": {
"type": "string",
},
"hadoop_version": {
"type": "string",
},
"default_image_id": {
"type": "string",
"format": "uuid",
},
"cluster_configs": {
"type": "configs",
},
"node_groups": {
"type": "array",
"items": {
"oneOf": [_cluster_tmpl_ng_tmpl_schema,
_cluster_tmpl_ng_schema]
}
},
"anti_affinity": {
"type": "array",
"items": {
"type": "string",
},
},
"description": {
"type": "string",
},
"neutron_management_network": {
"type": "string",
"format": "uuid"
},
},
"additionalProperties": False,
"required": [
"name",
"plugin_name",
"hadoop_version",
]
}
CLUSTER_TEMPLATE_UPDATE_SCHEMA = copy.copy(CLUSTER_TEMPLATE_SCHEMA)
CLUSTER_TEMPLATE_UPDATE_SCHEMA["required"] = []
def check_cluster_template_create(data, **kwargs):

View File

@ -21,14 +21,14 @@ import sahara.exceptions as ex
from sahara.i18n import _
import sahara.service.api as api
import sahara.service.validations.base as b
import sahara.service.validations.cluster_templates as cl_tmpl
import sahara.service.validations.cluster_template_schema as ct_schema
CONF = cfg.CONF
def _build_cluster_schema():
cluster_schema = copy.deepcopy(cl_tmpl.CLUSTER_TEMPLATE_SCHEMA)
cluster_schema = copy.deepcopy(ct_schema.CLUSTER_TEMPLATE_SCHEMA)
cluster_schema['properties'].update({
"is_transient": {
"type": "boolean"

View File

@ -20,11 +20,11 @@ from sahara.i18n import _
import sahara.plugins.base as plugin_base
import sahara.service.api as api
import sahara.service.validations.base as b
import sahara.service.validations.cluster_templates as cl_t
import sahara.service.validations.cluster_template_schema as ct_schema
def _build_node_groups_schema():
schema = copy.deepcopy(cl_t.CLUSTER_TEMPLATE_SCHEMA)
schema = copy.deepcopy(ct_schema.CLUSTER_TEMPLATE_SCHEMA)
return schema['properties']['node_groups']

View File

@ -14,6 +14,7 @@
# limitations under the License.
from sahara.service import api
from sahara.service.validations import cluster_template_schema as ct_schema
from sahara.service.validations import cluster_templates as ct
from sahara.tests.unit.service.validation import utils as u
@ -22,7 +23,7 @@ class TestClusterTemplateCreateValidation(u.ValidationTestCase):
def setUp(self):
super(TestClusterTemplateCreateValidation, self).setUp()
self._create_object_fun = ct.check_cluster_template_create
self.scheme = ct.CLUSTER_TEMPLATE_SCHEMA
self.scheme = ct_schema.CLUSTER_TEMPLATE_SCHEMA
api.plugin_base.setup_plugins()
def test_cluster_template_create_v_cluster_configs(self):

View File

@ -16,6 +16,7 @@
import copy
from sahara.service import api
from sahara.service.validations import cluster_template_schema as ct_schema
from sahara.service.validations import cluster_templates as ct
from sahara.tests.unit.service.validation import utils as u
@ -31,7 +32,7 @@ class TestClusterTemplateUpdateValidation(u.ValidationTestCase):
def setUp(self):
super(TestClusterTemplateUpdateValidation, self).setUp()
self._create_object_fun = ct.check_cluster_template_update
self.scheme = ct.CLUSTER_TEMPLATE_UPDATE_SCHEMA
self.scheme = ct_schema.CLUSTER_TEMPLATE_UPDATE_SCHEMA
api.plugin_base.setup_plugins()
def test_cluster_template_update_nothing_required(self):
@ -40,8 +41,8 @@ class TestClusterTemplateUpdateValidation(u.ValidationTestCase):
)
def test_cluster_template_update_schema(self):
create = copy.copy(ct.CLUSTER_TEMPLATE_SCHEMA)
update = copy.copy(ct.CLUSTER_TEMPLATE_UPDATE_SCHEMA)
create = copy.copy(ct_schema.CLUSTER_TEMPLATE_SCHEMA)
update = copy.copy(ct_schema.CLUSTER_TEMPLATE_UPDATE_SCHEMA)
# No required items for update
self.assertEqual(update["required"], [])