def testLogger(): logger = Logger("test logger", level = logging.DEBUG) logger.info("info message") logger.warn("warn message") logger.error("error message") logger.fatal("fatal message") logger.close()
def testLogger(): logger = Logger("test logger", level=logging.DEBUG) logger.info("info message") logger.warn("warn message") logger.warning("warning message") logger.error("error message") logger.critical("critical message") logger.fatal("fatal message") logger.debug("debug message") logger.close()
def testLoggerFile(): testFile = "testlogfile.log" if not os.path.exists(testFile): logger = Logger("test file logger", logFile = testFile, level = logging.INFO) testMessage = "testmessage" logger.info(testMessage) line = open(testFile, 'r').readlines() os.remove(testFile) last = line[-1].split()[-1] logger.close() assert testMessage == last else: m = "Can't do logging into file test, file %s exists." % testFile py.test.fail(m)
def testLoggerFile(): testFile = TEST_LOG_FILE if not os.path.exists(testFile): logger = Logger("test file logger", logFile=testFile, level=logging.INFO) testMessage = "testmessage" logger.info(testMessage) logger.close() line = open(testFile, 'r').readlines() os.remove(testFile) # not the last line which the logger closing plus 3 x \n , but # line before that last = line[-5].split()[-1] assert testMessage == last else: m = "Can't do logging into file test, file %s exists." % testFile py.test.fail(m)
def testReceivingServerActionCheckTargetFileNames(): logger = Logger() files = ["/mnt/data", "/etc/passwd", "/etc/something/nonsence", "/tmp"] options = dict(port=1000, gridUserDest="someuser", destFiles=files) a = ReceivingServerAction("some_id", options) logger.info("%s - checking presence of files at target location ..." % a.__class__.__name__) r = a._checkTargetFileNames(files) logger.debug("Results:\n%s" % r) expected = \ """ exists True: /mnt/data exists False: /mnt/.data exists True: /etc/passwd exists False: /etc/.passwd exists False: /etc/something/nonsence exists False: /etc/something/.nonsence exists True: /tmp exists False: /.tmp """ assert r == expected
def testReceivingServerAddressAlreadyInUse(): c = """ [general] port = 6700 debug = DEBUG portRangeFDTServer = 54321,54323 fdtReceivingServerCommand = java -jar ../fdtjava/fdt.jar -bs 64K -p %(port)s -wCount 5 -S -noupdates fdtServerLogOutputTimeout = 2 fdtServerLogOutputToWaitFor = "FDTServer start listening on port: %(port)s" fdtReceivingServerKillTimeout = 1 killCommand = "kill -9 %(pid)s" killCommandSudo = "kill -9 %(pid)s" """ f = getTempFile(c) inputOptions = "-d DEBUG -p 6700 --config=%s" % f.name conf = ConfigFDTD(inputOptions.split()) testName = inspect.stack()[0][3] logger = Logger(name=testName, level=logging.DEBUG) apMon = None daemon = FDTD(conf, apMon, logger) assert len(daemon._executors) == 0 files = ["/mnt/data", "/etc/passwd", "/etc/something/nonsence", "/tmp"] options = dict(gridUserDest="someuser", destFiles=files) a = ReceivingServerAction("some_id", options) a._checkForAddressAlreadyInUseError("some message", 222, logger) a._checkForAddressAlreadyInUseError("some message", 25, logger) a._checkForAddressAlreadyInUseError("Address already in use", 25, logger) a._checkForAddressAlreadyInUseError("Address already in use", 22225, logger) logger.info("Now real FDT Java server real attempts") logger.info('#' * 78) # 1) successful attempt logger.info('1' * 78) options = dict(gridUserDest="someuser", destFiles=files) a = ReceivingServerAction("some_id", options) assert len(daemon._executors) == 0 result = a.execute(conf=conf, caller=daemon, apMon=apMon, logger=logger) assert len(daemon._executors) == 1 assert result.status == 0 assert result.serverPort == 54321 assert result.msg == "FDT server is running" # 2) this executor attempt shall fail with Address already in use, # fool into reusing the same port 54321 as the previous process # by replacing caller.getFreePort() method which is used in # ReceivingServerAction.exectute() def myFoolGetFreePort(inp, logger): def returner(): logger.debug("myFoolGetFreePort called, returning %s" % inp) return inp return returner daemon.getFreePort = myFoolGetFreePort(54321, logger) logger.info('2' * 78) options = dict(gridUserDest="someuser", destFiles=files) a = ReceivingServerAction("some_id-2", options) py.test.raises(FDTDException, a.execute, conf=conf, caller=daemon, apMon=apMon, logger=logger) # starting FDT Java command failed, but the request remains in the # executor container for later cleanup assert len(daemon._executors) == 2 # 3) kill both executors / processes - one running, other failed logger.info('3' * 78) daemon.killProcess("some_id", logger, waitTimeout=False) assert len(daemon._executors) == 1 daemon.killProcess("some_id-2", logger, waitTimeout=False) assert len(daemon._executors) == 0 # 4) try starting FDT Java server on privileged port - will fail logger.info('4' * 78) options = dict(gridUserDest="someuser", destFiles=files) a = ReceivingServerAction("some_id", options) daemon.getFreePort = myFoolGetFreePort(999, logger) py.test.raises(FDTDException, a.execute, conf=conf, caller=daemon, apMon=apMon, logger=logger) assert len(daemon._executors) == 1 daemon.killProcess("some_id", logger, waitTimeout=False) assert len(daemon._executors) == 0 daemon.shutdown() daemon.pyroDaemon.closedown()
optBackup = sys.argv[:] try: conf = ConfigFDTCopy(sys.argv[1:]) conf.sanitize() except ConfigurationException, ex: print "fdtcp failed to start, reason: %s" % ex sys.exit(1) logger = Logger(name="fdtcp", logFile=conf.get("logFile"), level=conf.get("debug")) # ticket #35 - mercurial expandable keywords in the code # information from the SCM (expandable keywords) versionInfo = dict(Revision="$Revision: cf25e731af0a $", Tags="$Tags: tip $") logger.info("fdtcp starting ... version: %s" % logger.pprintFormat(versionInfo)) logger.debug("Search sys.path:\n%s\n" % logger.pprintFormat(sys.path)) logger.debug("PYRO_STORAGE: '%s'" % os.environ.get("PYRO_STORAGE")) logger.debug("Input command line arguments: '%s'" % optBackup) logger.debug("Configuration values (processed):\n%s\n" % logger.pprintFormat(conf._options)) apMon = None apMonDestConf = conf.get("apMonDestinations") if apMonDestConf: apMonDestinations = tuple(apMonDestConf.split(',')) logger.info("Initializing MonALISA ApMon, destinations: %s ..." % (apMonDestinations, )) apMon = apmon.ApMon(apMonDestinations) apMon.enableBgMonitoring(True)
def main(): # all values and action information held in the conf object optBackup = sys.argv[:] try: conf = ConfigFDTCopy(sys.argv[1:]) conf.sanitize() except ConfigurationException, ex: print "fdtcp failed to start, reason: %s" % ex sys.exit(1) logger = Logger(name = "fdtcp", logFile = conf.get("logFile"), level = conf.get("debug")) logger.info("fdtcp starting ...") logger.debug("Search sys.path: '%s'" % sys.path) logger.debug("PYRO_STORAGE: '%s'" % os.environ.get("PYRO_STORAGE")) logger.debug("Input command line arguments: '%s'" % optBackup) logger.debug("Configuration values (processed): '%s'" % conf._options) apMonDestConf = conf.get("apMonDestinations") apMonDestinations = tuple(apMonDestConf.split(',')) logger.info("Initializing MonALISA ApMon, destinations: %s ..." % (apMonDestinations,)) apMon = apmon.ApMon(apMonDestinations) apMon.enableBgMonitoring(True) # use DNS names rather than IP address Pyro.config.PYRO_DNS_URI = True