mirror of
https://github.com/kubevirt/kubevirt.core.git
synced 2026-03-26 19:03:16 +00:00
fix(kubevirt_vm): Set wait_condition based on running
To properly wait for a state change in the kubevirt_vm module the wait_condition needs to adapted to the state of running. Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
This commit is contained in:
@@ -380,7 +380,14 @@ def main() -> None:
|
||||
module.params["resource_definition"] = render_template(module.params)
|
||||
|
||||
# Set wait_condition to allow waiting for the ready state of the VirtualMachine
|
||||
module.params["wait_condition"] = {"type": "Ready", "status": True}
|
||||
if module.params["running"]:
|
||||
module.params["wait_condition"] = {"type": "Ready", "status": True}
|
||||
else:
|
||||
module.params["wait_condition"] = {
|
||||
"type": "Ready",
|
||||
"status": False,
|
||||
"reason": "VMINotExists",
|
||||
}
|
||||
|
||||
try:
|
||||
runner.run_module(module)
|
||||
|
||||
@@ -65,6 +65,46 @@ def vm_definition_create():
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def vm_definition_running():
|
||||
return {
|
||||
"apiVersion": "kubevirt.io/v1",
|
||||
"kind": "VirtualMachine",
|
||||
"metadata": {
|
||||
"name": "testvm",
|
||||
"namespace": "default",
|
||||
},
|
||||
"spec": {
|
||||
"running": True,
|
||||
"template": {
|
||||
"spec": {
|
||||
"domain": {"devices": {}},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def vm_definition_stopped():
|
||||
return {
|
||||
"apiVersion": "kubevirt.io/v1",
|
||||
"kind": "VirtualMachine",
|
||||
"metadata": {
|
||||
"name": "testvm",
|
||||
"namespace": "default",
|
||||
},
|
||||
"spec": {
|
||||
"running": False,
|
||||
"template": {
|
||||
"spec": {
|
||||
"domain": {"devices": {}},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def module_params_default():
|
||||
return {
|
||||
@@ -132,6 +172,24 @@ def module_params_create(module_params_default):
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def module_params_running(module_params_default):
|
||||
return module_params_default | {
|
||||
"name": "testvm",
|
||||
"namespace": "default",
|
||||
"running": True,
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def module_params_stopped(module_params_default):
|
||||
return module_params_default | {
|
||||
"name": "testvm",
|
||||
"namespace": "default",
|
||||
"running": False,
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def k8s_module_params_create(module_params_create, vm_definition_create):
|
||||
return module_params_create | {
|
||||
@@ -141,6 +199,24 @@ def k8s_module_params_create(module_params_create, vm_definition_create):
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def k8s_module_params_running(module_params_running, vm_definition_running):
|
||||
return module_params_running | {
|
||||
"generate_name": None,
|
||||
"resource_definition": dump(vm_definition_running, sort_keys=False),
|
||||
"wait_condition": {"type": "Ready", "status": True},
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def k8s_module_params_stopped(module_params_stopped, vm_definition_stopped):
|
||||
return module_params_stopped | {
|
||||
"generate_name": None,
|
||||
"resource_definition": dump(vm_definition_stopped, sort_keys=False),
|
||||
"wait_condition": {"type": "Ready", "status": False, "reason": "VMINotExists"},
|
||||
}
|
||||
|
||||
|
||||
def test_module_fails_when_required_args_missing(monkeypatch):
|
||||
monkeypatch.setattr(AnsibleModule, "fail_json", fail_json)
|
||||
with pytest.raises(AnsibleFailJson):
|
||||
@@ -157,6 +233,18 @@ def test_module_fails_when_required_args_missing(monkeypatch):
|
||||
"vm_definition_create",
|
||||
"create",
|
||||
),
|
||||
(
|
||||
"module_params_running",
|
||||
"k8s_module_params_running",
|
||||
"vm_definition_running",
|
||||
"update",
|
||||
),
|
||||
(
|
||||
"module_params_stopped",
|
||||
"k8s_module_params_stopped",
|
||||
"vm_definition_stopped",
|
||||
"update",
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_module(
|
||||
|
||||
Reference in New Issue
Block a user