Rename the remaining instance group tests for clarity

In preparation to move these tests to functional tests rename and
document what they do.
This also simplifies the launch config test as it does not need
the scaling group for this test.

Part of blueprint decouple-nested
Change-Id: I77d7fb38b852590a3004532d28b9b9fcf29dc819
This commit is contained in:
Angus Salkeld 2014-12-10 19:55:37 +10:00
parent 90c1189084
commit 3626409a6b

View File

@ -101,7 +101,8 @@ class InstanceGroupTest(common.HeatTestCase):
self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state) self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
return rsrc return rsrc
def test_instance_group(self): def test_basic_create_works(self):
"""Make sure the working case is good."""
t = template_format.parse(ig_template) t = template_format.parse(ig_template)
stack = utils.parse_stack(t) stack = utils.parse_stack(t)
@ -131,7 +132,7 @@ class InstanceGroupTest(common.HeatTestCase):
rsrc.delete() rsrc.delete()
self.m.VerifyAll() self.m.VerifyAll()
def test_instance_group_custom_resource(self): def test_override_aws_ec2_instance(self):
""" """
If AWS::EC2::Instance is overridden, InstanceGroup will automatically If AWS::EC2::Instance is overridden, InstanceGroup will automatically
use that overridden resource type. use that overridden resource type.
@ -160,7 +161,10 @@ class InstanceGroupTest(common.HeatTestCase):
rsrc.delete() rsrc.delete()
self.m.VerifyAll() self.m.VerifyAll()
def test_missing_image(self): 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.
"""
t = template_format.parse(ig_template) t = template_format.parse(ig_template)
stack = utils.parse_stack(t) stack = utils.parse_stack(t)
@ -196,7 +200,7 @@ class InstanceGroupTest(common.HeatTestCase):
self.m.VerifyAll() self.m.VerifyAll()
def test_handle_update_size(self): def test_size_updates_work(self):
t = template_format.parse(ig_template) t = template_format.parse(ig_template)
properties = t['Resources']['JobServerGroup']['Properties'] properties = t['Resources']['JobServerGroup']['Properties']
properties['Size'] = '2' properties['Size'] = '2'
@ -236,7 +240,7 @@ class InstanceGroupTest(common.HeatTestCase):
rsrc.delete() rsrc.delete()
self.m.VerifyAll() self.m.VerifyAll()
def test_create_error(self): def test_create_instance_error_causes_group_error(self):
""" """
If a resource in an instance group fails to be created, the instance If a resource in an instance group fails to be created, the instance
group itself will fail and the broken inner resource will remain. group itself will fail and the broken inner resource will remain.
@ -271,7 +275,7 @@ class InstanceGroupTest(common.HeatTestCase):
self.m.VerifyAll() self.m.VerifyAll()
def test_update_error(self): def test_update_instance_error_causes_group_error(self):
""" """
If a resource in an instance group fails to be created during an If a resource in an instance group fails to be created during an
update, the instance group itself will fail and the broken inner update, the instance group itself will fail and the broken inner
@ -321,7 +325,10 @@ class InstanceGroupTest(common.HeatTestCase):
self.m.VerifyAll() self.m.VerifyAll()
def test_update_fail_badprop(self): def test_update_group_replace(self):
"""Make sure that during a group update the non updatable
properties cause a replacement.
"""
t = template_format.parse(ig_template) t = template_format.parse(ig_template)
properties = t['Resources']['JobServerGroup']['Properties'] properties = t['Resources']['JobServerGroup']['Properties']
properties['Size'] = '2' properties['Size'] = '2'
@ -346,39 +353,6 @@ class InstanceGroupTest(common.HeatTestCase):
rsrc.delete() rsrc.delete()
self.m.VerifyAll() self.m.VerifyAll()
def test_update_config_metadata(self):
t = template_format.parse(ig_template)
properties = t['Resources']['JobServerGroup']['Properties']
properties['Size'] = '2'
stack = utils.parse_stack(t)
self._stub_create(2)
self.m.ReplayAll()
rsrc = self.create_resource(t, stack, 'JobServerConfig')
self.create_resource(t, stack, 'JobServerGroup')
props = copy.copy(rsrc.properties.data)
metadata = copy.copy(rsrc.metadata_get())
update_snippet = rsrc_defn.ResourceDefinition(rsrc.name,
rsrc.type(),
props,
metadata)
# Change nothing in the first update
scheduler.TaskRunner(rsrc.update, update_snippet)()
self.assertEqual('bar', metadata['foo'])
metadata['foo'] = 'wibble'
update_snippet = rsrc_defn.ResourceDefinition(rsrc.name,
rsrc.type(),
props,
metadata)
# Changing metadata in the second update triggers UpdateReplace
updater = scheduler.TaskRunner(rsrc.update, update_snippet)
self.assertRaises(resource.UpdateReplace, updater)
self.m.VerifyAll()
class TestInstanceGroup(common.HeatTestCase): class TestInstanceGroup(common.HeatTestCase):
def setUp(self): def setUp(self):
@ -455,3 +429,59 @@ class TestInstanceGroup(common.HeatTestCase):
mock_members.return_value = instances mock_members.return_value = instances
res = self.instance_group._resolve_attribute('InstanceList') res = self.instance_group._resolve_attribute('InstanceList')
self.assertEqual('2.1.3.1,2.1.3.2,2.1.3.3', res) self.assertEqual('2.1.3.1,2.1.3.2,2.1.3.3', res)
class TestLaunchConfig(common.HeatTestCase):
def create_resource(self, t, stack, resource_name):
# subsequent resources may need to reference previous created resources
# use the stack's resource objects instead of instantiating new ones
rsrc = stack[resource_name]
self.assertIsNone(rsrc.validate())
scheduler.TaskRunner(rsrc.create)()
self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
return rsrc
def test_update_metadata_replace(self):
"""Updating the config's metadata causes a config replacement."""
lc_template = '''
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Resources": {
"JobServerConfig" : {
"Type" : "AWS::AutoScaling::LaunchConfiguration",
"Metadata": {"foo": "bar"},
"Properties": {
"ImageId" : "foo",
"InstanceType" : "m1.large",
"KeyName" : "test",
}
}
}
}
'''
self.stub_ImageConstraint_validate()
self.stub_FlavorConstraint_validate()
self.stub_KeypairConstraint_validate()
self.m.ReplayAll()
t = template_format.parse(lc_template)
stack = utils.parse_stack(t)
rsrc = self.create_resource(t, stack, 'JobServerConfig')
props = copy.copy(rsrc.properties.data)
metadata = copy.copy(rsrc.metadata_get())
update_snippet = rsrc_defn.ResourceDefinition(rsrc.name,
rsrc.type(),
props,
metadata)
# Change nothing in the first update
scheduler.TaskRunner(rsrc.update, update_snippet)()
self.assertEqual('bar', metadata['foo'])
metadata['foo'] = 'wibble'
update_snippet = rsrc_defn.ResourceDefinition(rsrc.name,
rsrc.type(),
props,
metadata)
# Changing metadata in the second update triggers UpdateReplace
updater = scheduler.TaskRunner(rsrc.update, update_snippet)
self.assertRaises(resource.UpdateReplace, updater)
self.m.VerifyAll()