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)
def publish(self): """Publish the module.""" for kickstart_module in self._modules: kickstart_module.publish() DBus.publish_object(STORAGE.object_path, StorageInterface(self)) DBus.register_service(STORAGE.service_name)
def setUp(self): """Set up the module.""" self.storage_module = StorageModule() self.storage_interface = StorageInterface(self.storage_module)
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("", "")
def publish(self): """Publish the module.""" DBus.publish_object(STORAGE.object_path, StorageInterface(self)) DBus.register_service(STORAGE.service_name)