Skip to content

Commit

Permalink
tests: Check that smbios seed works
Browse files Browse the repository at this point in the history
- Verify that NoCloud smbios seed gets read for file://
- Verify that NoCloud smbios seed gets read from http:// and https://
  • Loading branch information
holmanb committed Feb 26, 2024
1 parent de85cb4 commit 5f29713
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cloudinit/sources/DataSourceNoCloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ def _merge_new_seed(cur, seeded):


def _parse_dmi() -> str:
serial = dmi.read_dmi_data("product_serial")
serial = dmi.read_dmi_data("system-serial-number")
if serial:
return sources.parse_cmdline_or_dmi(serial)
return ""
Expand Down
Binary file not shown.
98 changes: 98 additions & 0 deletions tests/integration_tests/datasources/test_nocloud.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""NoCloud datasource integration tests."""
from textwrap import dedent

import pytest
from pycloudlib.lxd.instance import LXDInstance

Expand Down Expand Up @@ -88,3 +90,99 @@ def test_nocloud_seedfrom_vendordata(client: IntegrationInstance):
client.restart()
assert client.execute("cloud-init status").ok
assert "seeded_vendordata_test_file" in client.execute("ls /var/tmp")


SMBIOS_USERDATA = """\
#cloud-config
runcmd:
- touch /var/tmp/smbios_test_file
"""
SMBIOS_SEED_DIR = "/smbios_seed"


def setup_nocloud_local_serial(instance: LXDInstance):
subp(
[
"lxc",
"config",
"set",
instance.name,
"raw.qemu=-smbios "
f"type=1,serial=ds=nocloud;s=file://{SMBIOS_SEED_DIR};h=myhost",
]
)


def setup_nocloud_network_serial(instance: LXDInstance):
subp(
[
"lxc",
"config",
"set",
instance.name,
"raw.qemu=-smbios "
"type=1,serial=ds=nocloud;s=http://0.0.0.0/;h=myhost",
]
)


@pytest.mark.lxd_use_exec
@pytest.mark.skipif(
PLATFORM != "lxd_vm",
reason="Requires NoCloud with raw QEMU serial setup",
)
class TestSmbios:
@pytest.mark.lxd_setup.with_args(setup_nocloud_local_serial)
def test_smbios_seed_local(self, client: IntegrationInstance):
"""Check that smbios seeds that use local disk work"""
assert client.execute(f"mkdir -p {SMBIOS_SEED_DIR}").ok
client.write_to_file(f"{SMBIOS_SEED_DIR}/user-data", SMBIOS_USERDATA)
client.write_to_file(f"{SMBIOS_SEED_DIR}/meta-data", "")
client.write_to_file(f"{SMBIOS_SEED_DIR}/vendor-data", "")
assert client.execute("cloud-init clean --logs").ok
client.restart()
assert client.execute("test -f /var/tmp/smbios_test_file").ok

@pytest.mark.lxd_setup.with_args(setup_nocloud_network_serial)
def test_smbios_seed_network(self, client: IntegrationInstance):
"""Check that smbios seeds that use network (http/https) work"""
service_file = "/lib/systemd/system/local-server.service"
client.write_to_file(
service_file,
dedent(
"""\
[Unit]
Description=Serve a local webserver
Before=cloud-config.service
Wants=cloud-init-local.service
DefaultDependencies=no
After=systemd-networkd-wait-online.service
After=networking.service
[Install]
WantedBy=cloud-init.target
[Service]
"""
f"WorkingDirectory={SMBIOS_SEED_DIR}"
"""
ExecStart=/usr/bin/env python3 -m http.server --bind 0.0.0.0 80
"""
),
)
assert client.execute(
"chmod 644 /lib/systemd/system/local-server.service"
).ok
assert client.execute("systemctl enable local-server.service").ok
client.write_to_file(
"/etc/cloud/cloud.cfg.d/91_do_not_use_lxd.cfg",
"datasource_list: [ NoCloud, None ]\n",
)
assert client.execute(f"mkdir -p {SMBIOS_SEED_DIR}").ok
client.write_to_file(f"{SMBIOS_SEED_DIR}/user-data", SMBIOS_USERDATA)
client.write_to_file(f"{SMBIOS_SEED_DIR}/meta-data", "")
client.write_to_file(f"{SMBIOS_SEED_DIR}/vendor-data", "")
assert client.execute("cloud-init clean --logs").ok
client.restart()
assert client.execute("test -f /var/tmp/smbios_test_file").ok

0 comments on commit 5f29713

Please sign in to comment.