Skip to content

Commit

Permalink
feat: prototype approach without loopback executor
Browse files Browse the repository at this point in the history
  • Loading branch information
mattculler committed Jan 28, 2025
1 parent 077a8e2 commit d2ff086
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
6 changes: 6 additions & 0 deletions craft_providers/bases/ubuntu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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
Expand Down
15 changes: 12 additions & 3 deletions craft_providers/util/os_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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():
Expand Down

0 comments on commit d2ff086

Please sign in to comment.