Federico Simoncelli has uploaded a new change for review. Change subject: test: add ddWatchCopy append tests ......................................................................
test: add ddWatchCopy append tests Change-Id: Ib3a8cc6b59b356b333f4338103e7b665af584cdc Signed-off-by: Federico Simoncelli <fsimo...@redhat.com> --- M tests/miscTests.py 1 file changed, 68 insertions(+), 9 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/75/20075/1 diff --git a/tests/miscTests.py b/tests/miscTests.py index d8b188a..b22ef64 100644 --- a/tests/miscTests.py +++ b/tests/miscTests.py @@ -50,11 +50,6 @@ SUDO_GROUP = "root" -def ddWatchCopy(srcPath, dstPath, callback, dataLen): - rc, out, err = misc.ddWatchCopy(srcPath, dstPath, callback, dataLen) - return rc, out, err - - def watchCmd(cmd, stop, cwd=None, data=None, recoveryCallback=None): ret, out, err = utils.watchCmd(cmd, stop, cwd=cwd, data=data, recoveryCallback=recoveryCallback) @@ -437,7 +432,7 @@ os.chmod(dstPath, 0666) #Copy - rc, out, err = ddWatchCopy(srcPath, dstPath, None, len(data)) + rc, out, err = misc.ddWatchCopy(srcPath, dstPath, None, len(data)) #Get copied data readData = open(dstPath).read() @@ -448,6 +443,70 @@ # Compare self.assertEquals(readData, data) + + def _createDataFile(self, data, repetitions): + fd, path = tempfile.mkstemp() + + try: + for i in xrange(repetitions): + os.write(fd, data) + self.assertEquals(os.stat(path).st_size, misc.MEGA) + except: + os.unlink(path) + raise + finally: + os.close(fd) + + return path + + def testAlignedAppend(self): + data = "ABCD" * 256 # 1Kb + repetitions = misc.MEGA / len(data) + + path = self._createDataFile(data, repetitions) + try: + # Using os.stat(path).st_size is part of the test, please do not + # remove or change. + rc, out, err = misc.ddWatchCopy( + "/dev/zero", path, None, misc.MEGA, os.stat(path).st_size) + + self.assertEquals(rc, 0) + self.assertEquals(os.stat(path).st_size, misc.MEGA * 2) + + with open(path, "r") as f: + for i in xrange(repetitions): + self.assertEquals(f.read(len(data)), data) + finally: + os.unlink(path) + + def testNonAlignedAppend(self): + data = "ABCD" * 256 # 1Kb + add_data = "E" + repetitions = misc.MEGA / len(data) + + path = self._createDataFile(data, repetitions) + try: + with open(path, "a") as f: # Appending additional data + f.write(add_data) + + self.assertEquals(os.stat(path).st_size, misc.MEGA + len(add_data)) + + # Using os.stat(path).st_size is part of the test, please do not + # remove or change. + rc, out, err = misc.ddWatchCopy( + "/dev/zero", path, None, misc.MEGA, os.stat(path).st_size) + + self.assertEquals(rc, 0) + self.assertEquals(os.stat(path).st_size, + misc.MEGA * 2 + len(add_data)) + + with open(path, "r") as f: + for i in xrange(repetitions): + self.assertEquals(f.read(len(data)), data) + # Checking the additional data + self.assertEquals(f.read(len(add_data)), add_data) + finally: + os.unlink(path) def testCopy(self): """ @@ -476,7 +535,7 @@ os.chmod(dstPath, 0666) #Copy - rc, out, err = ddWatchCopy(srcPath, dstPath, None, len(data)) + rc, out, err = misc.ddWatchCopy(srcPath, dstPath, None, len(data)) #Get copied data readData = open(dstPath).read() @@ -498,7 +557,7 @@ os.unlink(srcPath) #Copy - self.assertRaises(misc.se.MiscBlockWriteException, ddWatchCopy, + self.assertRaises(misc.se.MiscBlockWriteException, misc.ddWatchCopy, srcPath, "/tmp/tmp", None, 100) def testStop(self): @@ -510,7 +569,7 @@ os.unlink(src.name) os.mkfifo(src.name) with tempfile.NamedTemporaryFile() as dst: - ddWatchCopy(src.name, dst.name, lambda: True, 100) + misc.ddWatchCopy(src.name, dst.name, lambda: True, 100) except utils.ActionStopped: self.log.info("Looks like it stopped!") else: -- To view, visit http://gerrit.ovirt.org/20075 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib3a8cc6b59b356b333f4338103e7b665af584cdc Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Federico Simoncelli <fsimo...@redhat.com> _______________________________________________ vdsm-patches mailing list vdsm-patches@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches