Exemple #1
0
def create_new_root(storage, boot_drive):
    """Create a new root from the given devices.

    :param storage: an instance of Blivet
    :param boot_drive: a name of the bootloader drive
    :return: a new root
    """
    devices = filter_unsupported_disklabel_devices(
        collect_new_devices(storage=storage, boot_drive=boot_drive))

    bootloader_devices = filter_unsupported_disklabel_devices(
        collect_bootloader_devices(storage=storage, boot_drive=boot_drive))

    swaps = [d for d in devices if d.format.type == "swap"]

    mounts = {
        d.format.mountpoint: d
        for d in devices if getattr(d.format, "mountpoint", None)
    }

    for device in devices:
        if device in bootloader_devices:
            mounts[device.format.name] = device

    return Root(name=get_new_root_name(), mounts=mounts, swaps=swaps)
    def collect_supported_systems_test(self, update_size_info):
        """Test CollectSupportedSystems."""
        dev1 = DiskDevice("dev1", fmt=get_format("disklabel"))
        dev2 = StorageDevice(
            "dev2",
            parents=[dev1],
            fmt=get_format("ext4", mountpoint="/", exists=True),
        )
        dev3 = StorageDevice("dev3",
                             parents=[dev1],
                             fmt=get_format("swap", exists=True))

        self._add_device(dev1)
        self._add_device(dev2)
        self._add_device(dev3)

        self.storage.roots = [
            Root(name="My Linux", mounts={"/": dev2}, swaps=[dev3])
        ]

        os_data_list = self.interface.CollectSupportedSystems()
        self.assertEqual(get_native(os_data_list), [{
            'os-name': 'My Linux',
            'mount-points': {
                '/': 'dev2'
            },
            'swap-devices': ['dev3']
        }])
Exemple #3
0
    def find_existing_systems_with_task_test(self, publisher):
        """Test FindExistingSystemsWithTask."""
        task_path = self.interface.FindExistingSystemsWithTask()

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

        self.assertEqual(obj.implementation._devicetree, self.module.storage.devicetree)

        roots = [Root(name="My Linux")]
        obj.implementation._set_result(roots)
        obj.implementation.succeeded_signal.emit()
        self.assertEqual(self.storage.roots, roots)
    def find_existing_systems_with_task_test(self, publisher):
        """Test FindExistingSystemsWithTask."""
        task_path = self.interface.FindExistingSystemsWithTask()

        publisher.assert_called_once()
        object_path, obj = publisher.call_args[0]

        self.assertEqual(task_path, object_path)
        self.assertIsInstance(obj, TaskInterface)

        self.assertIsInstance(obj.implementation, FindExistingSystemsTask)
        self.assertEqual(obj.implementation._devicetree,
                         self.module.storage.devicetree)

        roots = [Root(name="My Linux")]
        obj.implementation._set_result(roots)
        obj.implementation.succeeded_signal.emit()
        self.assertEqual(self.storage.roots, roots)
Exemple #5
0
    def get_existing_systems_test(self):
        """Test GetExistingSystems."""
        self.assertEqual(self.interface.GetExistingSystems(), [])

        root_device = StorageDevice("dev1", fmt=get_format("ext4"))
        swap_device = StorageDevice("dev2", fmt=get_format("swap"))

        self.storage.roots = [Root(
            name="My Linux",
            mounts={"/": root_device},
            swaps=[swap_device]
        )]

        self.assertEqual(self.interface.GetExistingSystems(), [{
            'os-name': get_variant(Str, 'My Linux'),
            'mount-points': get_variant(Dict[Str, Str], {'/': 'dev1'}),
            'swap-devices': get_variant(List[Str], ['dev2'])
        }])
def collect_roots(storage):
    """Collect roots of existing installations.

    :param storage: an instance of Blivet
    :return: a list of roots
    """
    roots = []
    supported_devices = set(filter_unsupported_disklabel_devices(storage.devices))

    # Get the name of the new installation.
    new_root_name = get_new_root_name()

    for root in storage.roots:
        # Get the name.
        name = root.name

        # Get the supported swap devices.
        swaps = [
            d for d in root.swaps
            if d in supported_devices
            and (d.format.exists or root.name == new_root_name)
        ]

        # Get the supported mount points.
        mounts = {
            m: d for m, d in root.mounts.items()
            if d in supported_devices
            and (d.format.exists or root.name == new_root_name)
            and d.disks
        }

        if not swaps and not mounts:
            continue

        # Add a root with supported devices.
        roots.append(Root(
            name=name,
            mounts=mounts,
            swaps=swaps
        ))

    return roots