diff --git a/heat/tests/autoscaling/__init__.py b/heat/tests/autoscaling/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/heat/tests/autoscaling/inline_templates.py b/heat/tests/autoscaling/inline_templates.py new file mode 100644 index 0000000000..2304e843aa --- /dev/null +++ b/heat/tests/autoscaling/inline_templates.py @@ -0,0 +1,78 @@ +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +as_params = {'KeyName': 'test', 'ImageId': 'foo'} +as_template = ''' +{ + "AWSTemplateFormatVersion" : "2010-09-09", + "Description" : "AutoScaling Test", + "Parameters" : { + "ImageId": {"Type": "String"}, + "KeyName": {"Type": "String"} + }, + "Resources" : { + "WebServerGroup" : { + "Type" : "AWS::AutoScaling::AutoScalingGroup", + "Properties" : { + "AvailabilityZones" : ["nova"], + "LaunchConfigurationName" : { "Ref" : "LaunchConfig" }, + "MinSize" : "1", + "MaxSize" : "5", + "LoadBalancerNames" : [ { "Ref" : "ElasticLoadBalancer" } ] + } + }, + "WebServerScaleUpPolicy" : { + "Type" : "AWS::AutoScaling::ScalingPolicy", + "Properties" : { + "AdjustmentType" : "ChangeInCapacity", + "AutoScalingGroupName" : { "Ref" : "WebServerGroup" }, + "Cooldown" : "60", + "ScalingAdjustment" : "1" + } + }, + "WebServerScaleDownPolicy" : { + "Type" : "AWS::AutoScaling::ScalingPolicy", + "Properties" : { + "AdjustmentType" : "ChangeInCapacity", + "AutoScalingGroupName" : { "Ref" : "WebServerGroup" }, + "Cooldown" : "60", + "ScalingAdjustment" : "-1" + } + }, + "ElasticLoadBalancer" : { + "Type" : "AWS::ElasticLoadBalancing::LoadBalancer", + "Properties" : { + "AvailabilityZones" : ["nova"], + "Listeners" : [ { + "LoadBalancerPort" : "80", + "InstancePort" : "80", + "Protocol" : "HTTP" + }] + } + }, + "LaunchConfig" : { + "Type" : "AWS::AutoScaling::LaunchConfiguration", + "Properties": { + "ImageId" : {"Ref": "ImageId"}, + "InstanceType" : "bar", + "BlockDeviceMappings": [ + { + "DeviceName": "vdb", + "Ebs": {"SnapshotId": "9ef5496e-7426-446a-bbc8-01f84d9c9972", + "DeleteOnTermination": "True"} + }] + } + } + } +} +''' diff --git a/heat/tests/test_autoscaling.py b/heat/tests/test_autoscaling.py index 55131beec0..fb0f170343 100644 --- a/heat/tests/test_autoscaling.py +++ b/heat/tests/test_autoscaling.py @@ -33,74 +33,12 @@ from heat.engine.resources.neutron import loadbalancer as neutron_lb from heat.engine.resources import server from heat.engine import rsrc_defn from heat.engine import scheduler -from heat.tests.common import HeatTestCase +from heat.tests.autoscaling import inline_templates +from heat.tests import common from heat.tests import utils -as_template = ''' -{ - "AWSTemplateFormatVersion" : "2010-09-09", - "Description" : "AutoScaling Test", - "Parameters" : { - "ImageId": {"Type": "String"}, - "KeyName": {"Type": "String"} - }, - "Resources" : { - "WebServerGroup" : { - "Type" : "AWS::AutoScaling::AutoScalingGroup", - "Properties" : { - "AvailabilityZones" : ["nova"], - "LaunchConfigurationName" : { "Ref" : "LaunchConfig" }, - "MinSize" : "1", - "MaxSize" : "5", - "LoadBalancerNames" : [ { "Ref" : "ElasticLoadBalancer" } ] - } - }, - "WebServerScaleUpPolicy" : { - "Type" : "AWS::AutoScaling::ScalingPolicy", - "Properties" : { - "AdjustmentType" : "ChangeInCapacity", - "AutoScalingGroupName" : { "Ref" : "WebServerGroup" }, - "Cooldown" : "60", - "ScalingAdjustment" : "1" - } - }, - "WebServerScaleDownPolicy" : { - "Type" : "AWS::AutoScaling::ScalingPolicy", - "Properties" : { - "AdjustmentType" : "ChangeInCapacity", - "AutoScalingGroupName" : { "Ref" : "WebServerGroup" }, - "Cooldown" : "60", - "ScalingAdjustment" : "-1" - } - }, - "ElasticLoadBalancer" : { - "Type" : "AWS::ElasticLoadBalancing::LoadBalancer", - "Properties" : { - "AvailabilityZones" : ["nova"], - "Listeners" : [ { - "LoadBalancerPort" : "80", - "InstancePort" : "80", - "Protocol" : "HTTP" - }] - } - }, - "LaunchConfig" : { - "Type" : "AWS::AutoScaling::LaunchConfiguration", - "Properties": { - "ImageId" : {"Ref": "ImageId"}, - "InstanceType" : "bar", - "BlockDeviceMappings": [ - { - "DeviceName": "vdb", - "Ebs": {"SnapshotId": "9ef5496e-7426-446a-bbc8-01f84d9c9972", - "DeleteOnTermination": "True"} - }] - } - } - } -} -''' +as_template = inline_templates.as_template as_template_HoT = ''' { @@ -171,7 +109,7 @@ as_template_bad_group = ''' ''' -class AutoScalingTest(HeatTestCase): +class AutoScalingTest(common.HeatTestCase): dummy_instance_id = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa' params = {'KeyName': 'test', 'ImageId': 'foo'} params_HoT = {'flavor': 'test', 'image': 'foo'} @@ -1928,28 +1866,3 @@ class AutoScalingTest(HeatTestCase): self.assertIn(excepted_error, six.text_type(e)) self.m.VerifyAll() - - -class TestInstanceGroup(HeatTestCase): - params = {'KeyName': 'test', 'ImageId': 'foo'} - - def setUp(self): - super(TestInstanceGroup, self).setUp() - - t = template_format.parse(as_template) - stack = utils.parse_stack(t, params=self.params) - - defn = rsrc_defn.ResourceDefinition('ig', 'OS::Heat::InstanceGroup', - {'Size': 2, - 'LaunchConfigurationName': 'foo'}) - self.instance_group = asc.InstanceGroup('ig', defn, stack) - - def test_child_template(self): - self.instance_group._create_template = mock.Mock(return_value='tpl') - - self.assertEqual('tpl', self.instance_group.child_template()) - self.instance_group._create_template.assert_called_once_with(2) - - def test_child_params(self): - self.instance_group._environment = mock.Mock(return_value='env') - self.assertEqual('env', self.instance_group.child_params()) diff --git a/heat/tests/test_instance_group.py b/heat/tests/test_instance_group.py index 7dd108a384..3588f31048 100644 --- a/heat/tests/test_instance_group.py +++ b/heat/tests/test_instance_group.py @@ -13,18 +13,21 @@ import copy +import mock + from heat.common import exception from heat.common import template_format from heat.engine import parser from heat.engine import resource from heat.engine import resources +from heat.engine.resources import autoscaling as asc from heat.engine.resources import instance from heat.engine import rsrc_defn from heat.engine import scheduler -from heat.tests.common import HeatTestCase +from heat.tests.autoscaling import inline_templates +from heat.tests import common from heat.tests import utils - ig_template = ''' { "AWSTemplateFormatVersion" : "2010-09-09", @@ -62,10 +65,7 @@ ig_template = ''' ''' -class InstanceGroupTest(HeatTestCase): - def setUp(self): - super(InstanceGroupTest, self).setUp() - +class InstanceGroupTest(common.HeatTestCase): def _stub_create(self, num, instance_class=instance.Instance): """ Expect creation of C{num} number of Instances. @@ -362,3 +362,24 @@ class InstanceGroupTest(HeatTestCase): self.assertRaises(resource.UpdateReplace, updater) self.m.VerifyAll() + + +class TestChildTemplate(common.HeatTestCase): + def setUp(self): + super(TestChildTemplate, self).setUp() + t = template_format.parse(inline_templates.as_template) + stack = utils.parse_stack(t, params=inline_templates.as_params) + defn = rsrc_defn.ResourceDefinition('ig', 'OS::Heat::InstanceGroup', + {'Size': 2, + 'LaunchConfigurationName': 'foo'}) + self.instance_group = asc.InstanceGroup('ig', defn, stack) + + def test_child_template(self): + self.instance_group._create_template = mock.Mock(return_value='tpl') + + self.assertEqual('tpl', self.instance_group.child_template()) + self.instance_group._create_template.assert_called_once_with(2) + + def test_child_params(self): + self.instance_group._environment = mock.Mock(return_value='env') + self.assertEqual('env', self.instance_group.child_params())