def stopping(self): """ On stopping the server """ self.info("Stopping server...") # cleanup all child processes for f in os.listdir("%s/%s" % (Settings.getDirExec(), Settings.get('Paths', 'run'))): if f.endswith(".pid"): pid = f.split(".pid")[0] # kill the process if pid.isdigit(): self.info('Stopping chid processes %s...' % pid) try: while True: os.kill(int(pid), signal.SIGTERM) time.sleep(0.1) except OSError: pass time.sleep(1) # just to be sure, delete a second time try: os.remove("%s/%s/%s.pid" % (Settings.getDirExec(), Settings.get('Paths', 'run'), pid)) except Exception: pass
def __init__(self, listeningAddress, agentName='ESI', sslSupport=False, wsSupport=False, context=None): """ Event server interface @param listeningAddress: @type listeningAddress: @param agentName: agent name used on request @type agentName: string """ NetLayerLib.ServerAgent.__init__( self, listeningAddress=listeningAddress, agentName=agentName, keepAliveInterval=Settings.getInt('Network', 'keepalive-interval'), inactivityTimeout=Settings.getInt('Network', 'inactivity-timeout'), responseTimeout=Settings.getInt('Network', 'response-timeout'), selectTimeout=Settings.get('Network', 'select-timeout'), sslSupport=sslSupport, wsSupport=wsSupport, certFile='%s/%s' % (Settings.getDirExec(), Settings.get('Client_Channel', 'channel-ssl-cert')), keyFile='%s/%s' % (Settings.getDirExec(), Settings.get('Client_Channel', 'channel-ssl-key')), pickleVer=Settings.getInt('Network', 'pickle-version')) self.__mutex__ = threading.RLock() self.context = context
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 getTestsPath(envTmp=False): """ Get the path of all tests result @return: @rtype: string """ if envTmp: trPath = '%s%s' % (Settings.getDirExec(), Settings.get('Paths', 'testsresults-tmp')) else: trPath = '%s%s' % (Settings.getDirExec(), Settings.get('Paths', 'testsresults')) # normalize the path and return it return os.path.normpath(trPath)
def addPyInitFile(self, pathFile, descr="", helper="", allmodules="", adps=False, mainInit=False): """ Add the default __init__ file of the repository """ HEADER = '' tpl_path = "%s/%s/adapter_header.tpl" % ( Settings.getDirExec(), Settings.get('Paths', 'templates')) try: fd = open(tpl_path, "r") HEADER = fd.read() fd.close() except Exception as e: self.error('unable to read template adapter header: %s' % str(e)) try: if mainInit: default_init = MAIN_INIT % (HEADER, descr, helper, allmodules) else: default_init = ADP_INIT % (HEADER, descr) f = open('%s/__init__.py' % pathFile, 'w') f.write(default_init) f.close() except Exception as e: self.error(e) return False return True
def __init__(self): """ Repository manager for public test files """ RepoManager.RepoManager.__init__( self, pathRepo='%s%s' % (Settings.getDirExec(), Settings.get('Paths', 'public')), extensionsSupported=[])
def isUp(self): """ Try to connect to the database Detect the version of the mysql server """ db_name = "%s/%s/%s" % (Settings.getDirExec(), Settings.get('Paths', 'var'), Settings.get('Database', 'db')) sqlite3.connect(db_name) self.trace("database connection successful")
def getStaticArgs(envTmp=False): """ """ te_args = """root = r'%s/../' tests_result_path = r'%s' controller_ip = '%s' controller_port = %s """ % (os.path.normpath( Settings.getDirExec()), os.path.normpath(getTestsPath(envTmp=envTmp)), Settings.get('Bind', 'ip-tsi'), Settings.get('Bind', 'port-tsi')) return te_args
def __init__(self, listeningAddress, agentName='ASI', sslSupport=False, wsSupport=False, tsi=None, context=None): """ Construct Agent Server Interface @param listeningAddress: @type listeningAddress: @param agentName: @type agentName: string """ NetLayerLib.ServerAgent.__init__( self, listeningAddress=listeningAddress, agentName=agentName, keepAliveInterval=Settings.getInt('Network', 'keepalive-interval'), inactivityTimeout=Settings.getInt('Network', 'inactivity-timeout'), responseTimeout=Settings.getInt('Network', 'response-timeout'), selectTimeout=Settings.get('Network', 'select-timeout'), sslSupport=sslSupport, wsSupport=wsSupport, certFile='%s/%s' % (Settings.getDirExec(), Settings.get('Agent_Channel', 'channel-ssl-cert')), keyFile='%s/%s' % (Settings.getDirExec(), Settings.get('Agent_Channel', 'channel-ssl-key')), pickleVer=Settings.getInt('Network', 'pickle-version')) self.tsi = tsi self.context = context self.__mutex = threading.RLock() self.__mutexNotif = threading.RLock() self.agentsRegistered = {} self.agentsPublicIp = {}
def __init__(self, context): """ Storage data adapters """ RepoManager.RepoManager.__init__( self, pathRepo='%s%s' % (Settings.getDirExec(), Settings.get('Paths', 'tmp')), context=context) self.context = context self.prefixAdapters = "adapter" self.prefixAdaptersAll = "private_storage" self.adpDataPath = os.path.normpath("%s/AdaptersData" % self.testsPath) self.initStorage()
def initialize(logPathFile=None, level="INFO", size="5", nbFiles="10", noSettings=False): """ Initialize """ global LG if not noSettings: if logPathFile is not None: file = logPathFile else: file = "%s/%s/%s" % (Settings.getDirExec(), Settings.get(section='Paths', key='logs'), Settings.get(section='Trace', key='file')) level = Settings.get(section='Trace', key='level') size = Settings.get(section='Trace', key='max-size-file') maxBytes = int(size.split('M')[0]) * 1024 * 1024 nbFilesMax = Settings.getInt(section='Trace', key='nb-backup-max') else: file = logPathFile level = level size = size maxBytes = size nbFilesMax = nbFiles LG = logging.getLogger('Logger') if level == 'DEBUG': # write everything messages LG.setLevel(logging.DEBUG) elif level == 'ERROR': # write anything that is an error or worse. LG.setLevel(logging.ERROR) elif level == 'INFO': # write anything that is an info message or worse. LG.setLevel(logging.INFO) handler = logging.handlers.RotatingFileHandler(file, maxBytes=maxBytes, backupCount=nbFilesMax) # format='%(asctime)-6s: %(name)s - %(levelname)s - %(module)s - # %(funcName)s - %(lineno)d - %(message)s', formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s") handler.setFormatter(formatter) LG.addHandler(handler)
def __init__(self, context): """ Repository manager for archives files """ RepoManager.RepoManager.__init__(self, pathRepo='%s%s' % (Settings.getDirExec(), Settings.get('Paths', 'testsresults')), extensionsSupported=[RepoManager.TEST_RESULT_EXT, RepoManager.TXT_EXT, RepoManager.CAP_EXT, RepoManager.ZIP_EXT, RepoManager.PNG_EXT, RepoManager.JPG_EXT], context=context) self.context = context self.cacheUuids = {} self.cachingUuid() self.trace("nb entries in testresult cache: %s" % len(self.cacheUuids))
def __init__(self, context): """ Construct Adpaters Manager """ RepoManager.RepoManager.__init__( self, pathRepo='%s/%s/' % (Settings.getDirExec(), Settings.get('Paths', 'packages-sutadapters')), extensionsSupported=[RepoManager.PY_EXT, RepoManager.TXT_EXT], context=context) self.context = context # update main init file self.updateMainInit()
def __init__(self, context): """ Class Projects Manager """ self.tb_projects = 'projects' self.repoTests = '%s/%s' % (Settings.getDirExec(), Settings.get('Paths', 'tests')) self.context = context # load projects in cache, new in v19 self.__cache = [] self.loadCache() # Initialize the repository self.info('Deploying folders projects and reserved folders...') self.createDirProjects()
def getHelps(self): """ Returns the documentation cache """ self.trace("get helps") ret = '' try: complete_path = '%s/%s/documentations.dat' % (Settings.getDirExec(), Settings.get('Paths', 'var')) if os.path.exists(complete_path): fd = open(complete_path, "rb") data = fd.read() fd.close() ret = base64.b64encode(zlib.compress(data)) else: self.error('documentation cache does not exist') except Exception as e: self.error("unable to get helps: %s" % e) return ret.decode('utf8')
def __init__(self, context): """ Repository manager for tests files """ RepoManager.RepoManager.__init__( self, pathRepo='%s%s' % (Settings.getDirExec(), Settings.get('Paths', 'tests')), extensionsSupported=[ RepoManager.TEST_SUITE_EXT, RepoManager.TEST_PLAN_EXT, RepoManager.TEST_CONFIG_EXT, RepoManager.TEST_DATA_EXT, RepoManager.TEST_UNIT_EXT, RepoManager.PNG_EXT, #RepoManager.TEST_YAML_EXT, RepoManager.TEST_GLOBAL_EXT ], context=context) self.context = context
def querySQL(self, query, insertData=False, columnName=False, debugCaller=False, args=(), arg1=None, arg2=None, arg3=None, arg4=None, arg5=None, arg6=None, arg7=None, arg8=None, arg9=None, arg10=None, arg11=None, arg12=None): """ """ ret = False rows = None db_name = "%s/%s/%s" % (Settings.getDirExec(), Settings.get('Paths', 'var'), Settings.get('Database', 'db')) try: conn = sqlite3.connect(db_name) cursor = conn.cursor() if Settings.get('Trace', 'debug-level') == 'VERBOSE': if debugCaller: self.trace("SQL QUERY: %s - %s" % (caller(), query)) else: self.trace("SQL QUERY: %s" % (query)) sql_args = args if arg1 is not None: sql_args += (arg1, ) if arg2 is not None: sql_args += (arg2, ) if arg3 is not None: sql_args += (arg3, ) if arg4 is not None: sql_args += (arg4, ) if arg5 is not None: sql_args += (arg5, ) if arg6 is not None: sql_args += (arg6, ) if arg7 is not None: sql_args += (arg7, ) if arg8 is not None: sql_args += (arg8, ) if arg9 is not None: sql_args += (arg9, ) if arg10 is not None: sql_args += (arg10, ) if arg11 is not None: sql_args += (arg11, ) if arg12 is not None: sql_args += (arg12, ) cursor.execute(query, sql_args) if insertData: rows = cursor.lastrowid else: if columnName: rows = [] for row in cursor.fetchall(): fields = map(lambda x: x[0], cursor.description) rows.append(dict(zip(fields, row))) else: rows = cursor.fetchall() cursor.close() conn.commit() conn.close() ret = True except Exception as e: self.error("unable to execute sqlite3 query: %s" % e) return ret, rows
""" try: conn = sqlite3.connect(db) c = conn.cursor() c.execute(query) c.close() conn.commit() conn.close() except Exception as e: print("[query] %s - %s" % (str(e), query)) sys.exit(1) db_name = "%s/%s/%s" % (Settings.getDirExec(), Settings.get( 'Paths', 'var'), Settings.get('Database', 'db')) def error(msg): """ """ print("ERROR: %s" % msg) class CliFunctions(Logger.ClassLogger): """ """ def __init__(self, parent): """ """
swagger.append("tags:") for (k, v) in swagger_tags: cur = " " * swagger_tab swagger.append("%s- name: %s" % (cur, k)) swagger.append("%s%sdescription: %s" % (cur, cur, v)) if len(swagger_schemes): swagger.append("schemes:") for (s) in swagger_schemes: swagger.append("%s- %s" % (cur, s)) swagger.extend(swagger_paths) swagger.extend(swagger_defs) # write the file yaml_path = "/%s/scripts/swagger/tester_restapi.yaml" % (Settings.getDirExec()) with open(yaml_path, "wt") as f: f.write("\n".join(swagger)) ################## ################## # params for admins functions ################## ################## swagger = [] swagger_version = "2.0" swagger_email = SWAGGER_EMAIL swagger_licence = "LGPL 2.1" swagger_info = [ ("description", "Control your test server with %s API" % Settings.get('Server', 'name')),
def prepareDaemon(self): """ Prepare daemon """ if not Settings.cfgFileIsPresent(): sys.stdout.write(" (config file doesn't exist)") sys.exit(2) try: # Initialize Settings.initialize(path="./", cfgname='settings.ini') # create missing folders in var ? folder_var_run = "%s/%s" % (Settings.getDirExec(), Settings.get('Paths', 'run')) if not os.path.exists(folder_var_run): os.mkdir(folder_var_run, 0o755) folder_var_pub = "%s/%s" % (Settings.getDirExec(), Settings.get('Paths', 'public')) if not os.path.exists(folder_var_pub): os.mkdir(folder_var_pub, 0o755) folder_var_log = "%s/%s" % (Settings.getDirExec(), Settings.get('Paths', 'logs')) if not os.path.exists(folder_var_log): os.mkdir(folder_var_log, 0o755) folder_var_tmp = "%s/%s" % (Settings.getDirExec(), Settings.get('Paths', 'tmp')) if not os.path.exists(folder_var_tmp): os.mkdir(folder_var_tmp, 0o755) tests = "%s/%s" % (Settings.getDirExec(), Settings.get('Paths', 'tests')) if not os.path.exists(tests): os.mkdir(tests, 0o755) folder_var_testsresults = "%s/%s" % ( Settings.getDirExec(), Settings.get('Paths', 'testsresults')) if not os.path.exists(folder_var_testsresults): os.mkdir(folder_var_testsresults, 0o755) folder_var_bkp_tasks = "%s/%s" % (Settings.getDirExec(), Settings.get('Paths', 'backups-tasks')) if not os.path.exists(folder_var_bkp_tasks): os.mkdir(folder_var_bkp_tasks, 0o755) folder_adapters = "%s/%s" % (Settings.getDirExec(), Settings.get('Paths', 'packages-sutadapters')) if not os.path.exists(folder_adapters): os.mkdir(folder_adapters, 0o755) Logger.initialize() CliFunctions.initialize(parent=self) except Exception as e: self.error("Unable to initialize settings: %s" % str(e)) else: app_name = Settings.get('Server', 'name') app_name = app_name.replace(" ", "").lower() # config file exist so prepare the deamon self.prepare(pidfile="%s/%s/%s.pid" % (Settings.getDirExec(), Settings.get( 'Paths', 'run'), app_name), name=Settings.get('Server', 'name'), stdout="%s/%s/output.log" % (Settings.getDirExec(), Settings.get('Paths', 'logs')), stderr="%s/%s/output.log" % (Settings.getDirExec(), Settings.get('Paths', 'logs')), stdin="/dev/null", runningfile="%s/%s/%s.running" % (Settings.getDirExec(), Settings.get( 'Paths', 'run'), app_name), )
def show_data_storage(self): """show data storage path""" storage = "%s%s" % (Settings.getDirExec(), Settings.get('Paths', 'var')) sys.stdout.write("%s\n" % storage)
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA # ------------------------------------------------------------------- from ea.libs import Settings import pickle import sys import DocInspect sys.path.insert(0, '../../../') # initialize settings module to read the settings.ini file Settings.initialize(path="./") cache_pathfile = "%s/%s/documentations.dat" % (Settings.getDirExec(), Settings.get('Paths', 'var')) def extractTestExecutor(lib): """ """ pkg_te = __import__("ea.testexecutorlib", fromlist=[lib]) descr_pkg = getattr(pkg_te, '__DESCRIPTION__') lib_obj = getattr(pkg_te, lib) lib_descr = getattr(lib_obj, '__DESCRIPTION__') classes = getattr(lib_obj, '__HELPER__') pkg_desc = DocInspect.describePackage(pkg_te, modules=[(lib, classes, lib_descr)],