Added removal_policies support for role resource groups

Defaulted to [] which means it shouldn't affect anything unless it is
explicitly set.

Change-Id: Ie698cabec039b4bb0bbdf1d32c6dbfbfac9e24b0
This commit is contained in:
Jay Dobies 2015-05-14 14:17:48 -04:00
parent f06e9d80e8
commit ea39348b89
3 changed files with 52 additions and 10 deletions

View File

@ -34,9 +34,12 @@ import tuskar.templates.namespace as ns_utils
# Type string for a Heat resource group
HEAT_TYPE_RESOURCE_GROUP = 'OS::Heat::ResourceGroup'
# Name of the propety added to a resource group to control its scaling
# Name of the property added to a resource group to control its scaling
PROPERTY_SCALING_COUNT = 'count'
# Name of the property added to a resource group to control removing resources
PROPERTY_REMOVAL_POLICIES = 'removal_policies'
# Name of the property added to a resource group to define the resources
# in the group
PROPERTY_RESOURCE_DEFINITION = 'resource_def'
@ -172,6 +175,11 @@ class DeploymentPlan(object):
{'get_param': [generate_count_property_name(namespace)]})
heat_group.add_property(count_prop)
removal_prop = ResourceProperty(
PROPERTY_REMOVAL_POLICIES,
{'get_param': [generate_removal_policies_name(namespace)]})
heat_group.add_property(removal_prop)
def_prop = ResourceProperty(PROPERTY_RESOURCE_DEFINITION, resource)
heat_group.add_property(def_prop)
@ -193,8 +201,7 @@ class DeploymentPlan(object):
self.master_template.add_parameter(cloned)
# If scaling features are being automatically added in, create the
# template parameter for accepting the count for the resource with
# this namespace
# template parameters for configuring the group
if self.add_scaling:
count_param = Parameter(generate_count_property_name(namespace),
'number')
@ -202,6 +209,11 @@ class DeploymentPlan(object):
count_param.add_constraint(constraint)
self.master_template.add_parameter(count_param)
removal_param = Parameter(
generate_removal_policies_name(namespace), 'json')
removal_param.default = []
self.master_template.add_parameter(removal_param)
def _add_outputs(self, namespace, template, resource):
for add_me in template.outputs:
# The output creation is a bit trickier than simply copying the
@ -237,6 +249,10 @@ class DeploymentPlan(object):
count_param = EnvironmentParameter(count_param_name, '1')
self.environment.add_parameter(count_param)
removal_param_name = generate_removal_policies_name(namespace)
removal_param = EnvironmentParameter(removal_param_name, [])
self.environment.add_parameter(removal_param)
# Add Resource Registry Entry
registry_entry = RegistryEntry(resource_alias, filename)
self.environment.add_registry_entry(registry_entry)
@ -298,3 +314,14 @@ def generate_count_property_name(namespace):
:rtype: str
"""
return ns_utils.apply_template_namespace(namespace, 'count')
def generate_removal_policies_name(namespace):
"""Generates the name of the property to hold the removal policies for
a group. The property will be prefixed by the namespace in the same way
as other parameters for the resource.
:type namespace: str
:rtype: str
"""
return ns_utils.apply_template_namespace(namespace, 'removal_policies')

View File

@ -284,7 +284,7 @@ class PlansManagerTestCase(TestCase):
self.assertEqual('d1', found.description)
self.assertEqual(1, len(found.roles))
self.assertTrue(isinstance(found.roles[0], Role))
self.assertEqual(4, len(found.parameters)) # 3 + 1 for scaling
self.assertEqual(5, len(found.parameters)) # 3 + 2 for scaling
self.assertTrue(isinstance(found.parameters[0], PlanParameter))
def test_list_plans(self):
@ -326,11 +326,12 @@ class PlansManagerTestCase(TestCase):
# Pull it from the database again to make sure it was saved
found = self.plans_manager.retrieve_plan(test_plan.uuid)
found_params = sorted(found.parameters, key=lambda x: x.name)
self.assertEqual(4, len(found_params)) # 3 + 1 for scaling
self.assertEqual(5, len(found_params)) # 3 + 2 for scaling
self.assertEqual(found_params[0].value, '1')
self.assertEqual(found_params[1].value, 'test-image')
self.assertEqual(found_params[2].value, 'm1.small')
self.assertEqual(found_params[3].value, 'test-key')
self.assertEqual(found_params[4].value, [])
def test_set_non_existent_parameters(self):
# Setup
@ -367,7 +368,7 @@ class PlansManagerTestCase(TestCase):
# Pull it from the database to make sure it was modified
found = self.plans_manager.retrieve_plan(test_plan.uuid)
found_params = sorted(found.parameters, key=lambda x: x.name)
self.assertEqual(4, len(found_params)) # 3 + 1 for scaling
self.assertEqual(5, len(found_params)) # 3 + 2 for scaling
self.assertEqual(found_params[0].value, '1')
self.assertEqual(found_params[1].value,
'3e6270da-fbf7-4aef-bc78-6d0cfc3ad11b')

View File

@ -130,12 +130,17 @@ class DeploymentPlanTests(unittest.TestCase):
p.add_template('ns1', t, 'template-1.yaml')
# Verify Master Template Count Parameters
self.assertEqual(3, len(p.master_template.parameters))
self.assertEqual(4, len(p.master_template.parameters))
count_param = p.master_template.parameters[2]
expected_count_name = plan.generate_count_property_name('ns1')
self.assertEqual(count_param.name, expected_count_name)
self.assertEqual(count_param.param_type, 'number')
removal_param = p.master_template.parameters[3]
expected_removal_name = plan.generate_removal_policies_name('ns1')
self.assertEqual(removal_param.name, expected_removal_name)
self.assertEqual(removal_param.param_type, 'json')
self.assertEqual(1, len(count_param.constraints))
const = count_param.constraints[0]
self.assertTrue(isinstance(const, heat.ParameterConstraint))
@ -150,21 +155,30 @@ class DeploymentPlanTests(unittest.TestCase):
self.assertEqual(group_res.resource_type,
plan.HEAT_TYPE_RESOURCE_GROUP)
self.assertEqual(2, len(group_res.properties))
self.assertEqual(3, len(group_res.properties))
count_prop = group_res.properties[0]
self.assertEqual(count_prop.name, plan.PROPERTY_SCALING_COUNT)
self.assertEqual(count_prop.value,
{'get_param': [expected_count_name]})
def_prop = group_res.properties[1]
removal_prop = group_res.properties[1]
self.assertEqual(removal_prop.name, plan.PROPERTY_REMOVAL_POLICIES)
self.assertEqual(removal_prop.value,
{'get_param': [expected_removal_name]})
def_prop = group_res.properties[2]
self.assertEqual(def_prop.name, plan.PROPERTY_RESOURCE_DEFINITION)
self.assertTrue(isinstance(def_prop.value, heat.Resource))
# Verify Environment Parameters
self.assertEqual(3, len(p.environment.parameters))
self.assertEqual(4, len(p.environment.parameters))
count_param = p.environment.parameters[2]
self.assertEqual(count_param.name, expected_count_name)
self.assertEqual(count_param.value, '1')
removal_param = p.environment.parameters[3]
self.assertEqual(removal_param.name, expected_removal_name)
self.assertEqual(removal_param.value, [])
def test_remove_template(self):
# Setup & Sanity Check