def reload(self): """ Reload configuration Send a signal to the process """ sys.stdout.write("Reloading configuration...\n") if not self.parent.status(): sys.stdout.write("Server not started...\n") else: pid = self.parent.getPid() if pid is not None: self.parent.sendSignal(pid, signal.SIGHUP) sys.stdout.write("Configuration reloaded!\n") RepoAdapters.initialize(context=None) RepoAdapters.instance().updateMainInit() sys.stdout.write("Adapters reloaded!\n") sys.stdout.flush()
def installAdapter(self, name): """ """ RepoAdapters.initialize(context=None) folder_lib = "%s/%s/%s" % (Settings.getDirExec(), Settings.get('Paths', 'packages-sutadapters'), name) folder_lib = os.path.normpath(folder_lib) if os.path.exists(folder_lib): try: # install dependancies according to the plugin with pip pip_list = "%s/deps/pip_list.txt" % folder_lib pip_list = os.path.normpath(pip_list) if os.path.exists(pip_list) and os.path.getsize(pip_list) > 0: if platform.system() == "Windows": cmd = "%s -m pip install -r \"%s\"" % (Settings.get( 'Bin', 'python-win'), pip_list) else: cmd = "%s -m pip install -r %s" % (Settings.get( 'Bin', 'python'), pip_list) subprocess.call(cmd, shell=True) # system detect yum_list = "%s/deps/yum_list.txt" % folder_lib yum_list = os.path.normpath(yum_list) if os.path.exists(yum_list) and os.path.getsize(yum_list) > 0: if os.path.exists("/etc/os-release"): os_id = "" with open("/etc/os-release") as f: for line in f: if "=" in line: k, v = line.rstrip().split("=") if k == "ID": os_id = v.strip('"') break if "centos" in os_id or "rhel" in os_id: cmd = "yum install `cat %s | tr '\n' ' '`" % yum_list subprocess.call(cmd, shell=True) RepoAdapters.instance().updateMainInit() # install samples according to the plugin if os.path.exists("%s/samples/" % folder_lib): folder_sample = "%s/%s/1/Samples/Adapter_%s" % ( Settings.getDirExec(), Settings.get('Paths', 'tests'), name) shutil.copytree("%s/samples/" % folder_lib, folder_sample) print("Sut Adapter installation process terminated") except Exception as e: print("unable to install adapter: %s" % e) else: print("Sut Adapter (%s) not found!" % name) RepoAdapters.instance().updateMainInit()
def appendTestArgs(taskUuid, userName, userId, projectId, projectName, testName, testLocation, trPath, logFilename, var_path): testpath_norm = "%s/%s/" % (RepoTests.instance().testsPath, projectId) adapterpath_norm = "%s/" % (RepoAdapters.instance().testsPath) full_trpath = "%s/%s/" % (var_path, trPath) te = [] te.append("""taskuuid_ = '%s'\n""" % taskUuid) te.append("""user_ = '%s'\n""" % userName) te.append("""userid_ = '%s'\n""" % userId) te.append("""projectid_ = '%s'\n""" % projectId) te.append("""projectname_ = '%s'\n""" % projectName) te.append("""test_name = '%s'\n""" % testName) te.append("""test_location = '%s'\n""" % testLocation) te.append("""test_result_path = r'%s'\n""" % os.path.normpath(trPath)) te.append("""log_filename = '%s'\n""" % logFilename) te.append("""tests_path = r'%s'\n""" % os.path.normpath(testpath_norm)) te.append("""adapters_path = r'%s'\n""" % os.path.normpath(adapterpath_norm)) te.append("""full_tr_path = r'%s'\n""" % os.path.normpath(full_trpath)) return te
def cleanup(self): """ Cleanup the server """ self.info('Cleanup...') self.trace("Cleanup agent manager") try: AgentsManager.finalize() except Exception: pass self.trace("Cleanup context") try: Context.finalize() except Exception: pass self.trace("Cleanup projects manager") try: ProjectsManager.finalize() except Exception: pass self.trace("Cleanup users manager") try: UsersManager.finalize() except Exception: pass self.trace("Cleanup task manager") try: TaskManager.finalize() except Exception: pass self.trace("Cleanup test public manager") try: RepoPublic.finalize() except Exception: pass self.trace("Cleanup test repo manager") try: RepoTests.finalize() except Exception: pass self.trace("Cleanup test archives manager") try: RepoArchives.finalize() except Exception: pass self.trace("Cleanup helper manager") try: HelperManager.finalize() except Exception: pass self.trace("Cleanup adapters manager") try: RepoAdapters.finalize() except Exception: pass self.trace("Cleanup adapters data storage") try: StorageDataAdapters.finalize() except Exception: pass self.trace("Cleanup WSU") try: RestServerInterface.instance().stop() RestServerInterface.finalize() except Exception: pass self.trace("Cleanup ESI") try: EventServerInterface.instance().stopSA() EventServerInterface.finalize() except Exception: pass self.trace("Cleanup TSI") try: TestServerInterface.instance().stopSA() TestServerInterface.finalize() except Exception: pass self.trace("Cleanup ASI") try: AgentServerInterface.instance().stopSA() AgentServerInterface.finalize() except Exception: pass self.trace("Cleanup db manager") try: DbManager.finalize() except Exception: pass self.trace("Cleanup settings") try: Settings.finalize() except Exception: pass self.trace("Cleanup logger, cli") try: CliFunctions.finalize() Logger.finalize() except Exception: pass
def initialize(self): """ Starts all modules Exit if the service is alreayd running or if the config file is missing """ starttime = time.time() if self.isrunning(): sys.stdout.write(" (server is already running)") sys.exit(1) # run the server as daemon only for linux if platform.system() == "Linux": self.daemonize() try: # Initialize self.info("Starting up server...") self.trace("** System encoding (in): %s" % sys.stdin.encoding) self.trace("** System encoding (out): %s" % sys.stdout.encoding) self.info("Settings, Logger and CLI ready") DbManager.initialize() DbManager.instance().isUp() self.info("Database manager ready") # Initialize the core Context.initialize() self.info("Context ready") ProjectsManager.initialize(context=Context.instance()) self.info("Projects Manager ready") UsersManager.initialize(context=Context.instance()) self.info("Users Manager ready") TaskManager.initialize(context=Context) self.info("Task Manager ready") # Initialize all repositories RepoTests.initialize(context=Context.instance()) self.info("Repo manager for tests ready") RepoArchives.initialize(context=Context.instance()) self.info("Repo manager for archives ready") RepoAdapters.initialize(context=Context.instance()) StorageDataAdapters.initialize(context=Context.instance()) self.info("Adapters Manager and Storage Data ready") RepoPublic.initialize() self.info("Repo manager for public area is ready") HelperManager.initialize() self.info("Helper manager ready") AgentsManager.initialize(context=Context.instance()) self.info("Agents Manager ready") # Initialize all interfaces self.info("Starting ESI on %s:%s" % (Settings.get('Bind', 'ip-esi'), Settings.getInt('Bind', 'port-esi'))) EventServerInterface.initialize(listeningAddress=(Settings.get('Bind', 'ip-esi'), Settings.getInt( 'Bind', 'port-esi') ), sslSupport=Settings.getInt( 'Client_Channel', 'channel-ssl'), wsSupport=Settings.getInt( 'Client_Channel', 'channel-websocket-support'), context=Context.instance() ) self.info("Starting TSI on %s:%s" % (Settings.get('Bind', 'ip-tsi'), Settings.getInt('Bind', 'port-tsi'))) TestServerInterface.initialize(listeningAddress=(Settings.get('Bind', 'ip-tsi'), Settings.getInt( 'Bind', 'port-tsi') ), context=Context.instance() ) self.info("Starting RSU on %s:%s" % (Settings.get('Bind', 'ip-rsi'), Settings.getInt('Bind', 'port-rsi'))) RestServerInterface.initialize(listeningAddress=(Settings.get('Bind', 'ip-rsi'), Settings.getInt( 'Bind', 'port-rsi') ) ) self.info("Starting ASI on %s:%s" % (Settings.get('Bind', 'ip-asi'), Settings.getInt('Bind', 'port-asi'))) AgentServerInterface.initialize(listeningAddress=(Settings.get('Bind', 'ip-asi'), Settings.getInt( 'Bind', 'port-asi') ), sslSupport=Settings.getInt( 'Agent_Channel', 'channel-ssl'), wsSupport=Settings.getInt( 'Agent_Channel', 'channel-websocket-support'), tsi=TestServerInterface.instance(), context=Context.instance() ) # Start on modules RestServerInterface.instance().start() self.info("RSI is listening on tcp://%s:%s" % (Settings.get('Bind', 'ip-rsi'), Settings.get('Bind', 'port-rsi'))) EventServerInterface.instance().startSA() self.info("ESI is listening on tcp://%s:%s" % (Settings.get('Bind', 'ip-esi'), Settings.get('Bind', 'port-esi'))) TestServerInterface.instance().startSA() self.info("TSI is listening on tcp://%s:%s" % (Settings.get('Bind', 'ip-tsi'), Settings.get('Bind', 'port-tsi'))) AgentServerInterface.instance().startSA() self.info("ASI is listening on tcp://%s:%s" % (Settings.get('Bind', 'ip-asi'), Settings.get('Bind', 'port-asi'))) # Now start the scheduler and reload tasks taskReloaded = TaskManager.instance().loadBackups() if taskReloaded is None: self.info("Reload tasks disabled") elif taskReloaded: self.info("Tasks reloaded") else: self.error("Failed to reload tasks") except Exception as e: self.error("Unable to start server: %s" % str(e)) self.cleanup() sys.exit(3) stoptime = time.time() self.info("%s successfully started (in %s sec.)" % (Settings.get('Server', 'name'), int(stoptime - starttime))) # only for windows platform if platform.system() == "Windows": print("Server successfully started...") self.setrunning() self.run()