def test_remove_resource_by_id(self): # Test t = heat.Template() t.add_resource(heat.Resource('id1', 't1')) t.add_resource(heat.Resource('id2', 't2')) t.remove_resource_by_id('id1') # Verify self.assertEqual(1, len(t.resources)) self.assertEqual(t.resources[0].resource_type, 't2')
def test_find_resource_by_id(self): # Setup t = heat.Template() t.add_resource(heat.Resource('a', 'a1')) t.add_resource(heat.Resource('b', 'b1')) # Test found = t.find_resource_by_id('b') # Verify self.assertTrue(found is not None) self.assertEqual(found.resource_type, 'b1')
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 _sample_template(self): t = heat.Template(description='template-desc') # Complex Parameter param = heat.Parameter('p1', 't1', description='desc-1', label='l1', default='def-1', hidden=True) param.add_constraint( heat.ParameterConstraint('t1', 'def-1', description='desc-1')) t.add_parameter(param) # Simple Parameter t.add_parameter(heat.Parameter('p2', 't2')) # Simple Parameter Group t.add_parameter_group(heat.ParameterGroup('l1')) # Complex Parameter Group group = heat.ParameterGroup('l2', description='d2') group.add_parameter_name('foo', 'bar', 'baz') t.add_parameter_group(group) # Complex Resource resource = heat.Resource('r1', 't1', metadata='m1', depends_on='r2', update_policy={'u1': 'u2'}, deletion_policy={'d1': 'd2'}) t.add_resource(resource) # Simple Resource t.add_resource(heat.Resource('r2', 't2')) # Complex Output t.add_output(heat.Output('n1', 'v1', description='desc-1')) # Simple Output t.add_output(heat.Output('n2', 'v2')) return t
def test_add_remove_resource(self): t = heat.Template() r = heat.Resource('id', 't') # Test Add t.add_resource(r) self.assertEqual(1, len(t.resources)) self.assertEqual(r, t.resources[0]) # Test Remove t.remove_resource(r) self.assertEqual(0, len(t.resources))
def test_add_remove_property(self): r = heat.Resource('i', 't') p = heat.ResourceProperty('n', 'v') # Test Add r.add_property(p) self.assertEqual(1, len(r.properties)) self.assertEqual(p, r.properties[0]) # Test Remove r.remove_property(p) self.assertEqual(0, len(r.properties))
def test_find_property_by_name(self): # Setup r = heat.Resource('i', 't') r.add_property(heat.ResourceProperty('a', 'a1')) r.add_property(heat.ResourceProperty('b', 'b1')) # Test found = r.find_property_by_name('b') # Verify self.assertTrue(found is not None) self.assertEqual(found.value, 'b1')
def test_init(self): # Test r = heat.Resource('test-id', 'test-type', metadata='test-meta', depends_on='test-depends', update_policy='test-update', deletion_policy='test-delete') str(r) # should not error # Verify self.assertEqual('test-id', r.resource_id) self.assertEqual('test-type', r.resource_type) self.assertEqual('test-meta', r.metadata) self.assertEqual('test-depends', r.depends_on) self.assertEqual('test-update', r.update_policy) self.assertEqual('test-delete', r.deletion_policy)
def test_remove_property_not_found(self): r = heat.Resource('i', 't') self.assertRaises(ValueError, r.remove_property, heat.ResourceProperty('n', 'v'))
def test_find_property_by_name_missing(self): r = heat.Resource('i', 't') found = r.find_property_by_name('missing') self.assertEqual(found, None)