def test_IllegalPars_1(self): """ Synopsis: Missing parameters 1) Disk ID, 2) File ID, 3) File Version missing. Description: The purpose of the test is to verify the error handling when an illegal combination of parameters is submitted to the NG/AMS Server with the DISCARD Command. It is only allowed to execute the DISCARD Command referring to Disk ID/File ID/File Version if all three parameters are specified. Expected Result: When submitting the DISCARD Command with either of the 3 parameters missing, the command should be rejected and an Error Response returned indicating the problem. Test Steps: - Start NG/AMS Server. - Submit DISCARD Command with File ID/File Version. - Check that the request is rejected, indicating that the Disk ID is missing. - Submit DISCARD Command with Disk ID/File Version. - Check that the request is rejected, indicating that the File ID is missing. - Submit DISCARD Command with Disk ID/File ID. - Check that the request is rejected, indicating that the File Version is missing. Remarks: ... """ self.prepExtSrv() # Disk ID Missing: pars = [["file_id", "FileID"], ["file_version", "1"]] tmpStatFile = sendExtCmd(8888, NGAMS_DISCARD_CMD, pars) refStatFile = "ref/ngamsDiscardCmdTest_test_IllegalPars_1_1_ref" self.checkFilesEq(refStatFile, tmpStatFile, illStatDoc % "1") # File ID Missing: pars = [["disk_id", "DiskID"], ["file_version", "1"]] tmpStatFile = sendExtCmd(8888, NGAMS_DISCARD_CMD, pars) refStatFile = "ref/ngamsDiscardCmdTest_test_IllegalPars_1_2_ref" self.checkFilesEq(refStatFile, tmpStatFile, illStatDoc % "2") # File Version Missing: pars = [["file_id", "FileID"], ["disk_id", "DiskId"]] tmpStatFile = sendExtCmd(8888, NGAMS_DISCARD_CMD, pars) refStatFile = "ref/ngamsDiscardCmdTest_test_IllegalPars_1_3_ref" self.checkFilesEq(refStatFile, tmpStatFile, illStatDoc % "3")
def test_handleCmdInit_1(self): """ Synopsis: Normal execution of INIT Command/cfg. in file. Description: The purpose of the Test Case is to verify that the server re-initializes and reloads the associated cfg. file when the INIT Command is received. Expected Result: When the INIT Command is received by a server in Online State, the server should reload the configuration and go into Online State. Test Steps: - Start server. - Issue an INIT Command. - Check that response from the server is as expected. Remarks: TODO: Should change some parameters to verify that the cfg. file is actually re-loaded. """ self.prepExtSrv() # TODO: Change some cfg. parameter tmpStatFile = sendExtCmd(8888, NGAMS_INIT_CMD) refStatFile = "ref/ngamsInitCmdTest_test_handleCmdInit_1_1_ref" self.checkFilesEq(refStatFile, tmpStatFile, "Incorrect status returned for INIT Command") # TODO: Check that server has initialized with new parameter
def test_NoPars_2(self): """ Synopsis: Issue HELP Command with no parameters/Online State. Description: Check that the response to the HELP Command is as expected (taking into account that the HELP Command is not yet implemented). Expected Result: The server should send back an Error Response indicating that the HELP Command is not yet implemented. Test Steps: - Start server. - Issue HELP Command. - Check that output is as expected (command rejected). Remarks: This Test Case should be modified when the HELP Command has been implemented. """ self.prepExtSrv() tmpStatFile = sendExtCmd(8888, NGAMS_HELP_CMD) refStatFile = "ref/ngamsHelpCmdTest_test_NoPars_2_1_ref" self.checkFilesEq(refStatFile, tmpStatFile, "Incorrect status returned for HELP command")
def test_StdOffline_1(self): """ Synopsis: test standard execution of OFFLINE Command. Description: The purpose of the Test Case is to specify the normal execution of the OFFLINE Command when the server is Online/Idle and the command is accepted as expected and the server brought to Offline State. Expected Result: The server in Online State should accept the OFFLINE Command and should go Offline. Test Steps: - Start server (Auto Online=1). - Submit OFFLINE Command. - Check the response from the server. Remarks: TODO: Check that the server is in Offline State. """ self.prepExtSrv() tmpStatFile = sendExtCmd(8888, NGAMS_OFFLINE_CMD, genStatFile = 1) refStatFile = "ref/ngamsOfflineCmdTest_test_StdOffline_1_1_ref" self.checkFilesEq(refStatFile, tmpStatFile, "Incorrect status returned for OFFLINE command")
def test_OnlineCmd_1(self): """ Synopsis: Test basic handling of Online Command. Description: The purpose of the test is to verify that the server goes Online initializing with the specified cfg. file when the ONLINE Command is issued. Expected Result: After being started up and in Offline/Idle State and receiving the ONLINE Command, the server should re-load the cfg. and should bring the system to Online State according to the cfg. file. Test Steps: - Start server (Auto Online=0). - Send ONLINE Command. - Check that the response from the server is as expected. Remarks: TODO: Check that the server is Online (DB + STATUS Command). """ self.prepExtSrv(autoOnline=0) tmpStatFile = sendExtCmd(8888, NGAMS_ONLINE_CMD, genStatFile=1) refStatFile = "ref/ngamsOnlineCmdTest_test_OnlineCmd_1_1_ref" self.checkFilesEq(refStatFile, tmpStatFile, "Incorrect status returned for ONLINE command")
def test_NormalExec_1(self): """ Synopsis: File existing execute=0,1/Disk ID/File ID/File Version. Description: The purpose of the test is to verify that the normal functioning of the DISCARD Command when it is tried to DISCARD a file referred to by its corresponding Disk ID, File ID and File Version. Expected Result: The server should find the file, and should return a positive response when issuing the DISCARD Command with execute=0. Subsequently, when submitting the command with execute=1, the file should disappear from the NGAS DB and from the disk. Test Steps: - Start NG/AMS Server. - Archive a file. - Issue a DISCARD Command specifying the Disk ID/File ID/File Version of the file/execute=0. - Check that the response from the NG/AMS Server reports that only one copy is available of the file. - Issue a DISCARD Command specifying the Disk ID/File ID/File Version of the file/execute=1. - Check that the response from the NG/AMS Server reports that the file was DISCARDED. Remarks: ... """ self.prepExtSrv() sendPclCmd().archive(srcFitsFile) mDiskId = "tmp-ngamsTest-NGAS-FitsStorage1-Main-1" pars = [["disk_id", mDiskId], ["file_id", "TEST.2001-05-08T15:25:00.123"], ["file_version", "1"]] tmpStatFile = sendExtCmd(8888, NGAMS_DISCARD_CMD, pars + [["execute", "0"]]) refStatFile = "ref/ngamsDiscardCmdTest_test_NormalExec_1_1_ref" self.checkFilesEq(refStatFile, tmpStatFile, illStatDoc % "1") # TODO!: Check that file info is not removed from the DB # TODO!: Check that file is not removed from the disk refStatFile = "ref/ngamsDiscardCmdTest_test_NormalExec_1_2_ref" tmpStatFile = sendExtCmd(8888, NGAMS_DISCARD_CMD, pars + [["execute", "1"]]) self.checkFilesEq(refStatFile, tmpStatFile, illStatDoc % "2")
def test_NormalExec_2(self): """ Synopsis: File existing, remove via path, +/-execute. Description: The purpose of the test is to verify the normal functioning of the DISCARD Command when DISCARD'ing files referred to by their path. It is tried both to execute the command with execute=0 and execute=1. The file is not registered in the NGAS DB. This simulates the situation where spurious files are removed from the NGAS system only referred to by their path. Expected Result: When the DISCARD Command is issued, execute=0, the NG/AMS Server should find the file and return a response indicating that the file is only available in 1 copy. When submitting the DISCARD Command with execute=1, the file should disappear from the disk. Test Steps: - Start NG/AMS Server. - Copy a test file onto a disk of the NGAS System. - Issue a DISCARD Command specifying the copied file (execute=0). - Check that the response indicates that the DISCARD Request is granted. - Reissue the DISCARD Command specifying the copied file (execute=1). - Check that the response indicates that the file has been removed. - Check that the file has disappeared from the disk. Remarks: TODO!: Implement check to verify that file has been removed from the disk. """ self.prepExtSrv() trgFile = "/tmp/ngamsTest/NGAS/FitsStorage3-Main-5/saf/SmallFile.fits" cpFile(srcFitsFile, trgFile) tmpStatFile = sendExtCmd(8888, NGAMS_DISCARD_CMD, [["path", trgFile], ["execute", "0"]]) refStatFile = "ref/ngamsDiscardCmdTest_test_NormalExec_2_1_ref" self.checkFilesEq(refStatFile, tmpStatFile, illStatDoc % "1") tmpStatFile = sendExtCmd(8888, NGAMS_DISCARD_CMD, [["path", trgFile], ["execute", "1"]]) refStatFile = "ref/ngamsDiscardCmdTest_test_NormalExec_2_2_ref" self.checkFilesEq(refStatFile, tmpStatFile, illStatDoc % "2")
def test_RegisterCmd_1(self): """ Synopsis: REGISTER Command/register single file compl. path. Description: Test handling of the REGISTER Command under normal circumstances. Expected Result: The REGISTER Command should be accepted by the server and should be executed successfully. Test Steps: - Start server. - Copy file onto NGAS Disk. - Submit REGISTER Command requesting to register the file copied over (wait=1). - Check response from the server that the request was successfully executed. - Check the DB info for the registered file. Remarks: ... """ _, dbObj = self.prepExtSrv() srcFile = "src/SmallFile.fits" tmpSrcFile = "/tmp/ngamsTest/NGAS/" +\ "FitsStorage2-Main-3/saf/test/SmallFile.fits" checkCreatePath(os.path.dirname(tmpSrcFile)) shutil.copy(srcFile, tmpSrcFile) tmpStatFile = sendExtCmd(8888, NGAMS_REGISTER_CMD, [["path", tmpSrcFile]]) refStatFile = "ref/ngamsRegisterCmdTest_test_RegisterCmd_1_ref" self.checkFilesEq(refStatFile, tmpStatFile, "Incorrect status returned for REGISTER command") diskId = "tmp-ngamsTest-NGAS-FitsStorage2-Main-3" filePrefix = "ngamsRegisterCmdTest_test_RegisterCmd_1" fileInfoRef = "ref/" + filePrefix + "_FileInfo_ref" fileInfoTmp = "tmp/" + filePrefix + "_FileInfo_tmp" fileId = "TEST.2001-05-08T15:25:00.123" startTime = time.time() host_id = getHostName() + ":8888" while ((time.time() - startTime) < 10): tmpFileRes = dbObj.getFileInfoFromFileIdHostId( host_id, fileId, 1, diskId) if (tmpFileRes): break if not tmpFileRes: self.fail( "Couldn't get fileInfo result from database within 10 seconds") tmpFileObj = ngamsFileInfo.ngamsFileInfo().unpackSqlResult(tmpFileRes) saveInFile(fileInfoTmp, filterDbStatus1(tmpFileObj.dumpBuf())) self.checkFilesEq(fileInfoRef, fileInfoTmp, "Incorrect info in DB for registered file")
def test_NonExistingFile_1(self): """ Synopsis: File not existing +/-execute/Disk ID/File ID/File Version. Description: The purpose of the test is to verify the behavior of the DISCARD Command, when it is tried to DISCARD a file, which is not available on the contacted NGAS Node. This is both tried for execute=0 and execute=1. The file is referred to by its File ID. Expected Result: The NG/AMS Server should detect that the specified file is not found on the contacted NGAS Node and should generate an error message indicating this. Test Steps: - Start NG/AMS Server. - Submit DISCARD Command, specifying a non-existing file/execute=0. - Check that the error message from the NG/AMS Server is as expected. - Submit DISCARD Command, specifying a non-existing file/execute=1. - Check that the error message from the NG/AMS Server is as expected. Remarks: ... """ self.prepExtSrv() mDiskId = "tmp-ngamsTest-NGAS-FitsStorage1-Main-1" pars = [["disk_id", mDiskId], ["file_id", "NonExistingFileId"], ["file_version", "1"]] tmpStatFile = sendExtCmd(8888, NGAMS_DISCARD_CMD, pars + [["execute", "0"]]) refStatFile = "ref/ngamsDiscardCmdTest_test_NonExistingFile_1_1_ref" self.checkFilesEq(refStatFile, tmpStatFile, illStatDoc % "1") tmpStatFile = sendExtCmd(8888, NGAMS_DISCARD_CMD, pars + [["execute", "1"]]) self.checkFilesEq(refStatFile, tmpStatFile, illStatDoc % "2")
def test_ProxyMode_01(self): """ Synopsis: Test that the proxy mode is not possible for the REMFILE Command. Description: It is not possible to let a contacted NGAS Node act as proxy for the REMFILE Command (for security reasons). I.e., the node where data should be removed, must be contacted directly/explicitly. Expected Result: When issuing the REMFILE Command to the cluster master node, it should figure out that the file specified is stored on a sub-node and the request should be rejected. Test Steps: - Start simulated cluster with 1 MNU + 1 NCU. - Archive file onto the NMU. - Archive file onto the NCU. - Clone file onto another within the NCU. - Issue a REMFILE Command to the NMU specifying the file on the NCU (execute=0). - Verify that the mistake is detected and the request rejected. - Issue a REMFILE Command to the NMU specifying the file on the NCU (execute=1). - Verify that the mistake is detected and the request rejected. Remarks: ... Test Data: ... """ self.prepCluster((8000, 8011)) sendPclCmd(port=8000).archive("src/SmallFile.fits") client8011 = sendPclCmd(port=8011) stat = client8011.archive("src/SmallFile.fits") diskId = "tmp-ngamsTest-NGAS:8011-FitsStorage1-Main-1" fileId = "TEST.2001-05-08T15:25:00.123" fileVer = 2 client8011.clone(fileId, diskId, fileVer) for execute in [0, 1]: httpPars = [["disk_id", diskId], ["file_id", fileId], ["file_version", fileVer], ["execute", execute]] tmpStatFile = sendExtCmd(8000, NGAMS_REMFILE_CMD, pars=httpPars) refStatFile = "ref/ngamsRemFileCmdTest_test_ProxyMode_01_01_ref" self.checkFilesEq( refStatFile, tmpStatFile, "Incorrect handling of REMFILE Command detected")
def test_ProxyMode_01(self): """ Synopsis: Test that the proxy mode works for the CHECKFILE Command/cluster. Description: The purpose of the test is to verify that the proxy mode works properly for the CHECKFILE Command. In practice, this means that if a file to be check is stored on another NGAS Node than the contacted one, the contacted node (acting as cluster master) should locate the file and forward the request to the node hosting the file. Expected Result: When issuing the CHECKFILE Command to the cluster master node, it should figure out that the file specified is stored on a sub-node. The master node will forward the request to the sub-node, which will carry out the check and return the response, which is then forwarded to the client. Test Steps: - Start simulated cluster with 1 MNU + 1 NCU. - Archive file onto the NCU. - Archive file onto the NMU. - Issue a CHECKFILE Command to the NMU specifying the file on the NCU. - Verify that the proper file has been checked. Remarks: ... Test Data: ... """ self.prepCluster((8000, 8011)) sendPclCmd(port=8000).archive("src/SmallFile.fits") stat = sendPclCmd(port=8011).archive("src/SmallFile.fits") diskId = "tmp-ngamsTest-NGAS:8011-FitsStorage1-Main-1" fileId = "TEST.2001-05-08T15:25:00.123" fileVer = 2 httpPars = [["disk_id", diskId], ["file_id", fileId], ["file_version", fileVer]] tmpStatFile = sendExtCmd(8000, NGAMS_CHECKFILE_CMD, pars=httpPars, replaceLocalHost=1) refStatFile = "ref/ngamsCheckFileCmdTest_test_ProxyMode_01_01_ref" self.checkFilesEq(refStatFile, tmpStatFile, "Incorrect handling of "+\ "CHECKFILE Command detected")
def test_NonExistingFile_2(self): """ Synopsis: File not existing referred to by path, +/- execute. Description: The purpose of the test is to verify the behavior of the DISCARD Command when it is tried to DISCARD a file referred to by it path name. Expected Result: The NG/AMS Server should detect that the file referred to by a path name is not available on the contacted NGAS Node and should send back an Error Response. This goes both when execute=0 and execute=1. Test Steps: - Start NG/AMS Server. - Submit a DISCARD Command, specifying a non-existing file path (execute=0). - Check that the command is rejected by NG/AMS. - Submit a DISCARD Command, specifying a non-existing file path (execute=0). - Check that the command is rejected by NG/AMS. Remarks: ... """ self.prepExtSrv() pars = [["path", "/tmp/ngamsTest/NonExisting"]] tmpStatFile = sendExtCmd(8888, NGAMS_DISCARD_CMD, pars + [["execute", "0"]]) refStatFile = "ref/ngamsDiscardCmdTest_test_NonExistingFile_2_1_ref" self.checkFilesEq(refStatFile, tmpStatFile, illStatDoc % "1") tmpStatFile = sendExtCmd(8888, NGAMS_DISCARD_CMD, pars + [["execute", "1"]]) self.checkFilesEq(refStatFile, tmpStatFile, illStatDoc % "2")
def test_NormalExec_3(self): """ Synopsis: File existing/3 copies execute=0,1/Disk ID/File ID/File Version. Description: The purpose of the test is to verify that the normal functioning of the DISCARD Command when it is tried to DISCARD a file referred to by its corresponding Disk ID, File ID and File Version. The file is available in three copies. Expected Result: The server should find the file, and should return a positive response when issuing the DISCARD Command with execute=0. Subsequently, when submitting the command with execute=1, the file should disappear from the NGAS DB and from the disk. Test Steps: - Start NG/AMS Server. - Archive a file. - Clone the file onto another disk. - Issue a DISCARD Command specifying the Disk ID/File ID/File Version of the file/execute=0. - Check that the response from the NG/AMS Server reports that only one copy is available of the file. - Issue a DISCARD Command specifying the Disk ID/File ID/File Version of the file/execute=1. - Check that the response from the NG/AMS Server reports that the file was DISCARDED. Remarks: ... """ self.prepExtSrv() sendPclCmd().archive("src/SmallFile.fits") mDiskId = "tmp-ngamsTest-NGAS-FitsStorage1-Main-1" fileId = "TEST.2001-05-08T15:25:00.123" sendPclCmd().clone(fileId, mDiskId, 1) for execute in [0, 1]: httpPars = [["disk_id", mDiskId], ["file_id", fileId], ["file_version", "1"], ["execute", execute]] tmpStatFile = sendExtCmd(8888, NGAMS_DISCARD_CMD, pars=httpPars) refStatFile = "ref/ngamsDiscardCmdTest_test_NormalExec_3_%d_ref"%\ (execute + 1) self.checkFilesEq(refStatFile, tmpStatFile, "Unexpected result "+\ "of DISCARD Command (execute=%d)" % execute)
def test_LabelCmd_1(self): """ Synopsis: Test basic handling of the LABEL Command. Description: The purpose of the Test Case is to verify the normal execution of the LABEL Command when specifying to print out a label for a disk referring to theof the disk. Expected Result: The contacted server should find the information for the Test Steps: - Start server. - Submit LABEL Command specifying the host_id/slot_id of the disk. - Verify the response from the LABEL Command. - Verify the printer file generated by the LABEL Printer Plug-in. Remarks: ... """ # TODO: The host name is contained in the label, run only on # ngasdev2 for the moment ... if (getHostName() != "ngasdev2"): return self.prepExtSrv() tmpStatFile = sendExtCmd(8888, NGAMS_LABEL_CMD, pars=[["slot_id", "1"], ["host_id", getHostName()]]) refStatFile = "ref/ngamsLabelCmdTest_test_LabelCmd_1_1_ref" self.checkFilesEq(refStatFile, tmpStatFile, "Incorrect status returned for LABEL Command") tmpStatFile= "/tmp/ngamsTest/NGAS/tmp/ngamsLabel_NGAS-" +\ getHostName() + "-8888.prn" refStatFile = "ref/ngamsLabelCmdTest_test_LabelCmd_1_2_ref.prn" self.checkFilesEq(refStatFile, tmpStatFile, "Incorrect printer file generated by LABEL Command")
def test_ProxyMode_01(self): """ Synopsis: Test that the proxy mode is not possible for the REMDISK Command. Description: It is not possible to let a contacted NGAS Node act as proxy for the REMDISK Command (for security reasons). I.e., the node where data should be removed, must be contacted directly/explicitly. Expected Result: When issuing the REMDISK Command to the cluster master node, it should figure out that the disk specified is located in a sub-node and the request should be rejected. Test Steps: - Start simulated cluster with 1 MNU + 1 NCU. - Issue a REMDISK Command to the NMU specifying a disk in the NCU (execute=0). - Verify that the mistake is detected and the request rejected. - Issue a REMDISK Command to the NMU specifying a disk in the NCU (execute=1). - Verify that the mistake is detected and the request rejected. Remarks: ... Test Data: ... """ self.prepCluster((8000, 8011)) diskId = "tmp-ngamsTest-NGAS:8011-FitsStorage1-Main-1" for execute in [0, 1]: httpPars=[["disk_id", diskId], ["execute", execute]] tmpStatFile = sendExtCmd(8000, NGAMS_REMDISK_CMD, pars=httpPars) refStatFile = "ref/ngamsRemDiskCmdTest_test_ProxyMode_01_01_ref" self.checkFilesEq(refStatFile, tmpStatFile, "Incorrect handling of REMDISK Command detected")