def testTransfer(filesOrData, targetDir, targetName=None): numFiles, totalSize, containsDir = DataThreadBase.computeTotalSize(filesOrData) errors = False if type(filesOrData) is str or (numFiles is 1 and not containsDir): getCoreLogger().info("- Test single file transfer") sendAndReceive(filesOrData, totalSize, os.path.join(targetDir, targetName)) if not testResult(filesOrData, targetDir, targetName, useTarstream=False): errors = True getCoreLogger().info("- Test uncompressed auto transfer") sendDict = DataThreadBase.prepareSending(filesOrData, targetName) sendAndReceive(filesOrData, totalSize, targetDir, sendDict) if not testResult(filesOrData, targetDir, targetName, useTarstream=True): errors = True getCoreLogger().info("- Test bzip2 compressed auto transfer") sendDict = DataThreadBase.prepareSending(filesOrData, targetName, "bz2") sendAndReceive(filesOrData, totalSize, targetDir, sendDict) if not testResult(filesOrData, targetDir, targetName, useTarstream=True): errors = True getCoreLogger().info("- Test gzip compressed auto transfer") sendDict = DataThreadBase.prepareSending(filesOrData, targetName, "gz") sendAndReceive(filesOrData, totalSize, targetDir, sendDict) if not testResult(filesOrData, targetDir, targetName, useTarstream=True): errors = True return not errors
f1 = makeFile(baseDir, 1024) makeFile(baseDir, 1024) makeFile(subDir, 1024) makeFile(subDir, 1024) sl = makeFile(subDir, 1) os.remove(sl) os.symlink(os.path.join("..", os.path.basename(f1)), sl) if not testTransfer([baseDir], targetDir): errors = True getCoreLogger().info("") getCoreLogger().info("Trying to send more files than announced - should fail") inPath1 = makeFile(sourceDir, FILE_SIZE) inPath2 = makeFile(sourceDir, FILE_SIZE) inPath3 = makeFile(sourceDir, FILE_SIZE) sendDict = DataThreadBase.prepareSending([inPath1, inPath2]) sendAndReceive([inPath1, inPath2, inPath3], targetPath=targetDir, sendDict=sendDict) if not errorReceive: getCoreLogger().error("ERROR: This test should have failed.") errors = True if os.path.exists(os.path.join(targetDir, os.path.basename(inPath3))): getCoreLogger().error("ERROR: file %s hould not have been created", os.path.join(targetDir, os.path.basename(inPath2))) errors = True getCoreLogger().info("") getCoreLogger().info("Trying to send bigger file than announced (single file) - should fail") inPath1 = makeFile(sourceDir, FILE_SIZE) sendDict = DataThreadBase.prepareSending([inPath1]) sendDict[u"size"] = int(0.5 * FILE_SIZE) sendAndReceive([inPath1], targetPath=targetDir, sendDict=sendDict) if not errorReceive and not errorSend: