From 1b0aa5afaa00be67c3e47e63b766e7b5934fd266 Mon Sep 17 00:00:00 2001 From: Brett Holman Date: Mon, 16 Sep 2024 16:34:00 -0700 Subject: [PATCH] fix: lxd do not check for thinpool kernel module Rather than checking for kernel module file before running lxd, just fall back to disabling thinpool and retrying with thinpool disabled when cloud-init 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. --- cloudinit/config/cc_lxd.py | 27 ++++++++++++++------------- tests/unittests/config/test_cc_lxd.py | 4 ---- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/cloudinit/config/cc_lxd.py b/cloudinit/config/cc_lxd.py index aa77e9ef901..82365abba86 100644 --- a/cloudinit/config/cc_lxd.py +++ b/cloudinit/config/cc_lxd.py @@ -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.", @@ -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" diff --git a/tests/unittests/config/test_cc_lxd.py b/tests/unittests/config/test_cc_lxd.py index e52523264e8..74d58a7936e 100644 --- a/tests/unittests/config/test_cc_lxd.py +++ b/tests/unittests/config/test_cc_lxd.py @@ -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, )