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"))
def testCreateAndDeleteVDI(self): self.assertEquals(0, len(fixture.ListVDI())) self.assertTrue(fixture.CreateVDI("alpha", 128 * (1024**2))) self.assertTrue(fixture.CreateVDI("bravo", 192 * (1024**2))) vdis = fixture.ListVDI() self.assertEquals(2, len(vdis)) alpha = filter(lambda x: x["name"] == "alpha", vdis) self.assertEquals(1, len(alpha)) self.assertEquals(128 * (1024**2), alpha[0]["nb_size"]) bravo = filter(lambda x: x["name"] == "bravo", vdis) self.assertEquals(1, len(bravo)) self.assertEquals(192 * (1024**2), bravo[0]["nb_size"]) self.assertTrue(fixture.DeleteVDI("alpha")) self.assertEquals(1, len(fixture.ListVDI())) self.assertTrue(fixture.DeleteVDI("bravo")) self.assertEquals(0, len(fixture.ListVDI()))
def testGetVDICopiesDeleted(self): self.assertTrue(fixture.CreateVDI("alpha")) self.assertTrue(fixture.DeleteVDI("alpha")) self.assertEqual(0, len(fixture.ListVDI())) for p in self.__class__._ports: client = sheep.SheepdogClient(port=p) status = client.get_vdi_copies(1) a_state = self._assertUnique(None, status) self.assertEqual(1, a_state.deleted)
def testReadDelVDIs(self): self.assertTrue(fixture.CreateVDI("alpha")) alpha = self._assertUniqueName("alpha", fixture.ListVDI()) a_vid = alpha["vdi_id"] self.assertTrue(fixture.DeleteVDI("alpha")) self.assertEqual(0, len(fixture.ListVDI())) for p in self.__class__._ports: client = sheep.SheepdogClient(port=p) deleted = client.get_del_vids() self.assertEqual(1, len(deleted)) self.assertTrue(a_vid in deleted)
def testGetVDIsFrom(self): self.assertTrue(fixture.CreateVDI("alpha")) self.assertTrue(fixture.CreateVDI("bravo")) vdis = fixture.ListVDI() self.assertEqual(2, len(vdis)) alpha = self._assertUniqueName("alpha", vdis) a_vid = alpha["vdi_id"] bravo = self._assertUniqueName("bravo", vdis) b_vid = bravo["vdi_id"] self.assertTrue(fixture.DeleteVDI("bravo")) self.assertEqual(1, len(fixture.ListVDI())) for p in self.__class__._ports: client = sheep.SheepdogClient(port=p) # before status = client.get_vdi_copies(1) self.assertEqual(2, len(status)) a_state = self._assertUnique(lambda x: x.vid == a_vid, status) b_state = self._assertUnique(lambda x: x.vid == b_vid, status) self.assertEqual(1, b_state.deleted) # after deleted = client.get_del_vids() self.assertEqual(1, len(deleted)) self.assertTrue(a_vid not in deleted) self.assertTrue(b_vid in deleted) inuse = client.get_vids() self.assertTrue(a_vid in inuse) a_inode = client.get_inode(a_vid) self.assertEqual(a_state.nr_copies, a_inode.nr_copies) self.assertEqual(bool(a_state.snapshot), bool(a_inode.snap_ctime)) self.assertEqual(a_state.copy_policy, a_inode.copy_policy) self.assertEqual(a_state.block_size_shift, a_inode.block_size_shift) self.assertEqual(a_state.parent_vid, a_inode.parent_vdi_id)