How to use report_warning method in Slash

Best Python code snippet using slash

storage_utils.py

Source:storage_utils.py Github

copy

Full Screen

...123 """124 root = storage.fsset.rootDevice125 if root:126 if root.size < constraints["min_root"]:127 report_warning(_("Your root partition is less than %(size)s "128 "which is usually too small to install "129 "%(product)s.")130 % {'size': constraints["min_root"],131 'product': productName})132 else:133 report_error(_("You have not defined a root partition (/), "134 "which is required for installation of %s"135 " to continue.") % (productName,))136 if storage.rootDevice and storage.rootDevice.format.exists:137 e = storage.mustFormat(storage.rootDevice)138 if e:139 report_error(e)140 if storage.rootDevice and constraints["root_device_types"]:141 device_type = get_device_type(storage.rootDevice)142 device_types = constraints["root_device_types"]143 if device_type not in device_types:144 report_error(_("Your root partition must be on a device of type: %s.")145 % ", ".join(DEVICE_TEXT_MAP[t] for t in device_types))146def verify_partition_sizes(storage, constraints, report_error, report_warning):147 """ Verify the minimal and required partition sizes.148 :param storage: a storage to check149 :param constraints: a dictionary of constraints150 :param report_error: a function for error reporting151 :param report_warning: a function for warning reporting152 """153 filesystems = storage.mountpoints154 for (mount, size) in constraints["min_partition_sizes"].items():155 if mount in filesystems and filesystems[mount].size < size:156 report_warning(_("Your %(mount)s partition is less than "157 "%(size)s which is lower than recommended "158 "for a normal %(productName)s install.")159 % {'mount': mount, 'size': size,160 'productName': productName})161 for (mount, size) in constraints["req_partition_sizes"].items():162 if mount in filesystems and filesystems[mount].size < size:163 report_error(_("Your %(mount)s partition is less than "164 "%(size)s which is lower than required.")165 % {'mount': mount, 'size': size})166def verify_partition_format_sizes(storage, constraints, report_error, report_warning):167 """ Verify that the size of the device is allowed by the format used.168 :param storage: a storage to check169 :param constraints: a dictionary of constraints170 :param report_error: a function for error reporting171 :param report_warning: a function for warning reporting172 """173 filesystems = storage.mountpoints174 for (mount, device) in filesystems.items():175 problem = filesystems[mount].checkSize()176 if problem < 0:177 report_error(_("Your %(mount)s partition is too small for "178 "%(format)s formatting (allowable size is "179 "%(minSize)s to %(maxSize)s)")180 % {"mount": mount, "format": device.format.name,181 "minSize": device.minSize, "maxSize": device.maxSize})182 elif problem > 0:183 report_warning(_("Your %(mount)s partition is too large for "184 "%(format)s formatting (allowable size is "185 "%(minSize)s to %(maxSize)s)")186 % {"mount": mount, "format": device.format.name,187 "minSize": device.minSize, "maxSize": device.maxSize})188def verify_bootloader(storage, constraints, report_error, report_warning):189 """ Verify that the size of the device is allowed by the format used.190 :param storage: a storage to check191 :param constraints: a dictionary of constraints192 :param report_error: a function for error reporting193 :param report_warning: a function for warning reporting194 """195 if storage.bootloader and not storage.bootloader.skip_bootloader:196 stage1 = storage.bootloader.stage1_device197 if not stage1:198 report_error(_("No valid boot loader target device found. "199 "See below for details."))200 pe = _platform.stage1MissingError201 if pe:202 report_error(_(pe))203 else:204 storage.bootloader.is_valid_stage1_device(stage1)205 for msg in storage.bootloader.errors:206 report_error(msg)207 for msg in storage.bootloader.warnings:208 report_warning(msg)209 stage2 = storage.bootloader.stage2_device210 if stage1 and not stage2:211 report_error(_("You have not created a bootable partition."))212 else:213 storage.bootloader.is_valid_stage2_device(stage2)214 for msg in storage.bootloader.errors:215 report_error(msg)216 for msg in storage.bootloader.warnings:217 report_warning(msg)218 if not storage.bootloader.check():219 for msg in storage.bootloader.errors:220 report_error(msg)221def verify_gpt_biosboot(storage, constraints, report_error, report_warning):222 """ Verify that GPT boot disk on BIOS system has a BIOS boot partition.223 :param storage: a storage to check224 :param constraints: a dictionary of constraints225 :param report_error: a function for error reporting226 :param report_warning: a function for warning reporting227 """228 if storage.bootloader and not storage.bootloader.skip_bootloader:229 stage1 = storage.bootloader.stage1_device230 if _platform.weight(fstype="biosboot") and stage1 and stage1.isDisk \231 and getattr(stage1.format, "labelType", None) == "gpt":232 missing = True233 for part in [p for p in storage.partitions if p.disk == stage1]:234 if part.format.type == "biosboot":235 missing = False236 break237 if missing:238 report_error(_("Your BIOS-based system needs a special "239 "partition to boot from a GPT disk label. "240 "To continue, please create a 1MiB "241 "'biosboot' type partition."))242def verify_swap(storage, constraints, report_error, report_warning):243 """ Verify the existence of swap.244 :param storage: a storage to check245 :param constraints: a dictionary of constraints246 :param report_error: a function for error reporting247 :param report_warning: a function for warning reporting248 """249 swaps = storage.fsset.swapDevices250 if not swaps:251 installed = util.total_memory()252 required = Size("%s MiB" % (constraints["min_ram"] + isys.NO_SWAP_EXTRA_RAM))253 if installed < required:254 report_error(_("You have not specified a swap partition. "255 "%(requiredMem)s of memory is required to continue "256 "installation without a swap partition, but you only "257 "have %(installedMem)s.")258 % {"requiredMem": required, "installedMem": installed})259 else:260 report_warning(_("You have not specified a swap partition. "261 "Although not strictly required in all cases, "262 "it will significantly improve performance "263 "for most installations."))264def verify_swap_uuid(storage, constraints, report_error, report_warning):265 """ Verify swap uuid.266 :param storage: a storage to check267 :param constraints: a dictionary of constraints268 :param report_error: a function for error reporting269 :param report_warning: a function for warning reporting270 """271 swaps = storage.fsset.swapDevices272 no_uuid = [s for s in swaps if s.format.exists and not s.format.uuid]273 if no_uuid:274 report_warning(_("At least one of your swap devices does not have "275 "a UUID, which is common in swap space created "276 "using older versions of mkswap. These devices "277 "will be referred to by device path in "278 "/etc/fstab, which is not ideal since device "279 "paths can change under a variety of "280 "circumstances. "))281def verify_mountpoints_on_root(storage, constraints, report_error, report_warning):282 """ Verify mountpoints on the root.283 :param storage: a storage to check284 :param constraints: a dictionary of constraints285 :param report_error: a function for error reporting286 :param report_warning: a function for warning reporting287 """288 filesystems = storage.mountpoints...

Full Screen

Full Screen

utils.py

Source:utils.py Github

copy

Full Screen

...84 and not any(filter(mount.startswith, constraints[STORAGE_REFORMAT_BLOCKLIST]))85 and any(filter(mount.startswith, constraints[STORAGE_REFORMAT_ALLOWLIST]))86 ]87 for mount in mountpoints:88 report_warning(_("It is recommended to create a new file system on your "89 "%(mount)s partition.") % {'mount': mount})90def verify_partition_sizes(storage, constraints, report_error, report_warning):91 """ Verify the minimal and required partition sizes.92 :param storage: a storage to check93 :param constraints: a dictionary of constraints94 :param report_error: a function for error reporting95 :param report_warning: a function for warning reporting96 """97 filesystems = storage.mountpoints98 for (mount, size) in constraints[STORAGE_MIN_PARTITION_SIZES].items():99 if mount in filesystems and filesystems[mount].size < size:100 report_warning(_("Your %(mount)s partition is less than "101 "%(size)s which is lower than recommended "102 "for a normal %(productName)s install.")103 % {'mount': mount, 'size': size,104 'productName': productName})105 for (mount, size) in constraints[STORAGE_REQ_PARTITION_SIZES].items():106 if mount in filesystems and filesystems[mount].size < size:107 report_error(_("Your %(mount)s partition size is lower "108 "than required %(size)s.")109 % {'mount': mount, 'size': size})110def verify_partition_format_sizes(storage, constraints, report_error, report_warning):111 """ Verify that the size of the device is allowed by the format used.112 :param storage: a storage to check113 :param constraints: a dictionary of constraints114 :param report_error: a function for error reporting115 :param report_warning: a function for warning reporting116 """117 # storage.mountpoints is a property that returns a new dict each time, so118 # iterating over it is thread-safe.119 filesystems = storage.mountpoints120 for (mount, device) in filesystems.items():121 problem = filesystems[mount].check_size()122 if problem < 0:123 report_error(_("Your %(mount)s partition is too small for "124 "%(format)s formatting (allowable size is "125 "%(minSize)s to %(maxSize)s)")126 % {"mount": mount, "format": device.format.name,127 "minSize": device.min_size, "maxSize": device.max_size})128 elif problem > 0:129 report_error(_("Your %(mount)s partition is too large for "130 "%(format)s formatting (allowable size is "131 "%(minSize)s to %(maxSize)s)")132 % {"mount": mount, "format": device.format.name,133 "minSize": device.min_size, "maxSize": device.max_size})134def verify_bootloader(storage, constraints, report_error, report_warning):135 """ Verify that the size of the device is allowed by the format used.136 :param storage: a storage to check137 :param constraints: a dictionary of constraints138 :param report_error: a function for error reporting139 :param report_warning: a function for warning reporting140 """141 if storage.bootloader and not storage.bootloader.skip_bootloader:142 stage1 = storage.bootloader.stage1_device143 if not stage1:144 report_error(_("No valid boot loader target device found. "145 "See below for details."))146 report_error(platform.stage1_suggestion)147 else:148 storage.bootloader.is_valid_stage1_device(stage1)149 for msg in storage.bootloader.errors:150 report_error(msg)151 for msg in storage.bootloader.warnings:152 report_warning(msg)153 stage2 = storage.bootloader.stage2_device154 if stage1 and not stage2:155 report_error(_("You have not created a bootable partition."))156 else:157 storage.bootloader.is_valid_stage2_device(stage2)158 for msg in storage.bootloader.errors:159 report_error(msg)160 for msg in storage.bootloader.warnings:161 report_warning(msg)162 if not storage.bootloader.check():163 for msg in storage.bootloader.errors:164 report_error(msg)165def verify_gpt_biosboot(storage, constraints, report_error, report_warning):166 """ Verify that GPT boot disk on BIOS system has a BIOS boot partition.167 :param storage: a storage to check168 :param constraints: a dictionary of constraints169 :param report_error: a function for error reporting170 :param report_warning: a function for warning reporting171 """172 if storage.bootloader and not storage.bootloader.skip_bootloader:173 stage1 = storage.bootloader.stage1_device174 if arch.is_x86() and not arch.is_efi() and stage1 and stage1.is_disk \175 and getattr(stage1.format, "label_type", None) == "gpt":176 missing = True177 for part in [p for p in storage.partitions if p.disk == stage1]:178 if part.format.type == "biosboot":179 missing = False180 break181 if missing:182 report_error(_("Your BIOS-based system needs a special "183 "partition to boot from a GPT disk label. "184 "To continue, please create a 1MiB "185 "'biosboot' type partition."))186def verify_opal_compatibility(storage, constraints, report_error, report_warning):187 """ Verify the OPAL compatibility.188 :param storage: a storage to check189 :param constraints: a dictionary of constraints190 :param report_error: a function for error reporting191 :param report_warning: a function for warning reporting192 """193 if arch.get_arch() == "ppc64le" and arch.is_powernv():194 # Check the kernel version.195 version = _get_opal_firmware_kernel_version()196 if _check_opal_firmware_kernel_version(version, "5.10"):197 return198 # Is /boot on XFS?199 dev = storage.mountpoints.get("/boot") or storage.mountpoints.get("/")200 if dev and dev.format and dev.format.type == "xfs":201 report_error(_(202 "The system will not be bootable. The firmware does not "203 "support XFS file system features on the boot file system. "204 "Upgrade the firmware or change the file system type."205 ))206def _check_opal_firmware_kernel_version(detected_version, required_version):207 """Check the firmware kernel version for OPAL systems.208 :param detected_version: a string with the detected kernel version or None209 :param required_version: a string with the required kernel version or None210 :return: True or False211 """212 try:213 if detected_version and required_version:214 return parse_version(detected_version) >= parse_version(required_version)215 except Exception as e: # pylint: disable=broad-except216 log.warning("Couldn't check the firmware kernel version: %s", str(e))217 return False218def _get_opal_firmware_kernel_version():219 """Get the firmware kernel version for OPAL systems.220 For example: 5.10.50-openpower1-p59fd803221 :return: a string with the kernel version or None222 """223 version = None224 try:225 with open("/proc/device-tree/ibm,firmware-versions/linux") as f:226 version = f.read().strip().removeprefix("v")227 log.debug("The firmware kernel version is '%s'.", version)228 except IOError as e:229 log.warning("Couldn't get the firmware kernel version: %s", str(e))230 return version231def verify_swap(storage, constraints, report_error, report_warning):232 """ Verify the existence of swap.233 :param storage: a storage to check234 :param constraints: a dictionary of constraints235 :param report_error: a function for error reporting236 :param report_warning: a function for warning reporting237 """238 swaps = storage.fsset.swap_devices239 if not swaps:240 installed = util.total_memory()241 required = constraints[STORAGE_MIN_RAM] + Size("{} MiB".format(isys.NO_SWAP_EXTRA_RAM))242 if not constraints[STORAGE_SWAP_IS_RECOMMENDED]:243 if installed < required:244 report_warning(_("You have not specified a swap partition. "245 "%(requiredMem)s of memory is recommended to continue "246 "installation without a swap partition, but you only "247 "have %(installedMem)s.")248 % {"requiredMem": required, "installedMem": installed})249 else:250 if installed < required:251 report_error(_("You have not specified a swap partition. "252 "%(requiredMem)s of memory is required to continue "253 "installation without a swap partition, but you only "254 "have %(installedMem)s.")255 % {"requiredMem": required, "installedMem": installed})256 else:257 report_warning(_(258 "A swap partition has not been specified. To significantly "259 "improve performance for most installations, it is recommended "260 "to specify a swap partition."261 ))262def verify_swap_uuid(storage, constraints, report_error, report_warning):263 """ Verify swap uuid.264 :param storage: a storage to check265 :param constraints: a dictionary of constraints266 :param report_error: a function for error reporting267 :param report_warning: a function for warning reporting268 """269 swaps = storage.fsset.swap_devices270 no_uuid = [s for s in swaps if s.format.exists and not s.format.uuid]271 if no_uuid:272 report_warning(_("At least one of your swap devices does not have "273 "a UUID, which is common in swap space created "274 "using older versions of mkswap. These devices "275 "will be referred to by device path in "276 "/etc/fstab, which is not ideal since device "277 "paths can change under a variety of "278 "circumstances. "))279def verify_mountpoints_on_root(storage, constraints, report_error, report_warning):280 """ Verify mountpoints on the root.281 :param storage: a storage to check282 :param constraints: a dictionary of constraints283 :param report_error: a function for error reporting284 :param report_warning: a function for warning reporting285 """286 for mountpoint in storage.mountpoints:287 if mountpoint in constraints[STORAGE_MUST_BE_ON_ROOT]:288 report_error(_("This mount point is invalid. The %s directory must "289 "be on the / file system.") % mountpoint)290def verify_mountpoints_not_on_root(storage, constraints, report_error, report_warning):291 """ Verify mountpoints not on the root.292 :param storage: a storage to check293 :param constraints: a dictionary of constraints294 :param report_error: a function for error reporting295 :param report_warning: a function for warning reporting296 """297 filesystems = storage.mountpoints298 for mountpoint in constraints[STORAGE_MUST_NOT_BE_ON_ROOT]:299 if mountpoint not in filesystems:300 report_error(_("Your %s must be on a separate partition or LV.")301 % mountpoint)302def verify_mountpoints_on_linuxfs(storage, constraints, report_error, report_warning):303 """ Verify mountpoints on linuxfs.304 :param storage: a storage to check305 :param constraints: a dictionary of constraints306 :param report_error: a function for error reporting307 :param report_warning: a function for warning reporting308 """309 filesystems = storage.mountpoints310 for (mountpoint, dev) in filesystems.items():311 if mountpoint in constraints[STORAGE_MUST_BE_ON_LINUXFS] \312 and (not dev.format.mountable or not dev.format.linux_native):313 report_error(_("The mount point %s must be on a linux file system.") % mountpoint)314def verify_unlocked_devices_have_key(storage, constraints, report_error, report_warning):315 """ Verify that existing unlocked LUKS devices have some way of obtaining a key.316 Blivet doesn't remove decrypted devices after a teardown of unlocked LUKS devices317 and later fails to set them up without a key, so report an error to prevent a318 traceback during the installation.319 :param storage: a storage to check320 :param constraints: a dictionary of constraints321 :param report_error: a function for error reporting322 :param report_warning: a function for warning reporting323 """324 devices = [325 d for d in storage.devices326 if d.format.type == "luks"327 and d.format.exists328 and not d.format.has_key329 and d.children330 and any(c.name == d.format.map_name for c in d.children)331 ]332 for dev in devices:333 report_error(_("The existing unlocked LUKS device {} cannot be used for "334 "the installation without an encryption key specified for "335 "this device. Please, rescan the storage.").format(dev.name))336def verify_luks_devices_have_key(storage, constraints, report_error, report_warning):337 """ Verify that all non-existant LUKS devices have some way of obtaining a key.338 :param storage: a storage to check339 :param constraints: a dictionary of constraints340 :param report_error: a function for error reporting341 :param report_warning: a function for warning reporting342 Note: LUKS device creation will fail without a key.343 """344 devices = [d for d in storage.devices345 if d.format.type == "luks"346 and not d.format.exists347 and not d.format.has_key]348 for dev in devices:349 report_error(_("Encryption requested for LUKS device %s but no "350 "encryption key specified for this device.") % (dev.name,))351def verify_luks2_memory_requirements(storage, constraints, report_error, report_warning):352 """ Verify that there is enough available memory for LUKS2 format.353 :param storage: a storage to check354 :param constraints: a dictionary of constraints355 :param report_error: a function for error reporting356 :param report_warning: a function for warning reporting357 """358 devices = [d for d in storage.devices359 if d.format.type == "luks"360 and d.format.luks_version == "luks2"361 and d.format.pbkdf_args is None362 and not d.format.exists]363 available_memory = util.available_memory()364 log.debug("Available memory: %s", available_memory)365 if devices and available_memory < constraints[STORAGE_LUKS2_MIN_RAM]:366 report_warning(_("The available memory is less than %(size)s which can "367 "be too small for LUKS2 format. It may fail.")368 % {"size": constraints[STORAGE_LUKS2_MIN_RAM]})369def verify_mounted_partitions(storage, constraints, report_error, report_warning):370 """ Check the selected disks to make sure all their partitions are unmounted.371 Check both the currently known and original partitions.372 :param storage: a storage to check373 :param constraints: a dictionary of constraints374 :param report_error: a function for error reporting375 :param report_warning: a function for warning reporting376 """377 partitions_to_check = {}378 for disk in storage.disks:379 if disk.protected:380 continue...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Slash automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful