Merge "add the validation of MaxSize ,MinSize and DesiredCapacity"

This commit is contained in:
Jenkins 2014-01-24 01:11:03 +00:00 committed by Gerrit Code Review
commit f4337bc58c
2 changed files with 64 additions and 0 deletions

View File

@ -650,6 +650,24 @@ class AutoScalingGroup(InstanceGroup, CooldownMixin):
if res:
return res
# check validity of group size
min_size = int(self.properties[self.MIN_SIZE])
max_size = int(self.properties[self.MAX_SIZE])
if max_size < min_size:
msg = _("MinSize can not be greater than MaxSize")
raise exception.StackValidationFailed(message=msg)
if min_size < 0:
msg = _("The size of AutoScalingGroup can not be less than zero")
raise exception.StackValidationFailed(message=msg)
if self.properties[self.DESIRED_CAPACITY]:
desired_capacity = int(self.properties[self.DESIRED_CAPACITY])
if desired_capacity < min_size or desired_capacity > max_size:
msg = _("DesiredCapacity must be between MinSize and MaxSize")
raise exception.StackValidationFailed(message=msg)
# TODO(pasquier-s): once Neutron is able to assign subnets to
# availability zones, it will be possible to specify multiple subnets.
# For now, only one subnet can be specified. The bug #1096017 tracks

View File

@ -1526,3 +1526,49 @@ class AutoScalingTest(HeatTestCase):
self.assertRaises(exception.NotSupported, self.create_scaling_group, t,
stack, 'WebServerGroup')
def test_invalid_min_size(self):
t = template_format.parse(as_template)
properties = t['Resources']['WebServerGroup']['Properties']
properties['MinSize'] = '-1'
properties['MaxSize'] = '2'
stack = utils.parse_stack(t, params=self.params)
e = self.assertRaises(exception.StackValidationFailed,
self.create_scaling_group, t,
stack, 'WebServerGroup')
expected_msg = "The size of AutoScalingGroup can not be less than zero"
self.assertEqual(expected_msg, str(e))
def test_invalid_max_size(self):
t = template_format.parse(as_template)
properties = t['Resources']['WebServerGroup']['Properties']
properties['MinSize'] = '3'
properties['MaxSize'] = '1'
stack = utils.parse_stack(t, params=self.params)
e = self.assertRaises(exception.StackValidationFailed,
self.create_scaling_group, t,
stack, 'WebServerGroup')
expected_msg = "MinSize can not be greater than MaxSize"
self.assertEqual(expected_msg, str(e))
def test_invalid_desiredcapacity(self):
t = template_format.parse(as_template)
properties = t['Resources']['WebServerGroup']['Properties']
properties['MinSize'] = '1'
properties['MaxSize'] = '3'
properties['DesiredCapacity'] = '4'
stack = utils.parse_stack(t, params=self.params)
e = self.assertRaises(exception.StackValidationFailed,
self.create_scaling_group, t,
stack, 'WebServerGroup')
expected_msg = "DesiredCapacity must be between MinSize and MaxSize"
self.assertEqual(expected_msg, str(e))