コード例 #1
0
ファイル: module_blivet_test.py プロジェクト: dnsn/anaconda
    def unsupported_partitioning_test(self):
        """Test the UnsupportedPartitioningError."""
        # Forget imported modules from pyanaconda and blivetgui.
        for name in list(sys.modules):
            if name.startswith('pyanaconda') or name.startswith('blivetgui'):
                sys.modules.pop(name)

        # Disable the blivetgui package.
        sys.modules['blivetgui'] = None

        # Import the StorageModule again.
        from pyanaconda.modules.storage.storage import StorageModule

        # We should be able to create the Storage module
        storage_module = StorageModule()
        self.assertIsNotNone(storage_module.storage)

        # We should be able to create the Blivet module.
        from pyanaconda.modules.storage.partitioning.constants import PartitioningMethod
        blivet_module = storage_module.create_partitioning(PartitioningMethod.BLIVET)
        self.assertIsNotNone(blivet_module.storage)

        # Import the exception again.
        from pyanaconda.modules.common.errors.storage import UnsupportedPartitioningError

        # Handle the missing support.
        with self.assertRaises(UnsupportedPartitioningError):
            self.assertFalse(blivet_module.storage_handler)

        with self.assertRaises(UnsupportedPartitioningError):
            self.assertFalse(blivet_module.request_handler)

        with self.assertRaises(UnsupportedPartitioningError):
            request = pickle.dumps(("call", "get_disks", []))
            blivet_module.send_request(request)
コード例 #2
0
 def _process_kickstart(self, ks_in):
     """Process the kickstart."""
     storage_module = StorageModule()
     handler = storage_module.get_kickstart_handler()
     parser = storage_module.get_kickstart_parser(handler)
     parser.readKickstartFromString(ks_in)
     self.module.process_kickstart(handler)
コード例 #3
0
    def setUp(self):
        """Set up the module."""
        self.storage_module = StorageModule()
        self.storage_interface = StorageInterface(self.storage_module)

        self.module = self.storage_module._custom_part_module
        self.interface = CustomPartitioningInterface(self.module)
コード例 #4
0
class NVDIMMKickstartTestCase(unittest.TestCase):
    """Test updating of nvdimm command from UI.

    The update is done:
    - always by disk selection in UI.
    - optionally by reconfiguring NVDIMM in UI.
    """
    def setUp(self):
        self.storage_module = StorageModule()
        self.nvdimm_module = self.storage_module._nvdimm_module
        self.nvdimm_interface = NVDIMMInterface(self.nvdimm_module)

    def _read(self, input_ks):
        """Read the kickstart string."""
        with patch("pyanaconda.modules.storage.kickstart.nvdimm") as nvdimm:
            # Fake the existence of the namespaces.
            nvdimm.namespaces = ["namespace0.0", "namespace1.0"]

            # Parse the kickstart now.
            self.storage_module.read_kickstart(input_ks)

    def _use(self, namespaces):
        """Represents update for NVDIMM disks selected in UI."""
        self.nvdimm_module.set_namespaces_to_use(namespaces=namespaces)

    def _reconfigure(self, namespace, sector_size):
        """Represents update for NVDIMM disk reconfigured in UI."""
        self.nvdimm_module.update_action(namespace=namespace,
                                         mode=NVDIMM_MODE_SECTOR,
                                         sector_size=sector_size)

    def _check(self, expected_ks):
        """Check the generated kickstart."""
        self.assertEqual(self.storage_module.generate_kickstart().strip(),
                         dedent(expected_ks).strip())

    def _check_ignored(self, expected_devices):
        """Check the ignored devices."""
        with patch(
                "pyanaconda.modules.storage.nvdimm.nvdimm.nvdimm") as nvdimm:
            nvdimm.namespaces = {
                "namespace0.0":
                Mock(blockdev="pmem0",
                     mode=blockdev.NVDIMMNamespaceMode.SECTOR),
                "namespace1.0":
                Mock(blockdev="pmem1",
                     mode=blockdev.NVDIMMNamespaceMode.SECTOR),
                "namespace2.0":
                Mock(blockdev="pmem2",
                     mode=blockdev.NVDIMMNamespaceMode.MEMORY),
            }

            ignored_devices = self.nvdimm_module.get_devices_to_ignore()
            self.assertEqual(sorted(ignored_devices), expected_devices)

    # Test setting use from UI

    def ksuse_use_test(self):
        """Test updating of nvdimm commands based on device selection in UI."""
        input_ks = """
        nvdimm use --namespace=namespace0.0
        """
        expected_ks = """
        # NVDIMM devices setup
        nvdimm use --namespace=namespace0.0
        """
        self._read(input_ks)
        self._check_ignored(["pmem1", "pmem2"])
        self._use(["namespace0.0"])
        self._check(expected_ks)

    def ksuse_use2_test(self):
        """Test updating of nvdimm commands based on device selection in UI."""
        input_ks = """
        nvdimm use --namespace=namespace0.0
        """
        expected_ks = """
        # NVDIMM devices setup
        nvdimm use --namespace=namespace0.0
        nvdimm use --namespace=namespace1.0
        """
        self._read(input_ks)
        self._check_ignored(["pmem1", "pmem2"])
        self._use(["namespace0.0", "namespace1.0"])
        self._check(expected_ks)

    def ksuse_use_none_test(self):
        """Test updating of nvdimm commands based on device selection in UI."""
        input_ks = """
        nvdimm use --namespace=namespace0.0
        """
        expected_ks = """
        """
        self._read(input_ks)
        self._check_ignored(["pmem1", "pmem2"])
        self._use([])
        self._check(expected_ks)

    def ksnone_use2_test(self):
        """Test updating of nvdimm commands based on device selection in UI."""
        input_ks = """
        """
        expected_ks = """
        # NVDIMM devices setup
        nvdimm use --namespace=namespace0.0
        nvdimm use --namespace=namespace1.0
        """
        self._read(input_ks)
        self._check_ignored(["pmem0", "pmem1", "pmem2"])
        self._use(["namespace0.0", "namespace1.0"])
        self._check(expected_ks)

    def ksnone_repeated_use_test(self):
        """Test updating of nvdimm commands based on device selection in UI."""
        input_ks = """
        """
        expected_ks = """
        # NVDIMM devices setup
        nvdimm use --namespace=namespace0.0
        """
        self._read(input_ks)
        self._check_ignored(["pmem0", "pmem1", "pmem2"])
        self._use(["namespace0.0"])
        self._use(["namespace0.0"])
        self._check(expected_ks)

    def ksnone_use_none_test(self):
        """Test updating of nvdimm commands based on device selection in UI."""
        input_ks = """
        """
        expected_ks = """
        """
        self._read(input_ks)
        self._check_ignored(["pmem0", "pmem1", "pmem2"])
        self._use([])
        self._check(expected_ks)

    def ksnone_repeated_use_2_test(self):
        """Test updating of nvdimm commands based on device selection in UI."""
        input_ks = """
        """
        expected_ks = """
        # NVDIMM devices setup
        nvdimm use --namespace=namespace1.0
        """
        self._read(input_ks)
        self._check_ignored(["pmem0", "pmem1", "pmem2"])
        self._use(["namespace0.0"])
        # Next use should override the previous
        self._use(["namespace1.0"])
        self._check(expected_ks)

    def ksuse_another_use_test(self):
        """Test updating of nvdimm commands based on device selection in UI."""
        input_ks = """
        nvdimm use --namespace=namespace1.0
        """
        expected_ks = """
        # NVDIMM devices setup
        nvdimm use --namespace=namespace0.0
        """
        self._read(input_ks)
        self._check_ignored(["pmem0", "pmem2"])
        self._use(["namespace0.0"])
        self._check(expected_ks)

    def ksuse_none_test(self):
        """Test updating of nvdimm commands based on device selection in UI."""
        input_ks = """
        nvdimm use --namespace=namespace1.0
        """
        expected_ks = """
        """
        self._read(input_ks)
        self._check_ignored(["pmem0", "pmem2"])
        self._use([])
        self._check(expected_ks)

    def ksreconfigure_use_test(self):
        """Test updating of nvdimm commands based on device selection in UI."""
        input_ks = """
        nvdimm reconfigure --namespace=namespace0.0 --mode=sector --sectorsize=512
        """
        expected_ks = """
        # NVDIMM devices setup
        nvdimm reconfigure --namespace=namespace0.0 --mode=sector --sectorsize=512
        """
        self._read(input_ks)
        self._check_ignored(["pmem1", "pmem2"])
        self._use(["namespace0.0"])
        self._check(expected_ks)

    def ksreconfigure_use_none_test(self):
        """Test updating of nvdimm commands based on device selection in UI."""
        input_ks = """
        nvdimm reconfigure --namespace=namespace0.0 --mode=sector --sectorsize=512
        """
        expected_ks = """
        # NVDIMM devices setup
        nvdimm reconfigure --namespace=namespace0.0 --mode=sector --sectorsize=512
        """
        self._read(input_ks)
        self._check_ignored(["pmem1", "pmem2"])
        # Even when not used, the reconfiguration should go to generated kicksart
        self._use([])
        self._check(expected_ks)

    def ksreconfigure_another_use_test(self):
        """Test updating of nvdimm commands based on device selection in UI."""
        input_ks = """
        nvdimm reconfigure --namespace=namespace0.0 --mode=sector --sectorsize=512
        """
        expected_ks = """
        # NVDIMM devices setup
        nvdimm reconfigure --namespace=namespace0.0 --mode=sector --sectorsize=512
        nvdimm use --namespace=namespace1.0
        """
        self._read(input_ks)
        self._check_ignored(["pmem1", "pmem2"])
        self._use(["namespace1.0"])
        self._check(expected_ks)

    def ksreconfigure_ksuse_another_use_test(self):
        """Test updating of nvdimm commands based on device selection in UI."""
        input_ks = """
        nvdimm reconfigure --namespace=namespace0.0 --mode=sector --sectorsize=512
        nvdimm use --namespace=namespace1.0
        """
        expected_ks = """
        # NVDIMM devices setup
        nvdimm reconfigure --namespace=namespace0.0 --mode=sector --sectorsize=512
        """
        self._read(input_ks)
        self._check_ignored(["pmem2"])
        self._use(["namespace0.0"])
        self._check(expected_ks)

    def ksreconfigure_2_use_1_test(self):
        """Test updating of nvdimm commands based on device selection in UI."""
        input_ks = """
        nvdimm reconfigure --namespace=namespace0.0 --mode=sector --sectorsize=512
        nvdimm reconfigure --namespace=namespace1.0 --mode=sector --sectorsize=512
        """
        expected_ks = """
        # NVDIMM devices setup
        nvdimm reconfigure --namespace=namespace0.0 --mode=sector --sectorsize=512
        nvdimm reconfigure --namespace=namespace1.0 --mode=sector --sectorsize=512
        """
        self._read(input_ks)
        self._check_ignored(["pmem2"])
        self._use(["namespace0.0"])
        self._check(expected_ks)

    # Test reconfigure and use in UI
    # (if _reconfigure is done in UI, _use is always done as well)

    def ksnone_reconfigure_use_test(self):
        """Test updating of nvdimm commands based on device reconfiguration in UI."""
        input_ks = """
        """
        expected_ks = """
        # NVDIMM devices setup
        nvdimm reconfigure --namespace=namespace0.0 --mode=sector --sectorsize=512
        """
        self._read(input_ks)
        self._check_ignored(["pmem0", "pmem1", "pmem2"])
        self._reconfigure("namespace0.0", 512)
        self._use(["namespace0.0"])
        self._check(expected_ks)

    def ksnone_repeated_reconfigure_use_test(self):
        """Test updating of nvdimm commands based on device reconfiguration in UI."""
        input_ks = """
        """
        expected_ks = """
        # NVDIMM devices setup
        nvdimm reconfigure --namespace=namespace0.0 --mode=sector --sectorsize=4096
        """
        self._read(input_ks)
        self._check_ignored(["pmem0", "pmem1", "pmem2"])
        self._reconfigure("namespace0.0", 512)
        self._reconfigure("namespace0.0", 4096)
        self._use(["namespace0.0"])
        self._check(expected_ks)

    def ksnone_repeated_reconfigure_repeated_use_test(self):
        """Test updating of nvdimm commands based on device reconfiguration in UI."""
        input_ks = """
        """
        expected_ks = """
        # NVDIMM devices setup
        nvdimm reconfigure --namespace=namespace0.0 --mode=sector --sectorsize=512
        nvdimm reconfigure --namespace=namespace1.0 --mode=sector --sectorsize=512
        """
        self._read(input_ks)
        self._check_ignored(["pmem0", "pmem1", "pmem2"])
        self._reconfigure("namespace0.0", 512)
        self._use(["namespace0.0"])
        self._reconfigure("namespace1.0", 512)
        # Even when not used, reconfiguration goes to generated ks
        self._use(["namespace1.0"])
        self._check(expected_ks)

    def ksuse_reconfigure_other_use_other_test(self):
        """Test updating of nvdimm commands based on device reconfiguration in UI."""
        input_ks = """
        nvdimm use --namespace=namespace0.0
        """
        expected_ks = """
        # NVDIMM devices setup
        nvdimm reconfigure --namespace=namespace1.0 --mode=sector --sectorsize=512
        """
        self._read(input_ks)
        self._check_ignored(["pmem1", "pmem2"])
        self._reconfigure("namespace1.0", 512)
        self._use(["namespace1.0"])
        self._check(expected_ks)

    def ksuse_2_reconfigure_1_use_2_test(self):
        """Test updating of nvdimm commands based on device reconfiguration in UI."""
        input_ks = """
        nvdimm use --namespace=namespace0.0
        nvdimm use --namespace=namespace1.0
        """
        expected_ks = """
        # NVDIMM devices setup
        nvdimm reconfigure --namespace=namespace1.0 --mode=sector --sectorsize=512
        nvdimm use --namespace=namespace0.0
        """
        self._read(input_ks)
        self._check_ignored(["pmem2"])
        self._reconfigure("namespace1.0", 512)
        self._use(["namespace0.0", "namespace1.0"])
        self._check(expected_ks)

    def ksuse_reconfigure_other_use_none_test(self):
        """Test updating of nvdimm commands based on device reconfiguration in UI."""
        input_ks = """
        nvdimm use --namespace=namespace0.0
        """
        expected_ks = """
        # NVDIMM devices setup
        nvdimm reconfigure --namespace=namespace1.0 --mode=sector --sectorsize=512
        """
        self._read(input_ks)
        self._check_ignored(["pmem1", "pmem2"])
        self._reconfigure("namespace1.0", 512)

        # Even when not used, the reconfiguration should go to generated kickstart.
        self._use([])
        self._check(expected_ks)

    @patch("pyanaconda.modules.storage.kickstart.device_matches")
    def ksuse_blockdevs_test(self, device_matches):
        """Test using blockdevs."""
        input_ks = """
        nvdimm use --blockdev=pmem0,pmem2
        """
        expected_ks = """
        # NVDIMM devices setup
        nvdimm use --namespace=namespace0.0
        """
        device_matches.return_value = ["pmem0", "pmem2"]
        self._read(input_ks)
        self._check_ignored(["pmem1", "pmem2"])
        self._use(["namespace0.0"])
        self._check(expected_ks)
コード例 #5
0
 def setUp(self):
     self.storage_module = StorageModule()
     self.nvdimm_module = self.storage_module._nvdimm_module
     self.nvdimm_interface = NVDIMMInterface(self.nvdimm_module)
コード例 #6
0
 def setUp(self):
     """Set up the module."""
     self.storage_module = StorageModule()
コード例 #7
0
 def setUp(self):
     """Set up the module."""
     self.storage_module = StorageModule()
     self.storage_interface = StorageInterface(self.storage_module)
コード例 #8
0
class StorageInterfaceTestCase(unittest.TestCase):
    """Test DBus interface of the storage module."""
    def setUp(self):
        """Set up the module."""
        self.storage_module = StorageModule()
        self.storage_interface = StorageInterface(self.storage_module)

    @patch('pyanaconda.dbus.DBus.publish_object')
    def reset_with_task_test(self, publisher):
        """Test ResetWithTask."""
        task_path = self.storage_interface.ResetWithTask()

        # Check the task.
        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, StorageResetTask)
        self.assertIsNotNone(obj.implementation._storage)

        # Check the side affects.
        storage_changed_callback = Mock()
        self.storage_module.storage_changed.connect(storage_changed_callback)

        obj.implementation.stopped_signal.emit()
        storage_changed_callback.assert_called_once()

    @patch('pyanaconda.modules.storage.partitioning.validate.storage_checker')
    def apply_partitioning_test(self, storage_checker):
        """Test ApplyPartitioning."""
        storage_1 = Mock()
        storage_2 = storage_1.copy.return_value
        storage_3 = storage_2.copy.return_value

        report = StorageCheckerReport()
        storage_checker.check.return_value = report

        self.storage_module.set_storage(storage_1)
        self.assertEqual(self.storage_module.storage, storage_1)
        self.assertEqual(self.storage_module._auto_part_module.storage,
                         storage_2)

        self.storage_interface.ApplyPartitioning(AUTO_PARTITIONING.object_path)
        self.assertEqual(self.storage_module.storage, storage_3)

        with self.assertRaises(ValueError):
            self.storage_interface.ApplyPartitioning(ObjPath("invalid"))

    def collect_requirements_test(self):
        """Test CollectRequirements."""
        storage = Mock()
        storage.bootloader = GRUB2()
        storage.packages = ["lvm2"]

        self.storage_module.set_storage(storage)
        self.assertEqual(self.storage_interface.CollectRequirements(),
                         [{
                             "type": get_variant(Str, "package"),
                             "name": get_variant(Str, "lvm2"),
                             "reason": get_variant(Str, "storage")
                         }, {
                             "type": get_variant(Str, "package"),
                             "name": get_variant(Str, "grub2"),
                             "reason": get_variant(Str, "bootloader")
                         }, {
                             "type": get_variant(Str, "package"),
                             "name": get_variant(Str, "grub2-tools"),
                             "reason": get_variant(Str, "bootloader")
                         }])

    @patch('pyanaconda.dbus.DBus.publish_object')
    def install_with_tasks_test(self, publisher):
        """Test InstallWithTask."""
        task_classes = [
            ActivateFilesystemsTask, MountFilesystemsTask,
            WriteConfigurationTask
        ]

        # Get the installation tasks.
        with tempfile.TemporaryDirectory() as sysroot:
            task_paths = self.storage_interface.InstallWithTasks(sysroot)

        # Check the number of installation tasks.
        task_number = len(task_classes)
        self.assertEqual(task_number, len(task_paths))
        self.assertEqual(task_number, publisher.call_count)

        # Check the tasks.
        for i in range(task_number):
            object_path, obj = publisher.call_args_list[i][0]
            self.assertEqual(object_path, task_paths[i])
            self.assertIsInstance(obj, TaskInterface)
            self.assertIsInstance(obj.implementation, task_classes[i])

    def kickstart_properties_test(self):
        """Test kickstart properties."""
        self.assertEqual(self.storage_interface.KickstartCommands, [
            'autopart', 'bootloader', 'btrfs', 'clearpart', 'fcoe',
            'ignoredisk', 'logvol', 'mount', 'nvdimm', 'part', 'partition',
            'raid', 'reqpart', 'snapshot', 'volgroup', 'zerombr', 'zfcp'
        ])
        self.assertEqual(self.storage_interface.KickstartSections, [])
        self.assertEqual(self.storage_interface.KickstartAddons, [])

    def _test_kickstart(self, ks_in, ks_out, **kwargs):
        check_kickstart_interface(self, self.storage_interface, ks_in, ks_out,
                                  **kwargs)

    def no_kickstart_test(self):
        """Test with no kickstart."""
        ks_in = None
        ks_out = ""
        self._test_kickstart(ks_in, ks_out)

    def kickstart_empty_test(self):
        """Test with empty string."""
        ks_in = ""
        ks_out = ""
        self._test_kickstart(ks_in, ks_out)

    def zerombr_kickstart_test(self):
        """Test the zerombr command."""
        ks_in = """
        zerombr
        """
        ks_out = """
        # Clear the Master Boot Record
        zerombr
        """
        self._test_kickstart(ks_in, ks_out)

    def clearpart_none_kickstart_test(self):
        """Test the clearpart command with the none option."""
        ks_in = """
        clearpart --none
        """
        ks_out = """
        # Partition clearing information
        clearpart --none
        """
        self._test_kickstart(ks_in, ks_out)

    def clearpart_all_kickstart_test(self):
        """Test the clearpart command with the all option."""
        ks_in = """
        clearpart --all
        """
        ks_out = """
        # Partition clearing information
        clearpart --all
        """
        self._test_kickstart(ks_in, ks_out)

    def clearpart_linux_kickstart_test(self):
        """Test the clearpart command with the linux option."""
        ks_in = """
        clearpart --linux
        """
        ks_out = """
        # Partition clearing information
        clearpart --linux
        """
        self._test_kickstart(ks_in, ks_out)

    def clearpart_cdl_kickstart_test(self):
        """Test the clearpart command with the cdl option."""
        ks_in = """
        clearpart --all --cdl
        """
        ks_out = """
        # Partition clearing information
        clearpart --all --cdl
        """
        self._test_kickstart(ks_in, ks_out)

    def clearpart_initlabel_kickstart_test(self):
        """Test the clearpart command with the initlabel option."""
        ks_in = """
        clearpart --all --initlabel
        """
        ks_out = """
        # Partition clearing information
        clearpart --all --initlabel
        """
        self._test_kickstart(ks_in, ks_out)

    @patch("pyanaconda.modules.storage.kickstart.DiskLabel")
    def clearpart_disklabel_kickstart_test(self, disk_label):
        """Test the clearpart command with the disklabel option."""
        ks_in = """
        clearpart --all --disklabel=msdos
        """
        ks_out = """
        # Partition clearing information
        clearpart --all --disklabel=msdos
        """
        disk_label.get_platform_label_types.return_value = ["msdos", "gpt"]
        self._test_kickstart(ks_in, ks_out)

        disk_label.get_platform_label_types.return_value = ["gpt"]
        self._test_kickstart(ks_in, ks_out, ks_valid=False)

    @patch("pyanaconda.modules.storage.kickstart.device_matches")
    def clearpart_list_kickstart_test(self, device_matches):
        """Test the clearpart command with the list option."""
        ks_in = """
        clearpart --list=sdb1
        """
        ks_out = """
        # Partition clearing information
        clearpart --list=sdb1
        """
        device_matches.return_value = ["sdb1"]
        self._test_kickstart(ks_in, ks_out)

        device_matches.return_value = []
        self._test_kickstart(ks_in, ks_out, ks_valid=False)

    @patch("pyanaconda.modules.storage.kickstart.device_matches")
    def clearpart_drives_kickstart_test(self, device_matches):
        """Test the clearpart command with the drives option."""
        ks_in = """
        clearpart --all --drives=sda
        """
        ks_out = """
        # Partition clearing information
        clearpart --all --drives=sda
        """
        device_matches.return_value = ["sda"]
        self._test_kickstart(ks_in, ks_out)

        device_matches.return_value = []
        self._test_kickstart(ks_in, ks_out, ks_valid=False)

    @patch("pyanaconda.modules.storage.kickstart.device_matches")
    def ignoredisk_drives_kickstart_test(self, device_matches):
        """Test the ignoredisk command with the onlyuse option."""
        ks_in = """
        ignoredisk --only-use=sda
        """
        ks_out = """
        ignoredisk --only-use=sda
        """
        device_matches.return_value = ["sda"]
        self._test_kickstart(ks_in, ks_out)

        device_matches.return_value = []
        self._test_kickstart(ks_in, ks_out, ks_valid=False)

    @patch("pyanaconda.modules.storage.kickstart.device_matches")
    def ignoredisk_onlyuse_kickstart_test(self, device_matches):
        """Test the ignoredisk command with the drives option."""
        ks_in = """
        ignoredisk --drives=sdb
        """
        ks_out = """
        ignoredisk --drives=sdb
        """
        device_matches.return_value = ["sdb"]
        self._test_kickstart(ks_in, ks_out)

        device_matches.return_value = []
        self._test_kickstart(ks_in, ks_out, ks_valid=False)

    def bootloader_disabled_kickstart_test(self):
        """Test the bootloader command with the disabled option."""
        ks_in = """
        bootloader --disabled
        """
        ks_out = """
        # System bootloader configuration
        bootloader --disabled
        """
        self._test_kickstart(ks_in, ks_out)

    def bootloader_none_kickstart_test(self):
        """Test the bootloader command with the none option."""
        ks_in = """
        bootloader --location=none
        """
        ks_out = """
        # System bootloader configuration
        bootloader --location=none
        """
        self._test_kickstart(ks_in, ks_out)

    def bootloader_mbr_kickstart_test(self):
        """Test the bootloader command with the MBR option."""
        ks_in = """
        bootloader --location=mbr
        """
        ks_out = """
        # System bootloader configuration
        bootloader --location=mbr
        """
        self._test_kickstart(ks_in, ks_out)

    @patch(
        "pyanaconda.modules.storage.bootloader.bootloader.get_bootloader_class"
    )
    def bootloader_partition_kickstart_test(self, getter):
        """Test the bootloader command with the partition option."""
        ks_in = """
        bootloader --location=partition
        """
        ks_out = """
        # System bootloader configuration
        bootloader --location=partition
        """
        getter.return_value = ZIPL
        self._test_kickstart(ks_in, ks_out)

        getter.return_value = IPSeriesGRUB2
        self._test_kickstart(ks_in, ks_out, ks_valid=False)

    def bootloader_append_kickstart_test(self):
        """Test the bootloader command with the append option."""
        ks_in = """
        bootloader --append="hdd=ide-scsi ide=nodma"
        """
        ks_out = """
        # System bootloader configuration
        bootloader --append="hdd=ide-scsi ide=nodma" --location=mbr
        """
        self._test_kickstart(ks_in, ks_out)

    def bootloader_password_kickstart_test(self):
        """Test the bootloader command with the password option."""
        ks_in = """
        bootloader --password="******"
        """
        ks_out = """
        # System bootloader configuration
        bootloader --location=mbr --password="******"
        """
        self._test_kickstart(ks_in, ks_out)

    @patch(
        "pyanaconda.modules.storage.bootloader.bootloader.get_bootloader_class"
    )
    def bootloader_encrypted_password_kickstart_test(self, getter):
        """Test the bootloader command with the encrypted password option."""
        ks_in = """
        bootloader --password="******" --iscrypted
        """
        ks_out = """
        # System bootloader configuration
        bootloader --location=mbr --password="******" --iscrypted
        """
        getter.return_value = ZIPL
        self._test_kickstart(ks_in, ks_out)

        getter.return_value = GRUB2
        self._test_kickstart(ks_in, ks_out, ks_valid=False)

    @patch(
        "pyanaconda.modules.storage.bootloader.bootloader.get_bootloader_class"
    )
    def bootloader_encrypted_grub2_kickstart_test(self, getter):
        """Test the bootloader command with encrypted GRUB2."""
        ks_in = """
        bootloader --password="******" --iscrypted
        """
        ks_out = """
        # System bootloader configuration
        bootloader --location=mbr --password="******" --iscrypted
        """
        getter.return_value = GRUB2
        self._test_kickstart(ks_in, ks_out)

    def bootloader_driveorder_kickstart_test(self):
        """Test the bootloader command with the driveorder option."""
        ks_in = """
        bootloader --driveorder="sda,sdb"
        """
        ks_out = """
        # System bootloader configuration
        bootloader --location=mbr --driveorder="sda,sdb"
        """
        self._test_kickstart(ks_in, ks_out)

    def bootloader_timeout_kickstart_test(self):
        """Test the bootloader command with the timeout option."""
        ks_in = """
        bootloader --timeout=10
        """
        ks_out = """
        # System bootloader configuration
        bootloader --location=mbr --timeout=10
        """
        self._test_kickstart(ks_in, ks_out)

    def bootloader_md5pass_kickstart_test(self):
        """Test the bootloader command with the md5pass option."""
        ks_in = """
        bootloader --md5pass="******" --extlinux
        """
        ks_out = """
        # System bootloader configuration
        bootloader --location=mbr --password="******" --iscrypted --extlinux
        """
        self._test_kickstart(ks_in, ks_out)

    def bootloader_bootdrive_kickstart_test(self):
        """Test the bootloader command with the boot drive option."""
        ks_in = """
        bootloader --boot-drive="sda"
        """
        ks_out = """
        # System bootloader configuration
        bootloader --location=mbr --boot-drive=sda
        """
        self._test_kickstart(ks_in, ks_out)

    def bootloader_leavebootorder_kickstart_test(self):
        """Test the bootloader command with the leavebootorder option."""
        ks_in = """
        bootloader --leavebootorder
        """
        ks_out = """
        # System bootloader configuration
        bootloader --location=mbr --leavebootorder
        """
        self._test_kickstart(ks_in, ks_out)

    def bootloader_extlinux_kickstart_test(self):
        """Test the bootloader command with the extlinux option."""
        ks_in = """
        bootloader --extlinux
        """
        ks_out = """
        # System bootloader configuration
        bootloader --location=mbr --extlinux
        """
        self._test_kickstart(ks_in, ks_out)

    def bootloader_nombr_kickstart_test(self):
        """Test the bootloader command with the nombr option."""
        ks_in = """
        bootloader --nombr
        """
        ks_out = """
        # System bootloader configuration
        bootloader --location=mbr --nombr
        """
        self._test_kickstart(ks_in, ks_out)

    def autopart_kickstart_test(self):
        """Test the autopart command."""
        ks_in = """
        autopart
        """
        ks_out = """
        autopart
        """
        self._test_kickstart(ks_in, ks_out)

    def autopart_type_kickstart_test(self):
        """Test the autopart command with the type option."""
        ks_in = """
        autopart --type=thinp
        """
        ks_out = """
        autopart --type=thinp
        """
        self._test_kickstart(ks_in, ks_out)

    def autopart_fstype_kickstart_test(self):
        """Test the autopart command with the fstype option."""
        ks_in = """
        autopart --fstype=ext4
        """
        ks_out = """
        autopart --fstype=ext4
        """
        self._test_kickstart(ks_in, ks_out)

        ks_in = """
        autopart --fstype=invalid
        """
        ks_out = ""
        self._test_kickstart(ks_in, ks_out, ks_valid=False)

    def autopart_nopart_kickstart_test(self):
        """Test the autopart command with nohome, noboot and noswap options."""
        ks_in = """
        autopart --nohome --noboot --noswap
        """
        ks_out = """
        autopart --nohome --noboot --noswap
        """
        self._test_kickstart(ks_in, ks_out)

    def autopart_encrypted_kickstart_test(self):
        """Test the autopart command with the encrypted option."""
        ks_in = """
        autopart --encrypted
        """
        ks_out = """
        autopart --encrypted
        """
        self._test_kickstart(ks_in, ks_out)

    def autopart_cipher_kickstart_test(self):
        """Test the autopart command with the cipher option."""
        ks_in = """
        autopart --encrypted --cipher="aes-xts-plain64"
        """
        ks_out = """
        autopart --encrypted --cipher="aes-xts-plain64"
        """
        self._test_kickstart(ks_in, ks_out)

    def autopart_passphrase_kickstart_test(self):
        """Test the autopart command with the passphrase option."""
        ks_in = """
        autopart --encrypted --passphrase="123456"
        """
        ks_out = """
        autopart --encrypted --passphrase="123456"
        """
        self._test_kickstart(ks_in, ks_out)

    def autopart_escrowcert_kickstart_test(self):
        """Test the autopart command with the escrowcert option."""
        ks_in = """
        autopart --encrypted --escrowcert="file:///tmp/escrow.crt"
        """
        ks_out = """
        autopart --encrypted --escrowcert="file:///tmp/escrow.crt"
        """
        self._test_kickstart(ks_in, ks_out)

    def autopart_backuppassphrase_kickstart_test(self):
        """Test the autopart command with the backuppassphrase option."""
        ks_in = """
        autopart --encrypted --escrowcert="file:///tmp/escrow.crt" --backuppassphrase
        """
        ks_out = """
        autopart --encrypted --escrowcert="file:///tmp/escrow.crt" --backuppassphrase
        """
        self._test_kickstart(ks_in, ks_out)

    def mount_kickstart_test(self):
        """Test the mount command."""
        ks_in = """
        mount /dev/sda1 /boot
        """
        ks_out = """
        # Mount points configuration
        mount /dev/sda1 /boot
        """
        self._test_kickstart(ks_in, ks_out)

    def mount_none_kickstart_test(self):
        """Test the mount command with none."""
        ks_in = """
        mount /dev/sda1 none
        """
        ks_out = """
        # Mount points configuration
        mount /dev/sda1 none
        """
        self._test_kickstart(ks_in, ks_out)

    def mount_mountoptions_kickstart_test(self):
        """Test the mount command with the mountoptions."""
        ks_in = """
        mount /dev/sda1 /boot --mountoptions="user"
        """
        ks_out = """
        # Mount points configuration
        mount /dev/sda1 /boot --mountoptions="user"
        """
        self._test_kickstart(ks_in, ks_out)

    def mount_reformat_kickstart_test(self):
        """Test the mount command with the reformat option."""
        ks_in = """
        mount /dev/sda1 /boot --reformat
        """
        ks_out = """
        # Mount points configuration
        mount /dev/sda1 /boot --reformat
        """
        self._test_kickstart(ks_in, ks_out)

    def mount_mkfsoptions_kickstart_test(self):
        """Test the mount command with the mkfsoptions."""
        ks_in = """
        mount /dev/sda1 /boot --reformat=xfs --mkfsoptions="-L BOOT"
        """
        ks_out = """
        # Mount points configuration
        mount /dev/sda1 /boot --reformat=xfs --mkfsoptions="-L BOOT"
        """
        self._test_kickstart(ks_in, ks_out)

    def mount_multiple_kickstart_test(self):
        """Test multiple mount commands."""
        ks_in = """
        mount /dev/sda1 /boot
        mount /dev/sda2 /
        mount /dev/sdb1 /home
        mount /dev/sdb2 none
        """
        ks_out = """
        # Mount points configuration
        mount /dev/sda1 /boot
        mount /dev/sda2 /
        mount /dev/sdb1 /home
        mount /dev/sdb2 none
        """
        self._test_kickstart(ks_in, ks_out)

    def autopart_luks_version_kickstart_test(self):
        """Test the autopart command with the luks version option."""
        ks_in = """
        autopart --encrypted --luks-version=luks1
        """
        ks_out = """
        autopart --encrypted --luks-version=luks1
        """
        self._test_kickstart(ks_in, ks_out)

    def autopart_pbkdf_kickstart_test(self):
        """Test the autopart command with the pbkdf option."""
        ks_in = """
        autopart --encrypted --pbkdf=pbkdf2
        """
        ks_out = """
        autopart --encrypted --pbkdf=pbkdf2
        """
        self._test_kickstart(ks_in, ks_out)

    def autopart_pbkdf_memory_kickstart_test(self):
        """Test the autopart command with the pbkdf memory option."""
        ks_in = """
        autopart --encrypted --pbkdf-memory=256
        """
        ks_out = """
        autopart --encrypted --pbkdf-memory=256
        """
        self._test_kickstart(ks_in, ks_out)

    def autopart_pbkdf_time_kickstart_test(self):
        """Test the autopart command with the pbkdf time option."""
        ks_in = """
        autopart --encrypted --pbkdf-time=100
        """
        ks_out = """
        autopart --encrypted --pbkdf-time=100
        """
        self._test_kickstart(ks_in, ks_out)

    def autopart_pbkdf_iterations_kickstart_test(self):
        """Test the autopart command with the pbkdf iterations option."""
        ks_in = """
        autopart --encrypted --pbkdf-iterations=1000
        """
        ks_out = """
        autopart --encrypted --pbkdf-iterations=1000
        """
        self._test_kickstart(ks_in, ks_out)

    @patch("pyanaconda.modules.storage.kickstart.fcoe")
    @patch("pyanaconda.modules.storage.kickstart.get_supported_devices")
    def fcoe_kickstart_test(self, get_supported_devices, fcoe):
        """Test the fcoe command."""
        ks_in = """
        fcoe --nic=eth0 --dcb --autovlan
        """
        ks_out = """
        fcoe --nic=eth0 --dcb --autovlan
        """
        dev_info = Mock()
        dev_info.device_name = "eth0"
        get_supported_devices.return_value = [dev_info]
        self._test_kickstart(ks_in, ks_out)

        dev_info.device_name = "eth1"
        self._test_kickstart(ks_in, ks_out, ks_valid=False)

    @patch("pyanaconda.storage.initialization.load_plugin_s390")
    @patch("pyanaconda.modules.storage.kickstart.zfcp")
    @patch("pyanaconda.modules.storage.storage.arch.is_s390",
           return_value=True)
    def zfcp_kickstart_test(self, arch, zfcp, loader):
        """Test the zfcp command."""
        self.setUp()  # set up for s390x

        ks_in = """
        zfcp --devnum=0.0.fc00 --wwpn=0x401040a000000000 --fcplun=0x5105074308c212e9
        """
        ks_out = """
        zfcp --devnum=0.0.fc00 --wwpn=0x401040a000000000 --fcplun=0x5105074308c212e9
        """
        self._test_kickstart(ks_in, ks_out)

    @patch("pyanaconda.modules.storage.kickstart.nvdimm")
    def nvdimm_kickstart_test(self, nvdimm):
        """Test the nvdimm command."""
        ks_in = """
        nvdimm use --namespace=namespace0.0
        nvdimm reconfigure --namespace=namespace1.0 --mode=sector --sectorsize=512
        """
        ks_out = """
        # NVDIMM devices setup
        nvdimm use --namespace=namespace0.0
        nvdimm reconfigure --namespace=namespace1.0 --mode=sector --sectorsize=512
        """
        nvdimm.namespaces = ["namespace0.0", "namespace1.0"]
        self._test_kickstart(ks_in, ks_out)

        nvdimm.namespaces = ["namespace0.0"]
        self._test_kickstart(ks_in, ks_out, ks_valid=False)

        nvdimm.namespaces = ["namespace1.0"]
        self._test_kickstart(ks_in, ks_out, ks_valid=False)

    @patch("pyanaconda.modules.storage.kickstart.device_matches")
    def nvdimm_blockdevs_kickstart_test(self, device_matches):
        """Test the nvdimm command with blockdevs."""
        ks_in = """
        nvdimm use --blockdevs=pmem0
        """
        ks_out = """
        # NVDIMM devices setup
        nvdimm use --blockdevs=pmem0
        """
        device_matches.return_value = ["pmem0"]
        self._test_kickstart(ks_in, ks_out)

        device_matches.return_value = []
        self._test_kickstart(ks_in, ks_out, ks_valid=False)

    def snapshot_kickstart_test(self):
        """Test the snapshot command."""
        ks_in = """
        snapshot fedora/root --name=pre-snapshot --when=pre-install
        snapshot fedora/root --name=post-snapshot --when=post-install
        """
        ks_out = """
        snapshot fedora/root --name=pre-snapshot --when=pre-install
        snapshot fedora/root --name=post-snapshot --when=post-install
        """
        self._test_kickstart(ks_in, ks_out)

    def snapshot_invalid_kickstart_test(self):
        """Test the snapshot command with invalid origin."""
        ks_in = """
        snapshot invalid --name=pre-snapshot --when=pre-install
        """
        ks_out = """
        snapshot invalid --name=pre-snapshot --when=pre-install
        """
        self._test_kickstart(ks_in, ks_out, ks_valid=False)

    def snapshot_warning_kickstart_test(self):
        """Test the snapshot command with warnings."""
        ks_in = """
        zerombr
        clearpart --all
        snapshot fedora/root --name=pre-snapshot --when=pre-install
        """
        ks_out = """
        # Clear the Master Boot Record
        zerombr
        # Partition clearing information
        clearpart --all
        snapshot fedora/root --name=pre-snapshot --when=pre-install
        """
        with self.assertLogs(level=logging.WARN):
            self._test_kickstart(ks_in, ks_out)

    @patch("pyanaconda.dbus.DBus.get_proxy")
    def custom_partitioning_kickstart_test(self, proxy_getter):
        """Smoke test for the custom partitioning."""
        # Make sure that the storage model is created.
        self.assertTrue(self.storage_module.storage)

        # Make sure that the storage playground is created.
        self.assertTrue(self.storage_module._custom_part_module.storage)

        # Try to get kickstart data.
        self._test_kickstart("", "")
コード例 #9
0
class NVDIMMKickstartTestCase(unittest.TestCase):
    """Test updating of nvdimm command from UI.

    The update is done:
    - always by disk selection in UI.
    - optionally by reconfiguring NVDIMM in UI.
    """

    def setUp(self):
        self.storage_module = StorageModule()
        self.nvdimm_module = self.storage_module._nvdimm_module
        self.nvdimm_interface = NVDIMMInterface(self.nvdimm_module)

    def _read(self, input_ks):
        """Read the kickstart string."""
        with patch("pyanaconda.modules.storage.kickstart.nvdimm") as nvdimm:
            # Fake the existence of the namespaces.
            nvdimm.namespaces = ["namespace0.0", "namespace1.0"]

            # Parse the kickstart now.
            self.storage_module.read_kickstart(input_ks)

    def _use(self, namespaces):
        """Represents update for NVDIMM disks selected in UI."""
        self.nvdimm_module.set_namespaces_to_use(
            namespaces=namespaces
        )

    def _reconfigure(self, namespace, sector_size):
        """Represents update for NVDIMM disk reconfigured in UI."""
        self.nvdimm_module.update_action(
            namespace=namespace,
            mode=NVDIMM_MODE_SECTOR,
            sector_size=sector_size
        )

    def _check(self, expected_ks):
        """Check the generated kickstart."""
        self.assertEqual(
            self.storage_module.generate_kickstart().strip(),
            dedent(expected_ks).strip()
        )

    def _check_ignored(self, expected_devices):
        """Check the ignored devices."""
        with patch("pyanaconda.modules.storage.nvdimm.nvdimm.nvdimm") as nvdimm:
            nvdimm.namespaces = {
                "namespace0.0": Mock(blockdev="pmem0", mode=blockdev.NVDIMMNamespaceMode.SECTOR),
                "namespace1.0": Mock(blockdev="pmem1", mode=blockdev.NVDIMMNamespaceMode.SECTOR),
                "namespace2.0": Mock(blockdev="pmem2", mode=blockdev.NVDIMMNamespaceMode.MEMORY),
            }

            ignored_devices = self.nvdimm_module.get_devices_to_ignore()
            self.assertEqual(sorted(ignored_devices), expected_devices)

    # Test setting use from UI

    def ksuse_use_test(self):
        """Test updating of nvdimm commands based on device selection in UI."""
        input_ks = """
        nvdimm use --namespace=namespace0.0
        """
        expected_ks = """
        # NVDIMM devices setup
        nvdimm use --namespace=namespace0.0
        """
        self._read(input_ks)
        self._check_ignored(["pmem1", "pmem2"])
        self._use(["namespace0.0"])
        self._check(expected_ks)

    def ksuse_use2_test(self):
        """Test updating of nvdimm commands based on device selection in UI."""
        input_ks = """
        nvdimm use --namespace=namespace0.0
        """
        expected_ks = """
        # NVDIMM devices setup
        nvdimm use --namespace=namespace0.0
        nvdimm use --namespace=namespace1.0
        """
        self._read(input_ks)
        self._check_ignored(["pmem1", "pmem2"])
        self._use(["namespace0.0", "namespace1.0"])
        self._check(expected_ks)

    def ksuse_use_none_test(self):
        """Test updating of nvdimm commands based on device selection in UI."""
        input_ks = """
        nvdimm use --namespace=namespace0.0
        """
        expected_ks = """
        """
        self._read(input_ks)
        self._check_ignored(["pmem1", "pmem2"])
        self._use([])
        self._check(expected_ks)

    def ksnone_use2_test(self):
        """Test updating of nvdimm commands based on device selection in UI."""
        input_ks = """
        """
        expected_ks = """
        # NVDIMM devices setup
        nvdimm use --namespace=namespace0.0
        nvdimm use --namespace=namespace1.0
        """
        self._read(input_ks)
        self._check_ignored(["pmem0", "pmem1", "pmem2"])
        self._use(["namespace0.0", "namespace1.0"])
        self._check(expected_ks)

    def ksnone_repeated_use_test(self):
        """Test updating of nvdimm commands based on device selection in UI."""
        input_ks = """
        """
        expected_ks = """
        # NVDIMM devices setup
        nvdimm use --namespace=namespace0.0
        """
        self._read(input_ks)
        self._check_ignored(["pmem0", "pmem1", "pmem2"])
        self._use(["namespace0.0"])
        self._use(["namespace0.0"])
        self._check(expected_ks)

    def ksnone_use_none_test(self):
        """Test updating of nvdimm commands based on device selection in UI."""
        input_ks = """
        """
        expected_ks = """
        """
        self._read(input_ks)
        self._check_ignored(["pmem0", "pmem1", "pmem2"])
        self._use([])
        self._check(expected_ks)

    def ksnone_repeated_use_2_test(self):
        """Test updating of nvdimm commands based on device selection in UI."""
        input_ks = """
        """
        expected_ks = """
        # NVDIMM devices setup
        nvdimm use --namespace=namespace1.0
        """
        self._read(input_ks)
        self._check_ignored(["pmem0", "pmem1", "pmem2"])
        self._use(["namespace0.0"])
        # Next use should override the previous
        self._use(["namespace1.0"])
        self._check(expected_ks)

    def ksuse_another_use_test(self):
        """Test updating of nvdimm commands based on device selection in UI."""
        input_ks = """
        nvdimm use --namespace=namespace1.0
        """
        expected_ks = """
        # NVDIMM devices setup
        nvdimm use --namespace=namespace0.0
        """
        self._read(input_ks)
        self._check_ignored(["pmem0", "pmem2"])
        self._use(["namespace0.0"])
        self._check(expected_ks)

    def ksuse_none_test(self):
        """Test updating of nvdimm commands based on device selection in UI."""
        input_ks = """
        nvdimm use --namespace=namespace1.0
        """
        expected_ks = """
        """
        self._read(input_ks)
        self._check_ignored(["pmem0", "pmem2"])
        self._use([])
        self._check(expected_ks)

    def ksreconfigure_use_test(self):
        """Test updating of nvdimm commands based on device selection in UI."""
        input_ks = """
        nvdimm reconfigure --namespace=namespace0.0 --mode=sector --sectorsize=512
        """
        expected_ks = """
        # NVDIMM devices setup
        nvdimm reconfigure --namespace=namespace0.0 --mode=sector --sectorsize=512
        """
        self._read(input_ks)
        self._check_ignored(["pmem1", "pmem2"])
        self._use(["namespace0.0"])
        self._check(expected_ks)

    def ksreconfigure_use_none_test(self):
        """Test updating of nvdimm commands based on device selection in UI."""
        input_ks = """
        nvdimm reconfigure --namespace=namespace0.0 --mode=sector --sectorsize=512
        """
        expected_ks = """
        # NVDIMM devices setup
        nvdimm reconfigure --namespace=namespace0.0 --mode=sector --sectorsize=512
        """
        self._read(input_ks)
        self._check_ignored(["pmem1", "pmem2"])
        # Even when not used, the reconfiguration should go to generated kicksart
        self._use([])
        self._check(expected_ks)

    def ksreconfigure_another_use_test(self):
        """Test updating of nvdimm commands based on device selection in UI."""
        input_ks = """
        nvdimm reconfigure --namespace=namespace0.0 --mode=sector --sectorsize=512
        """
        expected_ks = """
        # NVDIMM devices setup
        nvdimm reconfigure --namespace=namespace0.0 --mode=sector --sectorsize=512
        nvdimm use --namespace=namespace1.0
        """
        self._read(input_ks)
        self._check_ignored(["pmem1", "pmem2"])
        self._use(["namespace1.0"])
        self._check(expected_ks)

    def ksreconfigure_ksuse_another_use_test(self):
        """Test updating of nvdimm commands based on device selection in UI."""
        input_ks = """
        nvdimm reconfigure --namespace=namespace0.0 --mode=sector --sectorsize=512
        nvdimm use --namespace=namespace1.0
        """
        expected_ks = """
        # NVDIMM devices setup
        nvdimm reconfigure --namespace=namespace0.0 --mode=sector --sectorsize=512
        """
        self._read(input_ks)
        self._check_ignored(["pmem2"])
        self._use(["namespace0.0"])
        self._check(expected_ks)

    def ksreconfigure_2_use_1_test(self):
        """Test updating of nvdimm commands based on device selection in UI."""
        input_ks = """
        nvdimm reconfigure --namespace=namespace0.0 --mode=sector --sectorsize=512
        nvdimm reconfigure --namespace=namespace1.0 --mode=sector --sectorsize=512
        """
        expected_ks = """
        # NVDIMM devices setup
        nvdimm reconfigure --namespace=namespace0.0 --mode=sector --sectorsize=512
        nvdimm reconfigure --namespace=namespace1.0 --mode=sector --sectorsize=512
        """
        self._read(input_ks)
        self._check_ignored(["pmem2"])
        self._use(["namespace0.0"])
        self._check(expected_ks)

    # Test reconfigure and use in UI
    # (if _reconfigure is done in UI, _use is always done as well)

    def ksnone_reconfigure_use_test(self):
        """Test updating of nvdimm commands based on device reconfiguration in UI."""
        input_ks = """
        """
        expected_ks = """
        # NVDIMM devices setup
        nvdimm reconfigure --namespace=namespace0.0 --mode=sector --sectorsize=512
        """
        self._read(input_ks)
        self._check_ignored(["pmem0", "pmem1", "pmem2"])
        self._reconfigure("namespace0.0", 512)
        self._use(["namespace0.0"])
        self._check(expected_ks)

    def ksnone_repeated_reconfigure_use_test(self):
        """Test updating of nvdimm commands based on device reconfiguration in UI."""
        input_ks = """
        """
        expected_ks = """
        # NVDIMM devices setup
        nvdimm reconfigure --namespace=namespace0.0 --mode=sector --sectorsize=4096
        """
        self._read(input_ks)
        self._check_ignored(["pmem0", "pmem1", "pmem2"])
        self._reconfigure("namespace0.0", 512)
        self._reconfigure("namespace0.0", 4096)
        self._use(["namespace0.0"])
        self._check(expected_ks)

    def ksnone_repeated_reconfigure_repeated_use_test(self):
        """Test updating of nvdimm commands based on device reconfiguration in UI."""
        input_ks = """
        """
        expected_ks = """
        # NVDIMM devices setup
        nvdimm reconfigure --namespace=namespace0.0 --mode=sector --sectorsize=512
        nvdimm reconfigure --namespace=namespace1.0 --mode=sector --sectorsize=512
        """
        self._read(input_ks)
        self._check_ignored(["pmem0", "pmem1", "pmem2"])
        self._reconfigure("namespace0.0", 512)
        self._use(["namespace0.0"])
        self._reconfigure("namespace1.0", 512)
        # Even when not used, reconfiguration goes to generated ks
        self._use(["namespace1.0"])
        self._check(expected_ks)

    def ksuse_reconfigure_other_use_other_test(self):
        """Test updating of nvdimm commands based on device reconfiguration in UI."""
        input_ks = """
        nvdimm use --namespace=namespace0.0
        """
        expected_ks = """
        # NVDIMM devices setup
        nvdimm reconfigure --namespace=namespace1.0 --mode=sector --sectorsize=512
        """
        self._read(input_ks)
        self._check_ignored(["pmem1", "pmem2"])
        self._reconfigure("namespace1.0", 512)
        self._use(["namespace1.0"])
        self._check(expected_ks)

    def ksuse_2_reconfigure_1_use_2_test(self):
        """Test updating of nvdimm commands based on device reconfiguration in UI."""
        input_ks = """
        nvdimm use --namespace=namespace0.0
        nvdimm use --namespace=namespace1.0
        """
        expected_ks = """
        # NVDIMM devices setup
        nvdimm reconfigure --namespace=namespace1.0 --mode=sector --sectorsize=512
        nvdimm use --namespace=namespace0.0
        """
        self._read(input_ks)
        self._check_ignored(["pmem2"])
        self._reconfigure("namespace1.0", 512)
        self._use(["namespace0.0", "namespace1.0"])
        self._check(expected_ks)

    def ksuse_reconfigure_other_use_none_test(self):
        """Test updating of nvdimm commands based on device reconfiguration in UI."""
        input_ks = """
        nvdimm use --namespace=namespace0.0
        """
        expected_ks = """
        # NVDIMM devices setup
        nvdimm reconfigure --namespace=namespace1.0 --mode=sector --sectorsize=512
        """
        self._read(input_ks)
        self._check_ignored(["pmem1", "pmem2"])
        self._reconfigure("namespace1.0", 512)

        # Even when not used, the reconfiguration should go to generated kickstart.
        self._use([])
        self._check(expected_ks)

    @patch("pyanaconda.modules.storage.kickstart.device_matches")
    def ksuse_blockdevs_test(self, device_matches):
        """Test using blockdevs."""
        input_ks = """
        nvdimm use --blockdev=pmem0,pmem2
        """
        expected_ks = """
        # NVDIMM devices setup
        nvdimm use --namespace=namespace0.0
        """
        device_matches.return_value = ["pmem0", "pmem2"]
        self._read(input_ks)
        self._check_ignored(["pmem1", "pmem2"])
        self._use(["namespace0.0"])
        self._check(expected_ks)
コード例 #10
0
 def setUp(self):
     self.storage_module = StorageModule()
     self.nvdimm_module = self.storage_module._nvdimm_module
     self.nvdimm_interface = NVDIMMInterface(self.nvdimm_module)
コード例 #11
0
import logging
logging.basicConfig(level=logging.DEBUG)

from pyanaconda.modules.storage.storage import StorageModule

storage_module = StorageModule()
storage_module.run()
コード例 #12
0
 def setUp(self):
     self.module = StorageModule()
     self.interface = DeviceTreeInterface(self.module)
コード例 #13
0
 def _setup_kickstart(self):
     """Set up the kickstart."""
     storage_module = StorageModule()
     handler = storage_module.get_kickstart_handler()
     self.module.setup_kickstart(handler)
     return handler