def _default_handlers(self, opts=None):
        if opts is None:
            opts = {}

        opts.update(
            {
                "paths": self.paths,
                "datasource": self.datasource,
            }
        )
        # TODO(harlowja) Hmmm, should we dynamically import these??
        cloudconfig_handler = CloudConfigPartHandler(**opts)
        shellscript_handler = ShellScriptPartHandler(**opts)
        def_handlers = [
            cloudconfig_handler,
            shellscript_handler,
            ShellScriptByFreqPartHandler(PER_ALWAYS, **opts),
            ShellScriptByFreqPartHandler(PER_INSTANCE, **opts),
            ShellScriptByFreqPartHandler(PER_ONCE, **opts),
            BootHookPartHandler(**opts),
            UpstartJobPartHandler(**opts),
        ]
        opts.update(
            {"sub_handlers": [cloudconfig_handler, shellscript_handler]}
        )
        def_handlers.append(JinjaTemplatePartHandler(**opts))
        return def_handlers
예제 #2
0
    def test_jinja_template_handle_subhandler_v3_with_clean_payload(self):
        """Call version 3 subhandler.handle_part with stripped payload."""
        cloudcfg_handler = CloudConfigPartHandler(self.paths)
        self.assertEqual(3, cloudcfg_handler.handler_version)

        # Create required instance-data.json file
        instance_json = os.path.join(self.run_dir, INSTANCE_DATA_FILE)
        instance_data = {"topkey": {"sub": "runcmd: [echo hi]"}}
        util.write_file(instance_json, util.json_dumps(instance_data))
        h = JinjaTemplatePartHandler(self.paths,
                                     sub_handlers=[cloudcfg_handler])
        with mock.patch.object(cloudcfg_handler, "handle_part") as m_part:
            # ctype with leading '!' not in handlers.CONTENT_SIGNALS
            h.handle_part(
                data="data",
                ctype="!" + handlers.CONTENT_END,
                filename="part01",
                payload="## template: jinja\n#cloud-config\n{{ topkey.sub }}",
                frequency="freq",
                headers="headers",
            )
        m_part.assert_called_once_with(
            "data",
            "!__end__",
            "part01",
            "#cloud-config\nruncmd: [echo hi]",
            "freq",
            "headers",
        )
예제 #3
0
 def test_jinja_template_part_handler_looks_up_subhandler_types(self):
     """When sub_handlers are passed, init lists types of subhandlers."""
     script_handler = ShellScriptPartHandler(self.paths)
     cloudconfig_handler = CloudConfigPartHandler(self.paths)
     h = JinjaTemplatePartHandler(
         self.paths, sub_handlers=[script_handler, cloudconfig_handler])
     self.assertCountEqual([
         'text/cloud-config', 'text/cloud-config-jsonp',
         'text/x-shellscript'
     ], h.sub_handlers)
예제 #4
0
파일: stages.py 프로젝트: akutz/cloud-init
    def _default_handlers(self, opts=None):
        if opts is None:
            opts = {}

        opts.update({
            'paths': self.paths,
            'datasource': self.datasource,
        })
        # TODO(harlowja) Hmmm, should we dynamically import these??
        cloudconfig_handler = CloudConfigPartHandler(**opts)
        shellscript_handler = ShellScriptPartHandler(**opts)
        def_handlers = [
            cloudconfig_handler,
            shellscript_handler,
            BootHookPartHandler(**opts),
            UpstartJobPartHandler(**opts),
        ]
        opts.update(
            {'sub_handlers': [cloudconfig_handler, shellscript_handler]})
        def_handlers.append(JinjaTemplatePartHandler(**opts))
        return def_handlers
예제 #5
0
    def test_jinja_template_handle_subhandler_v3_with_clean_payload(self):
        """Call version 3 subhandler.handle_part with stripped payload."""
        cloudcfg_handler = CloudConfigPartHandler(self.paths)
        self.assertEqual(3, cloudcfg_handler.handler_version)

        # Create required instance-data.json file
        instance_json = os.path.join(self.run_dir, 'instance-data.json')
        instance_data = {'topkey': {'sub': 'runcmd: [echo hi]'}}
        util.write_file(instance_json, util.json_dumps(instance_data))
        h = JinjaTemplatePartHandler(
            self.paths, sub_handlers=[cloudcfg_handler])
        with mock.patch.object(cloudcfg_handler, 'handle_part') as m_part:
            # ctype with leading '!' not in handlers.CONTENT_SIGNALS
            h.handle_part(
                data='data', ctype="!" + handlers.CONTENT_END,
                filename='part01',
                payload='## template: jinja\n#cloud-config\n{{ topkey.sub }}',
                frequency='freq', headers='headers')
        m_part.assert_called_once_with(
            'data', '!__end__', 'part01', '#cloud-config\nruncmd: [echo hi]',
            'freq', 'headers')