Exemple #1
0
    def testCloneVDI(self):
        self.assertTrue(fixture.CreateVDI("alpha", 4 * (1024**2)))
        alpha = filter(lambda x: x["name"] == "alpha", fixture.ListVDI())
        self.assertEquals(1, len(alpha))
        alpha = alpha[0]
        self.assertEquals(4 * (1024**2), alpha["nb_size"])

        contentToWrite = os.urandom(4 * (1024**2))
        self.assertEquals(4 * (1024**2), len(contentToWrite))
        self.assertTrue(fixture.WriteVDI("alpha", contentToWrite))

        self.assertTrue(fixture.SnapshotVDI("alpha", "alpha_1"))
        self.assertTrue(fixture.CloneVDI("alpha", "alpha_1", "bravo"))
        pred = lambda x: x["cloned"] and x["name"] == "bravo"
        self.assertEquals(1, len(filter(pred, fixture.ListVDI())))

        self.assertTrue(fixture.WriteVDI("alpha", os.urandom(4 * (1024**2))))

        contentRead = fixture.ReadVDI("bravo")
        self.assertEquals(4 * (1024**2), len(contentRead))

        expected = hashlib.md5(contentToWrite).digest()
        actual = hashlib.md5(contentRead).digest()
        self.assertEquals(expected, actual)

        self.assertTrue(fixture.DeleteVDI("alpha", "alpha_1"))
        self.assertTrue(fixture.DeleteVDI("alpha"))
        self.assertTrue(fixture.WriteVDI("bravo", os.urandom(4 * (1024**2))))
        self.assertTrue(fixture.DeleteVDI("bravo"))
Exemple #2
0
    def testReadObjOffset(self):
        NB_OBJECT = 1 << 22
        NB_SUBOBJECT = NB_OBJECT / 4
        assert NB_OBJECT % NB_SUBOBJECT == 0

        self.assertTrue(fixture.CreateVDI("alpha", NB_OBJECT))

        alpha = self._assertUniqueName("alpha", fixture.ListVDI())
        self.assertEqual(NB_OBJECT, alpha["nb_size"])
        a_vid = alpha["vdi_id"]
        oid = a_vid << 32

        contentToWrite = os.urandom(NB_OBJECT)
        self.assertEqual(NB_OBJECT, len(contentToWrite))
        self.assertTrue(fixture.WriteVDI("alpha", contentToWrite))

        for p in self.__class__._ports:
            client = sheep.SheepdogClient(port=p)
            for i in range(NB_OBJECT / NB_SUBOBJECT):
                s = NB_SUBOBJECT * i
                e = NB_SUBOBJECT * (i + 1)

                response = client.read_obj(oid, s, NB_SUBOBJECT)
                contentRead = response.data
                self.assertEqual(NB_SUBOBJECT, len(contentRead))

                expected = hashlib.md5(contentToWrite[s:e]).digest()
                actual = hashlib.md5(contentRead).digest()
                self.assertEqual(expected, actual)
Exemple #3
0
    def testWriteAndReadVDI(self):
        self.assertTrue(fixture.CreateVDI("alpha", 4 * (1024**2)))
        alpha = filter(lambda x: x["name"] == "alpha", fixture.ListVDI())
        self.assertEquals(1, len(alpha))
        alpha = alpha[0]
        self.assertEquals(4 * (1024**2), alpha["nb_size"])

        contentToWrite = os.urandom(4 * (1024**2))
        self.assertEquals(4 * (1024**2), len(contentToWrite))
        self.assertTrue(fixture.WriteVDI("alpha", contentToWrite))

        contentRead = fixture.ReadVDI("alpha")
        self.assertEquals(4 * (1024**2), len(contentRead))

        expected = hashlib.md5(contentToWrite).digest()
        actual = hashlib.md5(contentRead).digest()
        self.assertEquals(expected, actual)
Exemple #4
0
 def _assertMakeZero(self, vdi_name, data_size):
     data = ''.zfill(data_size)
     self.assertEqual(data_size, len(data))
     self.assertTrue(fixture.WriteVDI(vdi_name, data))
     return data
Exemple #5
0
 def _assertMakeRandom(self, vdi_name, data_size):
     data = os.urandom(data_size)
     self.assertEqual(data_size, len(data))
     self.assertTrue(fixture.WriteVDI(vdi_name, data))
     return data