]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Generate property Schema objects directly from parameters
authorZane Bitter <zbitter@redhat.com>
Mon, 19 Aug 2013 18:51:45 +0000 (20:51 +0200)
committerZane Bitter <zbitter@redhat.com>
Wed, 21 Aug 2013 14:53:32 +0000 (16:53 +0200)
Use Schema.from_parameter() instead of Property.schema_from_param() to
generate a property schema from a parameter schema.

Change-Id: I1049822057d954ddbb47027aad136f7b45541943

heat/engine/properties.py
heat/tests/test_properties.py

index 6937c4ff0b850ffcd674c0f2ad9ba2ad93114f9c..ea6f12dd63dd91bdf60102501033753368c19928 100644 (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 {}
 
index aa737fd0f2dc6ef17066bf3bbe2b88a2e9943ec9..33c98884ebccf7ea6ffb64aba366bcbfd305ac7e 100644 (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):