32 lines
1.2 KiB
Python
32 lines
1.2 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
|