Ejemplo n.º 1
0
 def publish(self):
     """Publish the module."""
     DBus.publish_object(MANUAL_PARTITIONING.object_path,
                         ManualPartitioningInterface(self))
Ejemplo n.º 2
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 publication_test(self):
        """Test the DBus representation."""
        self.assertIsInstance(self.module.for_publication(),
                              ManualPartitioningInterface)

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

    def enabled_property_test(self):
        """Test the enabled property."""
        self._test_dbus_property("Enabled", True)

        self._test_dbus_property("Enabled", False)

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

        in_value = [{"mount-point": "/boot", "device-spec": "/dev/sda1"}]

        out_value = [{
            "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._test_dbus_property("Requests", in_value, out_value)

        in_value = [{
            "mount-point": "/boot",
            "device-spec": "/dev/sda1",
            "reformat": True,
            "format-type": "xfs",
            "format-options": "-L BOOT",
            "mount-options": "user"
        }]

        out_value = [{
            "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._test_dbus_property(
            "Requests",
            in_value,
            out_value,
        )

        in_value = [{
            "mount-point": "/boot",
            "device-spec": "/dev/sda1"
        }, {
            "mount-point": "/",
            "device-spec": "/dev/sda2",
            "reformat": True
        }]

        out_value = [{
            "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, "")
        }, {
            "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._test_dbus_property("Requests", in_value, out_value)

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

    def gather_no_requests_test(self):
        """Test GatherRequests with no devices."""
        self.module.on_storage_reset(create_storage())
        self.assertEqual(self.interface.GatherRequests(), [])

    def gather_unusable_requests_test(self):
        """Test GatherRequests with unusable devices."""
        self.module.on_storage_reset(create_storage())

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

        self.assertEqual(self.interface.GatherRequests(), [])

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

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

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

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

    def gather_requests_test(self):
        """Test GatherRequests."""
        self.module.on_storage_reset(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")))

        self.assertEqual(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 gather_requests_combination_test(self):
        """Test GatherRequests with user requests."""
        self.module.on_storage_reset(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.
        self.assertEqual(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 configure_with_task_test(self, publisher):
        """Test ConfigureWithTask."""
        self.module.on_storage_reset(Mock())
        task_path = self.interface.ConfigureWithTask()

        obj = check_task_creation(self, task_path, publisher,
                                  ManualPartitioningTask)

        self.assertEqual(obj.implementation._storage, self.module.storage)

    @patch_dbus_publish_object
    def validate_with_task_test(self, publisher):
        """Test ValidateWithTask."""
        self.module.on_storage_reset(Mock())
        task_path = self.interface.ValidateWithTask()

        obj = check_task_creation(self, task_path, publisher,
                                  StorageValidateTask)

        self.assertEqual(obj.implementation._storage, self.module.storage)
Ejemplo n.º 3
0
 def setUp(self):
     """Set up the module."""
     self.module = ManualPartitioningModule()
     self.interface = ManualPartitioningInterface(self.module)
Ejemplo n.º 4
0
 def for_publication(self):
     """Return a DBus representation."""
     return ManualPartitioningInterface(self)