def __init__(self, aggregateTo, suiteName, testName, loglevel = logging.DEBUG): try: aggregateTo = os.path.join(aggregateTo, suiteName, testName) self.agg = LogAggregator(aggregateTo) setupLogging(logPath = os.path.join(aggregateTo, "%s.log " % testName), logToStream = True, logLevel = loglevel) Backup.backupOldLogs() Backup.backupCouchDB("hsn", exception = False) except (BackupException, IOError, OSError) as e: Backup.restoreFiles() raise e
def done(self): couchAggregate = False if ("couchdb", None) in Starter.inits or ("couchdb", "time to relax.\n") in Starter.inits: couchAggregate = True Starter.stopStartedInits() Website.shutdownWebsites() self.agg.aggregate(takeFrom = "/var/log/hsn2") if couchAggregate: self.agg.aggregate(takeFrom = "/var/log/couchdb") self.agg.aggregate("/var/log/rabbitmq", suffix = None) Backup.restoreFiles() setupLogging(logPath = None, logToStream = False)
def startService(serviceType=HSN2Service, taskProcessor=None): ''' Main function for starting a Python HSN 2 Service. @param serviceType: The service class. @param taskProcessor: The taskProcessor class. ''' service = serviceType(taskProcessor) cliargs = service.cliparse() from hsn2_commons import loggingSetup loggingSetup.setupLogging(logPath="/var/log/hsn2/%s.log" % cliargs.serviceName, logToStream=True, logLevel=cliargs.logLevel) signal.signal(signal.SIGINT, service.signalHandler) signal.signal(signal.SIGTERM, service.signalHandler) if service.sanityChecks(cliargs) is False: logging.error("Service not starting!") exit(-1) try: service.start(cliargs) service.run() service.stop() except Exception as exc: logging.exception(exc) exit(-1)
def addsample(self, label, uid): ''' Used for storing single test result a.k.a. sample. @param label: should match the label used for start method @param uid: should match the uid used for start method ''' self.dom.childNodes[0].appendChild(self.samples["%s%s" % (label, uid)].getDOMElement()) def toxml(self): return self.dom.toxml() def toprettyxml(self): return self.dom.toprettyxml() if __name__ == "__main__": setupLogging(logPath = None, logToStream = True, logLevel = logging.INFO) Configuration.setHSN2TestPath("/tmp/tests") try: Backup.backupOldLogs() Backup.backupCouchDB("hsn", exception = False) agg = LogAggregator(putTo = "/var/log/hsn2/c") except (BackupException, IOError, OSError) as e: Backup.restoreFiles() raise e setupLogging(logPath = "/var/log/hsn2/test.log", logToStream = True, logLevel = logging.DEBUG) logging.info("Testing commons") try: Configuration.resetJobCounter() Configuration.setConsoleConf("127.0.0.1", 5672, 4) Configuration.setCouchConf()