예제 #1
0
 def test_empty_sparse(self):
     with namedTemporaryDir() as tmpdir:
         filename = os.path.join(tmpdir, 'test')
         with io.open(filename, "wb") as f:
             f.truncate(MB)
         runs = qemuimg.map(filename)
         self.assertEqual(qcow2.count_clusters(runs), 0)
예제 #2
0
 def test_full(self):
     with namedTemporaryDir() as tmpdir:
         filename = os.path.join(tmpdir, 'test')
         with io.open(filename, "wb") as f:
             f.write(b"x" * qcow2.CLUSTER_SIZE * 3)
         runs = qemuimg.map(filename)
         self.assertEqual(qcow2.count_clusters(runs), 3)
예제 #3
0
 def test_full(self):
     with namedTemporaryDir() as tmpdir:
         filename = os.path.join(tmpdir, 'test')
         with io.open(filename, "wb") as f:
             f.write(b"x" * qcow2.CLUSTER_SIZE * 3)
         runs = qemuimg.map(filename)
         self.assertEqual(qcow2.count_clusters(runs), 3)
예제 #4
0
 def test_empty_sparse(self):
     with namedTemporaryDir() as tmpdir:
         filename = os.path.join(tmpdir, 'test')
         with io.open(filename, "wb") as f:
             f.truncate(MB)
         runs = qemuimg.map(filename)
         self.assertEqual(qcow2.count_clusters(runs), 0)
예제 #5
0
 def test_multiple_blocks(self, tmpdir):
     filename = str(tmpdir.join("test"))
     with io.open(filename, "wb") as f:
         f.write(b"x")
         f.seek(16 * 1024)
         f.write(b"x")
         f.seek(42 * 1024)
         f.write(b"x")
     runs = qemuimg.map(filename)
     assert qcow2.count_clusters(runs) == 1
예제 #6
0
 def test_multiple_blocks(self):
     with namedTemporaryDir() as tmpdir:
         filename = os.path.join(tmpdir, 'test')
         with io.open(filename, "wb") as f:
             f.write(b"x")
             f.seek(16 * 1024)
             f.write(b"x")
             f.seek(42 * 1024)
             f.write(b"x")
         runs = qemuimg.map(filename)
         self.assertEqual(qcow2.count_clusters(runs), 1)
예제 #7
0
 def test_multiple_blocks(self):
     with namedTemporaryDir() as tmpdir:
         filename = os.path.join(tmpdir, 'test')
         with io.open(filename, "wb") as f:
             f.write(b"x")
             f.seek(16 * 1024)
             f.write(b"x")
             f.seek(42 * 1024)
             f.write(b"x")
         runs = qemuimg.map(filename)
         self.assertEqual(qcow2.count_clusters(runs), 1)
예제 #8
0
    def test_big_sparse(self, tmpdir):
        filename = str(tmpdir.join("test"))
        with io.open(filename, "wb") as f:
            f.truncate(1024 * MB)

            # First cluster
            f.write(b"x")

            # Second cluster
            f.seek(512 * MB)
            f.write(b"x")

        runs = qemuimg.map(filename)
        assert qcow2.count_clusters(runs) == 2
예제 #9
0
    def test_big_sparse(self):
        with namedTemporaryDir() as tmpdir:
            filename = os.path.join(tmpdir, 'test')
            with io.open(filename, "wb") as f:
                f.truncate(1024 * MB)

                # First cluster
                f.write(b"x")

                # Second cluster
                f.seek(512 * MB)
                f.write(b"x")

            runs = qemuimg.map(filename)
            self.assertEqual(qcow2.count_clusters(runs), 2)
예제 #10
0
    def test_big_sparse(self):
        with namedTemporaryDir() as tmpdir:
            filename = os.path.join(tmpdir, 'test')
            with io.open(filename, "wb") as f:
                f.truncate(1024 * MB)

                # First cluster
                f.write(b"x")

                # Second cluster
                f.seek(512 * MB)
                f.write(b"x")

            runs = qemuimg.map(filename)
            self.assertEqual(qcow2.count_clusters(runs), 2)
예제 #11
0
    def test_partial(self, tmpdir):
        filename = str(tmpdir.join("test"))
        with io.open(filename, "wb") as f:
            f.truncate(MB)

            # First cluster
            f.seek(8192)
            f.write(b"x")

            # Second cluster
            f.seek(qcow2.CLUSTER_SIZE)
            f.write(b"x")
            f.seek(qcow2.CLUSTER_SIZE * 2 - 1)
            f.write(b"x")

            # Third cluster
            f.seek(qcow2.CLUSTER_SIZE * 2)
            f.write(b"x")

        runs = qemuimg.map(filename)
        assert qcow2.count_clusters(runs) == 3
예제 #12
0
    def test_partial(self):
        with namedTemporaryDir() as tmpdir:
            filename = os.path.join(tmpdir, 'test')
            with io.open(filename, "wb") as f:
                f.truncate(MB)

                # First cluster
                f.seek(8192)
                f.write(b"x")

                # Second cluster
                f.seek(qcow2.CLUSTER_SIZE)
                f.write(b"x")
                f.seek(qcow2.CLUSTER_SIZE * 2 - 1)
                f.write(b"x")

                # Third cluster
                f.seek(qcow2.CLUSTER_SIZE * 2)
                f.write(b"x")

            runs = qemuimg.map(filename)
            self.assertEqual(qcow2.count_clusters(runs), 3)
예제 #13
0
    def test_partial(self):
        with namedTemporaryDir() as tmpdir:
            filename = os.path.join(tmpdir, 'test')
            with io.open(filename, "wb") as f:
                f.truncate(MB)

                # First cluster
                f.seek(8192)
                f.write(b"x")

                # Second cluster
                f.seek(qcow2.CLUSTER_SIZE)
                f.write(b"x")
                f.seek(qcow2.CLUSTER_SIZE * 2 - 1)
                f.write(b"x")

                # Third cluster
                f.seek(qcow2.CLUSTER_SIZE * 2)
                f.write(b"x")

            runs = qemuimg.map(filename)
            self.assertEqual(qcow2.count_clusters(runs), 3)
예제 #14
0
 def test_full(self, tmpdir):
     filename = str(tmpdir.join("test"))
     with io.open(filename, "wb") as f:
         f.write(b"x" * qcow2.CLUSTER_SIZE * 3)
     runs = qemuimg.map(filename)
     assert qcow2.count_clusters(runs) == 3
예제 #15
0
 def test_empty_sparse(self, tmpdir):
     filename = str(tmpdir.join("test"))
     with io.open(filename, "wb") as f:
         f.truncate(MB)
     runs = qemuimg.map(filename)
     assert qcow2.count_clusters(runs) == 0
예제 #16
0
 def test_empty(self, tmpdir):
     filename = str(tmpdir.join("test"))
     with io.open(filename, "wb"):
         pass
     runs = qemuimg.map(filename)
     assert qcow2.count_clusters(runs) == 0