Skip to content

Commit

Permalink
test: Add integration test for /var mounts (#6033)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheRealFalcon authored Feb 20, 2025
1 parent ffd49b3 commit 7ddc766
Showing 1 changed file with 46 additions and 3 deletions.
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)

0 comments on commit 7ddc766

Please sign in to comment.