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
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", )
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)
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
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')