def test_validate_with_task(self, publisher): """Test ValidateWithTask.""" self.module.on_storage_changed(Mock()) task_path = self.interface.ValidateWithTask() obj = check_task_creation(task_path, publisher, StorageValidateTask) assert obj.implementation._storage == self.module.storage report = ValidationReport() report.error_messages = [ "Something is wrong.", "Something is very wrong." ] report.warning_messages = ["Something might be wrong."] obj.implementation._set_result(report) result = obj.GetResult() expected_result = get_variant( Structure, { "error-messages": get_variant( List[Str], ["Something is wrong.", "Something is very wrong."]), "warning-messages": get_variant(List[Str], ["Something might be wrong."]) }) assert isinstance(result, Variant) assert get_native(result) == get_native(expected_result) assert result.equal(expected_result)
def validate_selected_disks_test(self): """Test ValidateSelectedDisks.""" storage = create_storage() self.disk_selection_module.on_storage_changed(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( self.disk_selection_interface.ValidateSelectedDisks([])) self.assertEqual(report.is_valid(), True) report = ValidationReport.from_structure( 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( 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( self.disk_selection_interface.ValidateSelectedDisks( ["dev1", "dev2", "dev3"])) self.assertEqual(report.is_valid(), True)
def validate_selected_disks(self, drives): """Validate the list of selected disks. :param drives: a list of drives names :return: a validation report """ report = ValidationReport() report.error_messages = check_disk_selection(self.storage, drives) return report
def input(self, args, key): """Grab the disk choice and update things""" self.errors = [] if self._container.process_user_input(key): return InputState.PROCESSED_AND_REDRAW else: if key.lower() == Prompt.CONTINUE: if self._selected_disks: # Is DASD formatting supported? if DasdFormatting.is_supported(): # Wait for storage. threadMgr.wait(THREAD_STORAGE) # Allow to format DASDs. self._disk_init_module.SetFormatUnrecognizedEnabled( True) self._disk_init_module.SetFormatLDLEnabled(True) # Get selected disks. disks = filter_disks_by_names(self._available_disks, self._selected_disks) # Check if some of the disks should be formatted. dasd_formatting = DasdFormatting() dasd_formatting.search_disks(disks) if dasd_formatting.should_run(): # We want to apply current selection before running dasdfmt to # prevent this information from being lost afterward apply_disk_selection(self._selected_disks) # Run the dialog. self.run_dasdfmt_dialog(dasd_formatting) return InputState.PROCESSED_AND_REDRAW # make sure no containers were split up by the user's disk # selection report = ValidationReport.from_structure( self._disk_select_module.ValidateSelectedDisks( self._selected_disks)) self.errors.extend(report.get_messages()) if self.errors: # The disk selection has to make sense before we can # proceed. return InputState.PROCESSED_AND_REDRAW self.apply() new_spoke = PartTypeSpoke(self.data, self.storage, self.payload, self._storage_module, self._partitioning) ScreenHandler.push_screen_modal(new_spoke) self._partitioning = new_spoke.partitioning self.apply() self.execute() return InputState.PROCESSED_AND_CLOSE else: return super().input(args, key)
def _validate_storage(self, storage): """Validate the storage model. :param storage: an instance of Blivet :return: a validation report """ result = storage_checker.check(storage) for message in result.info: log.debug(message) validation_report = ValidationReport() validation_report.error_messages = result.errors validation_report.warning_messages = result.warnings return validation_report
def ValidateMountPoint(self, mount_point: Str) -> Structure: """Validate the given mount point. :param mount_point: a path to a mount point :return: a validation report """ return ValidationReport.to_structure( self.implementation.validate_mount_point(mount_point))
def CheckCompleteness(self, device_name: Str) -> Structure: """Check that the specified device is complete. :param device_name: a name of the device :return: a validation report """ return ValidationReport.to_structure( self.implementation.check_completeness(device_name))
def ValidateSelectedDisks(self, drives: List[Str]) -> Structure: """Validate the list of selected disks. :param drives: a list of drives names :return: a validation report """ return ValidationReport.to_structure( self.implementation.validate_selected_disks(drives))
def ValidateContainerName(self, name: Str) -> Structure: """Validate the given container name. :param name: a container name :return: a validation report """ return ValidationReport.to_structure( self.implementation.validate_container_name(name))
def convert_result(value) -> Variant: """Convert the validation report. Convert the validation report into a variant. :param value: a validation report :return: a variant with the structure """ return get_variant(Structure, ValidationReport.to_structure(value))
def ValidateDeviceFactoryRequest(self, request: Structure) -> Structure: """Validate the given device factory request. :param request: a device factory request :return: a validation report """ request = DeviceFactoryRequest.from_structure(request) report = self.implementation.validate_device_factory_request(request) return ValidationReport.to_structure(report)
def ValidateRaidLevel(self, raid_level: Str, num_members: Int) -> Structure: """Validate the given RAID level. :param raid_level: a RAID level name :param num_members: a number of members :return: a validation report """ return ValidationReport.to_structure( self.implementation.validate_raid_level(raid_level, num_members))
def _set_mount_point(self): self._mount_point = self.builder.get_object( "addMountPointEntry").get_active_text() if lowerASCII(self._mount_point) in ("swap", "biosboot", "prepboot"): return report = ValidationReport.from_structure( self._device_tree.ValidateMountPoint(self._mount_point)) self._error = " ".join(report.get_messages())
def apply_partitioning(partitioning, show_message_cb, reset_storage_cb): """Apply the given partitioning. :param partitioning: a DBus proxy of a partitioning :param show_message_cb: a callback for showing a message :param reset_storage_cb: a callback for resetting the storage :return: an instance of ValidationReport """ log.debug("Applying partitioning") report = ValidationReport() try: show_message_cb(_("Saving storage configuration...")) task_path = partitioning.ConfigureWithTask() task_proxy = STORAGE.get_proxy(task_path) sync_run_task(task_proxy) except StorageConfigurationError as e: show_message_cb(_("Failed to save storage configuration")) report.error_messages.append(str(e)) reset_bootloader() reset_storage_cb() except BootloaderConfigurationError as e: show_message_cb(_("Failed to save boot loader configuration")) report.error_messages.append(str(e)) reset_bootloader() else: show_message_cb(_("Checking storage configuration...")) task_path = partitioning.ValidateWithTask() task_proxy = STORAGE.get_proxy(task_path) sync_run_task(task_proxy) result = unwrap_variant(task_proxy.GetResult()) report = ValidationReport.from_structure(result) log.debug("Validation has been completed: %s", report) if report.is_valid(): storage_proxy = STORAGE.get_proxy() storage_proxy.ApplyPartitioning(get_object_path(partitioning)) log.debug("Partitioning has been applied.") return report
def validate_device_factory_request(self, request): """Validate the given device factory request. :param request: a device factory request :return: a validation report """ report = ValidationReport() error = utils.validate_device_factory_request(self.storage, request) if error: report.error_messages.append(error) return report
def validate_container_name(self, name): """Validate the given container name. :param name: a container name :return: a validation report """ report = ValidationReport() error = utils.validate_container_name(self.storage, name) if error: report.error_messages.append(error) return report
def check_completeness(self, device_name): """Check that the specified device is complete. :param device_name: a name of the device :return: a validation report """ report = ValidationReport() device = self._get_device(device_name) message = utils.check_device_completeness(device) if message: report.error_messages.append(message) return report
def validate_mount_point(self, mount_point): """Validate the given mount point. :param mount_point: a path to a mount point :return: a validation report """ report = ValidationReport() mount_points = self.storage.mountpoints.keys() error = utils.validate_mount_point(mount_point, mount_points) if error: report.error_messages.append(error) return report
def _check_disk_selection(self): # If there are some disk selection errors we don't let user to leave # the spoke, so these errors don't have to go to self.errors. report = ValidationReport.from_structure( self._disk_select_module.ValidateSelectedDisks(self._selected_disks) ) if not report.is_valid(): self._disks_errors = report.get_messages() self.set_error(_("There was a problem with your disk selection. " "Click here for details.")) return False self._disks_errors = [] return True
def validate_raid_level(self, raid_level, num_members): """Validate the given RAID level. :param raid_level: a RAID level name :param num_members: a number of members :return: a validation report """ report = ValidationReport() raid_level = utils.get_raid_level_by_name(raid_level) error = utils.validate_raid_level(raid_level, num_members) if error: report.error_messages.append(error) return report
def _check_name_entry(self, inputcheck): container_name = self.get_input(inputcheck.input_obj).strip() if container_name == self._original_name: return InputCheck.CHECK_OK if container_name in self._container_names: return _("Name is already in use.") report = ValidationReport.from_structure( self._device_tree.ValidateContainerName(container_name)) if not report.is_valid(): return " ".join(report.get_messages()) return InputCheck.CHECK_OK
def _validate_raid_level(self): raid_level = get_selected_raid_level(self._raidLevelCombo) self._error = "" if raid_level: paths = self._treeview.get_selection().get_selected_rows()[1] report = ValidationReport.from_structure( self._device_tree.ValidateRaidLevel(raid_level, len(paths))) if not report.is_valid(): self._error = " ".join(report.get_messages()) self._error_label.set_text(self._error) self.window.show_all() return False return True
def _do_check(self): self.clear_errors() StorageCheckHandler.errors = [] StorageCheckHandler.warnings = [] try: log.debug("Generating updated storage configuration") task_path = self._partitioning.ConfigureWithTask() task_proxy = STORAGE.get_proxy(task_path) sync_run_task(task_proxy) except BootloaderConfigurationError as e: log.error("Storage configuration failed: %s", e) StorageCheckHandler.errors = [str(e)] reset_bootloader() else: log.debug("Checking storage configuration...") task_path = self._partitioning.ValidateWithTask() task_proxy = STORAGE.get_proxy(task_path) sync_run_task(task_proxy) result = unwrap_variant(task_proxy.GetResult()) report = ValidationReport.from_structure(result) log.debug("Validation has been completed: %s", report) StorageCheckHandler.errors = report.error_messages StorageCheckHandler.warnings = report.warning_messages if report.is_valid(): self._storage_module.ApplyPartitioning( get_object_path(self._partitioning)) if self.errors: self.set_warning( _("Error checking storage configuration. <a href=\"\">Click for details</a> or press Done again to continue." )) elif self.warnings: self.set_warning( _("Warning checking storage configuration. <a href=\"\">Click for details</a> or press Done again to continue." )) # on_info_bar_clicked requires self._error to be set, so set it to the # list of all errors and warnings that storage checking found. self._error = "\n".join(self.errors + self.warnings) return self._error == ""
def _resolve_selection(self): """Resolve the new selection.""" log.debug("Resolving the software selection.") report = ValidationReport() with self._reported_errors(report): self._dnf_manager.disable_modules(self._selection.disabled_modules) with self._reported_errors(report): self._dnf_manager.enable_modules(self._selection.modules) with self._reported_errors(report): self._dnf_manager.apply_specs(self._include_list, self._exclude_list) with self._reported_errors(report): self._dnf_manager.resolve_selection() log.debug("Resolving has been completed: %s", report) return report