def testCamlistoreFileWriteAndCamputCompatibility(self):
        # Create a 1MB random file
        test_file = tempfile.NamedTemporaryFile()
        test_file.write(os.urandom(int(1.5 * (1024 << 10))))
        test_file.seek(0)

        log.debug('Random file generated')

        log.info('Putting file with camput file:')
        old_pwd = os.getcwd()
        sh.cd(CAMLIPY_CAMLISTORE_PATH)
        camput_blobref = sh.devcam('put', 'file', test_file.name)
        sh.cd(old_pwd)
        log.info('Camput blobRef: {0}'.format(camput_blobref))

        file_writer = FileWriter(self.server, fileobj=test_file)
        file_writer.chunk()
        camplipy_blobref = file_writer.bytes_writer()

        log.info('Camlipy blobRef: {0}'.format(camplipy_blobref))

        log.info('FileWriter cnt={0}'.format(file_writer.cnt))

        # Check that no data blob has been uploaded,
        # since we just uploaded the same file with camput file.

        # "<= 1" since sometimes, camlipy make a slightly bigger end blob.
        self.assertTrue(file_writer.cnt['uploaded'] <= 1)
    def testCamlistoreFileWriteAndCamputCompatibility(self):
        # Create a 1MB random file
        test_file = tempfile.NamedTemporaryFile()
        test_file.write(os.urandom(int(1.5 * (1024 << 10))))
        test_file.seek(0)

        log.debug('Random file generated')

        log.info('Putting file with camput file:')
        old_pwd = os.getcwd()
        sh.cd(CAMLIPY_CAMLISTORE_PATH)
        camput_blobref = sh.devcam('put', 'file', test_file.name)
        sh.cd(old_pwd)
        log.info('Camput blobRef: {0}'.format(camput_blobref))

        file_writer = FileWriter(self.server, fileobj=test_file)
        file_writer.chunk()
        camplipy_blobref = file_writer.bytes_writer()

        log.info('Camlipy blobRef: {0}'.format(camplipy_blobref))

        log.info('FileWriter cnt={0}'.format(file_writer.cnt))

        # Check that no data blob has been uploaded,
        # since we just uploaded the same file with camput file.

        # "<= 1" since sometimes, camlipy make a slightly bigger end blob.
        self.assertTrue(file_writer.cnt['uploaded'] <= 1)
Beispiel #3
0
    def testBigFile(self):
        # Create a 1MB random file
        test_blob = tempfile.TemporaryFile()
        test_blob.write(os.urandom(52428800))  # 1024 << 10

        log.debug('Random file generated')
        test_blob.seek(0)
        blob_hash = self.compute_hash(test_blob)
        test_blob.seek(0)
        file_writer = FileWriter(self.server, fileobj=test_blob)
        file_writer.chunk()

        self.assertEqual(
            list(file_writer.check_spans())[:len(file_writer.spans) - 2],
            range(len(file_writer.spans) - 2))

        blob_ref = file_writer.bytes_writer()

        log.info('FileWriter cnt={0}'.format(file_writer.cnt))

        file_reader = FileReader(self.server, blob_ref)
        file_reader.load_spans()

        out = file_reader.build()

        test_blob.seek(0)
        self.assertEqual(len(out.read()), len(test_blob.read()))
        out.seek(0)
        test_blob.seek(0)
        out_hash = self.compute_hash(out)
        self.assertEqual(out_hash, blob_hash)

        # Try to re-upload the same file and check that no data is re-uploaded
        file_writer2 = FileWriter(self.server, fileobj=test_blob)
        file_writer2.chunk()

        log.info('FileWriter2 cnt={0}'.format(file_writer2.cnt))

        self.assertEqual(file_writer2.cnt['uploaded'], 0)
        self.assertEqual(file_writer2.cnt['uploaded_size'], 0)
Beispiel #4
0
    def testBigFile(self):
        # Create a 1MB random file
        test_blob = tempfile.TemporaryFile()
        test_blob.write(os.urandom(52428800))  # 1024 << 10

        log.debug('Random file generated')
        test_blob.seek(0)
        blob_hash = self.compute_hash(test_blob)
        test_blob.seek(0)
        file_writer = FileWriter(self.server, fileobj=test_blob)
        file_writer.chunk()

        self.assertEqual(list(file_writer.check_spans())[:len(file_writer.spans) - 2], range(len(file_writer.spans) - 2))

        blob_ref = file_writer.bytes_writer()

        log.info('FileWriter cnt={0}'.format(file_writer.cnt))

        file_reader = FileReader(self.server, blob_ref)
        file_reader.load_spans()

        out = file_reader.build()

        test_blob.seek(0)
        self.assertEqual(len(out.read()), len(test_blob.read()))
        out.seek(0)
        test_blob.seek(0)
        out_hash = self.compute_hash(out)
        self.assertEqual(out_hash, blob_hash)

        # Try to re-upload the same file and check that no data is re-uploaded
        file_writer2 = FileWriter(self.server, fileobj=test_blob)
        file_writer2.chunk()

        log.info('FileWriter2 cnt={0}'.format(file_writer2.cnt))

        self.assertEqual(file_writer2.cnt['uploaded'], 0)
        self.assertEqual(file_writer2.cnt['uploaded_size'], 0)