def main(args=sys.argv): """ Entry point function. It's mapped to two different scripts, which is why we can distinguish here between them and start different processes """ # A minimum of 4 because we require at least -cfg <file> # e.g. ngamsDaemon.py start -cfg /path/to/ngas-server-7777.xml name = args[0] if len(args) < 4: print_usage(name) sys.exit(1) cmd = args[1] args = args[0:1] + args[2:] # We need to load the configuration file to know the root directory # and the IP address the server is listening on lower_args = [x.lower() for x in args] if '-cfg' not in lower_args: errmsg('At least -cfg <file> should be specified') sys.exit(2) cfg_idx = lower_args.index('-cfg') if cfg_idx == len(lower_args) - 1: errmsg('At least -cfg <file> should be specified') sys.exit(2) cfg_file = args[cfg_idx + 1] cfg = ngamsConfig.ngamsConfig() cfg.load(cfg_file) # The daemon PID file pid_path = os.path.join(cfg.getRootDirectory(), 'var', 'run', 'ngamsDaemon.pid') # In the event we receive the '-force' command line option we will forcibly restart the NGAS daemon # This will require stopping any NGAS daemon that might be currently running and removing the PID lock file if '-force' in lower_args: sys.stdout.write( "Force command line option is set. Will clean up PID lock file if one exists.\n" ) if os.path.isfile(pid_path): stop(pid_path) # Main command switch if 'start' == cmd: exit_code = start(args, cfg, pid_path) elif 'stop' == cmd: exit_code = stop(pid_path) elif 'restart' == cmd: stop(pid_path) exit_code = start(args, cfg, pid_path) elif 'status' == cmd: exit_code = status(cfg) else: errmsg("Unknown command: %s" % (cmd, )) print_usage(name) exit_code = 1 sys.exit(exit_code)
def main(args=sys.argv): """ Entry point function. It's mapped to two different scripts, which is why we can distinguish here between them and start different processes """ # A minimum of 4 because we require at least -cfg <file> name = args[0] if len(args) < 4: print_usage(name) sys.exit(1) cmd = args[1] args = args[0:1] + args[2:] # We need to load the configuration file to know the root directory # and the IP address the server is listening on largs = [x.lower() for x in args] if '-cfg' not in largs: err('At least -cfg <file> should be specified') sys.exit(2) cfg_idx = largs.index('-cfg') if cfg_idx == len(largs) - 1: err('At least -cfg <file> should be specified') sys.exit(2) cfgfile = args[cfg_idx + 1] cfg = ngamsConfig.ngamsConfig() cfg.load(cfgfile) # The daemon PID file pidfile = os.path.join(cfg.getRootDirectory(), 'var', 'run', 'ngamsDaemon.pid') # Main command switch if 'start' == cmd: exitCode = start(args, cfg, pidfile) elif 'stop' == cmd: exitCode = stop(pidfile) elif 'restart' == cmd: stop(pidfile) exitCode = start(args, cfg, pidfile) elif 'status' == cmd: exitCode = status(cfg) else: print "Unknown command: %s" % (cmd, ) print_usage(name) exitCode = 1 sys.exit(exitCode)
def test_DppiProc_02(self): """ Synopsis: Test the proper execution of DPPI processing/result in buffer. Description: When requesting a file from NGAS, it is possible to specify to have the file processed by a DPPI. The result can either be stored in a file or contained in the buffer when handed over to the NG/AMS Server. Expected Result: The DPPI should be invoked the file to be retrieved and the result (stored by the DPPI in a buffer), properly sent back to the client. Test Steps: - Start a server configured to invoke a test DPPI (header extraction). - Archive a file. - Retrieve the file, specifying to apply the DPPI on it. Result will be stored in a buffer in memory. - Check that the file has been processed as expected. Remarks: ... Test Data: ... """ tmpCfgFile = genTmpFilename("ngamsRetrieveCmdTest") cfg = ngamsConfig.ngamsConfig().load("src/ngamsCfg.xml") cfg.storeVal("NgamsCfg.Processing[1].PlugIn[1].Name", "ngamsTest.ngamsTestDppi1") cfg.storeVal("NgamsCfg.Processing[1].PlugIn[1].PlugInPars", "TAG=test_DppiProc_02,TARGET=BUFFER") cfg.save(tmpCfgFile, 0) self.prepExtSrv(cfgFile=tmpCfgFile) client = sendPclCmd() client.archive("src/SmallFile.fits") # Retrieve the file specifying to apply the DPPI. outFile = genTmpFilename("test_DppiProc_02") pars = [["test_suite", "ngamsRetrieveCmdTest"], ["test_case", "test_DppiProc_02"]] stat = client.retrieve("TEST.2001-05-08T15:25:00.123", targetFile=outFile, processing="ngamsTest.ngamsTestDppi1", pars=pars) refStatFile = "ref/ngamsRemFileCmdTest_test_DppiProc_02_01_ref" self.checkFilesEq(refStatFile, outFile, "Incorrect status for " +\ "RETRIEVE Command/DPPI Processing, result in buffer")
def test_Load_1(self): """ Synopsis: Test Purpose: Load configuration into DB. Description: The purpose of this Test Case is to test that the NG/AMS Configuration can be loaded properly from an XML configuration document into the NGAS DB. Expected Result: The XML based NG/AMS Configuration should be loaded into the NGAS DB. Test Steps: - Load configuration into instance of ngamsConfig and write it to the NGAS DB. - Load the previously loaded configuration from the DB into an object and dump this into an NG/AMS XML Configuration. - Verify that the contents is as expected after loading into the DB and dumping from the DB into an ASCII format in the NGAS XML Dictionary format. Remarks: ... """ cfgObj1, dbObj = self.loadCfg("test_Load_1") # Load + check the configuration from the DB. cfgObj2 = ngamsConfig.ngamsConfig() # Dump as XML Dictionary. cfgObj2.loadFromDb("test_Load_1", dbObj) refFile = "ref/ngamsConfigHandlingTest_test_Load_1_1_ref" cleanXmlDoc = _cleanXmlDoc(cfgObj2.dumpXmlDic(), r'^NgamsCfg.Db\[1\]') tmpStatFile = saveInFile(None, cleanXmlDoc) self.checkFilesEq(refFile, tmpStatFile, "Incorrect contents of " +\ "XML Dictionary of cfg. loaded from DB") # Dump as XML Document. refFile = "ref/ngamsConfigHandlingTest_test_Load_1_2_ref" tmpStatFile = saveInFile(None, without_db_element(cfgObj2.genXmlDoc())) self.checkFilesEq(refFile, tmpStatFile, "Incorrect contents of " +\ "XML Document of cfg. loaded from DB")
# Write the printer code file to the device. stat, out = ngamsPlugInApi.execCmd("cat " + printerFilename + " > " +\ parDic["dev"]) # This was previously excluded during the "test mode"; a proper way is by # having a configurable parameter if not 'keep_printer_file' in parDic: os.system("rm -f " + printerFilename) if (stat != 0): errMsg = "Problem occurred printing label! Error: " + str(out) ngamsPlugInApi.notify(srvObj, NGAMS_NOTIF_ERROR, "ngamsBrotherPT9200DxPlugIn: " +\ "PROBLEM PRINTING LABEL", errMsg) raise Exception(errMsg) if __name__ == '__main__': """ Main function. """ if (len(sys.argv) != 3): print("\nCorrect usage is:\n") print("% (python) ngamsBrotherPT9200DxPlugIn <NGAMS CFG> <text>\n") sys.exit(1) cfg = ngamsConfig.ngamsConfig() cfg.load(sys.argv[1]) ngamsBrotherPT9200DxPlugIn(cfg, sys.argv[2]) # EOF
ignore = 0 checksumPlugIn = "ngamsGenCrc32" exec "import " + checksumPlugIn checksum = eval(checksumPlugIn + "." + checksumPlugIn +\ "(None, baseFile, 0)") fileStatus = "00000000" # Open DB connection if specified. if (testParDic["DB"] != None): dbSrv, dbName, dbUser, dbPwd = testParDic["DB"].split(":") dbCon = ngamsDb.ngamsDb(dbSrv, dbName, dbUser, dbPwd, 0) else: dbCon = None # Open DB Snapshot. ngamsCfgObj = ngamsConfig.ngamsConfig().\ storeVal("NgamsCfg.Permissions[1].AllowArchiveReq", 1) dbSnapshotDbm = ngamsJanitorThread.\ _openDbSnapshot(ngamsCfgObj, testParDic["MOUNTPOINT"]) # Start 'archiving loop'. fileCount = 0 step = (1.0 / filesPerDay) # ((24 * 3600.0 / filesPerDay) / 24 * 3600.0) sys.stdout.write("Creating files (100 files/dot): ") sys.stdout.flush() prevBaseTimeMjd = baseTimeMjd while (fileCount < testParDic["NOOFFILES"]): dayFileCount = 0 startMjd = baseTimeMjd while ((dayFileCount < filesPerDay) and (fileCount < testParDic["NOOFFILES"])): baseTimeMjd += step
def runAllTests(notifEmail=None, skip=None): """ Run all tests in ngasUtils/test. notifEmail: List of email recipients that should be notified about the test results (list/email addresses). skip: Test Suites or Test Cases to skip. Comma separated list (string). Returns: Void. """ skipDic = {} if (skip): for test in skip.split(","): skipDic[test] = 1 testModList = getTestList() startTime = time.time() failModDic = {} noOfTests = len(testModList) testCount = 0 format = "Running Test Suite: %-32s %-8s" line = "\nNGAS UTILITIES FUNCTIONAL TESTS - TEST REPORT\n" print line testRep = line + "\n" line = "Date: %s" % PccUtTime.TimeStamp().getTimeStamp() print line testRep += line + "\n" line = "Host: %s" % getHostName() print line testRep += line + "\n" line = "NG/AMS Version: %s\n" % getNgamsVersion() print line testRep += line + "\n" for mod in testModList: if (skipDic.has_key(mod)): continue testCount += 1 line = format % (mod, ("(#%d/%d)" % (testCount, noOfTests))) testRep += line sys.stdout.write(line) sys.stdout.flush() suiteStartTime = time.time() stat, stdout, stderr = ngamsCore.execCmd("python " + mod + ".py", NGAMS_TEST_MAX_TS_TIME) testTime = (time.time() - suiteStartTime) if (testTime >= NGAMS_TEST_MAX_TS_TIME): failModDic[mod] = "TIME-OUT" stat = " - %-5.1fs - TIME-OUT!!\n" % testTime elif (stdout.find("FAILED") != -1): failModDic[mod] = stdout + " --- " + stderr stat = " - %-5.1fs - FAILURE!!\n" % testTime else: stat = " - %-5.1fs - SUCCESS\n" % testTime sys.stdout.write(stat) sys.stdout.flush() testRep += stat execTime = (time.time() - startTime) line = "\n\nExecuted %d Test Suites in %.3f seconds\n\n" %\ (len(testModList), execTime) print line testRep += line if (failModDic): line = 80 * "=" print line testRep += line line = "\n\nFAILED TEST SUITES:\n\n" print line testRep += line failMods = failModDic.keys() failMods.sort() for failMod in failMods: line = "\n%s:\n%s\n" % (failMod, failModDic[failMod]) print line testRep += line + "\n" line = 80 * "-" print line testRep += line line = 80 * "=" print line testRep += line # Send out email with test report if requested. if (notifEmail): notifEmail = notifEmail.split(",") par = "NgamsCfg.Server[1].MountRootDirectory" ngamsCfgObj = ngamsConfig.ngamsConfig().storeVal(par, "/NGAS") ngamsHighLevelLib.sendEmail(ngamsCfgObj, "localhost", "NGAS UTILITIES FUNCTIONAL TESTS REPORT", notifEmail, "ngas@%s" %\ ngamsLib.getCompleteHostName(), testRep)