Beispiel #1
0
class ManualPartitioningInterfaceTestCase(unittest.TestCase):
    """Test DBus interface of the manual partitioning module."""

    def setUp(self):
        """Set up the module."""
        self.module = ManualPartitioningModule()
        self.interface = ManualPartitioningInterface(self.module)

    def test_publication(self):
        """Test the DBus representation."""
        assert isinstance(self.module.for_publication(), ManualPartitioningInterface)

    def _check_dbus_property(self, *args, **kwargs):
        check_dbus_property(
            MANUAL_PARTITIONING,
            self.interface,
            *args, **kwargs
        )

    def test_mount_points_property(self):
        """Test the mount points property."""
        self._check_dbus_property(
            "Requests",
            []
        )

        request = {
            "mount-point": get_variant(Str, "/boot"),
            "device-spec": get_variant(Str, "/dev/sda1"),
            "reformat": get_variant(Bool, False),
            "format-type": get_variant(Str, ""),
            "format-options": get_variant(Str, ""),
            "mount-options": get_variant(Str, "")
        }
        self._check_dbus_property(
            "Requests",
            [request]
        )

        request = {
            "mount-point": get_variant(Str, "/boot"),
            "device-spec": get_variant(Str, "/dev/sda1"),
            "reformat": get_variant(Bool, True),
            "format-type": get_variant(Str, "xfs"),
            "format-options": get_variant(Str, "-L BOOT"),
            "mount-options": get_variant(Str, "user")
        }
        self._check_dbus_property(
            "Requests",
            [request]
        )

        request_1 = {
            "mount-point": get_variant(Str, "/boot"),
            "device-spec": get_variant(Str, "/dev/sda1"),
            "reformat": get_variant(Bool, False),
            "format-type": get_variant(Str, ""),
            "format-options": get_variant(Str, ""),
            "mount-options": get_variant(Str, "")
        }
        request_2 = {
            "mount-point": get_variant(Str, "/"),
            "device-spec": get_variant(Str, "/dev/sda2"),
            "reformat": get_variant(Bool, True),
            "format-type": get_variant(Str, ""),
            "format-options": get_variant(Str, ""),
            "mount-options": get_variant(Str, "")
        }
        self._check_dbus_property(
            "Requests",
            [request_1, request_2]
        )

    def _add_device(self, device):
        """Add a device to the device tree."""
        self.module.storage.devicetree._add_device(device)

    def test_gather_no_requests(self):
        """Test GatherRequests with no devices."""
        self.module.on_storage_changed(create_storage())
        assert self.interface.GatherRequests() == []

    def test_gather_unusable_requests(self):
        """Test GatherRequests with unusable devices."""
        self.module.on_storage_changed(create_storage())

        # Add device with no size.
        self._add_device(StorageDevice(
            "dev1",
            size=Size(0)
        ))

        assert self.interface.GatherRequests() == []

        # Add protected device.
        device = StorageDevice(
            "dev2",
            size=Size("1 GiB")
        )

        device.protected = True
        self._add_device(device)
        assert self.interface.GatherRequests() == []

        # Add unselected disk.
        self._add_device(DiskDevice(
            "dev3",
            size=Size("1 GiB")
        ))

        self.module.on_selected_disks_changed(["dev1", "dev2"])
        assert self.interface.GatherRequests() == []

    def test_gather_requests(self):
        """Test GatherRequests."""
        self.module.on_storage_changed(create_storage())

        self._add_device(StorageDevice(
            "dev1",
            size=Size("1 GiB"),
            fmt=get_format("ext4", mountpoint="/"))
        )

        self._add_device(StorageDevice(
            "dev2",
            size=Size("1 GiB"),
            fmt=get_format("swap"))
        )

        assert self.interface.GatherRequests() == [
            {
                'device-spec': get_variant(Str, '/dev/dev1'),
                'format-options': get_variant(Str, ''),
                'format-type': get_variant(Str, 'ext4'),
                'mount-options': get_variant(Str, ''),
                'mount-point': get_variant(Str, '/'),
                'reformat': get_variant(Bool, False)
            },
            {
                'device-spec': get_variant(Str, '/dev/dev2'),
                'format-options': get_variant(Str, ''),
                'format-type': get_variant(Str, 'swap'),
                'mount-options': get_variant(Str, ''),
                'mount-point': get_variant(Str, ''),
                'reformat': get_variant(Bool, False)
            }
        ]

    def test_gather_requests_combination(self):
        """Test GatherRequests with user requests."""
        self.module.on_storage_changed(create_storage())

        # Add devices dev1 and dev2.
        self._add_device(StorageDevice(
            "dev1",
            size=Size("1 GiB"),
            fmt=get_format("ext4", mountpoint="/"))
        )

        self._add_device(StorageDevice(
            "dev2",
            size=Size("1 GiB"),
            fmt=get_format("swap"))
        )

        # Add requests for dev1 and dev3.
        req1 = MountPointRequest()
        req1.device_spec = '/dev/dev1'
        req1.format_options = '-L BOOT'
        req1.format_type = 'xfs'
        req1.mount_options = 'user'
        req1.mount_point = '/home'
        req1.reformat = True

        req3 = MountPointRequest()
        req3.device_spec = '/dev/dev3'
        req3.mount_point = '/'

        self.module.set_requests([req1, req3])

        # Get requests for dev1 and dev2.
        assert self.interface.GatherRequests() == [
            {
                'device-spec': get_variant(Str, '/dev/dev1'),
                'format-options': get_variant(Str, '-L BOOT'),
                'format-type': get_variant(Str, 'xfs'),
                'mount-options': get_variant(Str, 'user'),
                'mount-point': get_variant(Str, '/home'),
                'reformat': get_variant(Bool, True)
            },
            {
                'device-spec': get_variant(Str, '/dev/dev2'),
                'format-options': get_variant(Str, ''),
                'format-type': get_variant(Str, 'swap'),
                'mount-options': get_variant(Str, ''),
                'mount-point': get_variant(Str, ''),
                'reformat': get_variant(Bool, False)
            }
        ]

    @patch_dbus_publish_object
    def test_configure_with_task(self, publisher):
        """Test ConfigureWithTask."""
        self.module.on_storage_changed(Mock())
        task_path = self.interface.ConfigureWithTask()

        obj = check_task_creation(task_path, publisher, ManualPartitioningTask)

        assert obj.implementation._storage == self.module.storage
        assert obj.implementation._requests == self.module.requests
Beispiel #2
0
 def setUp(self):
     """Set up the module."""
     self.module = ManualPartitioningModule()
     self.interface = ManualPartitioningInterface(self.module)
 def for_publication(self):
     """Return a DBus representation."""
     return ManualPartitioningInterface(self)