Generate property Schema objects directly from parameters

Use Schema.from_parameter() instead of Property.schema_from_param() to
generate a property schema from a parameter schema.

Change-Id: I1049822057d954ddbb47027aad136f7b45541943
This commit is contained in:
Zane Bitter 2013-08-19 20:51:45 +02:00
parent 01924a501f
commit 5769f8f31c
2 changed files with 68 additions and 48 deletions

View File

@ -643,7 +643,7 @@ class Properties(collections.Mapping):
:returns: an equivalent properties schema for the specified params
"""
if params_snippet:
return dict((k, Property.schema_from_param(v)) for k, v
return dict((n, Schema.from_parameter(p)) for n, p
in params_snippet.items())
return {}

View File

@ -1170,69 +1170,89 @@ class PropertiesTest(testtools.TestCase):
}
expected = {
"DBUsername": {
"Default": "admin",
"AllowedPattern": "[a-zA-Z][a-zA-Z0-9]*",
"MaxLength": "16",
"Type": "String",
"MinLength": "1"
"type": "string",
"description": "The WordPress database admin account username",
"required": False,
"constraints": [
{"length": {"min": 1, "max": 16}},
{"allowed_pattern": "[a-zA-Z][a-zA-Z0-9]*",
"description": "must begin with a letter and contain "
"only alphanumeric characters."},
]
},
"LinuxDistribution": {
"Default": "F17",
"Type": "String",
"AllowedValues": [
"F18",
"F17",
"U10",
"RHEL-6.1",
"RHEL-6.2",
"RHEL-6.3"
"type": "string",
"description": "Distribution of choice",
"required": False,
"constraints": [
{"allowed_values": ["F18", "F17", "U10",
"RHEL-6.1", "RHEL-6.2", "RHEL-6.3"]}
]
},
"InstanceType": {
"Default": "m1.large",
"Type": "String",
"AllowedValues": [
"t1.micro",
"m1.small",
"m1.large",
"m1.xlarge",
"m2.xlarge",
"m2.2xlarge",
"m2.4xlarge",
"c1.medium",
"c1.xlarge",
"cc1.4xlarge"
"type": "string",
"description": "WebServer EC2 instance type",
"required": False,
"constraints": [
{"allowed_values": ["t1.micro",
"m1.small",
"m1.large",
"m1.xlarge",
"m2.xlarge",
"m2.2xlarge",
"m2.4xlarge",
"c1.medium",
"c1.xlarge",
"cc1.4xlarge"],
"description": "must be a valid EC2 instance type."},
]
},
"DBRootPassword": {
"Default": "admin",
"AllowedPattern": "[a-zA-Z0-9]*",
"MaxLength": "41",
"Type": "String",
"MinLength": "1"
"type": "string",
"description": "Root password for MySQL",
"required": False,
"constraints": [
{"length": {"min": 1, "max": 41}},
{"allowed_pattern": "[a-zA-Z0-9]*",
"description": "must contain only alphanumeric "
"characters."},
]
},
"KeyName": {
"Required": "true",
"Type": "String"
"type": "string",
"description": ("Name of an existing EC2 KeyPair to enable "
"SSH access to the instances"),
"required": True,
},
"DBPassword": {
"Default": "admin",
"AllowedPattern": "[a-zA-Z0-9]*",
"MaxLength": "41",
"Type": "String",
"MinLength": "1"
"type": "string",
"description": "The WordPress database admin account password",
"required": False,
"constraints": [
{"length": {"min": 1, "max": 41}},
{"allowed_pattern": "[a-zA-Z0-9]*",
"description": "must contain only alphanumeric "
"characters."},
]
},
"DBName": {
"Default": "wordpress",
"AllowedPattern": "[a-zA-Z][a-zA-Z0-9]*",
"MaxLength": "64",
"Type": "String",
"MinLength": "1"
}
"type": "string",
"description": "The WordPress database name",
"required": False,
"constraints": [
{"length": {"min": 1, "max": 64}},
{"allowed_pattern": "[a-zA-Z][a-zA-Z0-9]*",
"description": "must begin with a letter and contain "
"only alphanumeric characters."},
]
},
}
params = dict((n, parameters.ParamSchema(s)) for n, s
in params_snippet.items())
props_schemata = properties.Properties.schema_from_params(params)
self.assertEqual(expected,
(properties.Properties
.schema_from_params(params_snippet)))
dict((n, dict(s)) for n, s in props_schemata.items()))
class PropertiesValidationTest(testtools.TestCase):