blob: e60575bd7b6248fc744fee3c8a9234747a8d8834 [file] [log] [blame]
Angus Salkeldebf15d72014-12-10 17:03:15 +10001# Licensed under the Apache License, Version 2.0 (the "License"); you may
2# not use this file except in compliance with the License. You may obtain
3# a copy of the License at
4#
5# http://www.apache.org/licenses/LICENSE-2.0
6#
7# Unless required by applicable law or agreed to in writing, software
8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10# License for the specific language governing permissions and limitations
11# under the License.
12
13import logging
14
15from heat_integrationtests.common import test
16
17
18LOG = logging.getLogger(__name__)
19
20
21class InstanceGroupTest(test.HeatIntegrationTest):
22
23 template = '''
24{
25 "AWSTemplateFormatVersion" : "2010-09-09",
26 "Description" : "Template to create multiple instances.",
27 "Parameters" : {"size": {"Type": "String", "Default": "1"},
28 "AZ": {"Type": "String", "Default": "nova"},
29 "image": {"Type": "String"},
30 "flavor": {"Type": "String"},
31 "keyname": {"Type": "String"}},
32 "Resources": {
33 "JobServerGroup": {
34 "Type": "OS::Heat::InstanceGroup",
35 "Properties": {
36 "LaunchConfigurationName" : {"Ref": "JobServerConfig"},
37 "Size" : {"Ref": "size"},
38 "AvailabilityZones" : [{"Ref": "AZ"}]
39 }
40 },
41
42 "JobServerConfig" : {
43 "Type" : "AWS::AutoScaling::LaunchConfiguration",
44 "Metadata": {"foo": "bar"},
45 "Properties": {
46 "ImageId" : {"Ref": "image"},
47 "InstanceType" : {"Ref": "flavor"},
48 "KeyName" : {"Ref": "keyname"},
49 "SecurityGroups" : [ "sg-1" ],
50 "UserData" : "jsconfig data",
51 }
52 }
53 },
54 "Outputs": {
55 "InstanceList": {"Value": {
56 "Fn::GetAtt": ["JobServerGroup", "InstanceList"]}}
57 }
58}
59'''
60
61 instance_template = '''
62heat_template_version: 2013-05-23
63parameters:
64 ImageId: {type: string}
65 InstanceType: {type: string}
66 KeyName: {type: string}
67 SecurityGroups: {type: comma_delimited_list}
68 UserData: {type: string}
69 Tags: {type: comma_delimited_list}
70
71resources:
72 random1:
73 type: OS::Heat::RandomString
74
75outputs:
76 PublicIp:
77 value: {get_attr: [random1, value]}
78'''
79
80 def setUp(self):
81 super(InstanceGroupTest, self).setUp()
82 self.client = self.orchestration_client
83 if not self.conf.image_ref:
84 raise self.skipException("No image configured to test")
85 if not self.conf.keypair_name:
86 raise self.skipException("No keyname configured to test")
87 if not self.conf.instance_type:
88 raise self.skipException("No flavor configured to test")
89
90 def test_basic_create_works(self):
91 """Make sure the working case is good.
92 Note this combines test_override_aws_ec2_instance into this test as
93 well, which is:
94 If AWS::EC2::Instance is overridden, InstanceGroup will automatically
95 use that overridden resource type.
96 """
97
98 stack_name = self._stack_rand_name()
99 files = {'provider.yaml': self.instance_template}
100 env = {'resource_registry': {'AWS::EC2::Instance': 'provider.yaml'},
101 'parameters': {'size': 4,
102 'image': self.conf.image_ref,
103 'keyname': self.conf.keypair_name,
104 'flavor': self.conf.instance_type}}
105
106 self.client.stacks.create(
107 stack_name=stack_name,
108 template=self.template,
109 files=files,
110 disable_rollback=True,
111 parameters={},
112 environment=env
113 )
114 self.addCleanup(self.client.stacks.delete, stack_name)
115
116 stack = self.client.stacks.get(stack_name)
117 stack_identifier = '%s/%s' % (stack_name, stack.id)
118
119 self._wait_for_stack_status(stack_identifier, 'CREATE_COMPLETE')
120 initial_resources = {
121 'JobServerConfig': 'AWS::AutoScaling::LaunchConfiguration',
122 'JobServerGroup': 'OS::Heat::InstanceGroup'}
123 self.assertEqual(initial_resources,
124 self.list_resources(stack_identifier))
125
126 stack = self.client.stacks.get(stack_name)
127 inst_list = self._stack_output(stack, 'InstanceList')
128 self.assertEqual(4, len(inst_list.split(',')))