]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Handle list properties that do not contain objects
authorZane Bitter <zbitter@redhat.com>
Tue, 30 Oct 2012 20:50:00 +0000 (21:50 +0100)
committerZane Bitter <zbitter@redhat.com>
Mon, 5 Nov 2012 17:02:17 +0000 (18:02 +0100)
The previous implementation of schema verfication on properties required
that the schema for the contents of a property list always be a map. Now
this is specified explicitly, so that in theory a property could also be a
list of Strings or Integers.

Change-Id: Icdd9a6c9f9b1e884f959c74f0803b7f3bd2aecc4
Signed-off-by: Zane Bitter <zbitter@redhat.com>
heat/engine/resources/autoscaling.py
heat/engine/resources/instance.py
heat/engine/resources/loadbalancer.py
heat/engine/resources/properties.py
heat/engine/resources/quantum/port.py
heat/engine/resources/quantum/subnet.py
heat/tests/test_properties.py

index a5161a88c597afc99ad4ca1f21b26b86e305e815..40c79189da15a9b68fc8ff0c7f86210030e428c9 100644 (file)
@@ -43,8 +43,8 @@ class AutoScalingGroup(resource.Resource):
                             'AllowedValues': ['EC2', 'ELB'],
                             'Implemented': False},
         'LoadBalancerNames': {'Type': 'List'},
-        'Tags': {'Type': 'List',
-                 'Schema': tags_schema}
+        'Tags': {'Type': 'List', 'Schema': {'Type': 'Map',
+                                            'Schema': tags_schema}}
     }
 
     def __init__(self, name, json_snippet, stack):
@@ -163,7 +163,8 @@ class LaunchConfiguration(resource.Resource):
         'BlockDeviceMappings': {'Type': 'String',
                                 'Implemented': False},
         'NovaSchedulerHints': {'Type': 'List',
-                               'Schema': tags_schema},
+                               'Schema': {'Type': 'Map',
+                                          'Schema': tags_schema}},
     }
 
     def __init__(self, name, json_snippet, stack):
index c6697a8665186b4df959bad7f488812375ee8278..6f9f2264dad3cf9b77c72f573b654ef57bd1a48f 100644 (file)
@@ -94,9 +94,13 @@ class Instance(resource.Resource):
                          'SubnetId': {'Type': 'String',
                                        'Implemented': False},
                          'Tags': {'Type': 'List',
-                                  'Schema': tags_schema},
+                                  'Schema': {'Type': 'Map',
+                                             'Schema': tags_schema}},
                          'NovaSchedulerHints': {'Type': 'List',
-                                                'Schema': tags_schema},
+                                                'Schema': {
+                                                    'Type': 'Map',
+                                                    'Schema': tags_schema
+                                                }},
                          'Tenancy': {'Type': 'String',
                                      'AllowedValues': ['dedicated', 'default'],
                                      'Implemented': False},
index 4e955cefd906aeced6c288f1d634f2606ebab836..534f1f1e427e3976389022d65138906e14fa592a 100644 (file)
@@ -192,7 +192,8 @@ class LoadBalancer(stack.Stack):
                         'Schema': healthcheck_schema},
         'Instances': {'Type': 'List'},
         'Listeners': {'Type': 'List',
-                      'Schema': listeners_schema},
+                      'Schema': {'Type': 'Map',
+                                 'Schema': listeners_schema}},
         'AppCookieStickinessPolicy': {'Type': 'String',
                                       'Implemented': False},
         'LBCookieStickinessPolicy': {'Type': 'String',
index dfd912ec5a7147042f1bd09d06629eef370cae83..3ef80e4bde7b9fab2b2a8b7c705a6ae92fc4aed6 100644 (file)
@@ -110,7 +110,7 @@ class Property(object):
             self._check_allowed(v)
 
         if SCHEMA in self.schema:
-            prop = Property({TYPE: MAP, SCHEMA: self.schema[SCHEMA]})
+            prop = Property(self.schema[SCHEMA])
             children = [prop.validate_data(d) for d in value]
         else:
             children = value
index 939040f9ba6a200bd04a83532fb169e639689c62..d12e6755f77ee27e525f5792a0ec8a8d13338d7c 100644 (file)
@@ -33,7 +33,8 @@ class Port(quantum.QuantumResource):
                                        'Default': {}},
                         'admin_state_up': {'Default': True},
                         'fixed_ips': {'Type': 'List',
-                                    'Schema': fixed_ip_schema},
+                                      'Schema': {'Type': 'Map',
+                                                 'Schema': fixed_ip_schema}},
                         'mac_address': {'Type': 'String'},
                         'device_id': {'Type': 'String'},
     }
index 90c6a02bcc212a0fa8f5beef5ee0f2c081312301..83f4be3bcd0929628ec953ad86a3cd088ce6d20a 100644 (file)
@@ -41,7 +41,10 @@ class Subnet(quantum.QuantumResource):
                                       'Default': 4},
                         'gateway_ip': {'Type': 'String'},
                         'allocation_pools': {'Type': 'List',
-                                           'Schema': allocation_schema}
+                                             'Schema': {
+                                                 'Type': 'Map',
+                                                 'Schema': allocation_schema
+                                             }}
     }
 
     def __init__(self, name, json_snippet, stack):
index 361b977a0bc4d2db248eab075f34e5a1ee116736..564c73a8f5822a2e89bcd9c8d6e4faa0cd14597c 100644 (file)
@@ -231,7 +231,8 @@ class PropertyTest(unittest.TestCase):
 
     def test_list_schema_good(self):
         map_schema = {'valid': {'Type': 'Boolean'}}
-        p = properties.Property({'Type': 'List', 'Schema': map_schema})
+        list_schema = {'Type': 'Map', 'Schema': map_schema}
+        p = properties.Property({'Type': 'List', 'Schema': list_schema})
         self.assertEqual(p.validate_data([{'valid': 'TRUE'},
                                           {'valid': 'False'}]),
                                          [{'valid': 'true'},
@@ -239,10 +240,21 @@ class PropertyTest(unittest.TestCase):
 
     def test_list_schema_bad_data(self):
         map_schema = {'valid': {'Type': 'Boolean'}}
-        p = properties.Property({'Type': 'List', 'Schema': map_schema})
+        list_schema = {'Type': 'Map', 'Schema': map_schema}
+        p = properties.Property({'Type': 'List', 'Schema': list_schema})
         self.assertRaises(ValueError, p.validate_data, [{'valid': 'True'},
                                                         {'valid': 'fish'}])
 
+    def test_list_schema_int_good(self):
+        list_schema = {'Type': 'Integer'}
+        p = properties.Property({'Type': 'List', 'Schema': list_schema})
+        self.assertEqual(p.validate_data([1, 2, 3]), [1, 2, 3])
+
+    def test_list_schema_int_bad_data(self):
+        list_schema = {'Type': 'Integer'}
+        p = properties.Property({'Type': 'List', 'Schema': list_schema})
+        self.assertRaises(TypeError, p.validate_data, [42, 'fish'])
+
 
 @attr(tag=['unit', 'properties'])
 @attr(speed='fast')