From 9b05e2429ff70bea4380da9d1ab2e8c8c64d00da Mon Sep 17 00:00:00 2001 From: Steve Baker Date: Mon, 26 Nov 2012 13:04:35 +1300 Subject: [PATCH] For tests, Parse all templates with parse_to_template Change-Id: Iedb6929f46dddbb888a7248034864855b5cd0205 --- heat/tests/functional/test_CFN_API_Actions.py | 4 +++- heat/tests/functional/util.py | 3 ++- heat/tests/test_autoscaling.py | 3 ++- heat/tests/test_dbinstance.py | 3 ++- heat/tests/test_eip.py | 3 ++- heat/tests/test_engine_service.py | 3 ++- heat/tests/test_instance.py | 5 +++-- heat/tests/test_loadbalancer.py | 5 +++-- heat/tests/test_parser.py | 3 ++- heat/tests/test_quantum.py | 3 ++- heat/tests/test_s3.py | 3 ++- heat/tests/test_user.py | 3 ++- heat/tests/test_validate.py | 13 +++++++------ heat/tests/test_volume.py | 3 ++- heat/tests/test_waitcondition.py | 5 +++-- 15 files changed, 39 insertions(+), 23 deletions(-) diff --git a/heat/tests/functional/test_CFN_API_Actions.py b/heat/tests/functional/test_CFN_API_Actions.py index a0edc877..e2593348 100644 --- a/heat/tests/functional/test_CFN_API_Actions.py +++ b/heat/tests/functional/test_CFN_API_Actions.py @@ -21,6 +21,8 @@ from nose.plugins.attrib import attr import unittest import json +from heat.engine import format + @attr(speed='slow') @attr(tag=['func', 'wordpress', 'api', 'cfn', 'F17']) @@ -280,7 +282,7 @@ class CfnApiFunctionalTest(unittest.TestCase): # Extract the JSON TemplateBody and prove it parses template = self.stack.response_xml_item(response, prefix, "TemplateBody") - json_load = json.loads(template) + json_load = format.parse_to_template(template) self.assertTrue(json_load != None) # Then sanity check content - I guess we could diff diff --git a/heat/tests/functional/util.py b/heat/tests/functional/util.py index 160d4f60..8d16220c 100644 --- a/heat/tests/functional/util.py +++ b/heat/tests/functional/util.py @@ -41,6 +41,7 @@ except ImportError: from novaclient.v1_1 import client as nova_client import heat from heat import utils +from heat.engine import format from heat.engine import parser from heat import client as heat_client from heat import boto_client as heat_client_boto @@ -248,7 +249,7 @@ class Instance(object): # time.sleep(1) # necessary for sendall to complete f = open(basepath + '/templates/' + template_file) - t = json.loads(f.read()) + t = format.parse_to_template(f.read()) f.close() template = parser.Template(t) diff --git a/heat/tests/test_autoscaling.py b/heat/tests/test_autoscaling.py index e581d07d..fe9df09c 100644 --- a/heat/tests/test_autoscaling.py +++ b/heat/tests/test_autoscaling.py @@ -24,6 +24,7 @@ import json from nose.plugins.attrib import attr from heat.common import context +from heat.engine import format from heat.engine.resources import autoscaling as asc from heat.engine.resources import loadbalancer from heat.engine import parser @@ -44,7 +45,7 @@ class AutoScalingTest(unittest.TestCase): self.path = os.path.dirname(os.path.realpath(__file__)).\ replace('heat/tests', 'templates') f = open("%s/AutoScalingMultiAZSample.template" % self.path) - t = json.loads(f.read()) + t = format.parse_to_template(f.read()) f.close() return t diff --git a/heat/tests/test_dbinstance.py b/heat/tests/test_dbinstance.py index 12c7efbe..f717194b 100644 --- a/heat/tests/test_dbinstance.py +++ b/heat/tests/test_dbinstance.py @@ -25,6 +25,7 @@ from nose.plugins.attrib import attr from heat.common import context from heat.common import exception +from heat.engine import format from heat.engine import parser from heat.engine.resources import stack from heat.engine.resources import dbinstance as dbi @@ -46,7 +47,7 @@ class DBInstanceTest(unittest.TestCase): self.path = os.path.dirname(os.path.realpath(__file__)).\ replace('heat/tests', 'templates') f = open("%s/WordPress_With_RDS.template" % self.path) - t = json.loads(f.read()) + t = format.parse_to_template(f.read()) f.close() return t diff --git a/heat/tests/test_eip.py b/heat/tests/test_eip.py index 6dba9f1f..41c64fc6 100644 --- a/heat/tests/test_eip.py +++ b/heat/tests/test_eip.py @@ -24,6 +24,7 @@ import json from nose.plugins.attrib import attr from heat.common import context +from heat.engine import format from heat.engine.resources import eip from heat.engine import parser from heat.tests.v1_1 import fakes @@ -47,7 +48,7 @@ class EIPTest(unittest.TestCase): self.path = os.path.dirname(os.path.realpath(__file__)).\ replace('heat/tests', 'templates') f = open("%s/WordPress_Single_Instance_With_EIP.template" % self.path) - t = json.loads(f.read()) + t = format.parse_to_template(f.read()) f.close() return t diff --git a/heat/tests/test_engine_service.py b/heat/tests/test_engine_service.py index 7eb4cb90..5dcf7069 100644 --- a/heat/tests/test_engine_service.py +++ b/heat/tests/test_engine_service.py @@ -27,6 +27,7 @@ from heat.common import context from heat.tests.v1_1 import fakes import heat.engine.api as engine_api import heat.db as db_api +from heat.engine import format from heat.engine import parser from heat.engine import service from heat.engine.resources import instance as instances @@ -54,7 +55,7 @@ def get_wordpress_stack(stack_name, ctx): tmpl_path = os.path.join(templates_dir, 'WordPress_Single_Instance_gold.template') with open(tmpl_path) as f: - t = json.load(f) + t = format.parse_to_template(f.read()) template = parser.Template(t) parameters = parser.Parameters(stack_name, template, diff --git a/heat/tests/test_instance.py b/heat/tests/test_instance.py index 7e12eff3..fe52dfb0 100644 --- a/heat/tests/test_instance.py +++ b/heat/tests/test_instance.py @@ -28,6 +28,7 @@ from nose import with_setup from heat.tests.v1_1 import fakes from heat.engine.resources import instance as instances import heat.db as db_api +from heat.engine import format from heat.engine import parser @@ -46,7 +47,7 @@ class instancesTest(unittest.TestCase): def test_instance_create(self): f = open("%s/WordPress_Single_Instance_gold.template" % self.path) - t = json.loads(f.read()) + t = format.parse_to_template(f.read()) f.close() template = parser.Template(t) @@ -88,7 +89,7 @@ class instancesTest(unittest.TestCase): def test_instance_create_delete(self): f = open("%s/WordPress_Single_Instance_gold.template" % self.path) - t = json.loads(f.read()) + t = format.parse_to_template(f.read()) f.close() template = parser.Template(t) diff --git a/heat/tests/test_loadbalancer.py b/heat/tests/test_loadbalancer.py index 6d3ed25f..f68aa853 100644 --- a/heat/tests/test_loadbalancer.py +++ b/heat/tests/test_loadbalancer.py @@ -27,6 +27,7 @@ from nose.plugins.attrib import attr from heat.common import exception from heat.common import context from heat.common import config +from heat.engine import format from heat.engine import parser from heat.engine.resources import instance from heat.engine.resources import loadbalancer as lb @@ -65,7 +66,7 @@ class LoadBalancerTest(unittest.TestCase): self.path = os.path.dirname(os.path.realpath(__file__)).\ replace('heat/tests', 'templates') f = open("%s/WordPress_With_LB.template" % self.path) - t = json.loads(f.read()) + t = format.parse_to_template(f.read()) f.close() return t @@ -123,7 +124,7 @@ class LoadBalancerTest(unittest.TestCase): self.assertEqual('LoadBalancer', resource.FnGetRefId()) - templ = json.loads(lb.lb_template) + templ = format.parse_to_template(lb.lb_template) ha_cfg = resource._haproxy_config(templ, resource.properties['Instances']) self.assertRegexpMatches(ha_cfg, 'bind \*:80') diff --git a/heat/tests/test_parser.py b/heat/tests/test_parser.py index b8a04d8a..e6d9b8f0 100644 --- a/heat/tests/test_parser.py +++ b/heat/tests/test_parser.py @@ -21,6 +21,7 @@ import json from heat.common import context from heat.common import exception +from heat.engine import format from heat.engine import parser from heat.engine import parameters from heat.engine import template @@ -98,7 +99,7 @@ class ParserTest(unittest.TestCase): self.assertEqual(join(raw), 'foo bar\nbaz') -mapping_template = json.loads('''{ +mapping_template = format.parse_to_template('''{ "Mappings" : { "ValidMapping" : { "TestKey" : { "TestValue" : "wibble" } diff --git a/heat/tests/test_quantum.py b/heat/tests/test_quantum.py index a5ab0e9d..42adef77 100644 --- a/heat/tests/test_quantum.py +++ b/heat/tests/test_quantum.py @@ -25,6 +25,7 @@ from nose.plugins.attrib import attr from heat.common import context from heat.common import exception +from heat.engine import format from heat.engine.resources import properties from heat.engine.resources.quantum import net from heat.engine.resources.quantum.quantum import QuantumResource as qr @@ -81,7 +82,7 @@ class QuantumTest(unittest.TestCase): self.path = os.path.dirname(os.path.realpath(__file__)).\ replace('heat/tests', 'templates') f = open("%s/Quantum.template" % self.path) - t = json.loads(f.read()) + t = format.parse_to_template(f.read()) f.close() return t diff --git a/heat/tests/test_s3.py b/heat/tests/test_s3.py index c9b4fad4..c884baa6 100644 --- a/heat/tests/test_s3.py +++ b/heat/tests/test_s3.py @@ -25,6 +25,7 @@ import json from nose.plugins.attrib import attr from heat.common import context +from heat.engine import format from heat.engine.resources import s3 from heat.engine import parser from utils import skip_if @@ -58,7 +59,7 @@ class s3Test(unittest.TestCase): self.path = os.path.dirname(os.path.realpath(__file__)).\ replace('heat/tests', 'templates') f = open("%s/S3_Single_Instance.template" % self.path) - t = json.loads(f.read()) + t = format.parse_to_template(f.read()) f.close() return t diff --git a/heat/tests/test_user.py b/heat/tests/test_user.py index 04244283..50666c09 100644 --- a/heat/tests/test_user.py +++ b/heat/tests/test_user.py @@ -27,6 +27,7 @@ from nose.plugins.attrib import attr from heat.common import context from heat.common import exception from heat.common import config +from heat.engine import format from heat.engine import parser from heat.engine.resources import user from heat.tests.v1_1 import fakes @@ -68,7 +69,7 @@ class UserTest(unittest.TestCase): self.path = os.path.dirname(os.path.realpath(__file__)).\ replace('heat/tests', 'templates') f = open("%s/Rails_Single_Instance.template" % self.path) - t = json.loads(f.read()) + t = format.parse_to_template(f.read()) f.close() return t diff --git a/heat/tests/test_validate.py b/heat/tests/test_validate.py index 3cbd4642..6cde6729 100644 --- a/heat/tests/test_validate.py +++ b/heat/tests/test_validate.py @@ -20,6 +20,7 @@ import json from nose.plugins.attrib import attr from heat.tests.v1_1 import fakes +from heat.engine import format from heat.engine.resources import instance as instances from heat.engine import service import heat.db as db_api @@ -219,7 +220,7 @@ class validateTest(unittest.TestCase): print "volumeTest teardown complete" def test_validate_volumeattach_valid(self): - t = json.loads(test_template_volumeattach % 'vdq') + t = format.parse_to_template(test_template_volumeattach % 'vdq') stack = parser.Stack(None, 'test_stack', parser.Template(t)) self.m.StubOutWithMock(db_api, 'resource_get_by_name_and_stack') @@ -231,7 +232,7 @@ class validateTest(unittest.TestCase): self.assertTrue(volumeattach.validate() is None) def test_validate_volumeattach_invalid(self): - t = json.loads(test_template_volumeattach % 'sda') + t = format.parse_to_template(test_template_volumeattach % 'sda') stack = parser.Stack(None, 'test_stack', parser.Template(t)) self.m.StubOutWithMock(db_api, 'resource_get_by_name_and_stack') @@ -243,7 +244,7 @@ class validateTest(unittest.TestCase): self.assertTrue(volumeattach.validate()) def test_validate_ref_valid(self): - t = json.loads(test_template_ref % 'WikiDatabase') + t = format.parse_to_template(test_template_ref % 'WikiDatabase') self.m.StubOutWithMock(instances.Instance, 'nova') instances.Instance.nova().AndReturn(self.fc) @@ -256,7 +257,7 @@ class validateTest(unittest.TestCase): self.assertEqual(res['Description'], 'test.') def test_validate_ref_invalid(self): - t = json.loads(test_template_ref % 'WikiDatabasez') + t = format.parse_to_template(test_template_ref % 'WikiDatabasez') self.m.StubOutWithMock(instances.Instance, 'nova') instances.Instance.nova().AndReturn(self.fc) @@ -268,7 +269,7 @@ class validateTest(unittest.TestCase): self.assertNotEqual(res['Description'], 'Successfully validated') def test_validate_findinmap_valid(self): - t = json.loads(test_template_findinmap_valid) + t = format.parse_to_template(test_template_findinmap_valid) self.m.StubOutWithMock(instances.Instance, 'nova') instances.Instance.nova().AndReturn(self.fc) @@ -280,7 +281,7 @@ class validateTest(unittest.TestCase): self.assertEqual(res['Description'], 'test.') def test_validate_findinmap_invalid(self): - t = json.loads(test_template_findinmap_invalid) + t = format.parse_to_template(test_template_findinmap_invalid) self.m.StubOutWithMock(instances.Instance, 'nova') instances.Instance.nova().AndReturn(self.fc) diff --git a/heat/tests/test_volume.py b/heat/tests/test_volume.py index 20320f23..1f388866 100644 --- a/heat/tests/test_volume.py +++ b/heat/tests/test_volume.py @@ -25,6 +25,7 @@ import unittest from nose.plugins.attrib import attr from heat.common import context +from heat.engine import format from heat.engine import parser from heat.engine.resources import volume as vol from heat.tests.v1_1 import fakes @@ -53,7 +54,7 @@ class VolumeTest(unittest.TestCase): self.path = os.path.dirname(os.path.realpath(__file__)).\ replace('heat/tests', 'templates') f = open("%s/WordPress_2_Instances_With_EBS.template" % self.path) - t = json.loads(f.read()) + t = format.parse_to_template(f.read()) f.close() return t diff --git a/heat/tests/test_waitcondition.py b/heat/tests/test_waitcondition.py index 570a4d79..c42f23cd 100644 --- a/heat/tests/test_waitcondition.py +++ b/heat/tests/test_waitcondition.py @@ -24,6 +24,7 @@ import unittest from nose.plugins.attrib import attr import heat.db as db_api +from heat.engine import format from heat.engine import parser from heat.engine.resources import wait_condition as wc from heat.common import context @@ -76,7 +77,7 @@ class stacksTest(unittest.TestCase): def test_post_success_to_handle(self): - t = json.loads(test_template_waitcondition) + t = format.parse_to_template(test_template_waitcondition) stack = self.create_stack('test_stack', t, {}) wc.WaitCondition._create_timeout().AndReturn(eventlet.Timeout(5)) @@ -105,7 +106,7 @@ class stacksTest(unittest.TestCase): def test_timeout(self): - t = json.loads(test_template_waitcondition) + t = format.parse_to_template(test_template_waitcondition) stack = self.create_stack('test_stack', t, {}) tmo = eventlet.Timeout(6) -- 2.45.2