From: Zane Bitter Date: Mon, 19 Aug 2013 18:51:45 +0000 (+0200) Subject: Generate property Schema objects directly from parameters X-Git-Tag: 2014.1~156^2 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=5769f8f31cb0c3173ec2775e61396d549a77383f;p=openstack-build%2Fheat-build.git 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 --- diff --git a/heat/engine/properties.py b/heat/engine/properties.py index 6937c4ff..ea6f12dd 100644 --- a/heat/engine/properties.py +++ b/heat/engine/properties.py @@ -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 {} diff --git a/heat/tests/test_properties.py b/heat/tests/test_properties.py index aa737fd0..33c98884 100644 --- a/heat/tests/test_properties.py +++ b/heat/tests/test_properties.py @@ -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):