Skip to content

Commit 3af1fc3

Browse files
committed
Create functional integration tests for hotplugging
Create some functional integration tests for hotplugging. Covering positive and negative cases, as well as onlining of vCPUs Signed-off-by: James Curtis <[email protected]>
1 parent e38069f commit 3af1fc3

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
"""Integration tests for hotplugging vCPUs"""
5+
6+
import re
7+
8+
import pytest
9+
10+
from framework import microvm
11+
from framework.defs import MAX_SUPPORTED_VCPUS
12+
from framework.microvm import Serial
13+
from framework.utils_cpuid import check_guest_cpuid_output
14+
15+
16+
@pytest.mark.parametrize("vcpu_count", [1, MAX_SUPPORTED_VCPUS - 1])
17+
def test_hotplug_vcpus(uvm_plain_rw, vcpu_count):
18+
"""Test hotplugging works as intended"""
19+
vm = uvm_plain_rw
20+
vm.jailer.extra_args.update({"no-seccomp": None})
21+
vm.spawn()
22+
vm.basic_config(vcpu_count=1, mem_size_mib=128)
23+
vm.add_net_iface()
24+
vm.start()
25+
26+
vm.api.hotplug.put(Vcpu={"add": vcpu_count})
27+
28+
check_guest_cpuid_output(
29+
vm,
30+
"lscpu",
31+
None,
32+
":",
33+
{
34+
"CPU(s)": str(1 + vcpu_count),
35+
"Off-line CPU(s) list": "1" if vcpu_count == 1 else f"1-{vcpu_count}",
36+
},
37+
)
38+
39+
40+
@pytest.mark.parametrize(
41+
"vcpu_count", [-1, 0, MAX_SUPPORTED_VCPUS, MAX_SUPPORTED_VCPUS + 1]
42+
)
43+
def test_negative_hotplug_vcpus(uvm_plain, vcpu_count):
44+
"""Test cases where hotplugging should fail."""
45+
uvm_plain.jailer.extra_args.update({"no-seccomp": None})
46+
uvm_plain.spawn()
47+
uvm_plain.basic_config(vcpu_count=1, mem_size_mib=128)
48+
uvm_plain.add_net_iface()
49+
uvm_plain.start()
50+
51+
if vcpu_count == 0:
52+
with pytest.raises(
53+
RuntimeError,
54+
match="Hotplug error: Vcpu hotplugging error: The number of vCPUs added must be greater than 0.",
55+
):
56+
uvm_plain.api.hotplug.put(Vcpu={"add": vcpu_count})
57+
elif vcpu_count < 0:
58+
with pytest.raises(
59+
RuntimeError,
60+
match=re.compile(
61+
f"An error occurred when deserializing the json body of a request: invalid value: integer `-\\d+`, expected u8+"
62+
),
63+
):
64+
uvm_plain.api.hotplug.put(Vcpu={"add": vcpu_count})
65+
elif vcpu_count > 31:
66+
with pytest.raises(
67+
RuntimeError,
68+
match="Hotplug error: Vcpu hotplugging error: The number of vCPUs added must be less than 32.",
69+
):
70+
uvm_plain.api.hotplug.put(Vcpu={"add": vcpu_count})
71+
72+
73+
@pytest.mark.parametrize("vcpu_count", [1, MAX_SUPPORTED_VCPUS - 1])
74+
def test_online_hotplugged_vcpus(uvm_plain, vcpu_count):
75+
"""Test that hotplugged CPUs can be onlined"""
76+
uvm_plain.jailer.extra_args.update({"no-seccomp": None})
77+
uvm_plain.spawn()
78+
uvm_plain.basic_config(vcpu_count=1, mem_size_mib=128)
79+
uvm_plain.add_net_iface()
80+
uvm_plain.start()
81+
82+
uvm_plain.api.hotplug.put(Vcpu={"add": vcpu_count})
83+
84+
_, _, stderr = uvm_plain.ssh.run(
85+
f"for i in {{1..{vcpu_count}}}; do echo 1 > /sys/devices/cpu/cpu$i/online; done"
86+
)
87+
88+
assert stderr == ""
89+
90+
check_guest_cpuid_output(
91+
uvm_plain,
92+
"lscpu",
93+
None,
94+
":",
95+
{
96+
"CPU(s)": str(1 + vcpu_count),
97+
"On-line CPU(s) list": "0,1" if vcpu_count == 1 else f"0-{vcpu_count}",
98+
},
99+
)

0 commit comments

Comments
 (0)