Skip to content

Commit 411f6d5

Browse files
author
Sergio Schvezov
committed
fix: only do LXD compat checks on Ubuntu
Signed-off-by: Sergio Schvezov <sergio.schvezov@canonical.com>
1 parent d4e3f46 commit 411f6d5

File tree

3 files changed

+64
-6
lines changed

3 files changed

+64
-6
lines changed

craft_providers/bases/checks.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright 2021-2023 Canonical Ltd.
2+
# Copyright 2021-2025 Canonical Ltd.
33
#
44
# This program is free software; you can redistribute it and/or
55
# modify it under the terms of the GNU Lesser General Public
@@ -77,13 +77,24 @@ def ensure_guest_compatible(
7777
"""Ensure host is compatible with guest instance."""
7878
if not issubclass(type(base_configuration), BuilddBase):
7979
# Not ubuntu, not sure how to check
80+
logger.debug(
81+
f"Base alias configuration is {base_configuration.alias!r}: no checks for non Buildd"
82+
)
8083
return
8184

85+
host_os_release = parse_os_release()
86+
# Return early for non Ubuntu hosts
87+
if host_os_release.get("ID") != "ubuntu":
88+
logger.debug(
89+
f"Host is {host_os_release.get('ID')}: no checks for non Ubuntu hosts"
90+
)
91+
return
92+
93+
host_base_alias = BuilddBaseAlias(host_os_release.get("VERSION_ID"))
94+
8295
guest_os_release = base_configuration._get_os_release(executor=instance)
8396
guest_base_alias = BuilddBaseAlias(guest_os_release.get("VERSION_ID"))
8497

85-
host_base_alias = BuilddBaseAlias(parse_os_release().get("VERSION_ID"))
86-
8798
# Strip off anything after the first space - sometimes "LTS" is appended
8899
lxd_version_split = lxd_version.strip().split(" ")[0].split(".")
89100
lxd_major = int(lxd_version_split[0])

docs/reference/changelog.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ Changelog
44
See the `Releases page`_ on GitHub for a complete list of commits that are
55
included in each version.
66

7-
2.3.1 (2025-Jun-05)
7+
2.3.1 (2025-Jun-19)
88
-------------------
99

1010
Bug fixes:
1111

1212
- Warn, but don't fail, on failures to mount a shared cache.
13+
- Fix issue where LXD failed to launch on non-Ubuntu distributions because
14+
all OS identities were interpreted as Ubuntu versions.
1315

1416
2.3.0 (2025-May-09)
1517
-------------------

tests/unit/bases/test_ensure_guest_compatible.py

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,40 @@ def test_ensure_guest_compatible_not_ubuntu(fake_executor, fake_process):
3737
base._get_os_release.assert_not_called()
3838

3939

40+
def test_ensure_guest_compatible_non_ubuntu_host(
41+
fake_executor,
42+
fake_process,
43+
):
44+
"""Check for combinations of host and guest OS unaffected by the lxd issue."""
45+
guest_base = ubuntu.BuilddBase(alias=ubuntu.BuilddBaseAlias.JAMMY)
46+
guest_base._get_os_release = MagicMock(spec=guest_base._get_os_release)
47+
48+
# Mock the host os-release file
49+
fake_process.register_subprocess(
50+
[*DEFAULT_FAKE_CMD, "cat", "/etc/os-release"],
51+
stdout='ID="fedora"',
52+
)
53+
54+
# Mock the host os-release file contents
55+
@contextlib.contextmanager
56+
def fake_open(*args, **kwargs):
57+
class Fake:
58+
def read(self):
59+
return 'ID="fedora"'
60+
61+
yield Fake()
62+
63+
with (
64+
patch.object(craft_providers.util.os_release.Path, "open", fake_open), # type: ignore[reportAttributeAccessIssue]
65+
):
66+
ensure_guest_compatible(guest_base, fake_executor, "4.0")
67+
68+
# The first thing that ensure_guest_compatible does is the base check. The next
69+
# thing is to call _get_os_release on the base. So if that isn't called then we
70+
# haven't progressed.
71+
guest_base._get_os_release.assert_not_called()
72+
73+
4074
@pytest.mark.parametrize(
4175
"base_alias",
4276
[
@@ -69,6 +103,7 @@ def fake_get_os_release(*args, **kwargs):
69103
# Mock the host os-release file
70104
fake_os_release = textwrap.dedent(
71105
f"""\
106+
ID="ubuntu"
72107
VERSION_ID="{base_alias.value}"
73108
WOOP="dedoo"
74109
"""
@@ -83,7 +118,12 @@ def fake_get_os_release(*args, **kwargs):
83118
def fake_open(*args, **kwargs):
84119
class Fake:
85120
def read(self):
86-
return f'VERSION_ID="{base_alias.value}"'
121+
return textwrap.dedent(
122+
f"""\
123+
ID="ubuntu"
124+
VERSION_ID="{base_alias.value}"
125+
"""
126+
)
87127

88128
yield Fake()
89129

@@ -147,7 +187,12 @@ def test_ensure_guest_compatible_bad_kernel_versions(
147187
def fake_open(*args, **kwargs):
148188
class Fake:
149189
def read(self):
150-
return f'VERSION_ID="{host_base_alias.value}"'
190+
return textwrap.dedent(
191+
f"""\
192+
ID="ubuntu"
193+
VERSION_ID="{host_base_alias.value}"
194+
"""
195+
)
151196

152197
yield Fake()
153198

0 commit comments

Comments
 (0)