def test_bsd(self):
        """
        ``install_optimal_reactor`` will install KQueueReactor on BSD.
        """
        reactor_mock = Mock()
        self.patch_reactor("kqreactor", reactor_mock)
        self.patch(sys, "platform", "freebsd11")

        # Emulate that a reactor has not been installed
        self.patch_modules()

        choosereactor.install_optimal_reactor()
        reactor_mock.install.assert_called_once_with()
        def test_linux(self):
            """
            ``install_optimal_reactor`` will install EPollReactor on Linux.
            """
            reactor_mock = Mock()
            self.patch_reactor("epollreactor", reactor_mock)
            self.patch(sys, "platform", "linux")

            # Emulate that a reactor has not been installed
            self.patch_modules()

            choosereactor.install_optimal_reactor()
            reactor_mock.install.assert_called_once_with()
    def test_bsd(self):
        """
        ``install_optimal_reactor`` will install KQueueReactor on BSD.
        """
        reactor_mock = Mock()
        self.patch_reactor("kqreactor", reactor_mock)
        self.patch(sys, "platform", "freebsd11")

        # Emulate that a reactor has not been installed
        self.patch_modules()

        choosereactor.install_optimal_reactor()
        reactor_mock.install.assert_called_once_with()
        def test_unknown(self):
            """
            ``install_optimal_reactor`` will use the default reactor if it is
            unable to detect the platform it is running on.
            """
            reactor_mock = Mock()
            self.patch_reactor("default", reactor_mock)
            self.patch(sys, "platform", "unknown")

            # Emulate that a reactor has not been installed
            self.patch_modules()

            choosereactor.install_optimal_reactor()
            reactor_mock.install.assert_called_once_with()
    def test_win(self):
        """
        ``install_optimal_reactor`` will install IOCPReactor on Windows.
        """
        if sys.platform != 'win32':
            raise unittest.SkipTest('unit test requires Windows')

        reactor_mock = Mock()
        self.patch_reactor("iocpreactor", reactor_mock)
        self.patch(sys, "platform", "win32")

        # Emulate that a reactor has not been installed
        self.patch_modules()

        choosereactor.install_optimal_reactor()
        reactor_mock.install.assert_called_once_with()
    def test_win(self):
        """
        ``install_optimal_reactor`` will install IOCPReactor on Windows.
        """
        if sys.platform != 'win32':
            raise unittest.SkipTest('unit test requires Windows')

        reactor_mock = Mock()
        self.patch_reactor("iocpreactor", reactor_mock)
        self.patch(sys, "platform", "win32")

        # Emulate that a reactor has not been installed
        self.patch_modules()

        choosereactor.install_optimal_reactor()
        reactor_mock.install.assert_called_once_with()
Esempio n. 7
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from autobahn.twisted import choosereactor

choosereactor.install_optimal_reactor(False)
import argparse, ConfigParser
from toughradius.tools import config as iconfig
from toughradius.tools.shell import shell
from toughradius.tools.dbengine import get_engine
from toughradius.tools import initdb as init_db
import sys, os, signal
import tempfile
import time


def check_env(config):
    """check runtime env"""
    try:
        backup_path = config.get("database", "backup_path")
        if not os.path.exists(backup_path):
            os.makedirs(backup_path)
    except Exception as err:
        shell.err("check_env error %s" % repr(err))


def get_service_tac(app):
    return "%s/%s_service.tac" % (tempfile.gettempdir(), app)


def get_service_pid(app):
    return "%s/%s_service.pid" % (tempfile.gettempdir(), app)
Esempio n. 8
0
#!/usr/bin/env python
# coding=utf-8
from autobahn.twisted import choosereactor
choosereactor.install_optimal_reactor(False)
from twisted.python import log
from toughlib import config as iconfig
from toughlib.dbengine import get_engine
from toughnms.common import initdb as init_db
from toughlib import dispatch,logger
from twisted.internet import reactor
from hashlib import md5
import argparse
import sys
import os

reactor.suggestThreadPoolSize(60)

def update_timezone(config):
    try:
        if 'TZ' not in os.environ:
            os.environ["TZ"] = config.system.tz
        time.tzset()
    except:
        pass

def check_env(config):
    try:
        backup_path = config.database.backup_path
        if not os.path.exists(backup_path):
            os.system("mkdir -p  %s" % backup_path)
        if not os.path.exists("/var/toughnms"):
Esempio n. 9
0
import txaio
txaio.use_twisted()  # noqa

from autobahn.twisted.choosereactor import install_optimal_reactor

#from crossbar.controller import cli
from crossbar.controller import personality

install_optimal_reactor()
Esempio n. 10
0
"""server

Usage:
    server.py [options]

Options:
    -p --port PORT   Port to listen on [default: 9000]
    -d --debug       Debug enabled? [default: False]
"""

import sys

from docopt import docopt

from autobahn.twisted.choosereactor import install_optimal_reactor
install_optimal_reactor()

from twisted.python import log
from twisted.internet import reactor
from autobahn.twisted.websocket import WebSocketServerFactory, WebSocketServerProtocol

from _message_factory import GatewayMessageFactory
from _messages_pb2 import LOGIN_REQUEST
from _messages_pb2 import LoginRequestMessage, LoginResponseMessage
from _messages_pb2 import SUCCESS, ALREADY_LOGGED_IN

class GatewayServerError(Exception):
    pass

class GatewayServerProtocolFactory(WebSocketServerFactory):
    def __init__(self, *args, **kargs):