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()