Exemplo n.º 1
0
    def __init__(self):
        super().__init__()
        # We need this so all the /dev/disk/* stuff is set up.
        udev.trigger(subsystem="block", action="change")

        self._modules = []

        self._disk_init_module = DiskInitializationModule()
        self._add_module(self._disk_init_module)

        self._disk_selection_module = DiskSelectionModule()
        self._add_module(self._disk_selection_module)

        self._bootloader_module = BootloaderModule()
        self._add_module(self._bootloader_module)

        self._auto_part_module = AutoPartitioningModule()
        self._add_module(self._auto_part_module)

        self._manual_part_module = ManualPartitioningModule()
        self._add_module(self._manual_part_module)

        self._dasd_module = None
        self._zfcp_module = None

        if arch.is_s390():
            self._dasd_module = DASDModule()
            self._add_module(self._dasd_module)

            self._zfcp_module = ZFCPModule()
            self._add_module(self._zfcp_module)
Exemplo n.º 2
0
    def __init__(self):
        super().__init__()
        # Initialize Blivet.
        enable_installer_mode()

        # The storage model.
        self._storage = None
        self.storage_changed = Signal()

        # Initialize modules.
        self._modules = []

        self._disk_init_module = DiskInitializationModule()
        self._add_module(self._disk_init_module)

        self._disk_selection_module = DiskSelectionModule()
        self._add_module(self._disk_selection_module)

        self._snapshot_module = SnapshotModule()
        self._add_module(self._snapshot_module)

        self._bootloader_module = BootloaderModule()
        self._add_module(self._bootloader_module)

        self._fcoe_module = FCOEModule()
        self._add_module(self._fcoe_module)

        self._nvdimm_module = NVDIMMModule()
        self._add_module(self._nvdimm_module)

        self._dasd_module = None
        self._zfcp_module = None

        if arch.is_s390():
            self._dasd_module = DASDModule()
            self._add_module(self._dasd_module)

            self._zfcp_module = ZFCPModule()
            self._add_module(self._zfcp_module)

        # Initialize the partitioning modules.
        self._partitioning_modules = {}

        self._auto_part_module = AutoPartitioningModule()
        self._add_partitioning_module(AUTO_PARTITIONING.object_path,
                                      self._auto_part_module)

        self._manual_part_module = ManualPartitioningModule()
        self._add_partitioning_module(MANUAL_PARTITIONING.object_path,
                                      self._manual_part_module)

        self._custom_part_module = CustomPartitioningModule()
        self._add_partitioning_module(CUSTOM_PARTITIONING.object_path,
                                      self._custom_part_module)

        # Connect modules to signals.
        self.storage_changed.connect(self._snapshot_module.on_storage_reset)
Exemplo n.º 3
0
 def setUp(self):
     """Set up the module."""
     self.module = ManualPartitioningModule()
     self.interface = ManualPartitioningInterface(self.module)
Exemplo n.º 4
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)