Rework autoscaling group current_size attribute
The current implementation requires a path which is not needed. rsrc.FnGetAtt('current_size', 'name') it should allow: rsrc.FnGetAtt('current_size') Also move the tests to the correct test module and make them more into unit tests. Change-Id: Id05a1f09ecc6741cbf677baf52fbb58d93028ac4
This commit is contained in:
parent
aa38bab972
commit
30ffcdca4e
@ -845,6 +845,8 @@ class AutoScalingResourceGroup(AutoScalingGroup):
|
|||||||
template_version=template_version)
|
template_version=template_version)
|
||||||
|
|
||||||
def FnGetAtt(self, key, *path):
|
def FnGetAtt(self, key, *path):
|
||||||
|
if key == self.CURRENT_SIZE:
|
||||||
|
return len(self.get_instances())
|
||||||
if path:
|
if path:
|
||||||
attrs = ((rsrc.name,
|
attrs = ((rsrc.name,
|
||||||
rsrc.FnGetAtt(*path)) for rsrc in self.get_instances())
|
rsrc.FnGetAtt(*path)) for rsrc in self.get_instances())
|
||||||
@ -852,8 +854,6 @@ class AutoScalingResourceGroup(AutoScalingGroup):
|
|||||||
return dict(attrs)
|
return dict(attrs)
|
||||||
if key == self.OUTPUTS_LIST:
|
if key == self.OUTPUTS_LIST:
|
||||||
return [value for name, value in attrs]
|
return [value for name, value in attrs]
|
||||||
if key == self.CURRENT_SIZE:
|
|
||||||
return len(list(attrs))
|
|
||||||
|
|
||||||
raise exception.InvalidTemplateAttribute(resource=self.name,
|
raise exception.InvalidTemplateAttribute(resource=self.name,
|
||||||
key=key)
|
key=key)
|
||||||
|
@ -40,53 +40,6 @@ from heat.tests import utils
|
|||||||
|
|
||||||
as_template = inline_templates.as_template
|
as_template = inline_templates.as_template
|
||||||
|
|
||||||
as_template_HoT = '''
|
|
||||||
{
|
|
||||||
"heat_template_version": "2013-05-23",
|
|
||||||
"description": "AutoScaling Test",
|
|
||||||
"parameters": {
|
|
||||||
"flavor": {"type": "string"},
|
|
||||||
"image": {"type": "string"}
|
|
||||||
},
|
|
||||||
"resources": {
|
|
||||||
"WebServerGroup": {
|
|
||||||
"type": "OS::Heat::AutoScalingGroup",
|
|
||||||
"properties": {
|
|
||||||
"min_size": 1,
|
|
||||||
"max_size": 5,
|
|
||||||
"desired_capacity": 1,
|
|
||||||
"resource": {
|
|
||||||
"type": "OS::Nova::Server",
|
|
||||||
"properties": {
|
|
||||||
"flavor": {"get_param": "flavor"},
|
|
||||||
"image": {"get_param": "image"},
|
|
||||||
"metadata": {"metering.stack": "test-metadata"}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"WebServerScaleUpPolicy": {
|
|
||||||
"type": "OS::Heat::ScalingPolicy",
|
|
||||||
"properties": {
|
|
||||||
"adjustment_type": "change_in_capacity",
|
|
||||||
"auto_scaling_group_id": {"get_resource": "WebServerGroup"},
|
|
||||||
"cooldown": 60,
|
|
||||||
"scaling_adjustment": 1
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"WebServerScaleDownPolicy": {
|
|
||||||
"type": "OS::Heat::ScalingPolicy",
|
|
||||||
"properties": {
|
|
||||||
"adjustment_type": "change_in_capacity",
|
|
||||||
"auto_scaling_group_id": {"get_resource": "WebServerGroup"},
|
|
||||||
"cooldown": 60,
|
|
||||||
"scaling_adjustment": -1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
'''
|
|
||||||
|
|
||||||
as_template_bad_group = '''
|
as_template_bad_group = '''
|
||||||
{
|
{
|
||||||
"AWSTemplateFormatVersion" : "2010-09-09",
|
"AWSTemplateFormatVersion" : "2010-09-09",
|
||||||
@ -1064,33 +1017,6 @@ class AutoScalingTest(common.HeatTestCase):
|
|||||||
rsrc.delete()
|
rsrc.delete()
|
||||||
self.m.VerifyAll()
|
self.m.VerifyAll()
|
||||||
|
|
||||||
def test_scaling_group_current_size(self):
|
|
||||||
t = template_format.parse(as_template_HoT)
|
|
||||||
stack = utils.parse_stack(t, params=self.params_HoT)
|
|
||||||
|
|
||||||
# create asg with size of 2
|
|
||||||
properties = t['resources']['WebServerGroup']['properties']
|
|
||||||
properties['desired_capacity'] = '2'
|
|
||||||
now = timeutils.utcnow()
|
|
||||||
self._stub_meta_expected(now, 'ExactCapacity : 2')
|
|
||||||
self._stub_create_hot(2)
|
|
||||||
self.m.ReplayAll()
|
|
||||||
rsrc = self.create_scaling_group_hot(t, stack, 'WebServerGroup')
|
|
||||||
self.assertEqual(2, rsrc.FnGetAtt("current_size", 'name'))
|
|
||||||
self.m.VerifyAll()
|
|
||||||
self.m.UnsetStubs()
|
|
||||||
|
|
||||||
# raise to 3
|
|
||||||
self._stub_meta_expected(now, 'ChangeInCapacity : 1')
|
|
||||||
self._stub_create_hot(1)
|
|
||||||
self._stub_scale_notification(adjust=1, groupname=rsrc.FnGetRefId(),
|
|
||||||
start_capacity=2, end_capacity=3)
|
|
||||||
self.m.ReplayAll()
|
|
||||||
rsrc.adjust(1)
|
|
||||||
self.assertEqual(3, rsrc.FnGetAtt("current_size", 'name'))
|
|
||||||
|
|
||||||
self.m.VerifyAll()
|
|
||||||
|
|
||||||
def test_scaling_policy_bad_group(self):
|
def test_scaling_policy_bad_group(self):
|
||||||
t = template_format.parse(as_template_bad_group)
|
t = template_format.parse(as_template_bad_group)
|
||||||
stack = utils.parse_stack(t, params=self.params)
|
stack = utils.parse_stack(t, params=self.params)
|
||||||
|
@ -21,15 +21,16 @@ from heat.common import exception
|
|||||||
from heat.common import short_id
|
from heat.common import short_id
|
||||||
from heat.common import template_format
|
from heat.common import template_format
|
||||||
from heat.engine import resource
|
from heat.engine import resource
|
||||||
|
from heat.engine.resources import autoscaling
|
||||||
from heat.engine import rsrc_defn
|
from heat.engine import rsrc_defn
|
||||||
from heat.engine import scheduler
|
from heat.engine import scheduler
|
||||||
from heat.engine import stack_resource
|
from heat.engine import stack_resource
|
||||||
from heat.tests.common import HeatTestCase
|
from heat.tests import common
|
||||||
from heat.tests import generic_resource
|
from heat.tests import generic_resource
|
||||||
from heat.tests import utils
|
from heat.tests import utils
|
||||||
|
|
||||||
|
|
||||||
class AutoScalingGroupTest(HeatTestCase):
|
class AutoScalingGroupTest(common.HeatTestCase):
|
||||||
|
|
||||||
as_template = '''
|
as_template = '''
|
||||||
heat_template_version: 2013-05-23
|
heat_template_version: 2013-05-23
|
||||||
@ -264,8 +265,23 @@ class AutoScalingGroupTest(HeatTestCase):
|
|||||||
self.assertEqual(dict((n, n) for n in member_names),
|
self.assertEqual(dict((n, n) for n in member_names),
|
||||||
rsrc.FnGetAtt('outputs', 'Bar'))
|
rsrc.FnGetAtt('outputs', 'Bar'))
|
||||||
|
|
||||||
|
def test_attribute_current_size(self):
|
||||||
|
rsrc = self.create_stack(self.parsed)['my-group']
|
||||||
|
mock_instances = self.patchobject(autoscaling.AutoScalingResourceGroup,
|
||||||
|
'get_instances')
|
||||||
|
mock_instances.return_value = ['one', 'two', 'three']
|
||||||
|
|
||||||
class HeatScalingGroupWithCFNScalingPolicyTest(HeatTestCase):
|
self.assertEqual(3, rsrc.FnGetAtt('current_size'))
|
||||||
|
|
||||||
|
def test_attribute_current_size_with_path(self):
|
||||||
|
rsrc = self.create_stack(self.parsed)['my-group']
|
||||||
|
mock_instances = self.patchobject(autoscaling.AutoScalingResourceGroup,
|
||||||
|
'get_instances')
|
||||||
|
mock_instances.return_value = ['one', 'two', 'three', 'four']
|
||||||
|
self.assertEqual(4, rsrc.FnGetAtt('current_size', 'name'))
|
||||||
|
|
||||||
|
|
||||||
|
class HeatScalingGroupWithCFNScalingPolicyTest(common.HeatTestCase):
|
||||||
as_template = '''
|
as_template = '''
|
||||||
heat_template_version: 2013-05-23
|
heat_template_version: 2013-05-23
|
||||||
description: AutoScaling Test
|
description: AutoScaling Test
|
||||||
@ -322,7 +338,7 @@ class HeatScalingGroupWithCFNScalingPolicyTest(HeatTestCase):
|
|||||||
group.FnGetAtt, 'InstanceList')
|
group.FnGetAtt, 'InstanceList')
|
||||||
|
|
||||||
|
|
||||||
class ScalingPolicyTest(HeatTestCase):
|
class ScalingPolicyTest(common.HeatTestCase):
|
||||||
# TODO(Qiming): Add more tests to the scaling policy
|
# TODO(Qiming): Add more tests to the scaling policy
|
||||||
as_template = '''
|
as_template = '''
|
||||||
heat_template_version: 2013-05-23
|
heat_template_version: 2013-05-23
|
||||||
@ -392,7 +408,7 @@ class ScalingPolicyTest(HeatTestCase):
|
|||||||
self.assertEqual(3, len(group.get_instance_names()))
|
self.assertEqual(3, len(group.get_instance_names()))
|
||||||
|
|
||||||
|
|
||||||
class RollingUpdatesTest(HeatTestCase):
|
class RollingUpdatesTest(common.HeatTestCase):
|
||||||
|
|
||||||
as_template = '''
|
as_template = '''
|
||||||
heat_template_version: 2013-05-23
|
heat_template_version: 2013-05-23
|
||||||
|
Loading…
Reference in New Issue
Block a user