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