diff --git a/cloudinit/config/cc_mounts.py b/cloudinit/config/cc_mounts.py index 1b4230c51d0..ccfda25847c 100644 --- a/cloudinit/config/cc_mounts.py +++ b/cloudinit/config/cc_mounts.py @@ -587,7 +587,16 @@ def handle(name: str, cfg: Config, cloud: Cloud, args: list) -> None: cfg_lines = ["\t".join(entry) for entry in updated_cfg] dirs = [d[1] for d in updated_cfg if d[1].startswith("/")] - + for entry in updated_cfg: + fstype = entry[2] + options = entry[3] + + if fstype == "overlay" or "overlay" in options: + for opt in options.split(","): + if opt.startswith("upperdir="): + util.ensure_dir(opt.split("=", 1)[1]) + elif opt.startswith("workdir="): + util.ensure_dir(opt.split("=", 1)[1]) for d in dirs: try: util.ensure_dir(d) diff --git a/tests/unittests/config/test_cc_mounts.py b/tests/unittests/config/test_cc_mounts.py index 80dbf5c6e11..2a8ed7a4ee9 100644 --- a/tests/unittests/config/test_cc_mounts.py +++ b/tests/unittests/config/test_cc_mounts.py @@ -534,6 +534,25 @@ def test_fstab_mounts_combinations(self): """ # noqa: E501 ).strip() ) + + def test_overlay_dirs_are_created(self, mocker, fake_fs): + ensure_dir = mocker.patch("cloudinit.config.cc_mounts.util.ensure_dir") + + cc = { + "mounts": [ + [ + "overlay", + "/mnt/test", + "overlay", + "lowerdir=/a,upperdir=/upper/path,workdir=/work/path", + ] + ] + } + + cc_mounts.handle("", cc, self.mock_cloud, []) + + ensure_dir.assert_any_call("/upper/path") + ensure_dir.assert_any_call("/work/path") class TestCreateSwapfile: