Beispiel #1
0
    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'])
Beispiel #2
0
    def _remove_from_environment(self, namespace):
        # Remove Parameters
        self.environment.remove_parameters_by_namespace(namespace)

        # Remove Resource Registry Entry
        resource_alias = ns_utils.apply_resource_alias_namespace(namespace)
        self.environment.remove_registry_entry_by_alias(resource_alias)
Beispiel #3
0
    def add_template(self, namespace, template, filename,
                     override_properties=None):
        """Adds a new template to the plan. The pieces of the template will
        be prefixed with the given namespace in the plan's master template.

        :param namespace: prefix to use to prevent parameter and output
                          naming conflicts
        :type  namespace: str
        :param template: template being added to the plan
        :type  template: tuskar.templates.heat.Template
        :param filename: name of the file where the template is stored, used
                         when mapping the template in the environment
        :type  filename: str
        :param override_properties: mapping of property name to specific value
               to use instead of the Tuskar-generated parameter
        :type override_properties: {str, str}
        :raise ValueError: if given namespace is already taken
        """
        override_properties = override_properties or {}

        if self.environment.has_parameter_in_namespace(namespace):
            raise ValueError(
                "Cannot add template to plan - namespace '%s' is taken."
                % namespace)

        resource_alias = ns_utils.apply_resource_alias_namespace(namespace)

        self._add_to_master_template(namespace, template, resource_alias,
                                     override_properties)
        self._add_to_environment(namespace, template, filename, resource_alias,
                                 override_properties)
Beispiel #4
0
    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('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'])
Beispiel #5
0
    def _remove_from_environment(self, namespace):
        # Remove Parameters
        self.environment.remove_parameters_by_namespace(namespace)

        # Remove Resource Registry Entry
        resource_alias = ns_utils.apply_resource_alias_namespace(namespace)
        self.environment.remove_registry_entry_by_alias(resource_alias)
Beispiel #6
0
    def add_template(self,
                     namespace,
                     template,
                     filename,
                     override_properties=None):
        """Adds a new template to the plan. The pieces of the template will
        be prefixed with the given namespace in the plan's master template.

        :param namespace: prefix to use to prevent parameter and output
                          naming conflicts
        :type  namespace: str
        :param template: template being added to the plan
        :type  template: tuskar.templates.heat.Template
        :param filename: name of the file where the template is stored, used
                         when mapping the template in the environment
        :type  filename: str
        :param override_properties: mapping of property name to specific value
               to use instead of the Tuskar-generated parameter
        :type override_properties: {str, str}
        :raise ValueError: if given namespace is already taken
        """
        override_properties = override_properties or {}

        if self.environment.has_parameter_in_namespace(namespace):
            raise ValueError(
                "Cannot add template to plan - namespace '%s' is taken." %
                namespace)

        resource_alias = ns_utils.apply_resource_alias_namespace(namespace)

        self._add_to_master_template(namespace, template, resource_alias,
                                     override_properties)
        self._add_to_environment(namespace, template, filename, resource_alias,
                                 override_properties)
Beispiel #7
0
    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')
Beispiel #8
0
    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')
Beispiel #9
0
 def test_apply_resource_alias_namespace(self):
     namespaced = namespace.apply_resource_alias_namespace('compute')
     self.assertEqual(namespaced, 'Tuskar::compute')
Beispiel #10
0
 def test_apply_resource_alias_namespace(self):
     namespaced = namespace.apply_resource_alias_namespace('compute')
     self.assertEqual(namespaced, 'Tuskar::compute')