예제 #1
0
    def test_assemble_nested(self):
        """
        Tests that the nested stack that implements the group is created
        appropriately based on properties.
        """
        stack = utils.parse_stack(template)
        snip = stack.t.resource_definitions(stack)['group1']
        resg = resource_group.ResourceGroup('test', snip, stack)
        templ = {
            "heat_template_version": "2013-05-23",
            "resources": {
                "0": {
                    "type": "OverwrittenFnGetRefIdType",
                    "properties": {
                        "Foo": "Bar"
                    }
                },
                "1": {
                    "type": "OverwrittenFnGetRefIdType",
                    "properties": {
                        "Foo": "Bar"
                    }
                },
                "2": {
                    "type": "OverwrittenFnGetRefIdType",
                    "properties": {
                        "Foo": "Bar"
                    }
                }
            }
        }

        self.assertEqual(templ, resg._assemble_nested(['0', '1', '2']))
예제 #2
0
 def test_handle_create(self):
     stack = utils.parse_stack(template2)
     snip = stack.t.resource_definitions(stack)['group1']
     resgrp = resource_group.ResourceGroup('test', snip, stack)
     resgrp.create_with_template = mock.Mock(return_value=None)
     resgrp.handle_create()
     self.assertEqual(1, resgrp.create_with_template.call_count)
예제 #3
0
 def test_handle_delete(self):
     stack = utils.parse_stack(template2)
     snip = stack.t.resource_definitions(stack)['group1']
     resgrp = resource_group.ResourceGroup('test', snip, stack)
     resgrp.delete_nested = mock.Mock(return_value=None)
     resgrp.handle_delete()
     resgrp.delete_nested.assert_called_once_with()
예제 #4
0
 def test_index_var(self):
     stack = utils.parse_stack(template_repl)
     snip = stack.t.resource_definitions(stack)['group1']
     resg = resource_group.ResourceGroup('test', snip, stack)
     expect = {
         "heat_template_version": "2013-05-23",
         "resources": {
             "0": {
                 "type": "ResourceWithListProp%index%",
                 "properties": {
                     "Foo": "Bar_0",
                     "listprop": ["0_0", "0_1", "0_2"]
                 }
             },
             "1": {
                 "type": "ResourceWithListProp%index%",
                 "properties": {
                     "Foo": "Bar_1",
                     "listprop": ["1_0", "1_1", "1_2"]
                 }
             },
             "2": {
                 "type": "ResourceWithListProp%index%",
                 "properties": {
                     "Foo": "Bar_2",
                     "listprop": ["2_0", "2_1", "2_2"]
                 }
             }
         }
     }
     nested = resg._assemble_nested(['0', '1', '2'])
     for res in nested['resources']:
         nested['resources'][res]['properties']['listprop'] = \
             list(nested['resources'][res]['properties']['listprop'])
     self.assertEqual(expect, nested)
예제 #5
0
 def test_assemble_nested_rolling_update_none(self):
     expect = {
         "heat_template_version": "2013-05-23",
         "resources": {
             "0": {
                 "depends_on": [],
                 "type": "OverwrittenFnGetRefIdType",
                 "properties": {
                     "foo": "bar"
                 }
             },
             "1": {
                 "depends_on": [],
                 "type": "OverwrittenFnGetRefIdType",
                 "properties": {
                     "foo": "bar"
                 }
             }
         }
     }
     resource_def = {
         "depends_on": [],
         "type": "OverwrittenFnGetRefIdType",
         "properties": {
             "foo": "baz"
         }
     }
     stack = utils.parse_stack(template)
     snip = stack.t.resource_definitions(stack)['group1']
     resg = resource_group.ResourceGroup('test', snip, stack)
     resg._nested = get_fake_nested_stack(['0', '1'])
     resg._build_resource_definition = mock.Mock(return_value=resource_def)
     self.assertEqual(expect, resg._assemble_for_rolling_update([], []))
예제 #6
0
 def test_index_var(self):
     stack = utils.parse_stack(template_repl)
     snip = stack.t.resource_definitions(stack)['group1']
     resg = resource_group.ResourceGroup('test', snip, stack)
     expect = {
         "heat_template_version": "2013-05-23",
         "resources": {
             "0": {
                 "type": "dummy.listresource%index%",
                 "properties": {
                     "Foo": "Bar_0",
                     "listprop": ["0_0", "0_1", "0_2"]
                 }
             },
             "1": {
                 "type": "dummy.listresource%index%",
                 "properties": {
                     "Foo": "Bar_1",
                     "listprop": ["1_0", "1_1", "1_2"]
                 }
             },
             "2": {
                 "type": "dummy.listresource%index%",
                 "properties": {
                     "Foo": "Bar_2",
                     "listprop": ["2_0", "2_1", "2_2"]
                 }
             }
         }
     }
     self.assertEqual(expect, resg._assemble_nested(['0', '1', '2']))
예제 #7
0
 def setUp(self):
     super(ReplaceTest, self).setUp()
     templ = copy.deepcopy(template)
     self.stack = utils.parse_stack(templ)
     snip = self.stack.t.resource_definitions(self.stack)['group1']
     self.group = resource_group.ResourceGroup('test', snip, self.stack)
     self.group.update_with_template = mock.Mock()
     self.group.check_update_complete = mock.Mock()
예제 #8
0
    def test_custom_index_var(self):
        templ = copy.deepcopy(template_repl)
        templ['resources']['group1']['properties']['index_var'] = "__foo__"
        stack = utils.parse_stack(templ)
        snip = stack.t.resource_definitions(stack)['group1']
        resg = resource_group.ResourceGroup('test', snip, stack)
        expect = {
            "heat_template_version": "2013-05-23",
            "resources": {
                "0": {
                    "type": "ResourceWithListProp%index%",
                    "properties": {
                        "Foo": "Bar_%index%",
                        "listprop": ["%index%_0", "%index%_1", "%index%_2"]
                    }
                }
            }
        }
        nested = resg._assemble_nested(['0'])
        nested['resources']['0']['properties']['listprop'] = \
            list(nested['resources']['0']['properties']['listprop'])
        self.assertEqual(expect, nested)

        res_def = snip['Properties']['resource_def']
        res_def['properties']['Foo'] = "Bar___foo__"
        res_def['properties']['listprop'] = [
            "__foo___0", "__foo___1", "__foo___2"
        ]
        res_def['type'] = "ResourceWithListProp__foo__"
        resg = resource_group.ResourceGroup('test', snip, stack)
        expect = {
            "heat_template_version": "2013-05-23",
            "resources": {
                "0": {
                    "type": "ResourceWithListProp__foo__",
                    "properties": {
                        "Foo": "Bar_0",
                        "listprop": ["0_0", "0_1", "0_2"]
                    }
                }
            }
        }
        nested = resg._assemble_nested(['0'])
        nested['resources']['0']['properties']['listprop'] = \
            list(nested['resources']['0']['properties']['listprop'])
        self.assertEqual(expect, nested)
예제 #9
0
 def test_assemble_nested_zero(self):
     templ = copy.deepcopy(template)
     templ['resources']['group1']['properties']['count'] = 0
     stack = utils.parse_stack(templ)
     snip = stack.t.resource_definitions(stack)['group1']
     resg = resource_group.ResourceGroup('test', snip, stack)
     expect = {"heat_template_version": "2013-05-23", "resources": {}}
     self.assertEqual(expect, resg._assemble_nested([]))
예제 #10
0
 def test_count_black_listed(self):
     stack = utils.parse_stack(template2)
     snip = stack.t.resource_definitions(stack)['group1']
     resgrp = resource_group.ResourceGroup('test', snip, stack)
     resgrp._nested = get_fake_nested_stack(self.existing)
     resgrp._name_blacklist = mock.Mock(return_value=set(self.black_listed))
     rcount = resgrp._count_black_listed()
     self.assertEqual(self.count, rcount)
예제 #11
0
 def test_handle_update_size(self):
     stack = utils.parse_stack(template2)
     snip = stack.t.resource_definitions(stack)['group1']
     resgrp = resource_group.ResourceGroup('test', snip, stack)
     resgrp._assemble_nested_for_size = mock.Mock(return_value=None)
     resgrp.properties.data[resgrp.COUNT] = 5
     self.patchobject(scheduler.TaskRunner, 'start')
     resgrp.handle_update(snip, None, None)
     resgrp._assemble_nested_for_size.assert_called_once_with(5)
예제 #12
0
    def test_child_template(self):
        stack = utils.parse_stack(template2)
        snip = stack.t.resource_definitions(stack)['group1']
        resgrp = resource_group.ResourceGroup('test', snip, stack)
        resgrp._assemble_nested = mock.Mock(return_value='tmpl')
        resgrp.properties.data[resgrp.COUNT] = 2

        self.assertEqual('tmpl', resgrp.child_template())
        resgrp._assemble_nested.assert_called_once_with(['0', '1'])
예제 #13
0
 def test_invalid_res_type(self):
     """Test that error raised for unknown resource type."""
     tmp = copy.deepcopy(template)
     grp_props = tmp['resources']['group1']['properties']
     grp_props['resource_def']['type'] = "idontexist"
     stack = utils.parse_stack(tmp)
     snip = stack.t.resource_definitions(stack)['group1']
     resg = resource_group.ResourceGroup('test', snip, stack)
     exc = self.assertRaises(exception.StackValidationFailed, resg.validate)
     self.assertIn('Unknown resource Type', six.text_type(exc))
예제 #14
0
 def test_invalid_removal_policies_nomap(self):
     """Test that error raised for malformed removal_policies."""
     tmp = copy.deepcopy(template)
     grp_props = tmp['resources']['group1']['properties']
     grp_props['removal_policies'] = ['notallowed']
     stack = utils.parse_stack(tmp)
     snip = stack.t.resource_definitions(stack)['group1']
     resg = resource_group.ResourceGroup('test', snip, stack)
     exc = self.assertRaises(exception.StackValidationFailed, resg.validate)
     errstr = '"notallowed" is not a map'
     self.assertIn(errstr, six.text_type(exc))
예제 #15
0
    def test_child_template(self):
        stack = utils.parse_stack(template2)
        snip = stack.t.resource_definitions(stack)['group1']

        def check_res_names(names):
            self.assertEqual(list(names), ['0', '1'])
            return 'tmpl'

        resgrp = resource_group.ResourceGroup('test', snip, stack)
        resgrp._assemble_nested = mock.Mock()
        resgrp._assemble_nested.side_effect = check_res_names
        resgrp.properties.data[resgrp.COUNT] = 2

        self.assertEqual('tmpl', resgrp.child_template())
        self.assertEqual(1, resgrp._assemble_nested.call_count)
예제 #16
0
 def test_definition(self):
     templ = copy.deepcopy(template)
     res_def = templ["resources"]["group1"]["properties"]['resource_def']
     res_def['properties']['Foo'] = self.value
     stack = utils.parse_stack(templ)
     snip = stack.t.resource_definitions(stack)['group1']
     resg = resource_group.ResourceGroup('test', snip, stack)
     exp1 = {
         "type": "OverwrittenFnGetRefIdType",
         "properties": self.expected,
     }
     exp2 = {
         "type": "OverwrittenFnGetRefIdType",
         "properties": self.expected_include,
     }
     self.assertEqual(exp1, resg._build_resource_definition())
     self.assertEqual(
         exp2, resg._build_resource_definition(include_all=True))
예제 #17
0
 def test_assemble_nested_include(self):
     templ = copy.deepcopy(template)
     res_def = templ["resources"]["group1"]["properties"]['resource_def']
     res_def['properties']['Foo'] = None
     stack = utils.parse_stack(templ)
     snip = stack.t.resource_definitions(stack)['group1']
     resg = resource_group.ResourceGroup('test', snip, stack)
     expect = {
         "heat_template_version": "2013-05-23",
         "resources": {
             "0": {
                 "type": "OverwrittenFnGetRefIdType",
                 "properties": {}
             }
         }
     }
     self.assertEqual(expect, resg._assemble_nested(['0']))
     expect['resources']["0"]['properties'] = {"Foo": None}
     self.assertEqual(
         expect, resg._assemble_nested(['0'], include_all=True))
예제 #18
0
 def test_assemble_nested_with_metadata(self):
     templ = copy.deepcopy(template)
     res_def = templ["resources"]["group1"]["properties"]['resource_def']
     res_def['properties']['Foo'] = None
     res_def['metadata'] = {'priority': 'low', 'role': 'webserver'}
     stack = utils.parse_stack(templ)
     snip = stack.t.resource_definitions(stack)['group1']
     resg = resource_group.ResourceGroup('test', snip, stack)
     expect = {
         "heat_template_version": "2013-05-23",
         "resources": {
             "0": {
                 "type": "OverwrittenFnGetRefIdType",
                 "properties": {},
                 "metadata": {
                     'priority': 'low',
                     'role': 'webserver'
                 }
             }
         }
     }
     self.assertEqual(expect, resg._assemble_nested(['0']))
예제 #19
0
 def test_child_params(self):
     stack = utils.parse_stack(template2)
     snip = stack.t.resource_definitions(stack)['group1']
     resgrp = resource_group.ResourceGroup('test', snip, stack)
     self.assertEqual({}, resgrp.child_params())
예제 #20
0
 def test_reference_attr(self):
     stack = utils.parse_stack(template2)
     snip = stack.t.resource_definitions(stack)['group1']
     resgrp = resource_group.ResourceGroup('test', snip, stack)
     self.assertIsNone(resgrp.validate())