def test_compose_nested_resource(self): # Setup t = heat.Template() t.add_resource(heat.Resource('r1', 't1')) # With add_scaling enabled, the plan will automatically wrap the # added template in a grouping resource, so we can use that as the # test data. p = plan.DeploymentPlan(add_scaling=True) p.add_template('ns1', t, 't.yaml') # Test composed = composer.compose_template(p.master_template) # Verify template = yaml.safe_load(composed) self.assertEqual(1, len(template['resources'])) wrapper_resource_name = plan._generate_group_id( plan._generate_resource_id('ns1')) group_resource = template['resources'][wrapper_resource_name] self.assertEqual(p.master_template.resources[0].resource_type, group_resource['type']) self.assertTrue('resource_def' in group_resource['properties']) nested_resource_details = group_resource['properties']['resource_def'] self.assertEqual(ns_utils.apply_resource_alias_namespace('ns1'), nested_resource_details['type'])
def test_add_template_no_scaling(self): # Test p = plan.DeploymentPlan(add_scaling=False) t = self._generate_template() p.add_template('ns1', t, 'template-1.yaml') # Verify Master Template Parameters self.assertEqual(2, len(p.master_template.parameters)) for original, added in zip(t.parameters, p.master_template.parameters): self.assertTrue(added is not original) expected_name = ns_utils.apply_template_namespace('ns1', original.name) self.assertEqual(added.name, expected_name) self.assertEqual(added.param_type, original.param_type) # Verify Resource self.assertEqual(1, len(p.master_template.resources)) added = p.master_template.resources[0] expected_id = plan._generate_resource_id('ns1') self.assertEqual(added.resource_id, expected_id) expected_type = ns_utils.apply_resource_alias_namespace('ns1') self.assertEqual(added.resource_type, expected_type) for param, prop in zip(t.parameters, added.properties): v = ns_utils.apply_template_namespace('ns1', param.name) expected_value = {'get_param': [v]} self.assertEqual(prop.value, expected_value) # Verify Environment Parameters self.assertEqual(2, len(p.environment.parameters)) for env_param, template_param in zip(p.environment.parameters, t.parameters): expected_name = ( ns_utils.apply_template_namespace('ns1', template_param.name)) self.assertEqual(env_param.name, expected_name) self.assertEqual(env_param.value, '') # Verify Resource Registry Entry self.assertEqual(1, len(p.environment.registry_entries)) added = p.environment.registry_entries[0] expected_alias = ns_utils.apply_resource_alias_namespace('ns1') self.assertEqual(added.alias, expected_alias) self.assertEqual(added.filename, 'template-1.yaml')
def test_add_template_no_scaling(self): # Test p = plan.DeploymentPlan(add_scaling=False) t = self._generate_template() p.add_template('ns1', t, 'template-1.yaml') # Verify Master Template Parameters self.assertEqual(2, len(p.master_template.parameters)) for original, added in zip(t.parameters, p.master_template.parameters): self.assertTrue(added is not original) expected_name = ns_utils.apply_template_namespace( 'ns1', original.name) self.assertEqual(added.name, expected_name) self.assertEqual(added.param_type, original.param_type) # Verify Resource self.assertEqual(1, len(p.master_template.resources)) added = p.master_template.resources[0] expected_id = plan._generate_resource_id('ns1') self.assertEqual(added.resource_id, expected_id) expected_type = ns_utils.apply_resource_alias_namespace('ns1') self.assertEqual(added.resource_type, expected_type) for param, prop in zip(t.parameters, added.properties): v = ns_utils.apply_template_namespace('ns1', param.name) expected_value = {'get_param': [v]} self.assertEqual(prop.value, expected_value) # Verify Environment Parameters self.assertEqual(2, len(p.environment.parameters)) for env_param, template_param in zip(p.environment.parameters, t.parameters): expected_name = (ns_utils.apply_template_namespace( 'ns1', template_param.name)) self.assertEqual(env_param.name, expected_name) self.assertEqual(env_param.value, '') # Verify Resource Registry Entry self.assertEqual(1, len(p.environment.registry_entries)) added = p.environment.registry_entries[0] expected_alias = ns_utils.apply_resource_alias_namespace('ns1') self.assertEqual(added.alias, expected_alias) self.assertEqual(added.filename, 'template-1.yaml')
def test_add_scaling_with_scaling(self): # Test p = plan.DeploymentPlan(add_scaling=True) t = self._generate_template() p.add_template('ns1', t, 'template-1.yaml') # Verify Master Template Count Parameters self.assertEqual(3, 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') self.assertEqual(1, len(count_param.constraints)) const = count_param.constraints[0] self.assertTrue(isinstance(const, heat.ParameterConstraint)) self.assertEqual(const.constraint_type, 'range') self.assertEqual(const.definition, {'min': 1}) # Verify Resource Group Wrapper self.assertEqual(1, len(p.master_template.resources)) group_res = p.master_template.resources[0] group_id = plan._generate_group_id(plan._generate_resource_id('ns1')) self.assertEqual(group_res.resource_id, group_id) self.assertEqual(group_res.resource_type, plan.HEAT_TYPE_RESOURCE_GROUP) self.assertEqual(2, 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] 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)) count_param = p.environment.parameters[2] self.assertEqual(count_param.name, expected_count_name) self.assertEqual(count_param.value, 1)