]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
validate_template returns whole Parameters snippet
authorSteve Baker <sbaker@redhat.com>
Wed, 20 Mar 2013 03:52:49 +0000 (16:52 +1300)
committerSteve Baker <sbaker@redhat.com>
Sun, 24 Mar 2013 20:59:19 +0000 (09:59 +1300)
Currently the engine validate_template returns cfn formatted
Parameters from the template, which isn't actually very useful
to build a full UI from a validate call.

This change returns the original Parameters template snippet
and changes the cfn api to reformat to the CFN API legacy format.

The Parameters section of the RPC and the REST APIs now return
a dictionary containing the parameters as specified in the template.
Previously the Parameters section contained a list in the CFN API
format.

Pseudo parameters are filtered out of the validate results.

Change-Id: Iea53dc847ff13f5f479ec3a66bcf141c4ccaeb25
Fixes: bug #1157537
heat/api/cfn/v1/stacks.py
heat/engine/service.py
heat/rpc/api.py
heat/tests/test_validate.py

index 413e32394ae42cbce8d0ba1bc6b7f8a07e893bf1..9a171991983eefa16cfd99b6c4203ca50f031fd6 100644 (file)
@@ -403,8 +403,23 @@ class StackController(object):
             return exception.HeatInvalidParameterValueError(detail=msg)
 
         logger.info('validate_template')
+
+        def format_validate_parameter(key, value):
+            """
+            Reformat engine output into the AWS "ValidateTemplate" format
+            """
+
+            return {
+                'ParameterKey': key,
+                'DefaultValue': value.get(engine_api.PARAM_DEFAULT, ''),
+                'Description': value.get(engine_api.PARAM_DESCRIPTION, ''),
+                'NoEcho': value.get(engine_api.PARAM_NO_ECHO, 'false')
+            }
+
         try:
             res = self.engine_rpcapi.validate_template(con, template)
+            res['Parameters'] = [format_validate_parameter(k, v)
+                                 for k, v in res['Parameters'].items()]
             return api_utils.format_response('ValidateTemplate', res)
         except rpc_common.RemoteError as ex:
             return exception.map_remote_error(ex)
index b56cf83aab503b7839609c9bac819ca6f651a114..efd962c1ac115c51a58d160e50c5d618fe8a5414 100644 (file)
@@ -26,6 +26,7 @@ from heat.engine import clients
 from heat.engine.event import Event
 from heat.common import exception
 from heat.common import identifier
+from heat.engine import parameters
 from heat.engine import parser
 from heat.engine import resource
 from heat.engine import resources  # pyflakes_bypass review 23102
@@ -286,20 +287,14 @@ class EngineService(service.Service):
                 return {'Error':
                         'Every Resources object must contain a Type member.'}
 
-        def describe_param(p):
-            description = {'NoEcho': p.no_echo() and 'true' or 'false',
-                           'ParameterKey': p.name,
-                           'Description': p.description()}
-            if p.has_default():
-                description['DefaultValue'] = p.default()
-
-            return description
-
-        params = parser.Parameters(None, tmpl).map(describe_param)
+        tmpl_params = parser.Parameters(None, tmpl)
+        format_validate_parameter = lambda p: dict(p.schema)
+        is_real_param = lambda p: p.name not in parameters.PSEUDO_PARAMETERS
+        params = tmpl_params.map(format_validate_parameter, is_real_param)
 
         result = {
             'Description': template.get('Description', ''),
-            'Parameters': params.values(),
+            'Parameters': params,
         }
         return result
 
index d1ac2453eb3b45a0c264124b305c291244bd72da..b7c9d5e0b5c8ce01687e5fe4ecc57b57b3340abe 100644 (file)
@@ -127,3 +127,15 @@ WATCH_DATA_KEYS = (
     'watch_name', 'metric_name', 'timestamp',
     'namespace', 'data'
 )
+
+VALIDATE_PARAM_KEYS = (
+    PARAM_TYPE, PARAM_DEFAULT, PARAM_NO_ECHO,
+    PARAM_ALLOWED_VALUES, PARAM_ALLOWED_PATTERN, PARAM_MAX_LENGTH,
+    PARAM_MIN_LENGTH, PARAM_MAX_VALUE, PARAM_MIN_VALUE,
+    PARAM_DESCRIPTION, PARAM_CONSTRAINT_DESCRIPTION
+) = (
+    'Type', 'Default', 'NoEcho',
+    'AllowedValues', 'AllowedPattern', 'MaxLength',
+    'MinLength', 'MaxValue', 'MinValue',
+    'Description', 'ConstraintDescription'
+)
index 5465fe5c4d240bcbee1cdb1f10d6df510de90cef..689b828aa94def3d86b71656294d6f81aa8a9bf2 100644 (file)
@@ -288,3 +288,17 @@ class validateTest(unittest.TestCase):
         engine = service.EngineService('a', 't')
         res = dict(engine.validate_template(None, t))
         self.assertNotEqual(res['Description'], 'Successfully validated')
+
+    def test_validate_parameters(self):
+        t = template_format.parse(test_template_ref % 'WikiDatabase')
+
+        self.m.StubOutWithMock(instances.Instance, 'nova')
+        instances.Instance.nova().AndReturn(self.fc)
+        self.m.ReplayAll()
+
+        engine = service.EngineService('a', 't')
+        res = dict(engine.validate_template(None, t))
+        self.assertEqual(res['Parameters'], {'KeyName': {
+            'Type': 'String',
+            'Description': 'Name of an existing EC2KeyPair to enable SSH '
+                           'access to the instances'}})