CI / test (3.10) (push) Successful in 30s
CI / test (3.11) (push) Successful in 26s
CI / test (3.12) (push) Successful in 28s
CI / test (3.10) (pull_request) Successful in 27s
CI / test (3.11) (pull_request) Successful in 26s
CI / test (3.12) (pull_request) Successful in 27s
Follows napalm-device-types 3.0, which replaces GUEST_AGENT_PACKAGES /
GUEST_AGENT_RUNCMD with GUEST_AGENTS = {guest_os: (packages, runcmd)}.
VMware lists Linux with open-vm-tools, as before, and refuses any other
guest_os before anything is created: BSD guests on VMware are optional
for now (NetOrk/netork#801).
The NoCloud network-config moved to napalm-device-types
(`provisioning.network_config`), which Proxmox now uses as well; the seed
module's copy is gone, and the tests check that the generic one is used.
80 lines
2.8 KiB
Python
80 lines
2.8 KiB
Python
"""The NoCloud seed: cloud-init's user-data, meta-data and network-config on an ISO."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import io
|
|
|
|
import pycdlib
|
|
import yaml
|
|
from napalm_device_types import provisioning as generic
|
|
|
|
from napalm_vmware import provisioning as prov
|
|
from napalm_vmware.provision import seed
|
|
from napalm_vmware.provision.seed import meta_data, nocloud_iso, user_data
|
|
|
|
|
|
class TestUserData:
|
|
def test_is_a_cloud_config(self):
|
|
text = user_data({"hostname": "web01", "packages": ["open-vm-tools"]}, None)
|
|
assert text.startswith("#cloud-config\n")
|
|
assert yaml.safe_load(text) == {"hostname": "web01", "packages": ["open-vm-tools"]}
|
|
|
|
def test_ssh_keys_are_added_without_duplicates(self):
|
|
config = {"ssh_authorized_keys": ["ssh-ed25519 AAA a"]}
|
|
text = user_data(config, ["ssh-ed25519 AAA a", "ssh-ed25519 BBB b"])
|
|
assert yaml.safe_load(text)["ssh_authorized_keys"] == [
|
|
"ssh-ed25519 AAA a",
|
|
"ssh-ed25519 BBB b",
|
|
]
|
|
assert config == {"ssh_authorized_keys": ["ssh-ed25519 AAA a"]} # caller's dict untouched
|
|
|
|
|
|
def test_meta_data():
|
|
assert yaml.safe_load(meta_data("web01", "iid-1")) == {
|
|
"instance-id": "iid-1",
|
|
"local-hostname": "web01",
|
|
}
|
|
|
|
|
|
class TestNetworkConfig:
|
|
"""Written by napalm-device-types, which Proxmox uses as well (NetOrk/netork#794)."""
|
|
|
|
def test_the_seed_is_built_with_the_generic_network_config(self):
|
|
assert prov.network_config is generic.network_config
|
|
|
|
def test_no_copy_of_it_is_left_here(self):
|
|
assert not hasattr(seed, "network_config")
|
|
|
|
|
|
def _read(iso: bytes, name: str) -> str:
|
|
reader = pycdlib.PyCdlib()
|
|
reader.open_fp(io.BytesIO(iso))
|
|
out = io.BytesIO()
|
|
reader.get_file_from_iso_fp(out, rr_path=f"/{name}")
|
|
reader.close()
|
|
return out.getvalue().decode()
|
|
|
|
|
|
class TestIso:
|
|
def test_carries_the_three_files_under_their_cloud_init_names(self):
|
|
iso = nocloud_iso("#cloud-config\n{}\n", "instance-id: x\n", {"version": 2})
|
|
assert _read(iso, "user-data") == "#cloud-config\n{}\n"
|
|
assert _read(iso, "meta-data") == "instance-id: x\n"
|
|
assert yaml.safe_load(_read(iso, "network-config")) == {"version": 2}
|
|
|
|
def test_volume_label_is_cidata(self):
|
|
"""cloud-init's NoCloud datasource finds the seed by this label."""
|
|
reader = pycdlib.PyCdlib()
|
|
reader.open_fp(io.BytesIO(nocloud_iso("u", "m", None)))
|
|
assert reader.pvd.volume_identifier.decode().strip() == "cidata"
|
|
reader.close()
|
|
|
|
def test_without_network_config(self):
|
|
reader = pycdlib.PyCdlib()
|
|
reader.open_fp(io.BytesIO(nocloud_iso("u", "m", None)))
|
|
names = [
|
|
c.rock_ridge.name().decode() for c in reader.list_children(rr_path="/") if c.rock_ridge
|
|
]
|
|
reader.close()
|
|
assert "network-config" not in names
|