Skip to content

Commit

Permalink
hotplug_virtio_mem: forbid virtio_mem unplug for QEMU < 8.1.0
Browse files Browse the repository at this point in the history
The unplug support for virtio_mem was introduced in RHEL 9.4
with QEMU 8.1, corrects the test to only do this action when
the proper QEMU is used. Also applies the black code formatter.

Signed-off-by: mcasquer <[email protected]>
  • Loading branch information
mcasquer committed Jul 17, 2024
1 parent ea04bbd commit 484a154
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 28 deletions.
6 changes: 5 additions & 1 deletion qemu/tests/cfg/hotplug_virtio_mem.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@
kernel_extra_params_add = "memhp_default_state=online_movable"
pcie_extra_root_port = 1
requested-size_test_vmem0 = "4G 2G"
error_msg = "virtio-mem device cannot get unplugged while 'size' != '0'"
variants operation:
- @default:
- with_unplug:
required_qemu = [8.1.0,)
error_msg = "virtio-mem device cannot get unplugged while 'size' != '0'"
60 changes: 33 additions & 27 deletions qemu/tests/hotplug_virtio_mem.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def run(test, params, env):
timeout = params.get_numeric("login_timeout", 240)
threshold = params.get_numeric("threshold", target_type=float)
error_msg = params.get("error_msg")
operation = params.get("operation")
vm = env.get_vm(params["main_vm"])
vm.verify_alive()
session = vm.wait_for_login(timeout=timeout)
Expand All @@ -37,36 +38,41 @@ def run(test, params, env):
device_id = vmem_dev.get_qid()
requested_size_vmem_test = params.get("requested-size_test_%s" % target_mem)

node_id = int(vmem_dev.get_param('node'))
req_size = vmem_dev.get_param('requested-size')
initial_req_size = str(int(float(normalize_data_size(req_size, 'B'))))
node_id = int(vmem_dev.get_param("node"))
req_size = vmem_dev.get_param("requested-size")
initial_req_size = str(int(float(normalize_data_size(req_size, "B"))))

virtio_mem_utils.check_memory_devices(device_id, initial_req_size,
threshold, vm, test)
virtio_mem_utils.check_numa_plugged_mem(node_id, initial_req_size,
threshold, vm, test)
virtio_mem_utils.check_memory_devices(
device_id, initial_req_size, threshold, vm, test
)
virtio_mem_utils.check_numa_plugged_mem(
node_id, initial_req_size, threshold, vm, test
)
for requested_size in requested_size_vmem_test.split():
req_size_normalized = int(float(normalize_data_size(requested_size,
'B')))
vm.monitor.qom_set(device_id, "requested-size",
req_size_normalized)
req_size_normalized = int(float(normalize_data_size(requested_size, "B")))
vm.monitor.qom_set(device_id, "requested-size", req_size_normalized)
time.sleep(30)
virtio_mem_utils.check_memory_devices(device_id, requested_size,
threshold, vm, test)
virtio_mem_utils.check_numa_plugged_mem(node_id, requested_size,
threshold, vm, test)
try:
hotplug_test.unplug_memory(vm, target_mem)
except QMPCmdError as e:
if error_msg not in str(e.data):
test.fail("Unexpected error message: %s" % str(e.data))
test.log.info(error_msg)
else:
test.fail("%s shouldn't have been unplugged! 'size' is greater than 0"
% target_mem)
virtio_mem_utils.check_memory_devices(
device_id, requested_size, threshold, vm, test
)
virtio_mem_utils.check_numa_plugged_mem(
node_id, requested_size, threshold, vm, test
)
if operation == "with_unplug":
try:
hotplug_test.unplug_memory(vm, target_mem)
except QMPCmdError as e:
if error_msg not in str(e.data):
test.fail("Unexpected error message: %s" % str(e.data))
test.log.info(error_msg)
else:
test.fail(
"%s shouldn't have been unplugged! 'size' is greater than 0"
% target_mem
)

vm.monitor.qom_set(device_id, "requested-size", 0)
time.sleep(10)
hotplug_test.unplug_memory(vm, target_mem)
vm.monitor.qom_set(device_id, "requested-size", 0)
time.sleep(10)
hotplug_test.unplug_memory(vm, target_mem)

session.close()

0 comments on commit 484a154

Please sign in to comment.