Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Add integration test for /var mounts #6033

Merged
merged 1 commit into from
Feb 20, 2025
Merged
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
49 changes: 46 additions & 3 deletions tests/integration_tests/modules/test_disk_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
from cloudinit.subp import subp
from tests.integration_tests.instances import IntegrationInstance
from tests.integration_tests.integration_settings import PLATFORM
from tests.integration_tests.releases import CURRENT_RELEASE, FOCAL, IS_UBUNTU
from tests.integration_tests.releases import (
CURRENT_RELEASE,
FOCAL,
IS_UBUNTU,
NOBLE,
)
from tests.integration_tests.util import verify_clean_boot, verify_clean_log

DISK_PATH = "/tmp/test_disk_setup_{}".format(uuid4())
Expand All @@ -24,8 +29,7 @@ def setup_and_mount_lxd_disk(instance: LXDInstance):

@pytest.fixture
def create_disk():
# 640k should be enough for anybody
subp("dd if=/dev/zero of={} bs=1k count=640".format(DISK_PATH).split())
subp("dd if=/dev/zero of={} bs=64k count=40".format(DISK_PATH).split())
yield
os.remove(DISK_PATH)

Expand Down Expand Up @@ -227,3 +231,42 @@ def test_disk_setup_no_partprobe(
self._verify_first_disk_setup(client, log)

assert "partprobe" not in log


def setup_lxd_disk_with_fs(instance: LXDInstance):
subp(["mkfs.ext4", DISK_PATH])
subp(
f"lxc config device add {instance.name} test-disk-setup-disk "
f"disk source={DISK_PATH}".split()
)


@pytest.mark.lxd_setup.with_args(setup_lxd_disk_with_fs)
@pytest.mark.skipif(not IS_UBUNTU, reason="Only ever tested on Ubuntu")
@pytest.mark.skipif(
PLATFORM != "lxd_vm", reason="Test requires additional mounted device"
)
def test_required_mounts(create_disk, client: IntegrationInstance):
"""Ensure /var is mounted before used.

GH-6001
LP: #2097441
"""
client.execute(
'echo "/dev/sdb /var auto defaults,nofail 0 2" >> /etc/fstab'
)
client.execute("cloud-init clean --logs")
client.restart()

service = (
"cloud-init-local.service"
if CURRENT_RELEASE <= NOBLE
else "cloud-init-main.service"
)

deps = client.execute(
f"systemctl list-dependencies --all {service}".split()
)
assert "var.mount" in deps, "Exepected 'var.mount' to be a dependency"

verify_clean_boot(client)