From d84c9bc0a6065a077ef7590aaec870ff3a34a20a Mon Sep 17 00:00:00 2001 From: Angus Salkeld Date: Tue, 7 Apr 2015 15:26:25 +1000 Subject: [PATCH] Make sure UpdatePolicy is unset for Heat scaling group It is defined within the properties as rolling_updates. This patch is to make it more obvious to users that UpdatePolicy is not supported. Change-Id: I8162d27036843d0b9282cd8f4aa4d2eb93afba19 Closes-bug: 1423426 --- .../openstack/heat/autoscaling_group.py | 1 + .../openstack/heat/instance_group.py | 7 ++-- .../autoscaling/test_heat_scaling_group.py | 39 +++++++++++++++++++ 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/heat/engine/resources/openstack/heat/autoscaling_group.py b/heat/engine/resources/openstack/heat/autoscaling_group.py index 9c9597956f..0e2a8584c2 100644 --- a/heat/engine/resources/openstack/heat/autoscaling_group.py +++ b/heat/engine/resources/openstack/heat/autoscaling_group.py @@ -123,6 +123,7 @@ class AutoScalingResourceGroup(aws_asg.AutoScalingGroup): _("The current size of AutoscalingResourceGroup.") ), } + update_policy_schema = {} def _get_instance_definition(self): rsrc = self.properties[self.RESOURCE] diff --git a/heat/engine/resources/openstack/heat/instance_group.py b/heat/engine/resources/openstack/heat/instance_group.py index d5e22fc299..23791e40d3 100644 --- a/heat/engine/resources/openstack/heat/instance_group.py +++ b/heat/engine/resources/openstack/heat/instance_group.py @@ -135,10 +135,11 @@ class InstanceGroup(stack_resource.StackResource): """ super(InstanceGroup, self).validate() - if self.update_policy: + if self.update_policy is not None: self.update_policy.validate() - policy_name = self.update_policy_schema.keys()[0] - if self.update_policy[policy_name]: + policy_name = self.ROLLING_UPDATE + if (policy_name in self.update_policy and + self.update_policy[policy_name] is not None): pause_time = self.update_policy[policy_name][self.PAUSE_TIME] if iso8601utils.parse_isoduration(pause_time) > 3600: msg = _('Maximum %s is 1 hour.') % self.PAUSE_TIME diff --git a/heat/tests/autoscaling/test_heat_scaling_group.py b/heat/tests/autoscaling/test_heat_scaling_group.py index 17f6cb1fbe..89f3a3c607 100644 --- a/heat/tests/autoscaling/test_heat_scaling_group.py +++ b/heat/tests/autoscaling/test_heat_scaling_group.py @@ -534,3 +534,42 @@ class RollingUpdatePolicyDiffTest(common.HeatTestCase): def test_update_policy_removed(self): self.validate_update_policy_diff(asg_tmpl_with_updt_policy(), inline_templates.as_heat_template) + + +class IncorrectUpdatePolicyTest(common.HeatTestCase): + def setUp(self): + super(IncorrectUpdatePolicyTest, self).setUp() + self.stub_keystoneclient(username='test_stack.CfnLBUser') + resource._register_class('ResourceWithPropsAndAttrs', + generic_resource.ResourceWithPropsAndAttrs) + cfg.CONF.set_default('heat_waitcondition_server_url', + 'http://127.0.0.1:8000/v1/waitcondition') + + def test_with_update_policy_aws(self): + t = template_format.parse(inline_templates.as_heat_template) + ag = t['resources']['my-group'] + ag["update_policy"] = {"AutoScalingRollingUpdate": { + "MinInstancesInService": "1", + "MaxBatchSize": "2", + "PauseTime": "PT1S" + }} + tmpl = template_format.parse(json.dumps(t)) + stack = utils.parse_stack(tmpl) + exc = self.assertRaises(exception.StackValidationFailed, + stack.validate) + self.assertIn('Unknown Property AutoScalingRollingUpdate', + six.text_type(exc)) + + def test_with_update_policy_inst_group(self): + t = template_format.parse(inline_templates.as_heat_template) + ag = t['resources']['my-group'] + ag["update_policy"] = {"RollingUpdate": { + "MinInstancesInService": "1", + "MaxBatchSize": "2", + "PauseTime": "PT1S" + }} + tmpl = template_format.parse(json.dumps(t)) + stack = utils.parse_stack(tmpl) + exc = self.assertRaises(exception.StackValidationFailed, + stack.validate) + self.assertIn('Unknown Property RollingUpdate', six.text_type(exc))