Пример #1
0
    def start(cls, config_path: str = CONFIG_PATH) -> None:
        """
        Starts the runtime server with all components

        :param config_path: Path to an alternative config directory
        """
        cls.CONFIG_PATH = config_path
        # set the config_path at the manager
        ConfigManager.set_config_path(config_path)

        # read from config the Vlan mode
        vlan_activate = ConfigManager.get_server_property("Vlan_On")
        cls.VLAN = vlan_activate

        # read from config if debug mode is on
        log_level = int(ConfigManager.get_server_property("Log_Level"))
        debug_mode = False
        if log_level is 10:
            debug_mode = True
        cls.DEBUG = debug_mode

        # create instance and give params to the logger object
        Logger().setup(log_level, log_level, log_level)

        # load Router configs
        cls.__load_configuration()

        if cls.VLAN:
            from util.router_info import RouterInfo
            # TODO: Die Funktion 'cls.update_router_info' sollte verwendet werden
            RouterInfo.update(cls.get_routers()[0])

        print("Runtime Server started")

        cls._ipc_server.start_ipc_server(cls, True)  # serves forever - works like a while(true)
Пример #2
0
    def start(cls, config_path: str = CONFIG_PATH) -> None:
        """
        Starts the runtime server with all components

        :param config_path: Path to an alternative config directory
        """
        cls.CONFIG_PATH = config_path
        # set the config_path at the manager
        ConfigManager.set_config_path(config_path)

        # read from config the Vlan mode
        vlan_activate = ConfigManager.get_server_property("Vlan_On")
        cls.VLAN = vlan_activate

        # read from config if debug mode is on
        log_level = ConfigManager.get_server_property("Log_Level")
        debug_mode = False
        if log_level is 10:
            debug_mode = True
        cls.DEBUG = debug_mode

        # load Router configs
        cls.__load_configuration()

        if cls.VLAN:
            from util.router_info import RouterInfo
            # TODO: Die Funktion 'cls.update_router_info' sollte verwendet werden
            RouterInfo.update(cls.get_routers()[0])

        print("Runtime Server started")

        cls._ipc_server.start_ipc_server(
            cls, True)  # serves forever - works like a while(true)
Пример #3
0
    def test_set_config_path(self):
        """
        Tests to set the config path
        :return: Tests results
        """
        base_dir = path.dirname(path.dirname(__file__))  # This is your Project Root

        config_path = path.join(base_dir, 'framework_unittests/configs/config_no_vlan')
        ConfigManager.set_config_path(config_path)
        self.assertEqual(ConfigManager.CONFIG_PATH, config_path, "Wrong path")

        config_path = path.join(base_dir, 'config')  # Join Project Root with config
        ConfigManager.set_config_path(config_path)
        self.assertEqual(ConfigManager.CONFIG_PATH, config_path, "Wrong path")
Пример #4
0
    def test_set_config_path(self):
        """
        Tests to set the config path
        :return: Tests results
        """
        base_dir = path.dirname(
            path.dirname(__file__))  # This is your Project Root

        config_path = path.join(base_dir,
                                'framework_unittests/configs/config_no_vlan')
        ConfigManager.set_config_path(config_path)
        self.assertEqual(ConfigManager.CONFIG_PATH, config_path, "Wrong path")

        config_path = path.join(base_dir,
                                'config')  # Join Project Root with config
        ConfigManager.set_config_path(config_path)
        self.assertEqual(ConfigManager.CONFIG_PATH, config_path, "Wrong path")
Пример #5
0
    def start(cls, config_path: str = CONFIG_PATH) -> None:
        """
        Starts the runtime server with all components

        :param config_path: Path to an alternative config directory
        """

        # server has to be run with root rights - except on travis CI
        if not os.geteuid() == 0 and not os.environ.get('TRAVIS'):
            sys.exit('Script must be run as root')

        cls.CONFIG_PATH = config_path
        # set the config_path at the manager
        ConfigManager.set_config_path(config_path)

        # read from config the Vlan mode
        vlan_activate = ConfigManager.get_server_property("Vlan_On")
        cls.VLAN = vlan_activate

        # read from config if debug mode is on
        log_level = int(ConfigManager.get_server_property("Log_Level"))
        debug_mode = False
        if log_level is 10:
            debug_mode = True
        cls.DEBUG = debug_mode

        cls._server_stop_event = Event()

        cls._pid = os.getpid()

        # create instance and give params to the logger object
        LoggerSetup.setup(log_level)

        # load Router configs
        cls.__load_configuration()

        for router in cls.get_routers():
            cls._running_task.append(None)
            cls._waiting_tasks.append(deque())

        # start thread for multiprocess stop wait
        t = threading.Thread(target=cls._close_wait)
        t.start()

        # start process/thread pool for job and test handling
        cls._max_subprocesses = (len(cls._routers) + 2)
        cls._task_pool = Pool(processes=cls._max_subprocesses,
                              initializer=init_process,
                              initargs=(cls._server_stop_event, ),
                              maxtasksperchild=1)
        cls._job_wait_executor = ThreadPoolExecutor(
            max_workers=(cls._max_subprocesses + 5))

        # add Namespace and Vlan for each Router
        if cls.VLAN:
            cls._nv_assistent = NVAssistent("eth0")

            for router in cls.get_routers():
                logging.debug("Add Namespace and Vlan for Router(" +
                              str(router.id) + ")")
                cls._nv_assistent.create_namespace_vlan(router)

            # add Namespace and Vlan for 1 Powerstrip (expand to more if necessary)
            logging.debug("Add Namespace and Vlan for Powerstrip")
            cls._nv_assistent.create_namespace_vlan(cls.get_power_strip())

            # update Router
            cls.router_online(None, update_all=True, blocked=True)
            cls.update_router_info(None, update_all=True)

        logging.info("Runtime Server started")

        try:
            cls._ipc_server.start_ipc_server(
                cls, True)  # serves forever - works like a while(true)
        except (KeyboardInterrupt, SystemExit):
            logging.info("Received an interrupt signal")
            cls.stop()
Пример #6
0
    def start(cls, config_path: str = CONFIG_PATH) -> None:
        """
        Starts the runtime server with all components.

        :param config_path: Path to an alternative config directory
        """

        # server has to be run with root rights - except on travis CI
        if not os.geteuid() == 0 and not os.environ.get('TRAVIS'):
            sys.exit('Script must be run as root')

        cls._stopped = Lock()
        signal.signal(signal.SIGTERM, cls._signal_term_handler)

        cls.CONFIG_PATH = config_path
        # set the config_path at the manager
        ConfigManager.set_config_path(config_path)

        # read from config the Vlan mode
        vlan_activate = ConfigManager.get_server_property("Vlan_On")
        cls.VLAN = vlan_activate

        # read from config if debug mode is on
        log_level = int(ConfigManager.get_server_property("Log_Level"))
        debug_mode = False
        if log_level is 10:
            debug_mode = True
        cls.DEBUG = debug_mode

        setproctitle("fftserver")

        cls._server_stop_event = Event()

        cls._pid = os.getpid()

        # create instance and give params to the logger object
        LoggerSetup.setup(log_level)

        # load Router configs
        cls.__load_configuration()

        for router in cls.get_routers():
            cls._running_task.append(None)
            cls._waiting_tasks.append(deque())

        # start process/thread pool for job and test handling
        cls._max_subprocesses = (len(cls._routers) + 1)  # plus one for the power strip
        cls._task_pool = Pool(processes=cls._max_subprocesses, initializer=init_process,
                              initargs=(cls._server_stop_event,), maxtasksperchild=1)
        cls._task_wait_executor = ThreadPoolExecutor(max_workers=(cls._max_subprocesses * 2))

        # start thread for multiprocess stop wait
        t = threading.Thread(target=cls._close_wait)
        t.start()

        # add Namespace and Vlan for each Router
        if cls.VLAN:
            cls._nv_assistent = NVAssistent("eth0")

            for router in cls.get_routers():
                logging.debug("Add Namespace and Vlan for Router(" + str(router.id) + ")")
                cls._nv_assistent.create_namespace_vlan(router)

            # add Namespace and Vlan for 1 Powerstrip (expand to more if necessary)
            logging.debug("Add Namespace and Vlan for Powerstrip")
            cls._nv_assistent.create_namespace_vlan(cls.get_power_strip())

            # update Router
            cls.router_online(None, update_all=True, blocked=True)
            cls.update_router_info(None, update_all=True)

        # open database and read old test results
        try:
            with shelve.open('test_results', 'c') as db:
                # read test values
                key_list = db.keys()
                for k in key_list:
                    t = TestResult()
                    dbt = db[str(k)]
                    t.failures = dbt.failures
                    t.errors = dbt.errors
                    t.testsRun = dbt.testsRun
                    t._original_stdout = None
                    t._original_stderr = None
                    cls._test_results.append((dbt.router_id, dbt.test_name, t))
        except Exception as e:
            logging.error("Error at read test results from DB: {0}".format(e))

        logging.info("Runtime Server started")

        try:
            cls._ipc_server.start_ipc_server(cls, True)  # serves forever - works like a while(true)
        except (KeyboardInterrupt, SystemExit):
            logging.info("Received an interrupt signal")
            cls.stop()