45 lines
1.7 KiB
Python
45 lines
1.7 KiB
Python
import importlib.util
|
|
import pathlib
|
|
|
|
_PATH = pathlib.Path(__file__).resolve().parent.parent / "scripts" / "integration-vm.py"
|
|
_spec = importlib.util.spec_from_file_location("integration_vm", _PATH)
|
|
ivm = importlib.util.module_from_spec(_spec)
|
|
_spec.loader.exec_module(ivm)
|
|
|
|
|
|
def test_valid_tiers():
|
|
assert ivm.VALID_TIERS == ("internal", "le-staging", "le-prod-wildcard")
|
|
|
|
|
|
def test_vm_name_prefix_and_suffix():
|
|
assert ivm.vm_name("askari", "ab12cd34") == "boma-it-askari-ab12cd34"
|
|
|
|
def test_vm_name_generates_suffix():
|
|
n = ivm.vm_name("askari")
|
|
assert n.startswith("boma-it-askari-") and len(n.split("-")[-1]) == 8
|
|
|
|
def test_free_mib_parses_memavailable():
|
|
sample = "MemTotal: 16331156 kB\nMemAvailable: 8388608 kB\n"
|
|
assert ivm.free_mib(sample) == 8192
|
|
|
|
def test_parse_lease_ip_extracts_ipv4():
|
|
out = (" Name MAC address Protocol Address\n"
|
|
"-------------------------------------------------------------------\n"
|
|
" vnet0 52:54:00:aa:bb:cc ipv4 192.168.150.42/24\n")
|
|
assert ivm.parse_lease_ip(out) == "192.168.150.42"
|
|
|
|
def test_parse_lease_ip_none_when_absent():
|
|
assert ivm.parse_lease_ip("no leases\n") is None
|
|
|
|
|
|
def test_meta_data_has_instance_and_hostname():
|
|
md = ivm.render_meta_data("iid-askari-x", "boma-it-askari-x")
|
|
assert "instance-id: iid-askari-x" in md
|
|
assert "local-hostname: boma-it-askari-x" in md
|
|
|
|
def test_user_data_injects_key_and_ansible_user():
|
|
ud = ivm.render_user_data("ssh-ed25519 AAAA... claude@ubongo", "ansible")
|
|
assert ud.startswith("#cloud-config")
|
|
assert "name: ansible" in ud
|
|
assert "ssh-ed25519 AAAA... claude@ubongo" in ud
|
|
assert "NOPASSWD:ALL" in ud
|