Example #1
0
    def runTest(self):
        self.assertTrue(self._part.set_system(_ped.file_system_type_get("fat32")))

        self.assertRaises(TypeError, self._part.set_system, 47)

        # Partitions that are inactive cannot have the system type set.
        self._part = _ped.Partition(self._disk, _ped.PARTITION_FREESPACE, 0, 100)
        self.assertRaises(_ped.PartitionException, self._part.set_system, _ped.file_system_type_get("ext2"))
Example #2
0
    def runTest(self):
        self.assertTrue(self._part.set_system(_ped.file_system_type_get("fat32")))

        self.assertRaises(TypeError, self._part.set_system, 47)

        # Partitions that are inactive cannot have the system type set.
        self._part = _ped.Partition(self._disk, _ped.PARTITION_FREESPACE, 0, 100)
        self.assertRaises(_ped.PartitionException, self._part.set_system,
                          _ped.file_system_type_get("ext2"))
Example #3
0
    def runTest(self):
        for f in ["affs0", "amufs", "apfs1", "asfs", "btrfs", "ext2", "ext3", "ext4", "fat16",
                  "fat32", "hfs", "hfs+", "hfsx", "hp-ufs", "jfs", "linux-swap",
                  "ntfs", "reiserfs", "sun-ufs", "xfs"]:
            # may be missing some filesystem types depending on the parted
            # build on the test system
            try:
                t = _ped.file_system_type_get(f)
                self.assertIsInstance(_ped.file_system_type_get(f), _ped.FileSystemType, "Could not get fs type %s" % f)
            except _ped.UnknownTypeException:
                pass

        self.assertRaises(_ped.UnknownTypeException, _ped.file_system_type_get, "nosuch")
Example #4
0
def create_partitions(device_path, partitions):
    try:
        device = parted.getDevice(device_path)
        disk = parted.Disk(device)

        # prompt user before wiping out disk...
        disk.deleteAllPartitions()
        disk.commitToDevice()
        disk.commitToOS()
    except parted.DiskLabelException:
        print "disk is not initialized, ignoring"

    # create volatile store for new partition information
    # create fat, ext4 and swap partition
    disk = parted.freshDisk(device, _ped.disk_type_get("msdos"))

    constraint = parted.Constraint(device=device)
    max_length_sectors = disk.device.getLength()
    fat32_size = mb_to_sector(disk, partitions[0]['length'])
    swap_size = mb_to_sector(disk, partitions[2]['length'])
    ext4_size = max_length_sectors - (fat32_size+swap_size)
    fat32_geom = parted.Geometry(device=device, start=0, length=fat32_size)
    ext4_geom = parted.Geometry(device=device, start=fat32_size, length=ext4_size)
    swap_geom = parted.Geometry(device=device, start=ext4_size+fat32_size, length=swap_size)
    for part_type, geom in [("fat32", fat32_geom), ("ext4", ext4_geom), ("linux-swap", swap_geom)]:
        print "creating %s with geom: %s" % (part_type, geom)
        partition = parted.Partition(disk=disk, type=parted.PARTITION_NORMAL, geometry=geom)
        disk.addPartition(partition,constraint=constraint)
        part_type_ped = _ped.file_system_type_get(part_type)
        partition.getPedPartition().set_system(part_type_ped)
    disk.commitToDevice()
    disk.commitToOS()
Example #5
0
    def runTest(self):
        # Check that not passing args to _ped.Partition.__init__ is caught.
        self.assertRaises(TypeError, _ped.Partition)

        # Or passing the arguments in the wrong order.
        self.assertRaises(TypeError, _ped.Partition, _ped.file_system_type_get("ext2"),
                                                     _ped.PARTITION_NORMAL, self._disk, 0, 100)

        part = _ped.Partition(self._disk, _ped.PARTITION_NORMAL, 0, 100,
                              _ped.file_system_type_get("ext2"))
        self.assertIsInstance(part, _ped.Partition)

        # You don't need to pass a filesystem type at all, since this partition
        # might be FREESPACE or METADATA.
        part = _ped.Partition(self._disk, _ped.PARTITION_NORMAL, 0, 100)
        self.assertIsInstance(part, _ped.Partition)
Example #6
0
    def runTest(self):
        # Test that passing the kwargs to __init__ works.
        self.assertEqual(self._part.disk, self._disk)
        self.assertIsInstance(self._part.geom, _ped.Geometry)
        self.assertEqual(self._part.type, _ped.PARTITION_NORMAL)
        self.assertEqual(self._part.fs_type.name, "ext2")

        # Test that setting the RW attributes directly works.
        self._part.type = _ped.PARTITION_EXTENDED
        self.assertEqual(getattr(self._part, "type"), _ped.PARTITION_EXTENDED)

        # Test that setting the RO attributes directly doesn't work.
        exn = (AttributeError, TypeError)
        self.assertRaises(exn, setattr, self._part, "num", 1)
        self.assertRaises(exn, setattr, self._part, "fs_type",
            _ped.file_system_type_get("fat32"))
        self.assertRaises(exn, setattr, self._part, "geom",
                                     _ped.Geometry(self._device, 10, 20))
        self.assertRaises(exn, setattr, self._part, "disk", self._disk)

        # Check that values have the right type.
        self.assertRaises(exn, setattr, self._part, "type", "blah")

        # Check that looking for invalid attributes fails properly.
        self.assertRaises(AttributeError, getattr, self._part, "blah")
Example #7
0
 def setUp(self):
     RequiresDisk.setUp(self)
     self._part = _ped.Partition(disk=self._disk,
                                 type=_ped.PARTITION_NORMAL,
                                 start=0,
                                 end=100,
                                 fs_type=_ped.file_system_type_get("ext2"))
    def runTest(self):
        # Check that not passing args to _ped.Partition.__init__ is caught.
        self.assertRaises(TypeError, _ped.Partition)

        # Or passing the arguments in the wrong order.
        self.assertRaises(TypeError, _ped.Partition, _ped.file_system_type_get("ext2"),
                                                     _ped.PARTITION_NORMAL, self._disk, 0, 100)

        part = _ped.Partition(self._disk, _ped.PARTITION_NORMAL, 0, 100,
                              _ped.file_system_type_get("ext2"))
        self.assertTrue(isinstance(part, _ped.Partition))

        # You don't need to pass a filesystem type at all, since this partition
        # might be FREESPACE or METADATA.
        part = _ped.Partition(self._disk, _ped.PARTITION_NORMAL, 0, 100)
        self.assertTrue(isinstance(part, _ped.Partition))
Example #9
0
    def runTest(self):
        # Test that passing the kwargs to __init__ works.
        self.assertEqual(self._part.disk, self._disk)
        self.assertIsInstance(self._part.geom, _ped.Geometry)
        self.assertEqual(self._part.type, _ped.PARTITION_NORMAL)
        self.assertEqual(self._part.fs_type.name, "ext2")

        # Test that setting the RW attributes directly works.
        self._part.type = _ped.PARTITION_EXTENDED
        self.assertEqual(getattr(self._part, "type"), _ped.PARTITION_EXTENDED)

        # Test that setting the RO attributes directly doesn't work.
        exn = (AttributeError, TypeError)
        self.assertRaises(exn, setattr, self._part, "num", 1)
        self.assertRaises(exn, setattr, self._part, "fs_type",
                          _ped.file_system_type_get("fat32"))
        self.assertRaises(exn, setattr, self._part, "geom",
                          _ped.Geometry(self._device, 10, 20))
        self.assertRaises(exn, setattr, self._part, "disk", self._disk)

        # Check that values have the right type.
        self.assertRaises(exn, setattr, self._part, "type", "blah")

        # Check that looking for invalid attributes fails properly.
        self.assertRaises(AttributeError, getattr, self._part, "blah")
    def runTest(self):
        fstype = _ped.file_system_type_get("ext3")

        self.assertIsInstance(fstype, _ped.FileSystemType)
        self.assertEqual(fstype.name, "ext3")
        self.assertEqual(getattr(fstype, "name"), "ext3")
        self.assertRaises(AttributeError, setattr, fstype, "name", "vfat")
        self.assertRaises(AttributeError, getattr, fstype, "junk")
    def runTest(self):
        fstype = _ped.file_system_type_get("ext3")

        self.assertTrue(isinstance(fstype, _ped.FileSystemType))
        self.assertEqual(fstype.name, "ext3")
        self.assertEqual(getattr(fstype, "name"), "ext3")
        self.assertRaises(AttributeError, setattr, fstype, "name", "vfat")
        self.assertRaises(AttributeError, getattr, fstype, "junk")
Example #12
0
    def runTest(self):
        for f in ["affs0", "amufs", "apfs1", "asfs", "ext2", "ext3", "fat16",
                  "fat32", "hfs", "hfs+", "hfsx", "hp-ufs", "jfs", "linux-swap",
                  "ntfs", "reiserfs", "sun-ufs", "xfs"]:
            self.assertIsInstance(_ped.file_system_type_get(f), _ped.FileSystemType,
                         "Could not get fs type %s" % f)

        self.assertRaises(_ped.UnknownTypeException, _ped.file_system_type_get, "nosuch")
Example #13
0
    def runTest(self):
        fstype = _ped.file_system_type_get("ext2")

        with self.assertRaises(TypeError):
            _ped.FileSystem(type=None, geom=None)
            _ped.FileSystem(type=fstype, geom=None)

        fs = _ped.FileSystem(type=fstype, geom=self._geometry)
        self.assertIsInstance(fs, _ped.FileSystem)
Example #14
0
    def runTest(self):
        fstype = _ped.file_system_type_get("ext2")

        with self.assertRaises(TypeError):
            _ped.FileSystem(type=None, geom=None)
            _ped.FileSystem(type=fstype, geom=None)

        fs = _ped.FileSystem(type=fstype, geom=self._geometry)
        self.assertIsInstance(fs, _ped.FileSystem)
Example #15
0
    def runTest(self):
        fstype = _ped.file_system_type_get("ext2")
        fs = _ped.FileSystem(type=fstype, geom=self._geometry)

        self.assertIsInstance(fs, _ped.FileSystem)
        self.assertEqual(fs.type, fstype)
        self.assertEqual(getattr(fs, "type"), fstype)
        # read-only attribute
        self.assertRaises(TypeError, setattr, fs, "type", fstype)
        self.assertRaises(AttributeError, getattr, fs, "junk")
Example #16
0
    def runTest(self):
        fstype = _ped.file_system_type_get("ext2")
        fs = _ped.FileSystem(type=fstype, geom=self._geometry)

        self.assertIsInstance(fs, _ped.FileSystem)
        self.assertEqual(fs.type, fstype)
        self.assertEqual(getattr(fs, "type"), fstype)
        # read-only attribute
        self.assertRaises(TypeError, setattr, fs, "type", fstype)
        self.assertRaises(AttributeError, getattr, fs, "junk")
Example #17
0
    def runTest(self):
        # The DOS disklabel does not support naming.
        self.assertRaises(_ped.PartitionException, self._part.set_name, "blah")

        # These should work.
        self._disk = _ped.disk_new_fresh(self._device, _ped.disk_type_get("mac"))
        self._part = _ped.Partition(self._disk, _ped.PARTITION_NORMAL, 0, 100, _ped.file_system_type_get("fat32"))
        self.assertTrue(self._part.set_name("blah"))
        self.assertEqual(self._part.get_name(), "blah")

        # Partitions that are inactive won't work.
        self._part = _ped.Partition(self._disk, _ped.PARTITION_FREESPACE, 0, 100)
        self.assertRaises(_ped.PartitionException, self._part.get_name)
Example #18
0
    def runTest(self):
        # The DOS disklabel does not support naming.
        self.assertRaises(_ped.PartitionException, self._part.set_name, "blah")

        # These should work.
        self._disk = _ped.disk_new_fresh(self._device, _ped.disk_type_get("mac"))
        self._part = _ped.Partition(self._disk, _ped.PARTITION_NORMAL, 0, 100,
                                    _ped.file_system_type_get("fat32"))
        self.assertTrue(self._part.set_name("blah"))
        self.assertEqual(self._part.get_name(), "blah")

        # Partitions that are inactive won't work.
        self._part = _ped.Partition(self._disk, _ped.PARTITION_FREESPACE, 0, 100)
        self.assertRaises(_ped.PartitionException, self._part.get_name)
Example #19
0
    def addPartition(self, type, filesystemType, start, end, flags = []):
        self._isSetup = True
        constraint = self._device.getConstraint()
        geom = parted.Geometry(self._device, start, end=end)
        #FIXME:parted.Partition needs filesystem??
        filesystem = _ped.file_system_type_get(filesystemType)
        part = parted.Partition(self._disk, type, filesystem, geom)

        for flag in flags:
            part.setFlag(flag)

        try:
            self._isSetup = True
            return self._disk.addPartition(part, constraint)
        except parted.error, e:
            raise DeviceError, e
Example #20
0
    def runTest(self):
        # The DOS disklabel does not support naming.
        self.assertRaises(_ped.PartitionException, self._part.get_name)

        # Partitions that are inactive won't work either.
        self._part = _ped.Partition(self._disk, _ped.PARTITION_FREESPACE, 0, 100)
        self.assertRaises(_ped.PartitionException, self._part.get_name)

        # Mac disk labels do support naming, but there still has to be a name.
        self._disk = _ped.disk_new_fresh(self._device, _ped.disk_type_get("mac"))
        self._part = _ped.Partition(self._disk, _ped.PARTITION_NORMAL, 0, 100, _ped.file_system_type_get("fat32"))
        self.assertEqual(self._part.get_name(), "untitled")

        # Finally, Mac disk labels with a name will work.
        self._part.set_name("blah")
        self.assertEqual(self._part.get_name(), "blah")
Example #21
0
    def runTest(self):
        # The DOS disklabel does not support naming.
        self.assertRaises(_ped.PartitionException, self._part.get_name)

        # Partitions that are inactive won't work either.
        self._part = _ped.Partition(self._disk, _ped.PARTITION_FREESPACE, 0, 100)
        self.assertRaises(_ped.PartitionException, self._part.get_name)

        # Mac disk labels do support naming, but there still has to be a name.
        self._disk = _ped.disk_new_fresh(self._device, _ped.disk_type_get("mac"))
        self._part = _ped.Partition(self._disk, _ped.PARTITION_NORMAL, 0, 100,
                                    _ped.file_system_type_get("fat32"))
        self.assertEqual(self._part.get_name(), "untitled")

        # Finally, Mac disk labels with a name will work.
        self._part.set_name("blah")
        self.assertEqual(self._part.get_name(), "blah")
Example #22
0
 def runTest(self):
     fstype = _ped.file_system_type_get("ext2")
     fs = _ped.FileSystem(type=fstype, geom=self._geometry)
     # don't use assertEqual b/c __str__ includes memory addresses of
     # fstype and geom objects. This is easier.
     self.assertTrue(str(fs).startswith("_ped.FileSystem instance --"))
    def runTest(self):
        fstype = _ped.file_system_type_get("ext3")

        self.assertEqual(str(fstype), "_ped.FileSystemType instance --\n  name: ext3")
    def runTest(self):
        fstype = _ped.file_system_type_get("ext3")

        self.assertEqual(str(fstype), "_ped.FileSystemType instance --\n  name: ext3")
Example #25
0
 def runTest(self):
     fstype = _ped.file_system_type_get("ext2")
     fs = _ped.FileSystem(type=fstype, geom=self._geometry)
     # don't use assertEqual b/c __str__ includes memory addresses of
     # fstype and geom objects. This is easier.
     self.assertTrue(str(fs).startswith("_ped.FileSystem instance --"))
Example #26
0
 def setUp(self):
     RequiresDisk.setUp(self)
     self._part = _ped.Partition(disk=self._disk, type=_ped.PARTITION_NORMAL,
                                 start=0, end=100, fs_type=_ped.file_system_type_get("ext2"))