Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion cloudinit/config/cc_mounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 19 additions & 0 deletions tests/unittests/config/test_cc_mounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading