Move basic instance group functional tests
Part of blueprint decouple-nested Change-Id: I6cb85c506a56d2fc2b8a22d1a207cfc67ee85f1e
This commit is contained in:
parent
3626409a6b
commit
595ba546c0
@ -21,7 +21,6 @@ from heat.common import grouputils
|
||||
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 instance
|
||||
from heat.engine.resources import instance_group as instgrp
|
||||
from heat.engine import rsrc_defn
|
||||
@ -101,66 +100,6 @@ class InstanceGroupTest(common.HeatTestCase):
|
||||
self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
|
||||
return rsrc
|
||||
|
||||
def test_basic_create_works(self):
|
||||
"""Make sure the working case is good."""
|
||||
|
||||
t = template_format.parse(ig_template)
|
||||
stack = utils.parse_stack(t)
|
||||
|
||||
# start with min then delete
|
||||
self._stub_create(1)
|
||||
self.m.StubOutWithMock(instance.Instance, 'FnGetAtt')
|
||||
instance.Instance.FnGetAtt('PublicIp').AndReturn('1.2.3.4')
|
||||
|
||||
self.m.ReplayAll()
|
||||
lc_rsrc = self.create_resource(t, stack, 'JobServerConfig')
|
||||
# check bdm in configuration
|
||||
self.assertIsNotNone(lc_rsrc.properties['BlockDeviceMappings'])
|
||||
|
||||
rsrc = self.create_resource(t, stack, 'JobServerGroup')
|
||||
self.assertEqual(utils.PhysName(stack.name, rsrc.name),
|
||||
rsrc.FnGetRefId())
|
||||
self.assertEqual('1.2.3.4', rsrc.FnGetAtt('InstanceList'))
|
||||
# check bdm in instance_definition
|
||||
instance_definition = rsrc._get_instance_definition()
|
||||
self.assertIn('BlockDeviceMappings',
|
||||
instance_definition['Properties'])
|
||||
|
||||
nested = rsrc.nested()
|
||||
self.assertEqual(rsrc.resource_id, nested.id)
|
||||
|
||||
rsrc.delete()
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_override_aws_ec2_instance(self):
|
||||
"""
|
||||
If AWS::EC2::Instance is overridden, InstanceGroup will automatically
|
||||
use that overridden resource type.
|
||||
"""
|
||||
# resources may need to be initialised if this is the first test run.
|
||||
resources.initialise()
|
||||
|
||||
class MyInstance(instance.Instance):
|
||||
"""A customized Instance resource."""
|
||||
|
||||
original_instance = resources.global_env().get_class(
|
||||
"AWS::EC2::Instance")
|
||||
resource._register_class("AWS::EC2::Instance", MyInstance)
|
||||
self.addCleanup(resource._register_class, "AWS::EC2::Instance",
|
||||
original_instance)
|
||||
|
||||
t = template_format.parse(ig_template)
|
||||
stack = utils.parse_stack(t)
|
||||
self._stub_create(1, instance_class=MyInstance)
|
||||
|
||||
self.m.ReplayAll()
|
||||
self.create_resource(t, stack, 'JobServerConfig')
|
||||
rsrc = self.create_resource(t, stack, 'JobServerGroup')
|
||||
self.assertEqual(utils.PhysName(stack.name, rsrc.name),
|
||||
rsrc.FnGetRefId())
|
||||
rsrc.delete()
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_create_config_prop_validation(self):
|
||||
"""Make sure that during a group create the instance
|
||||
properties are validated. And an error causes the group to fail.
|
||||
|
128
heat_integrationtests/functional/test_instance_group.py
Normal file
128
heat_integrationtests/functional/test_instance_group.py
Normal file
@ -0,0 +1,128 @@
|
||||
# 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.
|
||||
|
||||
import logging
|
||||
|
||||
from heat_integrationtests.common import test
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class InstanceGroupTest(test.HeatIntegrationTest):
|
||||
|
||||
template = '''
|
||||
{
|
||||
"AWSTemplateFormatVersion" : "2010-09-09",
|
||||
"Description" : "Template to create multiple instances.",
|
||||
"Parameters" : {"size": {"Type": "String", "Default": "1"},
|
||||
"AZ": {"Type": "String", "Default": "nova"},
|
||||
"image": {"Type": "String"},
|
||||
"flavor": {"Type": "String"},
|
||||
"keyname": {"Type": "String"}},
|
||||
"Resources": {
|
||||
"JobServerGroup": {
|
||||
"Type": "OS::Heat::InstanceGroup",
|
||||
"Properties": {
|
||||
"LaunchConfigurationName" : {"Ref": "JobServerConfig"},
|
||||
"Size" : {"Ref": "size"},
|
||||
"AvailabilityZones" : [{"Ref": "AZ"}]
|
||||
}
|
||||
},
|
||||
|
||||
"JobServerConfig" : {
|
||||
"Type" : "AWS::AutoScaling::LaunchConfiguration",
|
||||
"Metadata": {"foo": "bar"},
|
||||
"Properties": {
|
||||
"ImageId" : {"Ref": "image"},
|
||||
"InstanceType" : {"Ref": "flavor"},
|
||||
"KeyName" : {"Ref": "keyname"},
|
||||
"SecurityGroups" : [ "sg-1" ],
|
||||
"UserData" : "jsconfig data",
|
||||
}
|
||||
}
|
||||
},
|
||||
"Outputs": {
|
||||
"InstanceList": {"Value": {
|
||||
"Fn::GetAtt": ["JobServerGroup", "InstanceList"]}}
|
||||
}
|
||||
}
|
||||
'''
|
||||
|
||||
instance_template = '''
|
||||
heat_template_version: 2013-05-23
|
||||
parameters:
|
||||
ImageId: {type: string}
|
||||
InstanceType: {type: string}
|
||||
KeyName: {type: string}
|
||||
SecurityGroups: {type: comma_delimited_list}
|
||||
UserData: {type: string}
|
||||
Tags: {type: comma_delimited_list}
|
||||
|
||||
resources:
|
||||
random1:
|
||||
type: OS::Heat::RandomString
|
||||
|
||||
outputs:
|
||||
PublicIp:
|
||||
value: {get_attr: [random1, value]}
|
||||
'''
|
||||
|
||||
def setUp(self):
|
||||
super(InstanceGroupTest, self).setUp()
|
||||
self.client = self.orchestration_client
|
||||
if not self.conf.image_ref:
|
||||
raise self.skipException("No image configured to test")
|
||||
if not self.conf.keypair_name:
|
||||
raise self.skipException("No keyname configured to test")
|
||||
if not self.conf.instance_type:
|
||||
raise self.skipException("No flavor configured to test")
|
||||
|
||||
def test_basic_create_works(self):
|
||||
"""Make sure the working case is good.
|
||||
Note this combines test_override_aws_ec2_instance into this test as
|
||||
well, which is:
|
||||
If AWS::EC2::Instance is overridden, InstanceGroup will automatically
|
||||
use that overridden resource type.
|
||||
"""
|
||||
|
||||
stack_name = self._stack_rand_name()
|
||||
files = {'provider.yaml': self.instance_template}
|
||||
env = {'resource_registry': {'AWS::EC2::Instance': 'provider.yaml'},
|
||||
'parameters': {'size': 4,
|
||||
'image': self.conf.image_ref,
|
||||
'keyname': self.conf.keypair_name,
|
||||
'flavor': self.conf.instance_type}}
|
||||
|
||||
self.client.stacks.create(
|
||||
stack_name=stack_name,
|
||||
template=self.template,
|
||||
files=files,
|
||||
disable_rollback=True,
|
||||
parameters={},
|
||||
environment=env
|
||||
)
|
||||
self.addCleanup(self.client.stacks.delete, stack_name)
|
||||
|
||||
stack = self.client.stacks.get(stack_name)
|
||||
stack_identifier = '%s/%s' % (stack_name, stack.id)
|
||||
|
||||
self._wait_for_stack_status(stack_identifier, 'CREATE_COMPLETE')
|
||||
initial_resources = {
|
||||
'JobServerConfig': 'AWS::AutoScaling::LaunchConfiguration',
|
||||
'JobServerGroup': 'OS::Heat::InstanceGroup'}
|
||||
self.assertEqual(initial_resources,
|
||||
self.list_resources(stack_identifier))
|
||||
|
||||
stack = self.client.stacks.get(stack_name)
|
||||
inst_list = self._stack_output(stack, 'InstanceList')
|
||||
self.assertEqual(4, len(inst_list.split(',')))
|
Loading…
Reference in New Issue
Block a user