def test_format_stack_preview(self, mock_fmt_resource):
        def mock_format_resources(res, **kwargs):
            return 'fmt%s' % res

        mock_fmt_resource.side_effect = mock_format_resources
        resources = [1, [2, [3]]]
        self.stack.preview_resources = mock.Mock(return_value=resources)

        stack = api.format_stack_preview(self.stack)
        self.assertIsInstance(stack, dict)
        self.assertIsNone(stack.get('status'))
        self.assertIsNone(stack.get('action'))
        self.assertIsNone(stack.get('status_reason'))
        self.assertEqual('test_stack', stack['stack_name'])
        self.assertIn('resources', stack)
        resources = list(stack['resources'])
        self.assertEqual('fmt1', resources[0])

        resources = list(resources[1])
        self.assertEqual('fmt2', resources[0])

        resources = list(resources[1])
        self.assertEqual('fmt3', resources[0])

        kwargs = mock_fmt_resource.call_args[1]
        self.assertTrue(kwargs['with_props'])
Exemple #2
0
    def preview_stack(self, cnxt, stack_name, template, params, files, args):
        """
        Simulates a new stack using the provided template.

        Note that at this stage the template has already been fetched from the
        heat-api process if using a template-url.

        :param cnxt: RPC context.
        :param stack_name: Name of the stack you want to create.
        :param template: Template of stack you want to create.
        :param params: Stack Input Params
        :param files: Files referenced from the template
        :param args: Request parameters/args passed from API
        """

        logger.info(_('previewing stack %s') % stack_name)
        tmpl = parser.Template(template, files=files)
        self._validate_new_stack(cnxt, stack_name, tmpl)

        common_params = api.extract_args(args)
        env = environment.Environment(params)
        stack = parser.Stack(cnxt, stack_name, tmpl, env, **common_params)

        self._validate_deferred_auth_context(cnxt, stack)
        stack.validate()

        return api.format_stack_preview(stack)
Exemple #3
0
    def preview_stack(self, cnxt, stack_name, template, params, files, args):
        """
        Simulates a new stack using the provided template.

        Note that at this stage the template has already been fetched from the
        heat-api process if using a template-url.

        :param cnxt: RPC context.
        :param stack_name: Name of the stack you want to create.
        :param template: Template of stack you want to create.
        :param params: Stack Input Params
        :param files: Files referenced from the template
        :param args: Request parameters/args passed from API
        """

        LOG.info(_('previewing stack %s') % stack_name)
        tmpl = parser.Template(template, files=files)
        self._validate_new_stack(cnxt, stack_name, tmpl)

        common_params = api.extract_args(args)
        env = environment.Environment(params)
        stack = parser.Stack(cnxt, stack_name, tmpl, env, **common_params)

        self._validate_deferred_auth_context(cnxt, stack)
        stack.validate()

        return api.format_stack_preview(stack)
Exemple #4
0
    def test_format_stack_preview(self, mock_fmt_resource):
        def mock_format_resources(res, **kwargs):
            return 'fmt%s' % res

        mock_fmt_resource.side_effect = mock_format_resources
        resources = [1, [2, [3]]]
        self.stack.preview_resources = mock.Mock(return_value=resources)

        stack = api.format_stack_preview(self.stack)
        self.assertIsInstance(stack, dict)
        self.assertIsNone(stack.get('status'))
        self.assertIsNone(stack.get('action'))
        self.assertIsNone(stack.get('status_reason'))
        self.assertEqual('test_stack', stack['stack_name'])
        self.assertIn('resources', stack)
        resources = list(stack['resources'])
        self.assertEqual('fmt1', resources[0])

        resources = list(resources[1])
        self.assertEqual('fmt2', resources[0])

        resources = list(resources[1])
        self.assertEqual('fmt3', resources[0])

        kwargs = mock_fmt_resource.call_args[1]
        self.assertTrue(kwargs['with_props'])
    def test_format_stack_preview(self, mock_fmt_resource):
        def mock_format_resources(res):
            return 'fmt%s' % res

        mock_fmt_resource.side_effect = mock_format_resources
        resources = [1, [2, [3]]]
        self.stack.preview_resources = mock.Mock(return_value=resources)

        stack = api.format_stack_preview(self.stack)
        self.assertIsInstance(stack, dict)
        self.assertEqual('test_stack', stack['stack_name'])
        self.assertIn('resources', stack)
        self.assertEqual(['fmt1', ['fmt2', ['fmt3']]], stack['resources'])
    def test_format_stack_preview(self, mock_fmt_resource):
        def mock_format_resources(res):
            return 'fmt%s' % res

        mock_fmt_resource.side_effect = mock_format_resources
        resources = [1, [2, [3]]]
        self.stack.preview_resources = mock.Mock(return_value=resources)

        stack = api.format_stack_preview(self.stack)
        self.assertIsInstance(stack, dict)
        self.assertEqual('test_stack', stack['stack_name'])
        self.assertIn('resources', stack)
        self.assertEqual(['fmt1', ['fmt2', ['fmt3']]], stack['resources'])
    def test_format_stack_preview(self, mock_fmt_resource):
        def mock_format_resources(res):
            return "fmt%s" % res

        mock_fmt_resource.side_effect = mock_format_resources
        resources = [1, [2, [3]]]
        self.stack.preview_resources = mock.Mock(return_value=resources)

        stack = api.format_stack_preview(self.stack)
        self.assertIsInstance(stack, dict)
        self.assertEqual("test_stack", stack["stack_name"])
        self.assertIn("resources", stack)
        self.assertEqual(["fmt1", ["fmt2", ["fmt3"]]], stack["resources"])
Exemple #8
0
    def preview_stack(self, cnxt, stack_name, template, params, files, args):
        """
        Simulates a new stack using the provided template.

        Note that at this stage the template has already been fetched from the
        heat-api process if using a template-url.

        :param cnxt: RPC context.
        :param stack_name: Name of the stack you want to create.
        :param template: Template of stack you want to create.
        :param params: Stack Input Params
        :param files: Files referenced from the template
        :param args: Request parameters/args passed from API
        """

        LOG.info(_('previewing stack %s') % stack_name)
        stack = self._parse_template_and_validate_stack(
            cnxt, stack_name, template, params, files, args)

        return api.format_stack_preview(stack)
Exemple #9
0
    def preview_stack(self, cnxt, stack_name, template, params, files, args):
        """
        Simulates a new stack using the provided template.

        Note that at this stage the template has already been fetched from the
        heat-api process if using a template-url.

        :param cnxt: RPC context.
        :param stack_name: Name of the stack you want to create.
        :param template: Template of stack you want to create.
        :param params: Stack Input Params
        :param files: Files referenced from the template
        :param args: Request parameters/args passed from API
        """

        LOG.info(_('previewing stack %s') % stack_name)
        stack = self._parse_template_and_validate_stack(cnxt,
                                                        stack_name,
                                                        template,
                                                        params,
                                                        files,
                                                        args)

        return api.format_stack_preview(stack)