From d2ff08628bbee2678efb79392a009d67471223b5 Mon Sep 17 00:00:00 2001 From: Matt Culler Date: Tue, 28 Jan 2025 13:39:12 -0500 Subject: [PATCH] feat: prototype approach without loopback executor --- craft_providers/bases/ubuntu.py | 6 ++++++ craft_providers/util/os_release.py | 15 ++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/craft_providers/bases/ubuntu.py b/craft_providers/bases/ubuntu.py index 0a63d66a..ff8dfeb7 100644 --- a/craft_providers/bases/ubuntu.py +++ b/craft_providers/bases/ubuntu.py @@ -35,6 +35,7 @@ ) from craft_providers.executor import Executor from craft_providers.loopback_executor import LoopbackExecutor +from craft_providers.util.os_release import parse_os_release logger = logging.getLogger(__name__) @@ -300,8 +301,13 @@ def ensure_guest_compatible(base_configuration: Base, guest_instance: Executor) # _get_os_release, which uses timeout values from the base_configuration instance and # nothing else. guest_base_alias = _get_buildd_base_alias(base_configuration, guest_instance) + + # With loopback executor: host_base_alias = _get_buildd_base_alias(base_configuration, host_instance) + # Without loopback executor: + host_base_alias = BuilddBaseAlias(parse_os_release().get("VERSION_ID")) + # If the host OS is focal (20.04) or older, and the guest OS is oracular (24.10) # or newer, then the host lxd must be >=5.0.4 or >=5.21.2, and kernel must be # 5.15 or newer. Otherwise, weird systemd failures will occur due to a mismatch diff --git a/craft_providers/util/os_release.py b/craft_providers/util/os_release.py index 2f3761f5..e2164b22 100644 --- a/craft_providers/util/os_release.py +++ b/craft_providers/util/os_release.py @@ -16,10 +16,14 @@ # """Parser for /etc/os-release.""" + +from pathlib import Path from typing import Dict +OS_RELEASE_FILE = Path("/etc/os-release") + -def parse_os_release(content: str) -> Dict[str, str]: +def parse_os_release(content: str | None) -> Dict[str, str]: """Parser for /etc/os-release. Format documentation at: @@ -41,12 +45,17 @@ def parse_os_release(content: str) -> Dict[str, str]: VERSION_CODENAME=jammy UBUNTU_CODENAME=jammy - :param content: String contents of os-release file. + :param content: String contents of os-release file. If None, will read contents of + file from host. :returns: Dictionary of key-mappings found in os-release. Values are - stripped of encapsulating quotes. + stripped of encapsulating quotes. """ + if content is None: + with OS_RELEASE_FILE.open() as f: + content = f.read() + mappings: Dict[str, str] = {} for line in content.splitlines():