def ReadKickstart(self, kickstart): """Mock parsing for now. Returns parse error if PARSE_ERROR string is found in kickstart. """ self.kickstart = kickstart report = KickstartReport() for lnum, line in enumerate(kickstart.splitlines(), 1): if "PARSE_ERROR" in line: data = KickstartMessage() data.message = "Mocked parse error: \"PARSE_ERROR\" found" data.line_number = lnum report.error_messages.append(data) return get_native(KickstartReport.to_structure(report))
def setup_install_source_task_failed_to_mount_test(self, proxy_getter, os_stat, stat, mount): """Test Live OS setup installation source task mount error.""" device_tree = Mock() proxy_getter.return_value = device_tree device_tree.ResolveDevice = Mock() device_tree.ResolveDevice.return_value = "resolvedDeviceName" device = DeviceData() device.path = "/resolved/path/to/base/image" device_tree.GetDeviceData = Mock() device_tree.GetDeviceData.return_value = get_native(DeviceData.to_structure(device)) mount.return_value = -20 with self.assertRaises(SourceSetupError): SetupInstallationSourceTask( "/path/to/base/image", "/path/to/mount/source/image" ).run()
def setup_install_source_task_test(self, proxy_getter, os_stat, stat, mount): """Test Live OS setup installation source task.""" device_tree = Mock() proxy_getter.return_value = device_tree device_tree.ResolveDevice = Mock() device_tree.ResolveDevice.return_value = "resolvedDeviceName" device = DeviceData() device.path = "/resolved/path/to/base/image" device_tree.GetDeviceData = Mock() device_tree.GetDeviceData.return_value = get_native(DeviceData.to_structure(device)) mount.return_value = 0 SetupInstallationSourceTask( "/path/to/base/image", "/path/to/mount/source/image" ).run() device_tree.ResolveDevice.assert_called_once_with("/path/to/base/image") os_stat.assert_called_once_with("/resolved/path/to/base/image")
def setup_install_source_task_invalid_block_dev_test(self, proxy_getter, os_stat, stat_mock): """Test Live OS Source setup installation source task with invalid block device error.""" device_tree = Mock() proxy_getter.return_value = device_tree device_tree.ResolveDevice = Mock() device_tree.ResolveDevice.return_value = "resolvedDeviceName" device = DeviceData() device.path = "/resolved/path/to/base/image" device_tree.GetDeviceData = Mock() device_tree.GetDeviceData.return_value = get_native(DeviceData.to_structure(device)) stat_mock.S_ISBLK = Mock() stat_mock.S_ISBLK.return_value = False with self.assertRaises(SourceSetupError, msg="/path/to/base/image is not a valid block device"): SetUpLiveOSSourceTask( "/path/to/base/image", "/path/to/mount/source/image" ).run()
def validate_selected_disks_test(self): """Test ValidateSelectedDisks.""" storage = create_storage() self.disk_selection_module.on_storage_reset(storage) dev1 = DiskDevice("dev1", exists=False, size=Size("15 GiB"), fmt=get_format("disklabel")) dev2 = DiskDevice("dev2", exists=False, parents=[dev1], size=Size("6 GiB"), fmt=get_format("disklabel")) dev3 = DiskDevice("dev3", exists=False, parents=[dev2], size=Size("6 GiB"), fmt=get_format("disklabel")) storage.devicetree._add_device(dev1) storage.devicetree._add_device(dev2) storage.devicetree._add_device(dev3) report = ValidationReport.from_structure( get_native(self.disk_selection_interface.ValidateSelectedDisks( []))) self.assertEqual(report.is_valid(), True) report = ValidationReport.from_structure( get_native( self.disk_selection_interface.ValidateSelectedDisks(["dev1"]))) self.assertEqual(report.is_valid(), False) self.assertEqual(report.error_messages, [ "You selected disk dev1, which contains devices that also use " "unselected disks dev2, dev3. You must select or de-select " "these disks as a set." ]) self.assertEqual(report.warning_messages, []) report = ValidationReport.from_structure( get_native( self.disk_selection_interface.ValidateSelectedDisks( ["dev1", "dev2"]))) self.assertEqual(report.is_valid(), False) self.assertEqual(report.error_messages, [ "You selected disk dev1, which contains devices that also " "use unselected disk dev3. You must select or de-select " "these disks as a set.", "You selected disk dev2, which contains devices that also " "use unselected disk dev3. You must select or de-select " "these disks as a set." ]) self.assertEqual(report.warning_messages, []) report = ValidationReport.from_structure( get_native( self.disk_selection_interface.ValidateSelectedDisks( ["dev1", "dev2", "dev3"]))) self.assertEqual(report.is_valid(), True)