class BootloaderInterfaceTestCase(unittest.TestCase): """Test DBus interface of the bootloader module.""" def setUp(self): """Set up the module.""" self.bootloader_module = BootloaderModule() self.bootloader_interface = BootloaderInterface(self.bootloader_module) def _check_dbus_property(self, *args, **kwargs): check_dbus_property(self, BOOTLOADER, self.bootloader_interface, *args, **kwargs) def get_default_type_test(self): """Test GetDefaultType.""" self.assertEqual(self.bootloader_interface.GetDefaultType(), "DEFAULT") def bootloader_mode_property_test(self): """Test the bootloader mode property.""" self._check_dbus_property("BootloaderMode", BOOTLOADER_SKIPPED) def preferred_location_property_test(self): """Test the preferred location property.""" self._check_dbus_property("PreferredLocation", BOOTLOADER_LOCATION_PARTITION) def drive_property_test(self): """Test the drive property.""" self._check_dbus_property("Drive", "sda") def drive_order_property_test(self): """Test the drive order property.""" self._check_dbus_property("DriveOrder", ["sda", "sdb"]) def keep_mbr_property_test(self): """Test the keep MBR property.""" self._check_dbus_property("KeepMBR", True) def keep_boot_order_test(self): """Test the keep boot order property.""" self._check_dbus_property("KeepBootOrder", True) def extra_arguments_property_test(self): """Test the extra arguments property.""" self._check_dbus_property("ExtraArguments", ["hdd=ide-scsi", "ide=nodma"]) def timeout_property_test(self): """Test the timeout property.""" self._check_dbus_property("Timeout", 25) def secure_boot_property_test(self): """Test the secure boot property.""" self._check_dbus_property("ZIPLSecureBoot", "auto") def password_property_test(self): """Test the password property.""" self._check_dbus_property( "Password", "12345", setter=self.bootloader_interface.SetEncryptedPassword, changed={'IsPasswordSet': True}) def is_efi_test(self): """Test IsEFI.""" with self.assertRaises(UnavailableStorageError): self.bootloader_interface.IsEFI() storage = Mock() self.bootloader_module.on_storage_changed(storage) storage.bootloader = GRUB2() self.assertEqual(self.bootloader_interface.IsEFI(), False) storage.bootloader = EFIGRUB() self.assertEqual(self.bootloader_interface.IsEFI(), True) def get_arguments_test(self): """Test GetArguments.""" with self.assertRaises(UnavailableStorageError): self.bootloader_interface.GetArguments() storage = Mock() self.bootloader_module.on_storage_changed(storage) storage.bootloader = GRUB2() storage.bootloader.boot_args.update(["x=1", "y=2"]) self.assertEqual(self.bootloader_interface.GetArguments(), ["x=1", "y=2"]) def detect_windows_test(self): """Test DetectWindows.""" with self.assertRaises(UnavailableStorageError): self.bootloader_interface.DetectWindows() device = Mock() device.format.name = "ntfs" storage = Mock() storage.devices = [device] self.bootloader_module.on_storage_changed(storage) storage.bootloader.has_windows.return_value = False self.assertEqual(self.bootloader_interface.DetectWindows(), False) storage.bootloader.has_windows.return_value = True self.assertEqual(self.bootloader_interface.DetectWindows(), True) @patch_dbus_publish_object def configure_with_task_test(self, publisher): """Test ConfigureWithTask.""" storage = Mock() version = "4.17.7-200.fc28.x86_64" self.bootloader_module.on_storage_changed(storage) task_path = self.bootloader_interface.ConfigureWithTask([version]) obj = check_task_creation(self, task_path, publisher, ConfigureBootloaderTask) self.assertEqual(obj.implementation._storage, storage) self.assertEqual(obj.implementation._versions, [version]) @patch_dbus_publish_object def install_with_task_test(self, publisher): """Test InstallWithTask.""" storage = Mock() self.bootloader_module.on_storage_changed(storage) task_path = self.bootloader_interface.InstallWithTask() obj = check_task_creation(self, task_path, publisher, InstallBootloaderTask) self.assertEqual(obj.implementation._storage, storage) @patch_dbus_publish_object def fix_btrfs_with_task_test(self, publisher): """Test FixBTRFSWithTask.""" storage = Mock() version = "4.17.7-200.fc28.x86_64" self.bootloader_module.on_storage_changed(storage) task_path = self.bootloader_interface.FixBTRFSWithTask([version]) obj = check_task_creation(self, task_path, publisher, FixBTRFSBootloaderTask) self.assertEqual(obj.implementation._storage, storage) self.assertEqual(obj.implementation._versions, [version]) @patch_dbus_publish_object def fix_zipl_with_task_test(self, publisher): """Test FixZIPLWithTask.""" storage = Mock() self.bootloader_module.on_storage_changed(storage) task_path = self.bootloader_interface.FixZIPLWithTask() obj = check_task_creation(self, task_path, publisher, FixZIPLBootloaderTask) self.assertEqual(obj.implementation._mode, self.bootloader_module.bootloader_mode)
class BootloaderInterfaceTestCase(unittest.TestCase): """Test DBus interface of the bootloader module.""" def setUp(self): """Set up the module.""" self.bootloader_module = BootloaderModule() self.bootloader_interface = BootloaderInterface(self.bootloader_module) def _test_dbus_property(self, *args, **kwargs): check_dbus_property(self, BOOTLOADER, self.bootloader_interface, *args, **kwargs) def bootloader_mode_property_test(self): """Test the bootloader mode property.""" self._test_dbus_property("BootloaderMode", BOOTLOADER_SKIPPED) def bootloader_type_property_test(self): """Test the bootloader type property.""" self._test_dbus_property("BootloaderType", BOOTLOADER_TYPE_EXTLINUX) def preferred_location_property_test(self): """Test the preferred location property.""" self._test_dbus_property("PreferredLocation", BOOTLOADER_LOCATION_PARTITION) def drive_property_test(self): """Test the drive property.""" self._test_dbus_property("Drive", "sda") def drive_order_property_test(self): """Test the drive order property.""" self._test_dbus_property("DriveOrder", ["sda", "sdb"]) def keep_mbr_property_test(self): """Test the keep MBR property.""" self._test_dbus_property("KeepMBR", True) def keep_boot_order_test(self): """Test the keep boot order property.""" self._test_dbus_property("KeepBootOrder", True) def extra_arguments_property_test(self): """Test the extra arguments property.""" self._test_dbus_property("ExtraArguments", ["hdd=ide-scsi", "ide=nodma"]) def timeout_property_test(self): """Test the timeout property.""" self._test_dbus_property("Timeout", 25) def password_property_test(self): """Test the password property.""" self._test_dbus_property( "Password", "12345", setter=self.bootloader_interface.SetEncryptedPassword, changed={'IsPasswordSet': True}) def is_efi_test(self): """Test IsEFI.""" with self.assertRaises(UnavailableStorageError): self.bootloader_interface.IsEFI() storage = Mock() self.bootloader_module.on_storage_reset(storage) storage.bootloader = GRUB2() self.assertEqual(self.bootloader_interface.IsEFI(), False) storage.bootloader = EFIGRUB() self.assertEqual(self.bootloader_interface.IsEFI(), True) def get_arguments_test(self): """Test GetArguments.""" with self.assertRaises(UnavailableStorageError): self.bootloader_interface.GetArguments() storage = Mock() self.bootloader_module.on_storage_reset(storage) storage.bootloader = GRUB2() storage.bootloader.boot_args.update(["x=1", "y=2"]) self.assertEqual(self.bootloader_interface.GetArguments(), ["x=1", "y=2"]) def detect_windows_test(self): """Test DetectWindows.""" with self.assertRaises(UnavailableStorageError): self.bootloader_interface.DetectWindows() device = Mock() device.format.name = "ntfs" storage = Mock() storage.devices = [device] self.bootloader_module.on_storage_reset(storage) storage.bootloader.has_windows.return_value = False self.assertEqual(self.bootloader_interface.DetectWindows(), False) storage.bootloader.has_windows.return_value = True self.assertEqual(self.bootloader_interface.DetectWindows(), True) @patch('pyanaconda.dbus.DBus.publish_object') def configure_with_task_test(self, publisher): """Test ConfigureWithTask.""" storage = Mock() sysroot = "/mnt/sysroot" version = "4.17.7-200.fc28.x86_64" self.bootloader_module.on_storage_reset(storage) task_path = self.bootloader_interface.ConfigureWithTask( sysroot, [version]) 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, ConfigureBootloaderTask) self.assertEqual(obj.implementation._storage, storage) self.assertEqual(obj.implementation._sysroot, sysroot) self.assertEqual(obj.implementation._versions, [version]) @patch('pyanaconda.dbus.DBus.publish_object') def install_with_task_test(self, publisher): """Test InstallWithTask.""" storage = Mock() sysroot = "/mnt/sysroot" self.bootloader_module.on_storage_reset(storage) task_path = self.bootloader_interface.InstallWithTask(sysroot) 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, InstallBootloaderTask) self.assertEqual(obj.implementation._storage, storage) self.assertEqual(obj.implementation._sysroot, sysroot)