test_vms_cli: Trying new way of testing
This commit is contained in:
@@ -71,10 +71,14 @@ def run_vm_in_thread(machine_name: str) -> None:
|
|||||||
# wait for qmp socket to exist
|
# wait for qmp socket to exist
|
||||||
def wait_vm_up(state_dir: Path) -> None:
|
def wait_vm_up(state_dir: Path) -> None:
|
||||||
socket_file = state_dir / "qga.sock"
|
socket_file = state_dir / "qga.sock"
|
||||||
while True:
|
timeout: float = 50
|
||||||
|
while timeout > 0:
|
||||||
if socket_file.exists():
|
if socket_file.exists():
|
||||||
break
|
break
|
||||||
sleep(0.1)
|
sleep(0.1)
|
||||||
|
timeout -= 0.1
|
||||||
|
if timeout <= 0:
|
||||||
|
raise TimeoutError(f"{socket_file} did not appear")
|
||||||
|
|
||||||
|
|
||||||
# wait for vm to be down by checking if qga socket is down
|
# wait for vm to be down by checking if qga socket is down
|
||||||
@@ -156,26 +160,22 @@ def test_vm_qmp(
|
|||||||
# 'clan vms run' must be executed from within the flake
|
# 'clan vms run' must be executed from within the flake
|
||||||
monkeypatch.chdir(flake.path)
|
monkeypatch.chdir(flake.path)
|
||||||
|
|
||||||
|
# the state dir is a point of reference for qemu interactions as it links to the qga/qmp sockets
|
||||||
|
qmp_state_dir = temporary_home / "vm-tmp"
|
||||||
|
|
||||||
with monkeypatch_tempdir_with_custom_path(
|
with monkeypatch_tempdir_with_custom_path(
|
||||||
monkeypatch=monkeypatch,
|
monkeypatch=monkeypatch,
|
||||||
custom_path=str(temporary_home / "vm-tmp"),
|
custom_path=str(qmp_state_dir),
|
||||||
prefix_condition="clan_vm-",
|
prefix_condition="machine_vm-",
|
||||||
):
|
):
|
||||||
# the state dir is a point of reference for qemu interactions as it links to the qga/qmp sockets
|
|
||||||
state_dir = vm_state_dir(str(flake.path), "my_machine")
|
|
||||||
# start the VM
|
# start the VM
|
||||||
run_vm_in_thread("my_machine")
|
run_vm_in_thread("my_machine")
|
||||||
|
|
||||||
# connect with qmp
|
# connect with qmp
|
||||||
qmp = qmp_connect(state_dir)
|
qmp = qmp_connect(qmp_state_dir)
|
||||||
|
|
||||||
# verify that issuing a command works
|
# shutdown machine (prevent zombie qemu processes)
|
||||||
# result = qmp.cmd_obj({"execute": "query-status"})
|
qmp.command("system_powerdown")
|
||||||
result = qmp.command("query-status")
|
|
||||||
assert result["status"] == "running", result
|
|
||||||
|
|
||||||
# shutdown machine (prevent zombie qemu processes)
|
|
||||||
qmp.command("system_powerdown")
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(no_kvm, reason="Requires KVM")
|
@pytest.mark.skipif(no_kvm, reason="Requires KVM")
|
||||||
|
|||||||
Reference in New Issue
Block a user