예제 #1
0
    def test_backend_reload(self):
        """Test reload with different backends"""

        config = RawConfigParser()
        config.add_section('performance')
        # minimum scanner threads
        config.set('performance', 'minthreads', 2)
        # maximum scanner threads
        config.set('performance', 'maxthreads', 40)
        # Method for parallelism, either 'thread' or 'process'
        config.set('performance', 'backend', 'process')
        # Initial number of processes when backend='process'.
        # If 0 (the default), automatically selects twice the number of available virtual cores.
        # Despite its 'initial'-name, this number currently is not adapted automatically.
        config.set('performance', 'initialprocs', 10)
        config.set('performance', 'join_timeout', 2.0)

        mc = MainController(config)
        mc.propagate_core_defaults()

        # usually the backend is loaded by "startup()" which is run
        # in a separate thread because it goes to the event loop. I'll just
        # directly start a the threadpool here...
        mc.threadpool = mc._start_threadpool()
        time.sleep(0.1)
        try:
            self.assertIsNone(mc.procpool)
            self.assertIsNotNone(mc.threadpool)
        except AttributeError:
            # Python 2.6
            self.assertTrue(mc.procpool is None)
            self.assertTrue(mc.threadpool is not None)

        # now reload will replace the threadpool by a procpool
        mc.reload()
        time.sleep(0.1)
        try:
            self.assertIsNone(mc.threadpool)
            self.assertIsNotNone(mc.procpool)
        except AttributeError:
            # Python 2.6
            self.assertTrue(mc.threadpool is None)
            self.assertTrue(mc.procpool is not None)
        config.set('performance', 'backend', 'thread')

        # now reload will replace the procpool by a threadpool
        mc.reload()
        time.sleep(0.1)
        try:
            self.assertIsNone(mc.procpool)
            self.assertIsNotNone(mc.threadpool)
        except AttributeError:
            # Python 2.6
            self.assertTrue(mc.procpool is None)
            self.assertTrue(mc.threadpool is not None)
        mc.shutdown()
예제 #2
0
    def test_multiple_mcs(self):
        """Just start multiple controllers """

        config = RawConfigParser()
        mclist = []
        for i in range(10):
            mc = MainController(config)
            mc.propagate_core_defaults()
            mclist.append(mc)

        for mc in mclist:
            # usually the backend is loaded by "startup()" which is run
            # in a separate thread because it goes to the event loop. I'll just
            # directly start a the threadpool here...
            mc.threadpool = mc._start_threadpool()
        time.sleep(0.1)

        for mc in mclist:
            mc.shutdown()
예제 #3
0
    def test_prepender(self):
        """Test prepender plugin raising exception"""
        config = RawConfigParser()

        # -------------#
        # config: main #
        # -------------#
        config.add_section("main")
        config.set('main', 'plugins', '')
        config.set('main', 'prependers',
                   'sessionhandler_test.RaiseExceptionPrepender')
        config.set('main', 'appenders', '')

        # ------------------- #
        # config: performance #
        # ------------------- #
        config.add_section("performance")
        # minimum scanner threads
        config.set('performance', 'minthreads', 1)
        # maximum scanner threads
        config.set('performance', 'maxthreads', 1)
        # Method for parallelism, either 'thread' or 'process'
        config.set('performance', 'backend', 'process')

        mc = MainController(config)
        mc.propagate_core_defaults()
        ok = mc.load_plugins()

        suspect = Suspect('*****@*****.**',
                          '*****@*****.**', '/dev/null')

        shandler = SessionHandler(None, config, mc.prependers, mc.plugins,
                                  mc.appenders, 0)
        pluglist, applist = shandler.run_prependers(suspect)

        shandler.run_plugins(suspect, pluglist)

        ptags = suspect.get_tag("processingerrors")
        self.assertEqual([
            'Prepender RaiseExceptionPrepender failed: Prepender Plugin not implemented'
        ], ptags)
예제 #4
0
    def test_multiple_mcs_reload(self):
        """
        Even if there are multiple MainControllers they should not cause crashes as long as they
        don't start control servers...
        """
        config = RawConfigParser()
        config.add_section('performance')
        # minimum scanner threads
        config.set('performance', 'minthreads', 2)
        # maximum scanner threads
        config.set('performance', 'maxthreads', 40)
        # Method for parallelism, either 'thread' or 'process'
        config.set('performance', 'backend', 'process')
        # Initial number of processes when backend='process'.
        # If 0 (the default), automatically selects twice the number of available virtual cores.
        # Despite its 'initial'-name, this number currently is not adapted automatically.
        config.set('performance', 'initialprocs', 0)

        config = RawConfigParser()
        mclist = []
        for i in range(3):
            mc = MainController(config)
            mc.propagate_core_defaults()
            mclist.append(mc)

        for mc in mclist:
            # usually the backend is loaded by "startup()" which is run
            # in a separate thread because it goes to the event loop. I'll just
            # directly start a the threadpool here...
            mc.threadpool = mc._start_threadpool()
        time.sleep(0.1)
        for mc in mclist:
            mc.reload()
        time.sleep(0.1)

        for mc in mclist:
            mc.shutdown()
예제 #5
0
파일: plugdummy.py 프로젝트: gryphius/fuglu
        if isinstance(pluginstance, ScannerPlugin):
            scanners.append(plugin)
        elif isinstance(pluginstance, PrependerPlugin):
            prependers.append(plugin)
        elif isinstance(pluginstance, AppenderPlugin):
            appenders.append(plugin)
        else:
            print("%s doesn't seem to be a fuglu plugin - ignoring" % plugin)

    config.set('main', 'plugins', ','.join(scanners))
    config.set('main', 'appenders', ','.join(appenders))
    config.set('main', 'prependers', ','.join(prependers))

    # load plugin
    mc = MainController(config)
    mc.propagate_core_defaults()

    mc.load_extensions()
    ok = mc.load_plugins()
    if not ok:
        logging.error("Could not load plugin(s)")
        sys.exit(1)

    if opts.defaultconfig:
        sec = pluginstance.section

        print("Default config options for %s\n" % sec)
        try:
            for opt, val in config.items(sec):
                print("%s:%s" % (opt, val))
        except NoSectionError:
예제 #6
0
        if isinstance(pluginstance, ScannerPlugin):
            scanners.append(plugin)
        elif isinstance(pluginstance, PrependerPlugin):
            prependers.append(plugin)
        elif isinstance(pluginstance, AppenderPlugin):
            appenders.append(plugin)
        else:
            print("%s doesn't seem to be a fuglu plugin - ignoring" % plugin)

    config.set('main', 'plugins', ','.join(scanners))
    config.set('main', 'appenders', ','.join(appenders))
    config.set('main', 'prependers', ','.join(prependers))

    # load plugin
    mc = MainController(config)
    mc.propagate_core_defaults()

    mc.load_extensions()
    ok = mc.load_plugins()
    if not ok:
        logging.error("Could not load plugin(s)")
        sys.exit(1)

    if opts.defaultconfig:
        sec = pluginstance.section

        print("Default config options for %s\n" % sec)
        try:
            for opt, val in config.items(sec):
                print("%s:%s" % (opt, val))
        except ConfigParser.NoSectionError: