def log_test_item(self, elapsed, is_successful, result_type, result_info, \ command, is_verification): """Insert general result to the result database. params: elapsed : elapsed time of the MADlib invocation, is measured in ms, but in database, the elapsed time is measured in second. is_successful : is the MADlib invocation successful? result_type : choice of 'table' or 'output' result_info : the stdout of the MADlib invocation command : the command of the MADlib invocation is_verification : is the command a verification method? """ command = command.replace("'", '"') result_info = result_info.replace("'", '"') sql = """insert into %s.testitemresult values( '%s', %s, %s, '%s', '%s', %s, %s::bool, '%s', '%s', %s::bool); """ % (self.logger_schema, self.target_base_name, self.run_id, \ self.iteration_id, result_type, self.analyticstool, elapsed*1000, is_successful, str(result_info), command, is_verification) print sql run_sql.runSQL(sql, self.logusername, self.logpassword, self.loghostname, self.logport, self.logdatabase)
def initDB(self): """Recreate the DB.""" conf = self.db_conf hostname = conf['host'] username = conf['username'] superuser = conf['superuser'] dbname = conf['dbname'] dbtemplate = 'template1' port = str(conf['port']) print "###Init test DB start ###\n" # 0. Update pg_hba to allow madlibtester to access all databases self.addUserPGHBA(username, conf["master_dir"], conf['kind']) # clear up try : # sql = 'DROP SCHEMA %s CASCADE'%ResultSchema # run_sql.runSQL(sql, logusername = superuser, logport = port, logdatabase = dbname, \ # onErrorStop = False, source_path = conf['env']) sql = 'DROP SCHEMA %s CASCADE'%DataSchema run_sql.runSQL(sql, logusername = superuser, logport = port, logdatabase = dbname, \ onErrorStop = False, source_path = conf['env']) except Exception, e: print e print 'Database "%s" does not exist \nCreate the new database "%s"'%(dbname,dbname)
def initDB(self): """Recreate the DB.""" conf = self.db_conf hostname = conf['host'] username = conf['username'] superuser = conf['superuser'] dbname = conf['database'] dbtemplate = 'template1' port = conf['port'] print "###Init test DB start ###\n" # 0. Update pg_hba to allow madlibtester to access all databases self.addUserPGHBA(username, conf["master_dir"], conf['kind']) # clear up try : sql = 'DROP SCHEMA %s CASCADE'%ResultSchema run_sql.runSQL(sql, logusername = superuser, logport = port, logdatabase = dbname, \ onErrorStop = False, source_path = conf['env']) sql = 'DROP SCHEMA %s CASCADE'%DataSchema run_sql.runSQL(sql, logusername = superuser, logport = port, logdatabase = dbname, \ onErrorStop = False, source_path = conf['env']) except Exception, e: print e print 'Database "%s" does not exist \nCreate the new database "%s"'%(dbname,dbname)
def runSQL(self, sql): """Run sql statement in this logger database params: sql statement to run """ run_sql.runSQL(sql, self.logusername, self.logpassword, self.loghostname, \ self.logport, self.logdatabase)
def run(self): """Run the madlib invoking sql statement, and store the result to logger database.""" is_successful = False sql = self.sql #print executor command and invocation sql statement print '----------------------------------------------------' print ' '.join(self.argv) print self.sql timer = Timer() #the elapsed time is in second, but we will convert it to ms in database with timer: try: result = runSQL( sql , self.logusername, self.logpassword, self.loghostname , self.logport, self.logdatabase , ['--expanded'] ) is_successful = True except Exception as e: result = str(e) print str(e) try: #strip empty line, and use only the tail of 1k char result = '\n'.join( [ l for l in result.splitlines() if l.strip() != '' ] ) result = result[-1000:] self.logger.log_test_item(timer.elapsed, is_successful, "table", \ result, sql, "false") if is_successful: self.__store_db_result(result) except Exception as e: print 'ERROR', str(e)
def run(self): """Run the madlib invoking sql statement, and store the result to logger database.""" is_successful = False sql = self.sql #print executor command and invocation sql statement print '----------------------------------------------------' print ' '.join(self.argv) print self.sql timer = Timer() #the elapsed time is in second, but we will convert it to ms in database with timer: try: result = runSQL(sql, self.logusername, self.logpassword, self.loghostname, self.logport, self.logdatabase, ['--expanded']) is_successful = True except Exception as e: result = str(e) print str(e) try: #strip empty line, and use only the tail of 1k char result = '\n'.join( [l for l in result.splitlines() if l.strip() != '']) result = result[-1000:] self.logger.log_test_item(timer.elapsed, is_successful, "table", \ result, sql, "false") if is_successful: self.__store_db_result(result) except Exception as e: print 'ERROR', str(e)
def __load(self, db_manager, yaml_list, overload=False): """Load table into db.""" fail_list = [] for yaml_path in yaml_list: if os.path.exists(os.path.join(self.__yamlPath, yaml_path)) \ is False: continue yaml_content = yaml.load(open(os.path.join(self.__yamlPath, yaml_path))) if 'tables' in yaml_content: for table in yaml_content['tables']: # if 'skip' in table and \ # (table['skip'] == 'all' or (table['skip'] in kind)): # continue table_name = '.'.join([self.__schema, table['id']]) outSQL = os.path.join(self.__yamlPath, 'sql', table['id'] + '.sql') output = run_sql.runSQL("SELECT count(*) FROM %s" % table_name, psqlArgs=db_manager.getDBsqlArgs(), onErrorStop=False, Return="all") #If table exists and no nedd to overload, skip this sql. if output.find('not exist') < 0 and \ output.find(' 0') < 0 and overload is False: continue elif output.find(' 0') > 0 and overload is False: fail_list.append(table['id']) print "ERROR : Success create but copy failed : %s" % table['id'] continue try: start = time.time() subprocess.check_call('gunzip -f %s.gz' % outSQL, shell=True) run_sql.runSQL(outSQL, logport=str(db_manager.db_conf['port']), logdatabase=db_manager.db_conf['dbname'], onErrorStop=False, isFile=True, source_path=db_manager.getDBenv()) subprocess.check_call('gzip -f %s' % outSQL, shell=True) self.__logInfo(table['id'], 'load', time.time() - start) #Load additional sql file for table. if 'sql' in table: run_sql.runSQL(os.path.join(self.__yamlPath, os.path.dirname(yaml_path), table['sql']), logport=str(db_manager.db_conf['port']), logdatabase=db_manager.db_conf['dbname'], onErrorStop=False, isFile=True, source_path=db_manager.getDBenv()) print "INFO : Success Loaded : %s " % table['id'] except: fail_list.append(table['id']) print "ERROR : Fail Loaded : %s " % table['id'] #Load additional sql file for algorithm. if 'sql' in yaml_content: run_sql.runSQL(os.path.join(self.__yamlPath, os.path.dirname(yaml_path), yaml_content['sql']), logport=str(db_manager.db_conf['port']), logdatabase=db_manager.db_conf['dbname'], onErrorStop=False, isFile=True, source_path=db_manager.getDBenv()) print "FAILED LOAD TABLES:\n", fail_list
def runCases(getfile, skipfile, isList, isUnique, platform, testCaseDir, analyticsTool, run_id): configer = test_config.Configer( CfgSpecPath + file_path.Path.testconfigXml) configer.testconfig() if isList: cases = __getCasesFromMulti(getfile) else: cases = __getCasesFromSingle(getfile) if isUnique: cases = __distinctingCases(cases) executor = execute_case.TestCaseExecutor(cases, platform) if skipfile: skipfilepath = ScheduleDir + skipfile if cases is None: sys.exit('ERROR: Cases missing.') if skipfilepath is None or not os.path.isfile(skipfilepath): sys.exit('ERROR: Skip file missing.') try: skips = [] skipfileAbspath = os.path.abspath( skipfilepath ) sqlfileAbspath = os.path.abspath( cfgPath +'skipsqlfile.sql' ) skipfile_reader = read_skipfiles.ReadSkipfiles(skipfileAbspath,sqlfileAbspath) skips = skipfile_reader.getNoRunCases() except IOError: sys.exit('ERROR: Skip file open failed. ') except Exception,exp: print 'Error when parsing skip_files' executor.executeStart(analyticsTool) skippedcases = [] for case in cases: try: skips.index(case) f = open( CaseDir +case+'.case') lines = f.readlines() for line in lines: if len(line) < 10: continue pos =line.find('target_base_name') if pos > 0: target_base_name = line[pos + 17:].strip() else: continue print target_base_name pos = line.find('-c') cmd = line[pos + 3:].strip() sql = """insert into %s.testitemresult values( '%s', %s, %s, '%s', '%s', %s, %s, '%s', '%s', %s::bool); """ % (configer.metaDBSchema, target_base_name, run_id, \ 0, 'table', platform, 0, 'NULL', 'NULL', cmd, False) result = run_sql.runSQL(sql, configer.user, None, configer.host, configer.port, configer.database,['--expanded']) except ValueError: executor.executeOneCase(testCaseDir, platform, case, run_id) executor.executeStop()
self.addUserPGHBA(username, conf["master_dir"], conf['kind']) # clear up try : # sql = 'DROP SCHEMA %s CASCADE'%ResultSchema # run_sql.runSQL(sql, logusername = superuser, logport = port, logdatabase = dbname, \ # onErrorStop = False, source_path = conf['env']) sql = 'DROP SCHEMA %s CASCADE'%DataSchema run_sql.runSQL(sql, logusername = superuser, logport = port, logdatabase = dbname, \ onErrorStop = False, source_path = conf['env']) except Exception, e: print e print 'Database "%s" does not exist \nCreate the new database "%s"'%(dbname,dbname) sql = 'DROP USER %s CASCADE'%username run_sql.runSQL(sql, logusername = superuser, logport = port, logdatabase = dbtemplate, \ onErrorStop = False, source_path = conf['env']) # 1. Create non super user with super user sql = 'CREATE USER %s WITH CREATEDB'%username run_sql.runSQL(sql, logusername = superuser, logport = port, logdatabase = dbtemplate, \ onErrorStop = False, source_path = conf['env']) # 2. Create database non super user sql = 'CREATE DATABASE %s '%dbname run_sql.runSQL(sql, logusername = superuser, logport = port, logdatabase = dbtemplate, \ onErrorStop = False, source_path = conf['env']) # 3. Change database owner to non super user sql = 'ALTER DATABASE %s OWNER TO %s'%(dbname,username) run_sql.runSQL(sql, logusername = superuser, logport = port, logdatabase = dbtemplate, \ onErrorStop = False, source_path = conf['env'])
self.addUserPGHBA(username, conf["master_dir"], conf['kind']) # clear up try : sql = 'DROP SCHEMA %s CASCADE'%ResultSchema run_sql.runSQL(sql, logusername = superuser, logport = port, logdatabase = dbname, \ onErrorStop = False, source_path = conf['env']) sql = 'DROP SCHEMA %s CASCADE'%DataSchema run_sql.runSQL(sql, logusername = superuser, logport = port, logdatabase = dbname, \ onErrorStop = False, source_path = conf['env']) except Exception, e: print e print 'Database "%s" does not exist \nCreate the new database "%s"'%(dbname,dbname) sql = 'DROP USER %s CASCADE'%username run_sql.runSQL(sql, logusername = superuser, logport = port, logdatabase = dbtemplate, \ onErrorStop = False, source_path = conf['env']) # 1. Create non super user with super user sql = 'CREATE USER %s WITH CREATEDB'%username run_sql.runSQL(sql, logusername = superuser, logport = port, logdatabase = dbtemplate, \ onErrorStop = False, source_path = conf['env']) # 2. Create database non super user sql = 'CREATE DATABASE %s '%dbname run_sql.runSQL(sql, logusername = superuser, logport = port, logdatabase = dbtemplate, \ onErrorStop = False, source_path = conf['env']) # 3. Change database owner to non super user sql = 'ALTER DATABASE %s OWNER TO %s'%(dbname,username) run_sql.runSQL(sql, logusername = superuser, logport = port, logdatabase = dbtemplate, \ onErrorStop = False, source_path = conf['env'])