def test_upstart_frequency_single(self):
        # files should be written out when frequency is ! per-instance
        new_root = tempfile.mkdtemp()
        self.addCleanup(shutil.rmtree, new_root)

        self.patchOS(new_root)
        self.patchUtils(new_root)
        paths = helpers.Paths({
            'upstart_dir': "/etc/upstart",
        })

        util.ensure_dir("/run")
        util.ensure_dir("/etc/upstart")

        with mock.patch(self.mpath + 'SUITABLE_UPSTART', return_value=True):
            with mock.patch.object(util, 'subp') as m_subp:
                h = UpstartJobPartHandler(paths)
                h.handle_part('', handlers.CONTENT_START, None, None, None)
                h.handle_part('blah',
                              'text/upstart-job',
                              'test.conf',
                              'blah',
                              frequency=PER_INSTANCE)
                h.handle_part('', handlers.CONTENT_END, None, None, None)

        self.assertEqual(len(os.listdir('/etc/upstart')), 1)

        m_subp.assert_called_once_with(['initctl', 'reload-configuration'],
                                       capture=False)
    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_upstart_frequency_single(self):
        # files should be written out when frequency is ! per-instance
        new_root = tempfile.mkdtemp()
        self.addCleanup(shutil.rmtree, new_root)

        self.patchOS(new_root)
        self.patchUtils(new_root)
        paths = helpers.Paths({
            'upstart_dir': "/etc/upstart",
        })

        util.ensure_dir("/run")
        util.ensure_dir("/etc/upstart")

        with mock.patch(self.mpath + 'SUITABLE_UPSTART', return_value=True):
            with mock.patch.object(util, 'subp') as m_subp:
                h = UpstartJobPartHandler(paths)
                h.handle_part('', handlers.CONTENT_START,
                              None, None, None)
                h.handle_part('blah', 'text/upstart-job',
                              'test.conf', 'blah', frequency=PER_INSTANCE)
                h.handle_part('', handlers.CONTENT_END,
                              None, None, None)

        self.assertEqual(len(os.listdir('/etc/upstart')), 1)

        m_subp.assert_called_once_with(
            ['initctl', 'reload-configuration'], capture=False)
Beispiel #4
0
 def test_upstart_frequency_no_out(self):
     c_root = tempfile.mkdtemp()
     self.addCleanup(shutil.rmtree, c_root)
     up_root = tempfile.mkdtemp()
     self.addCleanup(shutil.rmtree, up_root)
     paths = helpers.Paths({
         'cloud_dir': c_root,
         'upstart_dir': up_root,
     })
     h = UpstartJobPartHandler(paths)
     # No files should be written out when
     # the frequency is ! per-instance
     h.handle_part('', handlers.CONTENT_START,
                   None, None, None)
     h.handle_part('blah', 'text/upstart-job',
                   'test.conf', 'blah', frequency=PER_ALWAYS)
     h.handle_part('', handlers.CONTENT_END,
                   None, None, None)
     self.assertEqual(0, len(os.listdir(up_root)))
Beispiel #5
0
    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_upstart_frequency_no_out(self):
     c_root = tempfile.mkdtemp()
     self.addCleanup(shutil.rmtree, c_root)
     up_root = tempfile.mkdtemp()
     self.addCleanup(shutil.rmtree, up_root)
     paths = helpers.Paths({
         'cloud_dir': c_root,
         'upstart_dir': up_root,
     })
     h = UpstartJobPartHandler(paths)
     # No files should be written out when
     # the frequency is ! per-instance
     h.handle_part('', handlers.CONTENT_START,
                   None, None, None)
     h.handle_part('blah', 'text/upstart-job',
                   'test.conf', 'blah', frequency=PER_ALWAYS)
     h.handle_part('', handlers.CONTENT_END,
                   None, None, None)
     self.assertEqual(0, len(os.listdir(up_root)))