Beispiel #1
0
def start_forwarder_backend():
    if parse_bool(config.get_conf('beah-backend').get('DEFAULT', 'DEVEL')):
        print_this = log_this(lambda s: log.debug(s), log_on=True)
        make_class_verbose(ForwarderBackend, print_this)
        make_class_verbose(_RemoteBackend, print_this)
    backend = ForwarderBackend()
    # Start a default TCP client:
    start_backend(backend)
    return backend
Beispiel #2
0
def start_forwarder_backend():
    if parse_bool(config.get_conf('beah-backend').get('DEFAULT', 'DEVEL')):
        print_this = log_this(lambda s: log.debug(s), log_on=True)
        make_class_verbose(ForwarderBackend, print_this)
        make_class_verbose(_RemoteBackend, print_this)
    backend = ForwarderBackend()
    # Start a default TCP client:
    start_backend(backend)
    return backend
Beispiel #3
0
def start_watchdog_backend(conf):
    '''Starts a watchdog backend with specified configuration.'''
    log = logging.getLogger('backend')
    if parse_bool(conf.get('DEFAULT', 'DEVEL')):
        print_this = log_this(log.debug, log_on=True)
        make_class_verbose(WatchdogBackend, print_this)
        make_class_verbose(Task, print_this)
    handlers = dict(DEFAULT_HANDLERS)
    load_plugins(WATCHDOG_ENTRYPOINT, handlers)
    backend = WatchdogBackend(conf=conf, log=log, handlers=handlers)
    query_interval = int(conf.get('DEFAULT', 'QUERY_WATCHDOG'))
    if query_interval > 0:
        watchdogs_request = LoopingCall(backend.query_watchdogs)
        watchdogs_request.start(query_interval, now=False)
        #pylint: disable=E1101
        reactor.addSystemEventTrigger('before', 'shutdown', watchdogs_request.stop)
    # Start a default TCP client:
    backend.initialize()
    start_backend(backend)
Beispiel #4
0
def start_watchdog_backend(conf):
    '''Starts a watchdog backend with specified configuration.'''
    log = logging.getLogger('backend')
    if parse_bool(conf.get('DEFAULT', 'DEVEL')):
        print_this = log_this(log.debug, log_on=True)
        make_class_verbose(WatchdogBackend, print_this)
        make_class_verbose(Task, print_this)
    handlers = dict(DEFAULT_HANDLERS)
    load_plugins(WATCHDOG_ENTRYPOINT, handlers)
    backend = WatchdogBackend(conf=conf, log=log, handlers=handlers)
    query_interval = int(conf.get('DEFAULT', 'QUERY_WATCHDOG'))
    if query_interval > 0:
        watchdogs_request = LoopingCall(backend.query_watchdogs)
        watchdogs_request.start(query_interval, now=False)
        #pylint: disable=E1101
        reactor.addSystemEventTrigger('before', 'shutdown',
                                      watchdogs_request.stop)
    # Start a default TCP client:
    backend.initialize()
    start_backend(backend)
Beispiel #5
0
def main():
    ################################################################################
    # EXECUTE:
    ################################################################################
    global conf, runtime, uploader, results
    conf = conf_main({}, sys.argv[1:])
    name = conf['name']
    var_path = os.path.join(conf['root'], VAR_PATH, name)
    runtime = runtimes.ShelveRuntime(os.path.join(var_path, "runtime"))
    log = logging.getLogger('beah_fakelc')
    twisted_logging(log, level=logging.WARNING)
    # FIXME: redirect to console or syslog?
    misc.make_log_handler(log, os.path.join(conf['root'], LOG_PATH),
                          "%s.log" % name)
    log.setLevel(misc.str2log_level(conf.get('LOG', 'warning')))
    if conf.get('DEVEL', False):
        print_this = log_this.log_this(lambda s: log.debug(s), log_on=True)
        # make the classes verbose:
        misc.make_class_verbose(LCRecipes, print_this)
        misc.make_class_verbose(LCRecipeTasks, print_this)
        misc.make_class_verbose(LCHandler, print_this)
    lc = LCHandler()
    lc.XMLRPC_TIMEOUT = safe_int(conf['timeout'], 0)
    s = server.Site(lc, None, 60 * 60 * 12)
    reactor.listenTCP(conf['port'], s, interface='')
    # To support testing in IPv6 and mixed IPv4/IPv6 environments,
    # we attempt to listen on the specified (defaults to IPv6)
    # interface as well.
    try:
        reactor.listenTCP(conf['port'], s, interface=conf['interface'])
    except CannotListenError:
        pass

    reactor.addSystemEventTrigger("before", "shutdown", close, log)
    upload_path = os.path.join(var_path, "fakelc-uploads")
    results = Results(var_path, upload_path)
    uploader = Uploader(upload_path)
    reactor.run()
Beispiel #6
0
def main():
################################################################################
# EXECUTE:
################################################################################
    global conf, runtime, uploader, results
    conf = conf_main({}, sys.argv[1:])
    name = conf['name']
    var_path = os.path.join(conf['root'], VAR_PATH, name)
    runtime = runtimes.ShelveRuntime(os.path.join(var_path, "runtime"))
    log = logging.getLogger('beah_fakelc')
    twisted_logging(log, level=logging.WARNING)
    # FIXME: redirect to console or syslog?
    misc.make_log_handler(log, os.path.join(conf['root'], LOG_PATH), "%s.log" % name)
    log.setLevel(misc.str2log_level(conf.get('LOG', 'warning')))
    if conf.get('DEVEL', False):
        print_this = log_this.log_this(lambda s: log.debug(s), log_on=True)
        # make the classes verbose:
        misc.make_class_verbose(LCRecipes, print_this)
        misc.make_class_verbose(LCRecipeTasks, print_this)
        misc.make_class_verbose(LCHandler, print_this)
    lc = LCHandler()
    lc.XMLRPC_TIMEOUT = safe_int(conf['timeout'], 0)
    s = server.Site(lc, None, 60*60*12)
    reactor.listenTCP(conf['port'], s, interface='')
    # To support testing in IPv6 and mixed IPv4/IPv6 environments, 
    # we attempt to listen on the specified (defaults to IPv6) 
    # interface as well.
    try:
        reactor.listenTCP(conf['port'], s, interface=conf['interface'])
    except CannotListenError:
        pass

    reactor.addSystemEventTrigger("before", "shutdown", close, log)
    upload_path = os.path.join(var_path, "fakelc-uploads")
    results = Results(var_path, upload_path)
    uploader = Uploader(upload_path)
    reactor.run()
Beispiel #7
0
def start_server(conf=None, backend_host=None, backend_port=None,
        backend_adaptor=BackendAdaptor_JSON,
        task_host=None, task_port=None,
        task_adaptor=TaskAdaptor_JSON, spawn=None):

    # CONFIG:
    if not conf:
        config.beah_conf()
        conf = config.get_conf('beah')

    # LOGGING:
    twisted_logging(log, level=logging.WARNING)
    log.setLevel(str2log_level(conf.get('CONTROLLER', 'LOG')))

    # Create a directory for runtime
    # FIXME: should try to create a temp path if following fails:
    ensuredir(conf.get('CONTROLLER', 'VAR_ROOT'))

    # Create a directory for logging and check permissions
    lp = conf.get('CONTROLLER', 'LOG_PATH')
    make_log_handler(log, lp, conf.get('CONTROLLER', 'LOG_FILE_NAME'),
            syslog=True, console=conf.get('CONTROLLER', 'CONSOLE_LOG', False))
    if parse_bool(config.get_conf('beah').get('CONTROLLER', 'DEVEL')):
        print_this = log_this(log.debug, True)
        make_class_verbose(Controller, print_this)
        make_class_verbose(MasterTask, print_this)

    # RUN:
    backend_host = backend_host or conf.get('BACKEND', 'INTERFACE')
    backend_port = backend_port or conf.get('BACKEND', 'PORT')
    task_host = task_host or conf.get('TASK', 'INTERFACE')
    task_port = task_port or int(conf.get('TASK', 'PORT'))
    if os.name == 'posix':
        if backend_port != '':
            backend_port = int(backend_port)
        backend_socket = conf.get('BACKEND', 'SOCKET')
        if task_port != '':
            task_port = int(task_port)
        task_socket = conf.get('TASK', 'SOCKET')
    else:
        backend_port = int(backend_port)
        backend_socket = ''
        task_port = int(task_port)
        task_socket = ''
    runtime = runtimes.ShelveRuntime(conf.get('CONTROLLER', 'RUNTIME_FILE_NAME'))
    runtime.vars = runtimes.TypeDict(runtime, 'vars')
    runtime.tasks = runtimes.TypeDict(runtime, 'tasks')
    controller = Controller(spawn or Spawn(task_host, task_port, socket=task_socket),  runtime=runtime)
    def on_killed():
        if not controller.backends:
            reactor.stop()
            return
        reactor.callLater(2, reactor.stop)
    controller.on_killed = on_killed
    log.info("################################")
    log.info("#   Starting a Controller...   #")
    log.info("################################")
    backend_listener = BackendListener(controller, backend_adaptor)
    if backend_port != '':
        if backend_host == 'localhost':
            listening = listen_loopback_tcp(backend_port, backend_listener)
        elif backend_host:
            listening = reactor.listenTCP(backend_port, backend_listener, interface=backend_host)
        else:
            listening = listen_all_tcp(backend_port,
                                       backend_listener,
                                       ipv6_disabled=parse_bool(conf.get('DEFAULT', 'IPV6_DISABLED')))
        log.info("Controller: BackendListener listening on %s port %s",
                listening.getHost().host, listening.getHost().port)
    if backend_socket:
        if os.path.exists(backend_socket):
            # clean-up after e.g. system crash:
            log.warning("Controller: BackendListener cleaning %s", backend_socket)
            os.remove(backend_socket)
        log.info("Controller: BackendListener listening on %s", backend_socket)
        reactor.listenUNIX(backend_socket, backend_listener)
    task_listener = TaskListener(controller, task_adaptor)
    if task_port != '':
        if task_host == 'localhost':
            listening = listen_loopback_tcp(task_port, task_listener)
        elif task_host:
            listening = reactor.listenTCP(task_port, task_listener, interface=task_host)
        else:
            listening = listen_all_tcp(task_port, 
                                       task_listener,
                                       ipv6_disabled=parse_bool(conf.get('DEFAULT', 'IPV6_DISABLED')))
        log.info("Controller: TaskListener listening on %s port %s",
                listening.getHost().host, listening.getHost().port)
    if task_socket:
        if os.path.exists(task_socket):
            # clean-up after e.g. system crash:
            log.warning("Controller: TaskListener cleaning %s", task_socket)
            os.remove(task_socket)
        log.info("Controller: TaskListener listening on %s", task_socket)
        reactor.listenUNIX(task_socket, task_listener)
    return controller
Beispiel #8
0
def start_server(conf=None,
                 backend_host=None,
                 backend_port=None,
                 backend_adaptor=BackendAdaptor_JSON,
                 task_host=None,
                 task_port=None,
                 task_adaptor=TaskAdaptor_JSON,
                 spawn=None):

    # CONFIG:
    if not conf:
        config.beah_conf()
        conf = config.get_conf('beah')

    # LOGGING:
    twisted_logging(log, level=logging.WARNING)
    log.setLevel(str2log_level(conf.get('CONTROLLER', 'LOG')))

    # Create a directory for runtime
    # FIXME: should try to create a temp path if following fails:
    ensuredir(conf.get('CONTROLLER', 'VAR_ROOT'))

    # Create a directory for logging and check permissions
    lp = conf.get('CONTROLLER', 'LOG_PATH')
    make_log_handler(log,
                     lp,
                     conf.get('CONTROLLER', 'LOG_FILE_NAME'),
                     syslog=True,
                     console=conf.get('CONTROLLER', 'CONSOLE_LOG', False))
    if parse_bool(config.get_conf('beah').get('CONTROLLER', 'DEVEL')):
        print_this = log_this(log.debug, True)
        make_class_verbose(Controller, print_this)
        make_class_verbose(MasterTask, print_this)

    # RUN:
    backend_host = backend_host or conf.get('BACKEND', 'INTERFACE')
    backend_port = backend_port or conf.get('BACKEND', 'PORT')
    task_host = task_host or conf.get('TASK', 'INTERFACE')
    task_port = task_port or int(conf.get('TASK', 'PORT'))
    if os.name == 'posix':
        if backend_port != '':
            backend_port = int(backend_port)
        backend_socket = conf.get('BACKEND', 'SOCKET')
        if task_port != '':
            task_port = int(task_port)
        task_socket = conf.get('TASK', 'SOCKET')
    else:
        backend_port = int(backend_port)
        backend_socket = ''
        task_port = int(task_port)
        task_socket = ''
    runtime = runtimes.ShelveRuntime(
        conf.get('CONTROLLER', 'RUNTIME_FILE_NAME'))
    runtime.vars = runtimes.TypeDict(runtime, 'vars')
    runtime.tasks = runtimes.TypeDict(runtime, 'tasks')
    controller = Controller(spawn
                            or Spawn(task_host, task_port, socket=task_socket),
                            runtime=runtime)

    def on_killed():
        if not controller.backends:
            reactor.stop()
            return
        reactor.callLater(2, reactor.stop)

    controller.on_killed = on_killed
    log.info("################################")
    log.info("#   Starting a Controller...   #")
    log.info("################################")
    backend_listener = BackendListener(controller, backend_adaptor)
    if backend_port != '':
        if backend_host == 'localhost':
            listening = listen_loopback_tcp(backend_port, backend_listener)
        elif backend_host:
            listening = reactor.listenTCP(backend_port,
                                          backend_listener,
                                          interface=backend_host)
        else:
            listening = listen_all_tcp(backend_port,
                                       backend_listener,
                                       ipv6_disabled=parse_bool(
                                           conf.get('DEFAULT',
                                                    'IPV6_DISABLED')))
        log.info("Controller: BackendListener listening on %s port %s",
                 listening.getHost().host,
                 listening.getHost().port)
    if backend_socket:
        if os.path.exists(backend_socket):
            # clean-up after e.g. system crash:
            log.warning("Controller: BackendListener cleaning %s",
                        backend_socket)
            os.remove(backend_socket)
        log.info("Controller: BackendListener listening on %s", backend_socket)
        reactor.listenUNIX(backend_socket, backend_listener)
    task_listener = TaskListener(controller, task_adaptor)
    if task_port != '':
        if task_host == 'localhost':
            listening = listen_loopback_tcp(task_port, task_listener)
        elif task_host:
            listening = reactor.listenTCP(task_port,
                                          task_listener,
                                          interface=task_host)
        else:
            listening = listen_all_tcp(task_port,
                                       task_listener,
                                       ipv6_disabled=parse_bool(
                                           conf.get('DEFAULT',
                                                    'IPV6_DISABLED')))
        log.info("Controller: TaskListener listening on %s port %s",
                 listening.getHost().host,
                 listening.getHost().port)
    if task_socket:
        if os.path.exists(task_socket):
            # clean-up after e.g. system crash:
            log.warning("Controller: TaskListener cleaning %s", task_socket)
            os.remove(task_socket)
        log.info("Controller: TaskListener listening on %s", task_socket)
        reactor.listenUNIX(task_socket, task_listener)
    return controller
Beispiel #9
0
        self.rem_call(p, 'retry_set', True, (2,))
        self.rem_call(p, 'retry', True, args=(), repeat=repeatingproxy.repeatAlways)
        self.rem_call(p, 'retry_set', True, (3,))
        self.rem_call(p, 'retry', False, args=(), repeat=repeatingproxy.repeatTimes(2))
        return p.when_idle()

    def test02NotSerializing(self):
        reactor.callLater(0, self.startServer)
        p = self.proxy
        p.serializing = False
        p.set_timeout(repeatingproxy.IncreasingTimeout(p.DELAY_TIMEOUT, factor=p.TIMEOUT_FACTOR))
        self.handler.retries = 2
        self.rem_call(p, 'test', True)
        self.rem_call(p, 'test', True)
        self.rem_call(p, 'test2', False)
        self.rem_call(p, 'test_exc', False)
        self.rem_call(p, 'test_exc2', False)
        self.rem_call(p, 'test_long_call', True, (p.LONG_CALL,))
        self.rem_call(p, 'test_long_call', True, (2*p.LONG_CALL,))
        self.rem_call(p, 'retry', True, args=(), repeat=repeatingproxy.repeatAlways)
        return p.when_idle()


if VERBOSE:
    repeatingproxy.RepeatingProxy._VERBOSE = repeatingproxy.RepeatingProxy._VERBOSE + repeatingproxy.RepeatingProxy._MORE_VERBOSE
    make_class_verbose(repeatingproxy.RepeatingProxy, print_this)
    make_class_verbose(TestHandler, print_this)
    make_class_verbose(TestRepeatingProxy, print_this)