Fix log disk states (#2902)
This commit is contained in:
parent
1464806f18
commit
7fd726f03f
|
|
@ -54,7 +54,7 @@ debug(f"Virtualization detected: {SysInfo.virtualization()}; is VM: {SysInfo.is_
|
|||
debug(f"Graphics devices detected: {SysInfo._graphics_devices().keys()}")
|
||||
|
||||
# For support reasons, we'll log the disk layout pre installation to match against post-installation layout
|
||||
debug(f"Disk states before installing: {disk.disk_layouts()}")
|
||||
debug(f"Disk states before installing:\n{disk.disk_layouts()}")
|
||||
|
||||
parser = ArgumentParser()
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ from typing import Any, Literal
|
|||
from parted import Device, Disk, DiskException, FileSystem, Geometry, IOException, Partition, PartitionException, freshDisk, getAllDevices, getDevice, newDisk
|
||||
|
||||
from ..exceptions import DiskError, UnknownFilesystemFormat
|
||||
from ..general import JSON, SysCallError, SysCommand, SysCommandWorker
|
||||
from ..general import SysCallError, SysCommand, SysCommandWorker
|
||||
from ..luks import Luks2
|
||||
from ..output import debug, error, info, log, warn
|
||||
from ..utils.util import is_subpath
|
||||
|
|
@ -42,6 +42,7 @@ from .device_model import (
|
|||
find_lsblk_info,
|
||||
get_all_lsblk_info,
|
||||
get_lsblk_info,
|
||||
get_lsblk_output,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -843,11 +844,9 @@ device_handler = DeviceHandler()
|
|||
|
||||
def disk_layouts() -> str:
|
||||
try:
|
||||
lsblk_info = get_all_lsblk_info()
|
||||
return json.dumps(lsblk_info, indent=4, sort_keys=True, cls=JSON)
|
||||
lsblk_output = get_lsblk_output()
|
||||
except SysCallError as err:
|
||||
warn(f"Could not return disk layouts: {err}")
|
||||
return ''
|
||||
except json.decoder.JSONDecodeError as err:
|
||||
warn(f"Could not return disk layouts: {err}")
|
||||
return ''
|
||||
|
||||
return lsblk_output.model_dump_json(indent=4)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import math
|
||||
import uuid
|
||||
from dataclasses import dataclass, field
|
||||
|
|
@ -14,7 +13,7 @@ from pydantic import BaseModel, Field, ValidationInfo, field_serializer, field_v
|
|||
|
||||
from ..exceptions import DiskError, SysCallError
|
||||
from ..general import SysCommand
|
||||
from ..output import debug, error
|
||||
from ..output import debug
|
||||
from ..storage import storage
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
|
@ -1402,7 +1401,7 @@ def _fetch_lsblk_info(
|
|||
dev_path: Path | str | None = None,
|
||||
reverse: bool = False,
|
||||
full_dev_path: bool = False
|
||||
) -> list[LsblkInfo]:
|
||||
) -> LsblkOutput:
|
||||
cmd = ['lsblk', '--json', '--bytes', '--output', ','.join(LsblkInfo.fields())]
|
||||
|
||||
if reverse:
|
||||
|
|
@ -1427,13 +1426,8 @@ def _fetch_lsblk_info(
|
|||
|
||||
raise err
|
||||
|
||||
try:
|
||||
data = json.loads(worker.output(remove_cr=False))
|
||||
except json.decoder.JSONDecodeError as err:
|
||||
error(f"Could not decode lsblk JSON:\n{worker.output().decode().rstrip()}")
|
||||
raise err
|
||||
|
||||
return LsblkOutput(**data).blockdevices
|
||||
output = worker.output(remove_cr=False)
|
||||
return LsblkOutput.parse_raw(output)
|
||||
|
||||
|
||||
def get_lsblk_info(
|
||||
|
|
@ -1441,13 +1435,19 @@ def get_lsblk_info(
|
|||
reverse: bool = False,
|
||||
full_dev_path: bool = False
|
||||
) -> LsblkInfo:
|
||||
if infos := _fetch_lsblk_info(dev_path, reverse=reverse, full_dev_path=full_dev_path):
|
||||
return infos[0]
|
||||
infos = _fetch_lsblk_info(dev_path, reverse=reverse, full_dev_path=full_dev_path)
|
||||
|
||||
if infos.blockdevices:
|
||||
return infos.blockdevices[0]
|
||||
|
||||
raise DiskError(f'lsblk failed to retrieve information for "{dev_path}"')
|
||||
|
||||
|
||||
def get_all_lsblk_info() -> list[LsblkInfo]:
|
||||
return _fetch_lsblk_info().blockdevices
|
||||
|
||||
|
||||
def get_lsblk_output() -> LsblkOutput:
|
||||
return _fetch_lsblk_info()
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -154,7 +154,7 @@ def perform_installation(mountpoint: Path) -> None:
|
|||
except:
|
||||
pass
|
||||
|
||||
debug(f"Disk states after installing: {disk.disk_layouts()}")
|
||||
debug(f"Disk states after installing:\n{disk.disk_layouts()}")
|
||||
|
||||
|
||||
def guided() -> None:
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ def perform_installation(mountpoint: Path) -> None:
|
|||
target.parent.mkdir(parents=True)
|
||||
|
||||
# For support reasons, we'll log the disk layout post installation (crash or no crash)
|
||||
debug(f"Disk states after installing: {disk.disk_layouts()}")
|
||||
debug(f"Disk states after installing:\n{disk.disk_layouts()}")
|
||||
|
||||
|
||||
def only_hd() -> None:
|
||||
|
|
|
|||
|
|
@ -228,7 +228,7 @@ def perform_installation(mountpoint: Path, exec_mode: ExecutionMode) -> None:
|
|||
except:
|
||||
pass
|
||||
|
||||
debug(f"Disk states after installing: {disk.disk_layouts()}")
|
||||
debug(f"Disk states after installing:\n{disk.disk_layouts()}")
|
||||
|
||||
|
||||
def swiss() -> None:
|
||||
|
|
|
|||
|
|
@ -154,7 +154,7 @@ def perform_installation(mountpoint: Path) -> None:
|
|||
except:
|
||||
pass
|
||||
|
||||
debug(f"Disk states after installing: {disk.disk_layouts()}")
|
||||
debug(f"Disk states after installing:\n{disk.disk_layouts()}")
|
||||
|
||||
|
||||
def _guided() -> None:
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ def perform_installation(mountpoint: Path) -> None:
|
|||
target.parent.mkdir(parents=True)
|
||||
|
||||
# For support reasons, we'll log the disk layout post installation (crash or no crash)
|
||||
debug(f"Disk states after installing: {disk.disk_layouts()}")
|
||||
debug(f"Disk states after installing:\n{disk.disk_layouts()}")
|
||||
|
||||
|
||||
def _only_hd() -> None:
|
||||
|
|
|
|||
Loading…
Reference in New Issue