Skip to content

Commit

Permalink
fix: lxd do not check for thinpool kernel module (canonical#5709)
Browse files Browse the repository at this point in the history
Rather than checking for kernel module file before running lxd, just
fall back to disabling thinpool and retrying with thinpool disabled
when subp() fails and it is using lvm as backing storage.

On some Ubuntu releases, the kernel module is compressed which causes
this check to fail and this warning to erroneously be logged. Making
this logic only run in the failure path and avoiding file matches on
kernel driver files should be less error prone.

BREAKING_CHANGE: On some Ubuntu series this changes behavior causing
lxd to now use lxd thinpool, which is the current lxd default.

LP: #1982780
  • Loading branch information
holmanb committed Sep 17, 2024
1 parent 654cb44 commit f657379
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
27 changes: 14 additions & 13 deletions cloudinit/config/cc_lxd.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,17 @@ def handle(name: str, cfg: Config, cloud: Cloud, args: list) -> None:
"trust_password",
)

# Bug https://bugs.launchpad.net/ubuntu/+source/linux-kvm/+bug/1982780
kernel = util.system_info()["uname"][2]
if init_cfg["storage_backend"] == "lvm" and not os.path.exists(
f"/lib/modules/{kernel}/kernel/drivers/md/dm-thin-pool.ko"
):
cmd = ["lxd", "init", "--auto"]
for k in init_keys:
if init_cfg.get(k):
cmd.extend(
["--%s=%s" % (k.replace("_", "-"), str(init_cfg[k]))]
)
try:
subp.subp(cmd)
except subp.ProcessExecutionError:
if init_cfg["storage_backend"] != "lvm":
raise
LOG.warning(
"cloud-init doesn't use thinpool by default on Ubuntu due to "
"LP #1982780. This behavior will change in the future.",
Expand All @@ -145,14 +151,9 @@ def handle(name: str, cfg: Config, cloud: Cloud, args: list) -> None:
init_keys = tuple(
key for key in init_keys if key != "storage_backend"
)

cmd = ["lxd", "init", "--auto"]
for k in init_keys:
if init_cfg.get(k):
cmd.extend(
["--%s=%s" % (k.replace("_", "-"), str(init_cfg[k]))]
)
subp.subp(cmd)
# Retry with thinpool in case of minimal image
# Bug https://bugs.launchpad.net/ubuntu/+source/linux-kvm/+bug/1982780
subp.subp(cmd)

# Set up lxd-bridge if bridge config is given
dconf_comm = "debconf-communicate"
Expand Down
4 changes: 0 additions & 4 deletions tests/unittests/config/test_cc_lxd.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,6 @@ def test_lxd_init(self, maybe_clean, which, subp, exists, system_info):
self.assertEqual(
[
mock.call(sem_file),
mock.call(
"/lib/modules/mykernel/"
"kernel/drivers/md/dm-thin-pool.ko"
),
],
exists.call_args_list,
)
Expand Down

0 comments on commit f657379

Please sign in to comment.