def test_create_snapshot(self): succ = BlockDev.btrfs_create_volume([self.loop_dev], "myShinyBtrfs", None, None, None) self.assertTrue(succ) mount(self.loop_dev, TEST_MNT) subvols = BlockDev.btrfs_list_subvolumes(TEST_MNT, True) self.assertEqual(len(subvols), 0) # R/W snapshot succ = BlockDev.btrfs_create_snapshot(TEST_MNT, TEST_MNT + "/snap1", False, None) self.assertTrue(succ) subvols = BlockDev.btrfs_list_subvolumes(TEST_MNT, True) self.assertEqual(len(subvols), 1) # RO snapshot succ = BlockDev.btrfs_create_snapshot(TEST_MNT, TEST_MNT + "/snap2", True, None) self.assertTrue(succ) subvols = BlockDev.btrfs_list_subvolumes(TEST_MNT, True) self.assertEqual(len(subvols), 2)
def test_create_delete_subvolume(self): """Verify that it is possible to create/delete subvolume""" btrfs_version = self._get_btrfs_version() if btrfs_version >= LooseVersion('4.13.2'): self.skipTest('subvolumes list is broken with btrfs-progs v4.13.2') succ = BlockDev.btrfs_create_volume([self.loop_dev], "myShinyBtrfs", None, None, None) self.assertTrue(succ) mount(self.loop_dev, TEST_MNT) subvols = BlockDev.btrfs_list_subvolumes(TEST_MNT, False) self.assertEqual(len(subvols), 0) succ = BlockDev.btrfs_create_subvolume(TEST_MNT, "subvol1", None) self.assertTrue(succ) subvols = BlockDev.btrfs_list_subvolumes(TEST_MNT, False) self.assertEqual(len(subvols), 1) # already there with self.assertRaises(GLib.GError): BlockDev.btrfs_create_subvolume(TEST_MNT, "subvol1", None) succ = BlockDev.btrfs_delete_subvolume(TEST_MNT, "subvol1", None) self.assertTrue(succ) subvols = BlockDev.btrfs_list_subvolumes(TEST_MNT, False) self.assertEqual(len(subvols), 0) # already removed with self.assertRaises(GLib.GError): BlockDev.btrfs_delete_subvolume(TEST_MNT, "subvol1", None) succ = BlockDev.btrfs_create_subvolume(TEST_MNT, "subvol1", None) self.assertTrue(succ) # add it back subvols = BlockDev.btrfs_list_subvolumes(TEST_MNT, False) self.assertEqual(len(subvols), 1) # and create another subvolume in it succ = BlockDev.btrfs_create_subvolume( os.path.join(TEST_MNT, "subvol1"), "subvol1.1", None) self.assertTrue(succ) subvols = BlockDev.btrfs_list_subvolumes(TEST_MNT, False) self.assertEqual(len(subvols), 2) # make sure subvolumes are sorted properly (parents before children) seen = set() for subvol in subvols: seen.add(subvol) self.assertTrue(subvol.parent_id == BlockDev.BTRFS_MAIN_VOLUME_ID or any(subvol.parent_id == other.id for other in seen))
def test_create_delete_subvolume(self): """Verify that it is possible to create/delete subvolume""" btrfs_version = self._get_btrfs_version() if btrfs_version >= LooseVersion('4.13.2'): self.skipTest('subvolumes list is broken with btrfs-progs v4.13.2') succ = BlockDev.btrfs_create_volume([self.loop_dev], "myShinyBtrfs", None, None, None) self.assertTrue(succ) mount(self.loop_dev, TEST_MNT) subvols = BlockDev.btrfs_list_subvolumes(TEST_MNT, False) self.assertEqual(len(subvols), 0) succ = BlockDev.btrfs_create_subvolume(TEST_MNT, "subvol1", None) self.assertTrue(succ) subvols = BlockDev.btrfs_list_subvolumes(TEST_MNT, False) self.assertEqual(len(subvols), 1) # already there with self.assertRaises(GLib.GError): BlockDev.btrfs_create_subvolume(TEST_MNT, "subvol1", None) succ = BlockDev.btrfs_delete_subvolume(TEST_MNT, "subvol1", None) self.assertTrue(succ) subvols = BlockDev.btrfs_list_subvolumes(TEST_MNT, False) self.assertEqual(len(subvols), 0) # already removed with self.assertRaises(GLib.GError): BlockDev.btrfs_delete_subvolume(TEST_MNT, "subvol1", None) succ = BlockDev.btrfs_create_subvolume(TEST_MNT, "subvol1", None) self.assertTrue(succ) # add it back subvols = BlockDev.btrfs_list_subvolumes(TEST_MNT, False) self.assertEqual(len(subvols), 1) # and create another subvolume in it succ = BlockDev.btrfs_create_subvolume(os.path.join(TEST_MNT, "subvol1"), "subvol1.1", None) self.assertTrue(succ) subvols = BlockDev.btrfs_list_subvolumes(TEST_MNT, False) self.assertEqual(len(subvols), 2) # make sure subvolumes are sorted properly (parents before children) seen = set() for subvol in subvols: seen.add(subvol) self.assertTrue(subvol.parent_id == BlockDev.BTRFS_MAIN_VOLUME_ID or any(subvol.parent_id == other.id for other in seen))
def test_set_default_subvolume(self): """Verify that setting default subvolume works as expected""" succ = BlockDev.btrfs_create_volume([self.loop_dev], "myShinyBtrfs", None, None) self.assertTrue(succ) mount(self.loop_dev, TEST_MNT) ret = BlockDev.btrfs_get_default_subvolume_id(TEST_MNT) self.assertEqual(ret, 5) succ = BlockDev.btrfs_create_subvolume(TEST_MNT, "subvol1") self.assertTrue(succ) subvols = BlockDev.btrfs_list_subvolumes(TEST_MNT, False) self.assertEqual(len(subvols), 1) new_id = next((subvol.id for subvol in subvols), None) self.assertIsNot(new_id, None) succ = BlockDev.btrfs_set_default_subvolume(TEST_MNT, new_id) self.assertTrue(succ) ret = BlockDev.btrfs_get_default_subvolume_id(TEST_MNT) self.assertEquals(ret, new_id) succ = BlockDev.btrfs_set_default_subvolume(TEST_MNT, 5) self.assertTrue(succ) ret = BlockDev.btrfs_get_default_subvolume_id(TEST_MNT) self.assertEquals(ret, 5)
def test_set_default_subvolume(self): """Verify that setting default subvolume works as expected""" succ = BlockDev.btrfs_create_volume([self.loop_dev], "myShinyBtrfs", None, None, None) self.assertTrue(succ) mount(self.loop_dev, TEST_MNT) ret = BlockDev.btrfs_get_default_subvolume_id(TEST_MNT) self.assertEqual(ret, 5) succ = BlockDev.btrfs_create_subvolume(TEST_MNT, "subvol1", None) self.assertTrue(succ) subvols = BlockDev.btrfs_list_subvolumes(TEST_MNT, False) self.assertEqual(len(subvols), 1) new_id = next((subvol.id for subvol in subvols), None) self.assertIsNot(new_id, None) succ = BlockDev.btrfs_set_default_subvolume(TEST_MNT, new_id, None) self.assertTrue(succ) ret = BlockDev.btrfs_get_default_subvolume_id(TEST_MNT) self.assertEqual(ret, new_id) succ = BlockDev.btrfs_set_default_subvolume(TEST_MNT, 5, None) self.assertTrue(succ) ret = BlockDev.btrfs_get_default_subvolume_id(TEST_MNT) self.assertEqual(ret, 5)
def test_list_subvolumes(self): """Verify that it is possible to get info about subvolumes""" succ = BlockDev.btrfs_create_volume([self.loop_dev], "myShinyBtrfs", None, None) self.assertTrue(succ) mount(self.loop_dev, TEST_MNT) subvols = BlockDev.btrfs_list_subvolumes(TEST_MNT, True) self.assertEqual(len(subvols), 0) succ = BlockDev.btrfs_create_subvolume(TEST_MNT, "subvol1") self.assertTrue(succ) subvols = BlockDev.btrfs_list_subvolumes(TEST_MNT, False) self.assertEqual(len(subvols), 1) self.assertEqual(subvols[0].parent_id, 5) self.assertEqual(subvols[0].path, "subvol1")
def test_list_subvolumes(self): """Verify that it is possible to get info about subvolumes""" succ = BlockDev.btrfs_create_volume([self.loop_dev], "myShinyBtrfs", None, None, None) self.assertTrue(succ) mount(self.loop_dev, TEST_MNT) subvols = BlockDev.btrfs_list_subvolumes(TEST_MNT, True) self.assertEqual(len(subvols), 0) succ = BlockDev.btrfs_create_subvolume(TEST_MNT, "subvol1", None) self.assertTrue(succ) subvols = BlockDev.btrfs_list_subvolumes(TEST_MNT, False) self.assertEqual(len(subvols), 1) self.assertEqual(subvols[0].parent_id, 5) self.assertEqual(subvols[0].path, "subvol1")
def test_create_snapshot(self): succ = BlockDev.btrfs_create_volume([self.loop_dev], "myShinyBtrfs", None, None) self.assertTrue(succ) mount(self.loop_dev, TEST_MNT) subvols = BlockDev.btrfs_list_subvolumes(TEST_MNT, True) self.assertEqual(len(subvols), 0) # R/W snapshot succ = BlockDev.btrfs_create_snapshot(TEST_MNT, TEST_MNT + "/snap1", False) self.assertTrue(succ) subvols = BlockDev.btrfs_list_subvolumes(TEST_MNT, True) self.assertEqual(len(subvols), 1) # RO snapshot succ = BlockDev.btrfs_create_snapshot(TEST_MNT, TEST_MNT + "/snap2", True) self.assertTrue(succ) subvols = BlockDev.btrfs_list_subvolumes(TEST_MNT, True) self.assertEqual(len(subvols), 2)
def test_list_subvols_weird_docker_data(self): """Verify that list_subvolumes works as expected on weird data from one Docker use case""" with fake_utils("tests/btrfs_subvols_docker"): subvols = BlockDev.btrfs_list_subvolumes("fake_dev", False) # make sure subvolumes are sorted properly (parents before children) seen = set() for subvol in subvols: seen.add(subvol) self.assertTrue(subvol.parent_id == BlockDev.BTRFS_MAIN_VOLUME_ID or any(subvol.parent_id == other.id for other in seen)) # check that one of the weird subvols is in the list of subvolumes self.assertTrue(any(subvol for subvol in subvols if subvol.path == "docker/btrfs/subvolumes/f2062b736fbabbe4da752632ac4deae87fcb916add6d7d8f5cecee4cbdc41fd9"))
def test_list_subvols_weird_docker_data(self): """Verify that list_subvolumes works as expected on weird data from one Docker use case""" with fake_utils("tests/btrfs_subvols_docker"): subvols = BlockDev.btrfs_list_subvolumes("fake_dev", False) # make sure subvolumes are sorted properly (parents before children) seen = set() for subvol in subvols: seen.add(subvol) self.assertTrue(subvol.parent_id == BlockDev.BTRFS_MAIN_VOLUME_ID or any(subvol.parent_id == other.id for other in seen)) # check that one of the weird subvols is in the list of subvolumes self.assertTrue(any(subvol for subvol in subvols if subvol.path == "docker/btrfs/subvolumes/f2062b736fbabbe4da752632ac4deae87fcb916add6d7d8f5cecee4cbdc41fd9"))