Ejemplo n.º 1
0
    def test_RetrieveCmd_7(self):
        """
        Synopsis:
        Rerieve file from cluster, Online/Suspended and Offline files
        contained in archive.

        Description:
        The purpose of the test is to verify that the problem that there are
        Online and Offline files in the archive and thus the cross-checking
        of the number of files for which info was queried from the NGAS DB
        detected erroneously a discrepancy.

        Expected Result:
        The RETRIEVE Command should execute successfully. The check of the
        possible files matching the query should not produce and error.

        Test Steps:
        - Prepare simulated cluster with three nodes. One node should
          suspend itself after few seconds.
        - Archive the same file onto the three nodes 3 times.
        - Make one node exit.
        - Wait till the node suspending itself has suspended itself.
        - Send RETRIEVE Command to retrieve a file given by its File ID.
        - Check that response from the server is OK.
        - Send RETRIEVE Command to retrieve a file given by its File ID
          and its File Version.
        - Check that the response from the server is OK.
        - Send RETRIEVE Command to retrieve a file given by the Disk ID,
          the File ID and the File Version.
        - Check that the response from the server is OK.

        Remarks:
        ...
        """
        nodes = [
            getHostName() + ":8000",
            getHostName() + ":8001",
            getHostName() + ":8002"
        ]
        suspPars = [["NgamsCfg.HostSuspension[1].IdleSuspension", "1"],
                    ["NgamsCfg.JanitorThread[1].SuspensionTime", "0T00:00:05"]]
        envDic = self.prepCluster((8000, 8001, (8002, suspPars)))
        for portNo in [8000, 8001, 8002]:
            for _ in range(3):
                self.archive(portNo, "src/SmallFile.fits")
        self.offline(8001)
        self.exit(8001)
        subNode2 = nodes[2]
        self.waitTillSuspended(envDic[subNode2][1], subNode2, 45, nodes)

        # Retrieve file (File ID).
        fileId = "TEST.2001-05-08T15:25:00.123"
        self.retrieve(8000, fileId)
        self.retrieve(8000, fileId, fileVersion=2)
Ejemplo n.º 2
0
def ngamsMount(srvObj, diskDic, slotIds, complReadOnly=0):
    """
    Function mounts all disks registered in the diskDic dictionary.

    NOTE: This is NGAMS specific and relies on the structure of the
          NGAMS Disk Dictionary.

    Synopsis:      ngamsMount(<diskDic>)

    srvObj:        Instance of the NG/AMS Server class (ngamsServer).

    diskDic:       Disk info dictionary (dictionary).

    slotIds:       List of Slot IDs for the disk to consider (list/string).

    complReadOnly: Mount completed volumes read-only (integer/0|1).

    Returns:       Void.
    """
    # Get information about this host.
    hostInfo = srvObj.getDb().getHostInfoFromHostIds([getHostName()])
    if (len(hostInfo) != 1):
        errMsg = "Problem querying information about host: " + getHostName() +\
                 " from the NGAS DB."
        raise Exception(errMsg)
    else:
        hostInfoObj = ngamsHostInfo.ngamsHostInfo().\
                      unpackFromSqlQuery(hostInfo[0])
    slotIds.sort()
    for slotId in slotIds:
        if (not diskDic.has_key(slotId)): continue
        #####entry = [diskDic[slotId].getDeviceName(),
        #####         diskDic[slotId].getMountPoint(),
        #####         "auto", "noauto,user", "0", "0"]
        #####createFstabEntry(entry)
        logger.debug("Mounting: %s", diskDic[slotId].getMountPoint())
        if (srvObj.getCfg().getAllowRemoveReq()
                or srvObj.getCfg().getAllowArchiveReq()):
            readOnly = 0
        else:
            readOnly = 1
        if (complReadOnly):
            if (srvObj.getDb().getDiskCompleted(diskDic[slotId].getDiskId())):
                readOnly = 1
        try:
            mountToMountpoint(diskDic[slotId].getDeviceName(),
                              diskDic[slotId].getMountPoint(),
                              readOnly,
                              fstype="")
        except Exception:
            del diskDic[slotId]
            logger.exception("Error while mounting")
            continue
Ejemplo n.º 3
0
    def test_WakeUpStatus_2(self):
        """
        Synopsis:
        Test that suspended server is woken up when STATUS?file_access is
        issued, specifying a file on a suspended sub-node.

        Description:
        The purpose of the test is to verify that a suspended sub-node is
        woken up by a master node acting as proxy if a STATUS?file_id is
        send pointing to a file on the suspended sub-node.

        Expected Result:
        The suspended sub-node should be woken up by the master node which
        after the suspended sub-node has come Online should forward the
        request which is executed on the sub-node and the result send back to
        the client through the master node.

        Test Steps:
        - Prepare simulated cluster with unit, which suspends itself.
        - Archive 3 files onto sub-node.
        - Wait till sub-node has suspended itself.
        - Send a STATUS?file_id request to the Master Node specifying one
          of the files previously archived.
        - Check the result returned from the sub-node via the Master Node.

        Remarks:
        ...
        """
        cfgParDic = {"8001": [["%s.IdleSuspensionTime" % SUSP_EL, "5"]]}
        dbConObj = prepSimCluster(self, cfgParDic=cfgParDic)[masterNode][1]

        # Archive some files on the two nodes and wait till sub-node
        # has suspended itself.
        sendPclCmd(port=8000, auth=AUTH).archive("src/TinyTestFile.fits")
        sendPclCmd(port=8000, auth=AUTH).archive("src/SmallFile.fits")
        sendPclCmd(port=8001, auth=AUTH).archive("src/SmallFile.fits")
        self.waitTillSuspended(dbConObj, subNode1, 20, susp_nodes)

        # Retrieve information about the file on the suspended sub-node.
        fileId = "TEST.2001-05-08T15:25:00.123"
        statObj = sendPclCmd(port=8000, auth=AUTH).\
                  get_status(NGAMS_STATUS_CMD, pars=[["file_access", fileId]])
        statBuf = filterOutLines(statObj.dumpBuf(), ["Date:", "Version:"])
        tmpStatFile = saveInFile(None, statBuf)
        refStatFile = "ref/ngamsIdleSuspensionTest_test_WakeUpStatus_2_1_ref"
        refStatFile = saveInFile(None, loadFile(refStatFile) %\
                                 (getHostName(), getHostName()))
        self.checkFilesEq(refStatFile, tmpStatFile,
                          "Unexpected reply to STATUS?file_access request")
Ejemplo n.º 4
0
    def test_Label_1(self):
        """
        Synopsis:
        Send LABEL Command via P-Client.

        Description:
        Test that it is possible to send LABEL Command via the P-Client.

        Expected Result:
        The LABEL Command should be send to the server and a label produced.

        Test Steps:
        - Start server.
        - Submit LABEL Command specifying Slot ID/Host ID.
        - Check response from the server.

        Remarks:
        ...
        """
        self.prepExtSrv()
        status = ngamsPClient.ngamsPClient(port=8888).\
                 label("1", getHostName() + ":8888")
        refMsg = "Successfully handled command LABEL"
        self.checkEqual(refMsg, status.getMessage(), "Problem executing " +\
                        "LABEL Command")
Ejemplo n.º 5
0
def clone_check_file(disk_id, file_id, file_version, connection, ngas_client):
    """
    Clone a file a check afterwards if it was successfully cloned

    :param disk_id: ID of disk cloned (string)
    :param file_id: ID of file cloned (string)
    :param file_version: Version of file to check (integer)
    :param connection: DB connection object (ngamsDb)
    :param ngas_client: Initiated instance of NG/AMS P-Client Object (ngamsPClient)
    :return: Updated Check Report (string)
    """
    message = "\n-> Attempting to clone file: {:s}/{:s}/{:s}".format(
        disk_id, file_id, file_version)
    print(message)
    message += " - status: "
    result = ngas_client.clone(file_id, disk_id, file_version, wait=1)
    if result.getStatus() == "FAILURE":
        status = "FAILURE: " + str(result.get_message()) + "\n"
    else:
        # Check if file was really cloned
        result = connection.getFileInfoFromFileIdHostId(
            _get_target_host(), file_id, file_version)
        if not result:
            status = "FAILURE: File not cloned!\n"
        else:
            file_info = ngamsFileInfo.ngamsFileInfo().unpackSqlResult(result)
            file_status_parameters = [["disk_id",
                                       file_info.get_disk_id()],
                                      ["file_access", file_id],
                                      ["file_version", file_version]]
            client = ngamsPClient.ngamsPClient(getHostName(),
                                               ngas_client.getPort())
            result = client.status(file_status_parameters)
            status = result.get_message() + "\n"
    return message + status
Ejemplo n.º 6
0
def _delFile(srvObj, path, hostId, execute):
    """
    Delete (remove from disk) the file specified by the path on the given host.

    srvObj:        Reference to NG/AMS server class object (ngamsServer).

    path:          Path of file (string).

    hostId:        ID of host where file is stored (string).

    Returns:       Message with info about the execution (string).
    """
    if (hostId and (hostId != srvObj.getHostId())):
        raise Exception, "DISCARD Command can only be executed locally!"

    # Handle the discard request locally.
    ngasHostId = "%s:%d" % (getHostName(), srvObj.getCfg().getPortNo())
    if (os.path.exists(path)):
        if (not ngamsLib.fileRemovable(path)):
            return genLog("NGAMS_ER_DISCARD_NOT_REM", [path, ngasHostId])
        if (not execute):
            msg = genLog("NGAMS_INFO_DISCARD_GRANTED", [path, ngasHostId])
        else:
            rmFile(path)
            if (os.path.exists(path)):
                return genLog("NGAMS_ER_DISCARD_FAILED",
                              [path, ngasHostId, "Not removable"])
            else:
                msg = genLog("NGAMS_INFO_DISCARD_OK", [path, ngasHostId])
    else:
        return genLog("NGAMS_ER_DISCARD_NOT_FOUND", [path, ngasHostId])

    return msg
Ejemplo n.º 7
0
    def test_StatusCmd_1(self):
        """
        Synopsis:
        Issue STATUS Command/basic (no parameters).

        Description:
        Issue a STATUS Command via the C-Client (on the shell).

        Expected Result:
        The STATUS Command should be accepted and executed by the C-Client
        and the server.

        Test Steps:
        - Start standard server.
        - Execute the ngamsCClient tool on the shell.
        - Capture the output from the ngamsCClient and compare this with the
          expected output.

        Remarks:
        ...

        """
        cfgObj, dbObj = self.prepExtSrv(port=8000)
        statObj = _execCClient(pars=[["-port", "8000"], ["-cmd", "STATUS"]])[0]
        refStatFile = "ref/ngamsCClientTest_test_StatusCmd_1_1_ref"
        refStatFile = saveInFile(
            None,
            loadFile(refStatFile) % (getHostName() + ":8000"))
        tmpStatFile = saveInFile(
            None, filterOutLines(statObj.dumpBuf(), ["Date", "Version"]))
        self.checkFilesEq(refStatFile, tmpStatFile, "Incorrect info in " +\
                          "STATUS Command XML Status Document")
Ejemplo n.º 8
0
    def test_StatusCmd_2(self):
        """
        Synopsis:
        Issue STATUS Command/proxy mode (host_id).

        Description:
        The purpose of this Test Case is to check that the ngamsCClient
        accepts the -hostId command line parameter and transfers this
        properly to the server. This is used for the proxy mode.

        Expected Result:
        The STATUS Command should be issued to the server, which will act
        as proxy and forward the request to the specified target node.

        Test Steps:
        - Start two servers.
        - Issue STATUS Command to one of them specifying the other as target.
        - Check that the command is successfully handled on the given target
          node.

        Remarks:
        The check to see if the command is actually executed on the specified
        target node is not yet fully implemented.
        """
        self.prepCluster((8000, 8011))
        hostId = "%s:%d" % (getHostName(), 8011)
        statObj = _execCClient(pars=[["-port", "8000"],
                                     ["-cmd", "STATUS"],
                                     ["-hostId", hostId]])[0]
        self.checkTags(statObj.dumpBuf(),
                       [hostId, "Successfully handled command STATUS"])
Ejemplo n.º 9
0
    def test_FileVerHandling_01(self):
        """
        Synopsis:
        Test that REMFILE removes proper File Version.

        Description:
        The purpose of the test is to verify that if several versions of a
        file are found in the archive, the proper version is deleted.

        Expected Result:
        The chosen version of the file, should be selected and should be
        removed.

        Test Steps:
        - Start server.
        - Archive a file 3 times into the archive.
        - Clone the file onto another disk.
        - Remove version 2 of the cloned file.

        Remarks:
        ...

        Test Data:
        ...
        """
        _, dbObj = self.prepExtSrv(cfgProps=(('NgamsCfg.Db[1].Snapshot',
                                              "0"), ))
        for _ in range(3):
            self.archive("src/SmallFile.fits")

        diskId1 = self.ngas_disk_id("FitsStorage1/Main/1")
        fileId = "TEST.2001-05-08T15:25:00.123"
        fileVer = 2
        self.get_status(NGAMS_CLONE_CMD, pars=[["disk_id", diskId1]])

        diskId2 = self.ngas_disk_id("FitsStorage2/Main/3")
        filePath = self.ngas_path("FitsStorage2-Main-3/saf/" +\
                   "2001-05-08/2/TEST.2001-05-08T15:25:00.123.fits.gz")
        for execute in [0, 1]:
            httpPars = [["disk_id", diskId2], ["file_id", fileId],
                        ["file_version", fileVer], ["execute", execute]]
            self.get_status(NGAMS_REMFILE_CMD, pars=httpPars)

            fileInfo = ngamsFileInfo.ngamsFileInfo()
            try:
                fileInfo.read(getHostName(), dbObj, fileId, fileVer, diskId2)
            except:
                pass
            if (execute == 0):
                if (not os.path.exists(filePath)):
                    self.fail("File removed unexpectedly")
            else:
                if (os.path.exists(filePath)):
                    self.fail("File not removed as expected")

            refStatFile = "ref/ngamsRemFileCmdTest_test_" +\
                          "FileVerHandling_01_0%d_ref" % (execute + 3)
            msg = "Incorrect status for REMFILE Command/execution"
            self.assert_status_ref_file(refStatFile, fileInfo, msg=msg)
Ejemplo n.º 10
0
def discard_files(file_list_file, execute, notification_email):
    """
    Remove files from the NGAS DB + from from the disk. If files are given by their full path, only the file is
    removed from disk, but the DB information remains.

    :param file_list_file: Name of file containing list with references to files to remove (string)
    :param execute: Actual remove the files (integer/0|1)
    :param notification_email: List of email addresses to inform about the execution of the discard procedure (string)
    """
    host = ngasUtilsLib.get_parameter_ngas_resource_file(ngasUtilsLib.NGAS_RC_PAR_HOST)
    port = int(ngasUtilsLib.get_parameter_ngas_resource_file(ngasUtilsLib.NGAS_RC_PAR_PORT))
    # client = ngamsPClient.ngamsPClient(host, port, auth="ngas:password")
    client = ngamsPClient.ngamsPClient(host, port)

    # Try to issue a DISCARD Command to the associated NG/AMS Server for each file listed in the File List
    with open(file_list_file) as fo:
        file_list_buffer = fo.readlines()
    success_stat_list = []
    failed_stat_list = []
    for line in file_list_buffer:
        line = line.strip()
        if line == "" or line[0] == "#":
            continue
        if line[0] != "/":
            # It's a "<Disk ID> <File ID> <File Version>" line
            disk_id, file_id, file_version = _unpack_file_info(line)
            parameters = [["disk_id", disk_id], ["file_id", file_id],
                          ["file_version", file_version], ["execute", execute]]
        else:
            # The file is referred to by its complete path.
            parameters = [["path", line], ["execute", execute]]
        status = client.get_status(NGAMS_DISCARD_CMD, pars=parameters)
        if status.getStatus() == NGAMS_SUCCESS:
            success_stat_list.append((line, status))
        else:
            failed_stat_list.append((line, status))

    # Generate report (Email Notification)
    report = "FILE DISCARD REPORT:\n"
    report += "Host: {:s}".format(getHostName())
    if len(failed_stat_list):
        if execute:
            report += "\n\n=Failed File Discards:\n\n"
        else:
            report += "\n\n=Rejected File Discard Requests:\n\n"
        for statInfo in failed_stat_list:
            report += "{:s}: {:s}\n".format(statInfo[0], statInfo[1].getMessage())
    if len(success_stat_list):
        if execute:
            report += "\n\n=Discarded Files:\n\n"
        else:
            report += "\n\n=Accepted Discard File Requests:\n\n"
        for statInfo in success_stat_list:
            report += "{:s}: {:s}\n".format(statInfo[0], statInfo[1].getMessage())
    report += "\n# EOF\n"
    print("\n" + report)
    if notification_email:
        ngasUtilsLib.send_email("ngasDiscardFiles: FILE DISCARD REPORT", notification_email, report)
Ejemplo n.º 11
0
def _checkFileAccess(srvObj,
                     reqPropsObj,
                     httpRef,
                     fileId,
                     fileVersion=-1,
                     diskId=""):
    """
    Check if a file is accessible either on the local host or on a remotely
    located host.

    srvObj:         Instance of the server object (ngamsServer).

    reqPropsObj:    Request Property object to keep track of actions done
                    during the request handling (ngamsReqProps).

    httpRef:        Reference to the HTTP request handler
                    object (ngamsHttpRequestHandler).

    fileId:         File ID (string).

    fileVersion:    File Version (integer).

    diskId:         Disk ID (string).

    Returns:        Returns message indicating if the file is available
                    (string).
    """
    T = TRACE()

    logger.debug("Checking for access to file with ID: %s", fileId)

    # Check if the file is located on this host, or if the request should be
    # forwarded (if this server should act as proxy).
    location, fileHost, ipAddress, filePortNo, mountPoint, filename, fileId,\
              fileVersion, mimeType =\
              ngamsFileUtils.locateArchiveFile(srvObj, fileId, fileVersion,
                                               diskId)

    if (location != NGAMS_HOST_LOCAL):
        # Go and get it!
        host, port = srvObj.get_remote_server_endpoint(fileHost)
        pars = (('file_access', fileId), ('file_version', fileVersion),
                ('disk_id', diskId))
        resp = ngamsHttpUtils.httpGet(host, port, 'STATUS', pars, timeout=60)
        with contextlib.closing(resp):
            return ngamsStatus.to_status(resp, fileHost, 'STATUS').getMessage()

    else:
        # First check if this system allows for Retrieve Requests.
        if (not srvObj.getCfg().getAllowRetrieveReq()):
            msg = genLog("NGAMS_INFO_SERVICE_UNAVAIL", ["File Retrieval"])
        else:
            fileHost = "%s:%d" % (getHostName(), filePortNo)
            msg = genLog("NGAMS_INFO_FILE_AVAIL",
                         [fileId + "/Version: " + str(fileVersion), fileHost])
        return msg
Ejemplo n.º 12
0
def _get_target_host():
    """
    Get DB name for the target host where the auto clone was executed

    :return: DB reference for target host (string)
    """
    if "_NGAS_VERIFY_CLONING_TARGET_HOST_" in os.environ:
        target_host = os.environ["_NGAS_VERIFY_CLONING_TARGET_HOST_"]
    else:
        target_host = getHostName()
    return target_host
Ejemplo n.º 13
0
    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")
Ejemplo n.º 14
0
def buildHttpClient(url,
                    mimeType,
                    contentDisp,
                    contentLength,
                    checksum = None):
    """
    construct the http client which sends file data to the remote next url

    Returns:        httplib
    """
    # Separate the URL from the command.
    idx = (url[7:].find("/") + 7)
    tmpUrl = url[7:idx]
    cmd    = url[(idx + 1):]
    http = httplib.HTTP(tmpUrl)

    logger.debug("Sending HTTP header ...")
    logger.debug("HTTP Header: %s: %s", NGAMS_HTTP_POST, cmd)
    http.putrequest(NGAMS_HTTP_POST, cmd)
    logger.debug("HTTP Header: Content-Type: %s", mimeType)
    http.putheader("Content-Type", mimeType)

    logger.debug("HTTP Header: Content-Disposition: %s", contentDisp)
    http.putheader("Content-Disposition", contentDisp)
    logger.debug("HTTP Header: Content-Length: %s", str(contentLength))
    http.putheader("Content-Length", str(contentLength))

    logger.debug("HTTP Header: Host: %s", getHostName())
    http.putheader("Host", getHostName())

    if (checksum):
        http.putheader(NGAMS_HTTP_HDR_CHECKSUM, checksum)

    http.endheaders()
    logger.debug("HTTP header sent")

    # rtobar, 14/3/16: the default timeout here was 1 [hr]! I'm keeping it like
    #                  that, but probably it's too much
    http._conn.sock.settimeout(3600)

    return http
Ejemplo n.º 15
0
    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")
Ejemplo n.º 16
0
    def test_WakeUpStatus_1(self):
        """
        Synopsis:
        Test that suspended server is woken up when
        STATUS?host_id=<Sub-Node> specifying that node is sent.

        Description:
        If a STATUS Command is send to a node requesting status from another
        node (Proxy Mode), and the target is suspended, the contacted node
        must wake up the suspended target node. The purpose of this test
        is to verify this use case.

        Expected Result:
        The contacted node should identify the target node as suspended,
        and should wake it up prior to forwarding the STATUS Command acting
        as proxy.

        Test Steps:
        - Start simulated cluster specifying that one node can suspend itself.
        - Wait till sub-node has suspended itself.
        - Send STATUS Command to the simulated master requesting status from
          the suspended sub-node.
        - Check the response to the STATUS Command.
        - Cross check that the suspended node is now woken up by sending
          a STATUS Command directly to the sub-node.

        Remarks:
        ...
        """
        cfgParDic = {"8001": [["%s.IdleSuspensionTime" % SUSP_EL, "5"]]}
        dbConObj = prepSimCluster(self, cfgParDic=cfgParDic)[masterNode][1]
        self.waitTillSuspended(dbConObj, subNode1, 30, susp_nodes)

        # 1. Send STATUS Command to sub-node using master as proxy.
        statObj = sendPclCmd(port=8000, auth=AUTH).\
                      get_status(NGAMS_STATUS_CMD, pars = [["host_id", subNode1]])
        statBuf = filterOutLines(statObj.dumpBuf(), ["Date:", "Version:"])
        tmpStatFile = saveInFile(None, statBuf)
        refStatFile = "ref/ngamsIdleSuspensionTest_test_WakeUpStatus_1_1_ref"
        refStatFile = saveInFile(None, loadFile(refStatFile) % getHostName())
        self.checkFilesEq(refStatFile, tmpStatFile,
                          "Sub-node not woken up as expected")

        # 2. Double-check that sub-node is no longer suspended.
        statObj = sendPclCmd(port=8001, auth=AUTH).status()
        statBuf = filterOutLines(statObj.dumpBuf(), ["Date:", "Version:"])
        tmpStatFile = saveInFile(None, statBuf)
        self.checkFilesEq(refStatFile, tmpStatFile,
                          "Sub-node not woken up as expected")

        # Clean up.
        self.markNodesAsUnsusp(dbConObj, susp_nodes)
Ejemplo n.º 17
0
def get_fully_qualified_name(ngams_server):
    """
    Get fully qualified server name for the input NGAS server object
    :param ngams_server: ngamsServer, Reference to NG/AMS server class object
    :return: string, fully qualified host name (host name + domain + port)
    """
    # Get hots_id, domain and port using ngamsLib functions
    host_name = getHostName()
    domain = ngamsLib.getDomain()
    # Concatenate all elements to construct full qualified name
    # Notice that host_id may contain port number
    fqdn = host_name + "." + domain
    return fqdn
Ejemplo n.º 18
0
    def test_ServerMultiplexing_01(self):
        """
        Synopsis:
        Test server multiplexing feature of the Python-API/Client.

        Description:
        The purpose of the test is to verify the proper functioning of the
        server context switching (multiplexing) provided by the Python-
        API/Client. With this feature a list of servers + ports is given, and
        the C-API switches between the specified servers.

        A STATUS Command will be sent out to test the server multiplexing.

        Expected Result:
        After a limited number of attempts, all servers available, should
        have been contacted by the Python-Client.

        Test Steps:
        - Start simulated cluster with 5 units.
        - Submit STATUS Command invoking the Python-Client with the list of
          servers.
        - Verify that within 100 attempts, all servers have been contacted.

        Remarks:
        ...

        Test Data:
        ...
        """

        ports = range(8000, 8005)
        hostname = getHostName()
        self.prepCluster(ports)

        srvList = [('127.0.0.1', p) for p in ports]
        client = ngamsPClient.ngamsPClient(servers=srvList)

        nodeDic = {"%s:%d" % (hostname, p): 0 for p in ports}
        noOfNodes = len(nodeDic.keys())
        nodeCount = 0
        for n in range(100):
            status = client.status()
            if (nodeDic[status.getHostId()] == 0):
                nodeDic[status.getHostId()] = 1
                nodeCount += 1
                if (nodeCount == noOfNodes): break
        if (nodeCount != noOfNodes):
            self.fail("Not all specified NGAS Nodes were contacted " +\
                      "within 100 attempts")
Ejemplo n.º 19
0
def notifyRegistrationService(srvObj, svrStatus='online'):
    """
    to notify the ngas registration service that I am online now

    svrStatus = online|offline
    """

    parDicOnline = ngamsPlugInApi.\
                    parseRawPlugInPars(srvObj.getCfg().getOnlinePlugInPars())
    if (parDicOnline.has_key("regsvr_host")):

        if (svrStatus == "online"):
            errTag = "NGAMS_ER_ONLINE_PLUGIN"
        else:
            errTag = "NGAMS_ER_OFFLINE_PLUGIN"

        regsvr_host = parDicOnline["regsvr_host"]
        regsvr_port = parDicOnline["regsvr_port"]
        regsvr_path = parDicOnline["regsvr_path"]
        host_name = getHostName()
        host_port = srvObj.getCfg().getPortNo()

        body = urllib.urlencode({
            'ngas_host': host_name,
            'ngas_port': host_port,
            'status': svrStatus
        })
        hdrs = {"Accept": "text/plain"}
        resp = ngamsHttpUtils.httpPost(
            regsvr_host,
            regsvr_port,
            regsvr_path,
            body,
            mimeType='application/x-www-form-urlencoded',
            hdrs=hdrs,
            timeout=10)
        with contextlib.closing(resp):
            if resp.status != 200:
                errMsg = "Problem notifying registration service! Error " + resp.reason
                errMsg = genLog(errTag, [errMsg])
                logger.error(errMsg)
                #raise Exception, errMsg
            else:
                logger.debug("Successfully notified registration service: %s",
                             svrStatus)
                logger.info(resp.read())

    return
Ejemplo n.º 20
0
def checkGenPars(optDic, volInfoDic, forceQuery):
    """
    Check/generate the parameters.

    optDic:      Options dictionary (dictionary).

    volInfoDic:  Dictionary with parameters from the Volume Info File
                 (dictionary).

    forceQuery:  If True, query the parameters (boolean).

    Returns:     Void.
    """
    # Generate the Volume ID (=Disk ID) if not defined.
    if (not volInfoDic.has_key(NGAS_VOL_INFO_ID)):
        # Generate key as md5 checksum of:
        # <Host Name> + <Volume Path> + <Time Microsecond Res>
        pat = "%s_%s_%.6f" % (getHostName(), optDic["path"], time.time())
        volInfoDic[NGAS_VOL_INFO_ID] = md5.new(pat).hexdigest()

    # NGAS_VOL_INFO_TYPE
    if ((not volInfoDic.has_key(NGAS_VOL_INFO_TYPE))
            or (volInfoDic[NGAS_VOL_INFO_TYPE] == NGAS_VOL_INFO_UNDEF)
            or forceQuery):
        if (forceQuery
                and (volInfoDic[NGAS_VOL_INFO_TYPE] != NGAS_VOL_INFO_UNDEF)):
            type = volInfoDic[NGAS_VOL_INFO_TYPE]
        else:
            type = NGAS_VOL_INFO_UNDEF
        msg = "Enter disk type [%s]" % type
        newType = raw_input(msg)
        if (newType != ""): type = newType
        volInfoDic[NGAS_VOL_INFO_TYPE] = type

    # NGAS_VOL_INFO_MANUFACT
    if ((not volInfoDic.has_key(NGAS_VOL_INFO_MANUFACT))
            or (volInfoDic[NGAS_VOL_INFO_MANUFACT] == NGAS_VOL_INFO_UNDEF)
            or forceQuery):
        if (forceQuery and
            (volInfoDic[NGAS_VOL_INFO_MANUFACT] != NGAS_VOL_INFO_UNDEF)):
            manufact = volInfoDic[NGAS_VOL_INFO_MANUFACT]
        else:
            manufact = NGAS_VOL_INFO_UNDEF
        msg = "Enter manufacturer [%s]" % manufact
        newManufact = raw_input(msg)
        if (newManufact != ""): manufact = newManufact
        volInfoDic[NGAS_VOL_INFO_MANUFACT] = manufact
Ejemplo n.º 21
0
    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:
        ...
        """
        _, db_obj = self.prepExtSrv()
        status = self.copy_and_register()
        msg = "Incorrect status returned for REGISTER command"
        ref_stat_file = "ref/ngamsRegisterCmdTest_test_RegisterCmd_1_ref"
        self.assert_status_ref_file(ref_stat_file, status, msg=msg)
        disk_id = self.ngas_disk_id("FitsStorage2/Main/3")
        file_prefix = "ngamsRegisterCmdTest_test_RegisterCmd_1"
        file_info_ref = "ref/" + file_prefix + "_FileInfo_ref"
        file_id = "TEST.2001-05-08T15:25:00.123"
        start_time = time.time()

        host_id = getHostName() + ":8888"
        while (time.time() - start_time) < 10:
            tmp_file_res = db_obj.getFileInfoFromFileIdHostId(
                host_id, file_id, 1, disk_id)
            if tmp_file_res: break
        if not tmp_file_res:
            self.fail(
                "Couldn't get fileInfo result from database within 10 seconds")
        tmp_file_obj = ngamsFileInfo.ngamsFileInfo().unpackSqlResult(
            tmp_file_res)
        msg = "Incorrect info in DB for registered file"
        self.assert_status_ref_file(file_info_ref, tmp_file_obj, msg=msg)
Ejemplo n.º 22
0
    def _test_basic_subscription(self, crc_method):

        # We configure the second server to send notifications via socket
        # to the listener we start later
        servers = self._prep_subscription_cluster(8888, (8889, [], True))
        db = servers['%s:8888' % getHostName()][1]

        subscribe = functools.partial(ngamsHttpUtils.httpGet,
                                      'localhost',
                                      8888,
                                      'SUBSCRIBE',
                                      timeout=5)

        subscription_listener = self.upload_subscription_files(
            8888, 8889, pars=[('crc_variant', crc_method)])

        # Create subscription
        params = {
            'url': 'http://localhost:8889/QARCHIVE',
            'subscr_id': 'HERE-TO-THERE',
            'priority': 1,
            'start_date': '%sT00:00:00.000' % time.strftime("%Y-%m-%d"),
            'concurrent_threads': 1
        }
        with contextlib.closing(subscribe(pars=params)) as resp:
            self.assertEqual(resp.status, 200)

        self.check_subscription_transfer(subscription_listener, 8889)

        # Both versions have the same checksum, regardless of the crc variant
        checksums = db.query2(
            "SELECT checksum from ngas_files where file_id = 'SmallFile.fits'")
        self.assertEqual(2, len(checksums))
        self.assertEqual(1, len(set(checksums)),
                         'not only one checksum: %r' % (checksums, ))

        # Both versions use the same checksum variant, which is the same we intended to use
        checksum_variants = db.query2(
            "SELECT checksum_plugin from ngas_files where file_id = 'SmallFile.fits'"
        )
        self.assertEqual(2, len(checksum_variants))
        self.assertEqual(
            1, len(set(checksum_variants)),
            'not only one checksum_variant %r' % (checksum_variants, ))
        self.assertEqual(crc_method, checksum_variants[0][0])
        self.terminateAllServer()
Ejemplo n.º 23
0
    def test_custom_auth_subscription(self):
        ca = trustme.CA()
        with ca.cert_pem.tempfile() as ca_temp_path:
            os.environ["NGAS_CA_PATH"] = ca_temp_path
            server_cert = ca.issue_cert(
                u"localhost",
                six.u(getHostName()),
                u"127.0.0.1",
            )
            cert_file = genTmpFilename(suffix='pem')
            server_cert.private_key_and_cert_chain_pem.write_to_path(cert_file)
            # We configure the second server to send notifications via socket
            # to the listener we start later
            auth_plugin_cfg = (("NgamsCfg.SubscriptionAuth[1].PlugInName",
                                'test.support.subscription_auth_plugin'), )
            self._prep_subscription_cluster(
                (8778, auth_plugin_cfg, False),
                (8779, [], True),
                cert_file=cert_file,
            )

            subscription_listener = self.upload_subscription_files(8778, 8779)

            # Create subscription
            params = {
                'url': 'https://localhost:8779/QARCHIVE',
                'subscr_id': 'HERE-TO-THERE',
                'priority': 1,
                'start_date': '%sT00:00:00.000' % time.strftime("%Y-%m-%d"),
                'concurrent_threads': 1
            }

            self.assertEqual(
                requests.get(
                    "https://127.0.0.1:8778/SUBSCRIBE",
                    params=params,
                    verify=ca_temp_path,
                ).status_code, 200)

            self.check_subscription_transfer(subscription_listener, 8779)

        del os.environ["NGAS_CA_PATH"]
Ejemplo n.º 24
0
def get_full_qualified_name(srvObj):
    """
    Get full qualified server name for the input NGAS server object

    INPUT:
        srvObj  ngamsServer, Reference to NG/AMS server class object

    RETURNS:
        fqdn    string, full qualified host name (host name + domain + port)
    """

    # Get hots_id, domain and port using ngamsLib functions
    hostName = getHostName()
    domain = ngamsLib.getDomain()
    # Concatenate all elements to construct full qualified name
    # Notice that host_id may contain port number
    fqdn = hostName + "." + domain

    # Return full qualified server name
    return fqdn
Ejemplo n.º 25
0
def getParNgasRcFile(par):
    """
    Retrieve a parameter from the NGAS resource file.

    The function has a built-in check to ensure that it is not possible
    to execute the tool on a test machine. A test machine has one of the
    following substrings in its name: 'wg0ngas', 'dev', 'tst'.

    par:      Parameter name (string).

    Returns:  Value of parameter or None (string|None).
    """
    # Determine if running on a test system.
    testSystems = ['wg0ngas', 'dev', 'tst']
    testSystem = 0
    for tstSysPat in testSystems:
        if (getHostName().find(tstSysPat) != -1): testSystem = 1
    try:
        fo = open(getNgasResourceFile())
    except Exception, e:
        raise Exception, "Error accessing NGAS Resource File: " + str(e)
Ejemplo n.º 26
0
    def test_NormalExec_1(self):
        """
        Synopsis:
        Normal execution of CHECKFILE Command.

        Description:
        The purpose of this Text Case is to test the normal/standard
        execution of the CHECKFILE Command.

        Expected Result:
        The CHECKFILE Command should be accepted and executed successfully
        by the server on an existing file.

        Test Steps:
        - Start NG/AMS Server.
        - Archive a file successfully.
        - Check the file specifying Disk ID/File Id/File Version.
        - Check the the result returned by the NG/AMS Server is as expected.

        Remarks:
        ...
        """
        self.prepExtSrv()
        sendPclCmd().archive("src/SmallFile.fits")
        diskId = "tmp-ngamsTest-NGAS-FitsStorage1-Main-1"
        fileId = "TEST.2001-05-08T15:25:00.123"
        statObj = sendPclCmd(port=8888).get_status(NGAMS_CHECKFILE_CMD,
                                                   pars=[["disk_id", diskId],
                                                         ["file_id", fileId],
                                                         ["file_version",
                                                          "1"]])
        refStatFile = "ref/ngamsCheckFileCmdTest_test_NormalExec_1_1_ref"
        refStatFile = saveInFile(
            None,
            loadFile(refStatFile) % ("%s:%d" % (getHostName(), 8888)))
        tmpStatFile = saveInFile(None, statObj.getMessage())
        self.checkFilesEq(refStatFile, tmpStatFile, "Incorrect info in " +\
                          "STATUS Command XML Status Document")
Ejemplo n.º 27
0
def checkSrvRunning(host=None, port=7777):
    """
    Function to check if server is running. It returns the status of the
    server, which is one of the following values:

      - NOT-RUNNING: Server is not running.
      - OFFLINE:     Server is running and is in OFFLINE State.
      - ONLINE:      Server is running and is in ONLINE State.

    host:     Host to check if server is running (string).

    port:     Port number used by server (integer).

    Returns:  Status (string).
    """
    if host is None:
        host = getHostName()
    try:
        res = ngamsPClient.ngamsPClient().\
              sendCmdGen(host, port, NGAMS_STATUS_CMD)
        status = res.getState()
    except Exception, e:
        status = NGAMS_NOT_RUN_STATE
def _httpPostUrl(url,
                mimeType,
                contDisp = "",
                dataRef = "",
                dataSource = "BUFFER",
                dataTargFile = "",
                blockSize = 65536,
                suspTime = 0.0,
                timeOut = None,
                authHdrVal = "",
                dataSize = -1,
                session_uuid = ""):
    """
    Post the the data referenced on the given URL. This function is adapted from
    ngamsLib.httpPostUrl, which does not support block-level suspension and cancelling for file transfer

    The data send back from the remote server + the HTTP header information
    is return in a list with the following contents:

      [<HTTP status code>, <HTTP status msg>, <HTTP headers (list)>, <data>]

    url:          URL to where data is posted (string).

    mimeType:     Mime-type of message (string).

    contDisp:     Content-Disposition of the data (string).

    dataRef:      Data to post or name of file containing data to send
                  (string).

    dataSource:   Source where to pick up the data (string/BUFFER|FILE|FD).

    dataTargFile: If a filename is specified with this parameter, the
                  data received is stored into a file of that name (string).

    blockSize:    Block size (in bytes) used when sending the data (integer).

    suspTime:     Time in seconds to suspend between each block (double).

    timeOut:      Timeout in seconds to wait for replies from the server
                  (double).

    authHdrVal:   Authorization HTTP header value as it should be sent in
                  the query (string).

    dataSize:     Size of data to send if read from a socket (integer).

    Returns:      List with information from reply from contacted
                  NG/AMS Server (reply, msg, hdrs, data) (list).
    """
    T = TRACE()

    # Separate the URL from the command.
    idx = (url[7:].find("/") + 7)
    tmpUrl = url[7:idx]
    cmd    = url[(idx + 1):]
    http = httplib.HTTP(tmpUrl)
    logger.debug("HTTP Header: %s: %s", NGAMS_HTTP_POST, cmd)
    http.putrequest(NGAMS_HTTP_POST, cmd)
    logger.debug("HTTP Header: Content-Type: %s", mimeType)
    http.putheader("Content-Type", mimeType)
    if (contDisp != ""):
        logger.debug("HTTP Header: Content-Disposition: %s", contDisp)
        http.putheader("Content-Disposition", contDisp)
    if (authHdrVal):
        if (authHdrVal[-1] == "\n"): authHdrVal = authHdrVal[:-1]
        logger.debug("HTTP Header: Authorization: %s", authHdrVal)
        http.putheader("Authorization", authHdrVal)
    if (dataSource == "FILE"):
        dataSize = getFileSize(dataRef)
    elif (dataSource == "BUFFER"):
        dataSize = len(dataRef)

    if (dataSize != -1):
        logger.debug("HTTP Header: Content-Length: %s", str(dataSize))
        http.putheader("Content-Length", str(dataSize))
    logger.debug("HTTP Header: Host: %s", getHostName())
    http.putheader("Host", getHostName())
    http.endheaders()
    logger.debug("HTTP header sent")

    http._conn.sock.settimeout(timeOut)

    # Send the data.
    logger.debug("Sending data ...")
    if (dataSource == "FILE"):
        fdIn = open(dataRef)
        block = "-"
        blockAccu = 0
        http._conn.sock.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 87380) # to fit Fornax
        while (block != ""):
            """
            if (threadRunDic.has_key(session_uuid) and threadRunDic[session_uuid] == 0):
                info(3, "Received cancel/suspend request, discard remaining blocks")
                break
            """
            block = fdIn.read(blockSize)
            blockAccu += len(block)
            http._conn.sock.sendall(block)
            if (suspTime > 0.0): time.sleep(suspTime)
        fdIn.close()
    elif (dataSource == "FD"):
        fdIn = dataRef
        dataRead = 0
        while (dataRead < dataSize):
            if ((dataSize - dataRead) < blockSize):
                rdSize = (dataSize - dataRead)
            else:
                rdSize = blockSize
            block = fdIn.read(rdSize)
            http._conn.sock.sendall(block)
            dataRead += len(block)
            if (suspTime > 0.0): time.sleep(suspTime)
    else:
        # dataSource == "BUFFER"
        http.send(dataRef)
    logger.debug("Data sent")
    if (threadRunDic.has_key(session_uuid) and threadRunDic[session_uuid] == 0):
        logger.debug("Received cancel/suspend request, close HTTP connection and return None values")
        if (http != None):
            http.close()
            del http
        return [None, None, None, None]
    # Receive + unpack reply.
    logger.debug("Waiting for reply ...")

    reply, msg, hdrs = http.getreply()

    if (hdrs == None):
        errMsg = "Illegal/no response to HTTP request encountered!"
        raise Exception(errMsg)

    if (hdrs.has_key("content-length")):
        dataSize = int(hdrs["content-length"])
    else:
        dataSize = 0
    if (dataTargFile == ""):
        data = http.getfile().read(dataSize)
    else:
        fd = None
        try:
            data = dataTargFile
            fd = open(dataTargFile, "w")
            fd.write(http.getfile().read(dataSize))
            fd.close()
        except Exception as e:
            if (fd != None): fd.close()
            raise e

    # Dump HTTP headers if Verbose Level >= 4.
    logger.debug("HTTP Header: HTTP/1.0 " + str(reply) + " " + msg)
    if logger.isEnabledFor(logging.DEBUG):
        for hdr in hdrs.keys():
            logger.debug("HTTP Header: %s: %s", hdr, hdrs[hdr])

    if (http != None):
        http.close()
        del http

    return [reply, msg, hdrs, data]
Ejemplo n.º 29
0
This module contains the Test Suite for the handling of Idle Suspension.
"""

import time
import urllib

from ngamsLib.ngamsCore import getHostName, NGAMS_STATUS_CMD, \
    NGAMS_CHECKFILE_CMD, rmFile, NGAMS_SUCCESS
from ngamsTestLib import ngamsTestSuite, sendPclCmd, \
    filterOutLines, saveInFile, loadFile, genTmpFilename, unzip

SUSP_EL = "NgamsCfg.HostSuspension[1]"
AUTH = "bmdhczpuZ2Fz"

# Simulated nodes in the cluster.
masterNode = getHostName() + ":8000"
subNode1 = getHostName() + ":8001"
subNode2 = getHostName() + ":8002"
susp_nodes = (subNode1, subNode2)

# Log files.
_logPat = "/tmp/ngamsTest/NGAS:%d/log/LogFile.nglog"
masterNodeLog = _logPat % 8000
subNode1Log = _logPat % 8001
subNode2Log = _logPat % 8002


def prepSimCluster(testObj, noOfSubNodes=1, cfgParDic={}):
    """
    Prepare a simulated cluster with 1 master node and 2 sub-nodes. The
    two sub-nodes will suspend themselves within 10 seconds of idling.
Ejemplo n.º 30
0
    def test_FileVerHandling_01(self):
        """
        Synopsis:
        Test that REMFILE removes proper File Version.

        Description:
        The purpose of the test is to verify that if several versions of a
        file are found in the archive, the proper version is deleted.

        Expected Result:
        The chosen version of the file, should be selected and should be
        removed.

        Test Steps:
        - Start server.
        - Archive a file 3 times into the archive.
        - Clone the file onto another disk.
        - Remove version 2 of the cloned file.

        Remarks:
        ...

        Test Data:
        ...
        """
        _, dbObj = self.prepExtSrv(cfgProps=(('NgamsCfg.Db[1].Snapshot',
                                              "0"), ))
        client = sendPclCmd()
        for n in range(3):
            stat = client.archive("src/SmallFile.fits")
            self.assertEquals('SUCCESS', stat.getStatus())

        diskId1 = "tmp-ngamsTest-NGAS-FitsStorage1-Main-1"
        fileId = "TEST.2001-05-08T15:25:00.123"
        fileVer = 2
        status = client.get_status(NGAMS_CLONE_CMD,
                                   pars=[["disk_id", diskId1]])
        self.assertEquals('SUCCESS', status.getStatus())

        diskId2 = "tmp-ngamsTest-NGAS-FitsStorage2-Main-3"
        filePath = "/tmp/ngamsTest/NGAS/FitsStorage2-Main-3/saf/" +\
                   "2001-05-08/2/TEST.2001-05-08T15:25:00.123.fits.gz"
        for execute in [0, 1]:
            httpPars = [["disk_id", diskId2], ["file_id", fileId],
                        ["file_version", fileVer], ["execute", execute]]
            stat = client.get_status(NGAMS_REMFILE_CMD, pars=httpPars)
            self.assertStatus(stat)

            fileInfo = ngamsFileInfo.ngamsFileInfo()
            try:
                fileInfo.read(getHostName(), dbObj, fileId, fileVer, diskId2)
            except:
                pass
            if (execute == 0):
                if (not os.path.exists(filePath)):
                    self.fail("File removed unexpectedly")
            else:
                if (os.path.exists(filePath)):
                    self.fail("File not removed as expected")

            refStatFile = "ref/ngamsRemFileCmdTest_test_" +\
                          "FileVerHandling_01_0%d_ref" % (execute + 3)
            tmpStatFile = saveInFile(None, filterDbStatus1(fileInfo.dumpBuf()))
            self.checkFilesEq(
                refStatFile, tmpStatFile,
                "Incorrect status for REMFILE Command/execution")