예제 #1
0
    def runTest(self):
        # Check that not passing args to _ped.Geometry.__init__ is caught.
        self.assertRaises(TypeError, _ped.Geometry)

        # Or passing in the parameters in the wrong order.
        self.assertRaises(TypeError, _ped.Geometry, 0, self._device, 100)

        # And then the correct ways of creating a _ped.Geometry.
        self.assertIsInstance(_ped.Geometry(self._device, 0, 100), _ped.Geometry)
        self.assertIsInstance(_ped.Geometry(self._device, 0, 100, 101), _ped.Geometry)
예제 #2
0
    def runTest(self):
        self.assertRaises(TypeError, _ped.constraint_any, None)

        constraint = _ped.constraint_any(self._device)
        self.assertIsInstance(constraint, _ped.Constraint)

        for testGeom in [_ped.Geometry(self._device, 0, 5),
                         _ped.Geometry(self._device, 10, 25),
                         _ped.Geometry(self._device, 0, 100)]:
            self.assertTrue(constraint.is_solution(testGeom))
예제 #3
0
    def runTest(self):
        self.assertRaises(TypeError, _ped.constraint_new_from_max, None)

        max = _ped.Geometry(self._device, 10, 20)
        constraint = _ped.constraint_new_from_max(max)

        self.assertIsInstance(constraint, _ped.Constraint)
        self.assertTrue(constraint.is_solution(_ped.Geometry(self._device, 10, 20)))
        self.assertFalse(constraint.is_solution(_ped.Geometry(self._device, 5, 25)))
        self.assertTrue(constraint.is_solution(_ped.Geometry(self._device, 11, 19)))
        self.assertFalse(constraint.is_solution(_ped.Geometry(self._device, 15, 25)))
예제 #4
0
    def setUp(self):
        RequiresDevice.setUp(self)
        align1 = _ped.Alignment(10, 5)
        align2 = _ped.Alignment(10, 5)
        geom1 = _ped.Geometry(self._device, 0, 50)
        geom2 = _ped.Geometry(self._device, 25, 50)

        self.c = _ped.Constraint(align1,
                                 align2,
                                 geom1,
                                 geom2,
                                 min_size=10,
                                 max_size=100)
예제 #5
0
    def setUp(self):
        self._fileSystemType = {}
        type = _ped.file_system_type_get_next()
        self._fileSystemType[type.name] = type

        while True:
            try:
                type = _ped.file_system_type_get_next(type)
                self._fileSystemType[type.name] = type
            except:
                break

        (
            fd,
            self.path,
        ) = tempfile.mkstemp(prefix="temp-device-")
        f = os.fdopen(fd)
        f.seek(140000)
        os.write(fd, b"0")
        f.close()

        os.system("/sbin/mke2fs -F -q %s" % (self.path, ))

        self._device = _ped.device_get(self.path)
        self._geometry = _ped.Geometry(self._device, 0,
                                       self._device.length - 1)
예제 #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")
예제 #7
0
    def setUp(self):
        self.addCleanup(self.removeTempDevice)

        self._fileSystemType = {}
        ty = _ped.file_system_type_get_next()
        self._fileSystemType[ty.name] = ty

        while True:
            try:
                ty = _ped.file_system_type_get_next(ty)
                self._fileSystemType[ty.name] = ty
            except (IndexError, TypeError, _ped.UnknownTypeException):
                break

        self.temp_prefix = "temp-device-"
        (
            self.fd,
            self.path,
        ) = tempfile.mkstemp(prefix=self.temp_prefix)
        self.f = os.fdopen(self.fd)
        self.f.seek(140000)
        os.write(self.fd, b"0")
        self.f.close()

        os.system("mke2fs -F -q %s" % (self.path, ))

        self._device = _ped.device_get(self.path)
        self._geometry = _ped.Geometry(self._device, 0,
                                       self._device.length - 1)
예제 #8
0
    def runTest(self):
        align1 = _ped.Alignment(10, 5)
        align2 = _ped.Alignment(10, 5)
        geom1 = _ped.Geometry(self._device, 0, 50)
        geom2 = _ped.Geometry(self._device, 25, 50)

        # Check that not passing enough args to _ped.Constraint.__init__ is caught.
        self.assertRaises(TypeError, _ped.Constraint)
        self.assertRaises(TypeError, _ped.Constraint, align1, align2)

        # Or the parameters in the wrong order.
        self.assertRaises(TypeError, _ped.Constraint, align1, align2, 10, 100,
                          geom1, geom2)

        # And then the correct way of creating a _ped.Constraint.
        c = _ped.Constraint(align1, align2, geom1, geom2, 10, 100)
        self.assertIsInstance(c, _ped.Constraint)
예제 #9
0
    def __init__(self, device=None, start=None, length=None, end=None,
                 PedGeometry=None):
        """Create a new Geometry object for the given _ped.Device that extends
           for length sectors from the start sector.  Optionally, an end sector
           can also be provided."""
        if PedGeometry:
            self.__geometry = PedGeometry

            if device is None:
                self._device = parted.Device(PedDevice=self.__geometry.dev)
            else:
                self._device = device
        elif not end:
            self._device = device
            self.__geometry = _ped.Geometry(self.device.getPedDevice(), start, length)
        elif not length and (end > start):
            self._device = device
            self.__geometry = _ped.Geometry(self.device.getPedDevice(), start, (end - start + 1), end=end)
        elif start and length and end and (end > start):
            self._device = device
            self.__geometry = _ped.Geometry(self.device.getPedDevice(), start, length, end=end)
        else:
            raise parted.GeometryException("must specify PedGeometry or (device, start, length) or (device, start, end) or (device, start, length, end)")
예제 #10
0
    def runTest(self):
        geom = _ped.Geometry(self._device, 0, 100)

        self.assertRaises(TypeError, _ped.constraint_exact, None)

        constraint = _ped.constraint_exact(geom)
        self.assertIsInstance(constraint, _ped.Constraint)

        for testGeom in [_ped.Geometry(self._device, 1, 100),
                         _ped.Geometry(self._device, 0, 99),
                         _ped.Geometry(self._device, 10, 20),
                         _ped.Geometry(self._device, 50, 101)]:
            self.assertFalse(constraint.is_solution(testGeom))

        self.assertTrue(constraint.is_solution(_ped.Geometry(self._device, 0, 100)))
예제 #11
0
 def setUp(self):
     RequiresDevice.setUp(self)
     self.g1 = _ped.Geometry(self._device, start=0, length=100)
     self.g2 = _ped.Geometry(self._device, start=0, length=100)
예제 #12
0
 def setUp(self):
     RequiresDevice.setUp(self)
     self.g = _ped.Geometry(self._device, start=0, length=100)
     self.a = _ped.Alignment(10, 0)
예제 #13
0
 def setUp(self):
     RequiresDeviceAlignment.setUp(self)
     self.trivialA = _ped.Alignment(10, 0)
     self.complexA = _ped.Alignment(512, 34)
     self.geometry = _ped.Geometry(self._device, start=0, length=100)
     self.sector = 47
예제 #14
0
 def setUp(self):
     RequiresDevice.setUp(self)
     self.g = _ped.Geometry(self._device, start=0, length=100)
     self.dup = self.g.duplicate()
예제 #15
0
 def setUp(self):
     RequiresDevice.setUp(self)
     self.c1 = self._device.get_constraint()
     self.g1 = _ped.Geometry(self._device, 1, 8)
예제 #16
0
    def runTest(self):
        self.assertRaises(TypeError, _ped.constraint_new_from_min_max, None)

        # min is required to be within max, so test various combinations of
        # that not being the case.
        self.assertRaises(_ped.CreateException,
                          _ped.constraint_new_from_min_max,
                          _ped.Geometry(self._device, 0, 10),
                          _ped.Geometry(self._device, 15, 25))
        self.assertRaises(_ped.CreateException,
                          _ped.constraint_new_from_min_max,
                          _ped.Geometry(self._device, 10, 20),
                          _ped.Geometry(self._device, 15, 25))

        # Now test a correct call.
        minimum = _ped.Geometry(self._device, 10, 20)
        maximum = _ped.Geometry(self._device, 0, 30)
        constraint = _ped.constraint_new_from_min_max(minimum, maximum)

        self.assertIsInstance(constraint, _ped.Constraint)
        self.assertTrue(
            constraint.is_solution(_ped.Geometry(self._device, 10, 20)))
        self.assertFalse(
            constraint.is_solution(_ped.Geometry(self._device, 11, 20)))
        self.assertTrue(
            constraint.is_solution(_ped.Geometry(self._device, 5, 25)))
        self.assertTrue(
            constraint.is_solution(_ped.Geometry(self._device, 0, 30)))
        self.assertFalse(
            constraint.is_solution(_ped.Geometry(self._device, 0, 35)))