Beispiel #1
0
def testSendingClientAction():
    c = \
        """
[general]
fdtSendingClientCommand = bash wrapper_fdt.sh -P 35 -p %(port)s -c %(hostDest)s -d / -fl %(fileList)s -noupdates
fdtReceivingServerCommand = bash wrapper_fdt.sh -bs 2M -p %(port)s -noupdates
"""
    f = getTempFile(c)
    inputOption = "--config=%s" % f.name
    conf = ConfigFDTD(inputOption.split())
    options = dict(port="some_port", hostDest="host_dest", transferFiles=[])
    a = SendingClientAction("some_id", options)
    a._setUp(conf)
    assert a.options["fileList"] == "/tmp/fileLists/fdt-fileList-some_id"
    # this one did not get interpolated for client action, so it's not set
    py.test.raises(KeyError, a.options.__getitem__,
                   "fdtReceivingServerCommand")
    assert a.command == "bash wrapper_fdt.sh -P 35 -p some_port -c host_dest -d / -fl /tmp/fileLists/fdt-fileList-some_id -noupdates"
    # clean up after test, only if succeeded
    os.unlink(a.options["fileList"])
Beispiel #2
0
def testSendingClientAction():
    c = \
"""
[general]
fdtSendingClientCommand = bash wrapper_fdt.sh -P 35 -p %(port)s -c %(hostDest)s -d / -fl %(fileList)s -noupdates
fdtReceivingServerCommand = bash wrapper_fdt.sh -bs 2M -p %(port)s -noupdates
"""
    f = getTempFile(c)
    inputOption = "--config=%s" % f.name
    conf = ConfigFDTD(inputOption.split())
    options = dict(port = "some_port", hostDest = "host_dest", transferFiles = [])        
    a = SendingClientAction("some_id", options)
    a._setUp(conf)
    assert a.options["fileList"] == "/tmp/fdt-fileList-some_id"
    # this one did not get interpolated for client action, so it's not set
    py.test.raises(KeyError, a.options.__getitem__, "fdtReceivingServerCommand")
    assert a.command == "bash wrapper_fdt.sh -P 35 -p some_port -c host_dest -d / -fl /tmp/fdt-fileList-some_id -noupdates"
    
    # clean up after test, only if succeeded
    os.unlink(a.options["fileList"])
Beispiel #3
0
def testInputCopyJobFileTranslationIntoFDTFileList():
    # correct data - input copyjobfile - all must be the same source host,
    # destination host pairs, otherwise such input copyjobfile will break
    # into a number of FDT fileList files on corresponding source hosts 
    inputData = \
"""fdt://localhost:111/tmp/file  fdt://localhost:222/tmp/fileX1
fdt://localhost:111/tmp/fileGY   fdt://localhost:222/tmp/fileX2
fdt://localhost:111/tmp/fileWA   fdt://localhost:222/tmp/fileX
fdt://localhost:111/tmp/fileWQ   fdt://localhost:222/tmp/fileTY
fdt://localhost:111/tmp/file9Y   fdt://localhost:222/tmp/fileIO"""

    # desired output fileList for FDT client
    outputData = \
"""/tmp/file / /tmp/fileX1
/tmp/fileGY / /tmp/fileX2
/tmp/fileWA / /tmp/fileX
/tmp/fileWQ / /tmp/fileTY
/tmp/file9Y / /tmp/fileIO"""
    
    logger = logger = Logger("test logger",  level = logging.DEBUG)
    copyJobFile = tempfile.NamedTemporaryFile("w+") # read / write
    copyJobFile.write(inputData)
    copyJobFile.flush()
    copyJobFile.seek(0)
    
    inputOption = "--copyjobfile=%s" % copyJobFile.name
    conf = ConfigFDTCopy(inputOption.split())
    apMon = None
    transfers = Transfers(conf, apMon, logger)
    
    # since having the same source host, destination host pair, should have
    # only one transfer job
    t = transfers.transfers["localhost:111-localhost:222"]
    assert len(transfers.transfers) == 1
    assert len(t.files) == 5
    
    # do relevant stuff from fdtcp performTransfer method now
    testAction = TestAction(timeout = 5)
    t.id = testAction.id
    options = dict(port = "some_port", hostDest = t.hostDest, transferFiles = t.files)
    sndClientAction = SendingClientAction(testAction.id, options)
    
    assert sndClientAction.options["port"] == "some_port"
    assert sndClientAction.options["hostDest"] == t.hostDest
    
    # fileList is constructed at the side of fdtd service (remote site)
    # simulate this process ...
    class MockFDTDConfig(Mock):
        # mock class only to satisfy sndClientAction._setUp() call 
        def get(self, what):
            return "some string"
    sndClientAction._setUp(MockFDTDConfig()) # this method is called on fdtd service site
    assert sndClientAction.options["fileList"] == "/tmp/fdt-fileList-%s" % sndClientAction.id

    # now check content of the fileList file - shall be as the output data
    data = open(sndClientAction.options["fileList"], 'r').readlines()
    for line1, line2 in zip(data, outputData.split('\n')):
        assert line1.strip() == line2
        
    # clean up after test, only if succeeded
    os.unlink(sndClientAction.options["fileList"])
Beispiel #4
0
def testInputCopyJobFileTranslationIntoFDTFileList():
    # correct data - input copyjobfile - all must be the same source host,
    # destination host pairs, otherwise such input copyjobfile will break
    # into a number of FDT fileList files on corresponding source hosts
    inputData = \
        """fdt://localhost:111/tmp/file  fdt://localhost:222/tmp/fileX1
fdt://localhost:111/tmp/fileGY   fdt://localhost:222/tmp/fileX2
fdt://localhost:111/tmp/fileWA   fdt://localhost:222/tmp/fileX
fdt://localhost:111/tmp/fileWQ   fdt://localhost:222/tmp/fileTY
fdt://localhost:111/tmp/file9Y   fdt://localhost:222/tmp/fileIO"""

    # desired output fileList for FDT client
    outputData = \
        """/tmp/file / /tmp/fileX1
/tmp/fileGY / /tmp/fileX2
/tmp/fileWA / /tmp/fileX
/tmp/fileWQ / /tmp/fileTY
/tmp/file9Y / /tmp/fileIO"""

    logger = Logger("test logger", level=logging.DEBUG)
    copyJobFile = tempfile.NamedTemporaryFile("w+")  # read / write
    copyJobFile.write(inputData)
    copyJobFile.flush()
    copyJobFile.seek(0)

    inputOption = "--copyjobfile=%s" % copyJobFile.name
    conf = ConfigFDTCopy(inputOption.split())
    apMon = None
    transfers = Transfers(conf, apMon, logger)

    # since having the same source host, destination host pair, should have
    # only one transfer job
    t = transfers.transfers["localhost:111-localhost:222"]
    assert len(transfers.transfers) == 1
    assert len(t.files) == 5

    # do relevant stuff from fdtcp performTransfer method now
    testAction = TestAction(t.hostSrc, t.hostDest, timeout=5)
    t.id = testAction.id
    options = dict(port="some_port",
                   hostDest=t.hostDest,
                   transferFiles=t.files)
    sndClientAction = SendingClientAction(testAction.id, options)

    assert sndClientAction.options["port"] == "some_port"
    assert sndClientAction.options["hostDest"] == t.hostDest

    # fileList is constructed at the side of fdtd service (remote site)
    # simulate this process ...
    class MockFDTDConfig(Mock):
        # mock class only to satisfy sndClientAction._setUp() call - when
        # it checks for log file

        def get(self, what):
            return "/tmp/logfile"

    # this method is called on fdtd service site
    sndClientAction._setUp(MockFDTDConfig())
    assert sndClientAction.options["fileList"] == \
        "/tmp/fileLists/fdt-fileList-%s" % sndClientAction.id

    # now check content of the fileList file - shall be as the output data
    data = open(sndClientAction.options["fileList"], 'r').readlines()
    for line1, line2 in zip(data, outputData.split('\n')):
        assert line1.strip() == line2

    # clean up after test, only if succeeded
    os.unlink(sndClientAction.options["fileList"])