Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix log disk states #2902

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion archinstall/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
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()

Expand Down
11 changes: 5 additions & 6 deletions archinstall/lib/disk/device_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
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
Expand Down Expand Up @@ -42,6 +42,7 @@
find_lsblk_info,
get_all_lsblk_info,
get_lsblk_info,
get_lsblk_output,
)


Expand Down Expand Up @@ -843,11 +844,9 @@ def udev_sync() -> None:

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)
24 changes: 12 additions & 12 deletions archinstall/lib/disk/device_model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

import json
import math
import uuid
from dataclasses import dataclass, field
Expand All @@ -14,7 +13,7 @@

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:
Expand Down Expand Up @@ -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:
Expand All @@ -1427,27 +1426,28 @@ 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(
dev_path: Path | str,
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()


Expand Down
2 changes: 1 addition & 1 deletion archinstall/scripts/guided.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion archinstall/scripts/only_hd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion archinstall/scripts/swiss.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion examples/interactive_installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion examples/only_hd_installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down