def run(log_level="INFO"): config = configuration.configuration() config.fileConfig(myglobal.LOGGINGINI) config.setValue("handler_fileHandler", "args", ('dispatcher.log', 'a')) config.setValue("handler_fileHandler", "level", log_level) config.setValue("handler_consoleHandler", "level", log_level) # logging.config.fileConfig(FILE_FOLDER + configuration.configuration("dispatcher.ini").getValue('Log','file')) logging.config.fileConfig(myglobal.LOGGINGINI) logger = logging.getLogger('main') d = dispatcher.dispatcher() while True: logger.info("Run periodically build and queue check.") #run scheduled build check d.scheduledCheck() #check the queue to see if any new job to do d.scanQueue() ''' #add nightly jobs only on designated time currentTime=time.strftime('%H%M',time.localtime()) scheduledTime=scheduled_nightly_time.replace(":","") if int(currentTime)>=int(scheduledTime) and int(currentTime)<(int(scheduledTime)+timeout/60): #print "It comes to the scheduled time, add nightly jobs." logger.info("It comes to the scheduled time, add nightly jobs.") d.addNightlyJobs() ''' #wait for a whole logger.info("Sleep for %i minutes" % (timeout / 60)) time.sleep(timeout) continue
def __new__(cls, log_config): mutex = threading.Lock() mutex.acquire() # 上锁,防止多线程下出问题 if not hasattr(cls, 'instance'): cls.instance = super(LogSignleton, cls).__new__(cls) config = configuration.configuration() config.fileConfig(log_config) print os.path.abspath(log_config) cls.instance.log_filename = config.getValue('LOGGING', 'log_file') cls.instance.max_bytes_each = int( config.getValue('LOGGING', 'max_bytes_each')) cls.instance.backup_count = int( config.getValue('LOGGING', 'backup_count')) cls.instance.fmt = config.getValue('LOGGING', 'fmt') cls.instance.log_level_in_console = int( config.getValue('LOGGING', 'log_level_in_console')) cls.instance.log_level_in_logfile = int( config.getValue('LOGGING', 'log_level_in_logfile')) cls.instance.logger_name = config.getValue('LOGGING', 'logger_name') cls.instance.console_log_on = int( config.getValue('LOGGING', 'console_log_on')) cls.instance.logfile_log_on = int( config.getValue('LOGGING', 'logfile_log_on')) cls.instance.logger = logging.getLogger(cls.instance.logger_name) cls.instance.__config_logger() mutex.release() return cls.instance
def run(dname, loop, rtype): global DEVICENAME, CONFIG, DEVICE, LogPath global LOOP_NUM, RESULT_DICT, FAIL_CASE CONFIG = configuration.configuration() fname = PATH('../config/' + 'configuration.ini') CONFIG.fileConfig(fname) DEVICENAME = dname DEVICE = device.Device(DEVICENAME) # initial test environment init_env() # run test case logname = desktop.get_log_name(dname, 'TestTasks') LogPath = os.path.dirname(os.path.abspath(logname)) utest_log = os.path.join(LogPath, 'unittest.html') # ##RESULT_DICT format {casename:{Result:['PASS','PASS'],Log:['','']}}##### RESULT_DICT = {} FAIL_CASE = [] try: for LOOP_NUM in range(loop): fileobj = file(utest_log, 'a+') if LOOP_NUM == 0 or rtype.upper() == 'ALL': suite = unittest.TestLoader().loadTestsFromTestCase(TestTask) else: suite = unittest.TestSuite() for name in FAIL_CASE: suite.addTest(TestTask(name)) FAIL_CASE = [] if suite.countTestCases() > 0: runner = HTMLTestRunner.HTMLTestRunner( stream=fileobj, verbosity=2, title='Task Testing Report', description='Test Result', ) runner.run(suite) fileobj.close() sleep(5) # write log to summary report if LOOP_NUM == loop - 1: desktop.summary_result(utest_log, True, RESULT_DICT) else: desktop.summary_result(utest_log, False, RESULT_DICT) except Exception, ex: print ex
def __init__(self): self.__config = configuration.configuration() self.__config.fileConfig(myglobal.DISPATCHERINI) logging.config.fileConfig(myglobal.LOGGINGINI) self.__logger = logging.getLogger('distributor') host = self.__config.getValue("Database", "host") user = self.__config.getValue("Database", "username") pwd = self.__config.getValue("Database", "password") schema = self.__config.getValue("Database", "db") port = self.__config.getValue("Database", "port") self.__db = database.database() self.__db.initDB(host, user, pwd, schema, port)
def __init__(self): self._config = configuration.configuration() self._config.fileConfig(myglobal.CONFIGURATONINI) host = self._config.getValue("Database", "host") user = self._config.getValue("Database", "username") pwd = self._config.getValue("Database", "password") schema = self._config.getValue("Database", "db") port = self._config.getValue("Database", "port") self.__db = db.database() self.__db.initDB(host, user, pwd, schema, port) logging.config.fileConfig(myglobal.LOGGINGINI) self._logger = logging.getLogger('genreport') '''
def __init__(self): self.__config = configuration.configuration() self.__config.fileConfig(myglobal.CONFIGURATONINI) logging.config.fileConfig(myglobal.LOGGINGINI) self._logger = logging.getLogger('savelog') self.__total_data = '' self.__mapping_data = '' self.__result_data = '' self.__component = '' self.__category = '' self.__splitter = "^" self.__db = None self._xml = None self._nRet = True self._initData()
def __init__(self, config_file, db): config = configuration.configuration() config.fileConfig(config_file) self.host = config.getValue(db, 'host') self.port = config.getValue(db, 'port') self.user = config.getValue(db, 'user') self.passwd = config.getValue(db, 'passwd') self.db_name = config.getValue(db, 'db') self.charset = config.getValue(db, 'charset') try: self.dbconn = mysql.connector.connect(host=self.host, port=self.port, user=self.user, password=self.passwd, database=self.db_name, charset=self.charset) except Exception as e: logger.error('Initial database is failed:%s' % e) sys.exit()
uid = args.uid loop_number = args.lnum loop_type = args.ltype if uid is None: sys.exit(0) # verify if device is connected devices = device.Device.get_connected_devices() if uid not in devices: print "Device is not connected, please check" sys.exit(0) try: # verify if device is configuration config = configuration.configuration() config.fileConfig(myglobal.CONFIGURATONINI) except Exception, ex: print "There is no related configuration information" sys.exit(0) try: case_list = config.getValue(uid, 'test_list').split(';') for cases in case_list: if cases.startswith('test_startup_register'): test_startup_register.run(uid, loop_number, loop_type) if cases.startswith('test_tasks'): test_tasks.run(uid, loop_number, loop_type) if cases.startswith('test_module'): myglobal.logger.debug('Start to test module') test_module_update.run(uid, loop_number, loop_type,
import sys from time import sleep import os import time import datetime from library import device from logger import log from library import desktop from library import configuration from library import logcat from library import pJson from library import myglobal from library import imagemagick CONFIG = configuration.configuration() print os.path.abspath(myglobal.CONFIGURATONINI) CONFIG.fileConfig(myglobal.CONFIGURATONINI) def start_service(): my_device.device_service_operation('STOP') sleep(2) my_device.device_service_operation('START') wtime = CONFIG.getValue('Runtime', 'waittime') sleep(wtime) def detect_logcat(out, durtation):
__author__ = 'Xuxh' import os from library.mylog import log from library import configuration __all__ = ['logger', 'theme_config', 'magazine_config', 'device_config'] PATH = lambda p: os.path.abspath(os.path.join(os.path.dirname(__file__), p)) logsignleton = log.LogSignleton(PATH('../config/logconfig.ini')) logger = logsignleton.get_logger() # theme configuration file theme_config = configuration.configuration() fname = PATH('../config/theme.ini') theme_config.fileConfig(fname) # magazine configuration file magazine_config = configuration.configuration() fname = PATH('../config/magazine.ini') magazine_config.fileConfig(fname) # wallpaper configuration file wallpaper_config = configuration.configuration() fname = PATH('../config/wallpaper.ini') wallpaper_config.fileConfig(fname) # device config device_config = configuration.configuration() fname = PATH('../config/device.ini')
def runit(log_level="INFO"): nResult = True _config = configuration.configuration() _config.fileConfig(myglobal.LOGGINGINI) _config.setValue("handler_fileHandler", "args", ('testserver.log', 'a')) _config.setValue("handler_fileHandler", "level", log_level) _config.setValue("handler_consoleHandler", "level", log_level) logging.config.fileConfig(myglobal.LOGGINGINI) _logger = logging.getLogger('main') ts = testserver.testserver() _logger.info("Lock the test server and target server in database") ts.setStatus("1") _logger.info("Download and push the build to target server") nResult = ts.getBuildReady() if not nResult: _logger.error("Failed to get build, break this test session") _sendAlert() _logger.info("Unlock the test server and target server in database") ts.setStatus("0") _logger.info("Update job status as FAILED in database") ts.updateJobStatus("FAILED") #to Send alert message _logger.info("=======Quit the job========") return _logger.info("Execute Robot Framework Test...") ts.startTest() _logger.info("Robot Framework Test Done") if not os.path.exists(_XML_FILE): _logger.error("The robot framework test is broken unexpected") _logger.info("Update job status as FAILED in database") ts.updateJobStatus("FAILED") _logger.error("Failed to get output.xml, the test is abnormal") _sendAlert() _logger.info("Unlock the test server and target server in database") ts.setStatus("0") _logger.info("=======Quit the job========") return _logger.info("Save the test result in database") save = savelog.savelog() if not save.isTrue(): _logger.error("Fail to save log") _logger.info("Update job status as FAILED in database") ts.updateJobStatus("FAILED") _logger.info("Fail to save log to database, send alert") _sendAlert() _logger.info("Unlock the test server and target server in database") ts.setStatus("0") _logger.info("=======Quit the job========") return nResult = save.insertDetailedRecords() nResult = nResult and save.insertMappingRecord() nResult = nResult and save.insertTotalRecord() # nResult = nResult and save.updateIndividualLPB() if not nResult: _logger.error("Fail to save log") _logger.info("Update job status as FAILED in database") ts.updateJobStatus("FAILED") _logger.info("Fail to save log to database, send alert") _sendAlert() _logger.info("Unlock the test server and target server in database") ts.setStatus("0") _logger.info("=======Quit the job========") return _logger.info("Generate the test result data") report = genreport.genreport() _logger.info("Upload the robot framework logs") ts.uploadLog() _logger.info("Update job status as SUCCEED in database") ts.updateJobStatus("SUCCEED") _logger.info("Send out test report by email") if not report.sendreport(): _logger.info("Update job status as FAILED in database") ts.updateJobStatus("FAILED") _logger.info("Fail to send out test report by email, send alert") _sendAlert() _logger.info("Unlock the test server and target server in database") ts.setStatus("0") _logger.info("========Test server completes the job==========")