def testConfigFDTDCorrectValues(): c = \ """ [general] port = 9000 fdtSendingClientCommand = cmd1 fdtReceivingServerCommand = cmd2 portAuthService = 9001 daemonize = False pidFile = /tmp/something.log portRangeFDTServer = 54321,54400 transferSeparateLogFile = True debug = INFO fdtSendingClientKillTimeout = 10 fdtServerLogOutputTimeout = 11 fdtReceivingServerKillTimeout = 12 authServiceLogOutputTimeout = 13 fdtServerLogOutputToWaitFor = somelog authServiceLogOutputToWaitFor = someotherlog # strings - both with " and without " shall work identically authServiceCommand = "authcommand" killCommandSudo = "kill command sudo" killCommand = "kill command" """ f = getTempFile(c) inputOption = "--config=%s" % f.name conf = ConfigFDTD(inputOption.split()) conf.sanitize() f = getTempFile(c) inputOption = "-d DEBUG -p 6700 --config=%s" % f.name conf = ConfigFDTD(inputOption.split()) conf.sanitize() assert conf.get("debug") == logging.DEBUG assert conf.get("port") == 6700 assert conf.get("fdtSendingClientCommand") == "cmd1" assert conf.get("fdtReceivingServerCommand") == "cmd2" assert conf.get("nonsenceoption") == None # processing happens on this stage assert conf.get("portRangeFDTServer") == "54321,54400" assert conf.get("transferSeparateLogFile") == True assert conf.get("fdtSendingClientKillTimeout") == 10 assert conf.get("fdtServerLogOutputTimeout") == 11 assert conf.get("fdtReceivingServerKillTimeout") == 12 assert conf.get("authServiceLogOutputTimeout") == 13 assert conf.get("fdtServerLogOutputToWaitFor") == "somelog" assert conf.get("authServiceLogOutputToWaitFor") == "someotherlog" assert conf.get("authServiceCommand") == "authcommand" assert conf.get("killCommandSudo") == "kill command sudo" assert conf.get("killCommand") == "kill command" assert conf.get("daemonize") == False assert conf.get("pidFile") == "/tmp/something.log"
def testMainLogFileOpeningDuringDaemonisation(): py.test.skip("Test skipped, messes up with input/output streams for " "other test, better to run it stand-alone: " "py.test fdtcplib/test/test_fdtd.py -s -k testMainLogFileOpeningDuringDaemonisation") """ As described in the problem #41:comment:9, the main log file remains open thrice (under different descriptor) after initial daemonisation. In order to include this particular test into whole test suite running (issue with file descriptors being redirected, etc in fdtd.daemonize() function), perhaps after running this test, the file descriptors can be put back from backup sys.__stdout__, etc? """ c = """ [general] logFile = /tmp/fdtd.log pidFile = /tmp/fdtd.pid """ testName = inspect.stack()[0][3] f = getTempFile(c) inputOption = "--config=%s" % f.name conf = ConfigFDTD(inputOption.split()) f.close() logFile = "%s-%s" % (conf.get("logFile"), testName) pidFile = conf.get("pidFile") if os.path.exists(logFile): print("test: %s: file '%s' exists, removing ..." % (testName, logFile)) os.remove(logFile) if os.path.exists(pidFile): print("test: %s: file '%s' exists, removing ..." % (testName, pidFile)) os.remove(pidFile) logger = Logger(name=testName, logFile=logFile, level=logging.DEBUG) logger.debug("Before daemonization ...") numFiles, filesStr = getOpenFilesList() logger.debug("Logging open files: %s items:\n%s" % (numFiles, filesStr)) try: daemonize(conf, logger) except SystemExit: # previous leading process continues here return # here continues the newly created background daemon f = open(pidFile, 'r') rc = f.read() f.close() rc = rc.strip() pid = int(rc) numFiles, filesStr = getOpenFilesList() logger.debug("Logging open files: %s items:\n%s" % (numFiles, filesStr)) logger.debug("Before finishing ... ") logger.close() # the log file may be open more times due to streams descriptor # duplication as done in fdtd.daemonization() but now, once is # closed, there should not any other outstanding open file assert numFiles == 0
def testMainLogFileOpeningDuringDaemonisation(): py.test.skip( "Test skipped, messes up with input/output streams for " "other test, better to run it stand-alone: " "py.test fdtcplib/test/test_fdtd.py -s -k testMainLogFileOpeningDuringDaemonisation" ) """ As described in the problem #41:comment:9, the main log file remains open thrice (under different descriptor) after initial daemonisation. In order to include this particular test into whole test suite running (issue with file descriptors being redirected, etc in fdtd.daemonize() function), perhaps after running this test, the file descriptors can be put back from backup sys.__stdout__, etc? """ c = """ [general] logFile = /tmp/fdtd.log pidFile = /tmp/fdtd.pid """ testName = inspect.stack()[0][3] f = getTempFile(c) inputOption = "--config=%s" % f.name conf = ConfigFDTD(inputOption.split()) f.close() logFile = "%s-%s" % (conf.get("logFile"), testName) pidFile = conf.get("pidFile") if os.path.exists(logFile): print("test: %s: file '%s' exists, removing ..." % (testName, logFile)) os.remove(logFile) if os.path.exists(pidFile): print("test: %s: file '%s' exists, removing ..." % (testName, pidFile)) os.remove(pidFile) logger = Logger(name=testName, logFile=logFile, level=logging.DEBUG) logger.debug("Before daemonization ...") numFiles, filesStr = getOpenFilesList() logger.debug("Logging open files: %s items:\n%s" % (numFiles, filesStr)) try: daemonize(conf, logger) except SystemExit: # previous leading process continues here return # here continues the newly created background daemon f = open(pidFile, "r") rc = f.read() f.close() rc = rc.strip() pid = int(rc) numFiles, filesStr = getOpenFilesList() logger.debug("Logging open files: %s items:\n%s" % (numFiles, filesStr)) logger.debug("Before finishing ... ") logger.close() # the log file may be open more times due to streams descriptor # duplication as done in fdtd.daemonization() but now, once is # closed, there should not any other outstanding open file assert numFiles == 0