add the validation of MaxSize ,MinSize and DesiredCapacity

* check whether MinSize is less than MaxSize
* check whether MinSize and MaxSize is not less than 0
* if DesiredCapacity is offered,check whether it is between
  MinSize and MaxSize

Change-Id: I79a7b6c0e61f109ac7e71d3fd48d93fb741bbc64
Closes-Bug: #1270070
This commit is contained in:
Zhang Yang 2014-01-17 19:07:18 -08:00
parent 371bbdea47
commit e1d75b4a7c
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))