Skip to content

Commit 9e084d4

Browse files
committed
chore: add vsock_type field to python integration tests
add changelog entry for the modified field Signed-off-by: aerosouund <aerosound161@gmail.com>
1 parent 3fa8359 commit 9e084d4

7 files changed

Lines changed: 74 additions & 26 deletions

File tree

tests/framework/utils_vsock.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,17 @@ class HostEchoWorker(Thread):
3131
contents of `blob_path`.
3232
"""
3333

34-
def __init__(self, uds_path, blob_path):
34+
def __init__(self, uds_path, blob_path, vsock_type=SOCK_STREAM):
3535
"""."""
3636
super().__init__()
3737
self.uds_path = uds_path
3838
self.blob_path = blob_path
3939
self.hash = None
40+
self.vsock_type = vsock_type
4041
self.error = None
41-
self.sock = _vsock_connect_to_guest(self.uds_path, ECHO_SERVER_PORT)
42+
self.sock = _vsock_connect_to_guest(
43+
self.uds_path, ECHO_SERVER_PORT, self.vsock_type
44+
)
4245

4346
def run(self):
4447
"""Thread code payload.
@@ -285,9 +288,9 @@ def make_host_port_path(uds_path, port):
285288
return "{}_{}".format(uds_path, port)
286289

287290

288-
def _vsock_connect_to_guest(uds_path, port):
291+
def _vsock_connect_to_guest(uds_path, port, vsock_type):
289292
"""Return a Unix socket, connected to the guest vsock port `port`."""
290-
sock = socket(AF_UNIX, SOCK_STREAM)
293+
sock = socket(AF_UNIX, vsock_type)
291294
sock.connect(uds_path)
292295

293296
buf = bytearray("CONNECT {}\n".format(port).encode("utf-8"))

tests/integration_tests/functional/test_api.py

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -965,26 +965,30 @@ def test_api_vsock(uvm_nano):
965965
"""
966966
vm = uvm_nano
967967
# Create a vsock device.
968-
vm.api.vsock.put(guest_cid=15, uds_path="vsock.sock")
968+
vm.api.vsock.put(guest_cid=15, uds_path="vsock.sock", vsock_type="stream")
969969

970970
# Updating an existing vsock is currently fine.
971-
vm.api.vsock.put(guest_cid=166, uds_path="vsock.sock")
971+
vm.api.vsock.put(guest_cid=166, uds_path="vsock.sock", vsock_type="stream")
972972

973973
# Check PUT request. Although vsock_id is deprecated, it must still work.
974-
response = vm.api.vsock.put(vsock_id="vsock1", guest_cid=15, uds_path="vsock.sock")
974+
response = vm.api.vsock.put(
975+
vsock_id="vsock1", guest_cid=15, uds_path="vsock.sock", vsock_type="stream"
976+
)
975977
assert response.headers["deprecation"]
976978

977979
# Updating an existing vsock is currently fine even with deprecated
978980
# `vsock_id`.
979-
response = vm.api.vsock.put(vsock_id="vsock1", guest_cid=166, uds_path="vsock.sock")
981+
response = vm.api.vsock.put(
982+
vsock_id="vsock1", guest_cid=166, uds_path="vsock.sock", vsock_type="stream"
983+
)
980984
assert response.headers["deprecation"]
981985

982986
# No other vsock action is allowed after booting the VM.
983987
vm.start()
984988

985989
# Updating an existing vsock should not be fine at this point.
986990
with pytest.raises(RuntimeError):
987-
vm.api.vsock.put(guest_cid=17, uds_path="vsock.sock")
991+
vm.api.vsock.put(guest_cid=17, uds_path="vsock.sock", vsock_type="stream")
988992

989993

990994
def test_api_entropy(uvm_plain):
@@ -1342,8 +1346,12 @@ def test_get_full_config_after_restoring_snapshot(microvm_factory, uvm_nano):
13421346
}
13431347

13441348
# Add a vsock device.
1345-
uvm_nano.api.vsock.put(guest_cid=15, uds_path="vsock.sock")
1346-
setup_cfg["vsock"] = {"guest_cid": 15, "uds_path": "vsock.sock"}
1349+
uvm_nano.api.vsock.put(guest_cid=15, uds_path="vsock.sock", vsock_type="stream")
1350+
setup_cfg["vsock"] = {
1351+
"guest_cid": 15,
1352+
"uds_path": "vsock.sock",
1353+
"vsock_type": "stream",
1354+
}
13471355

13481356
setup_cfg["memory-hotplug"] = {
13491357
"total_size_mib": 1024,
@@ -1478,9 +1486,14 @@ def test_get_full_config(uvm_plain):
14781486
}
14791487

14801488
# Add a vsock device.
1481-
response = test_microvm.api.vsock.put(guest_cid=15, uds_path="vsock.sock")
1482-
expected_cfg["vsock"] = {"guest_cid": 15, "uds_path": "vsock.sock"}
1483-
1489+
response = test_microvm.api.vsock.put(
1490+
guest_cid=15, uds_path="vsock.sock", vsock_type="stream"
1491+
)
1492+
expected_cfg["vsock"] = {
1493+
"guest_cid": 15,
1494+
"uds_path": "vsock.sock",
1495+
"vsock_type": "stream",
1496+
}
14841497
# Add hot-pluggable memory.
14851498
expected_cfg["memory-hotplug"] = {
14861499
"total_size_mib": 1024,
@@ -1619,7 +1632,7 @@ def test_negative_snapshot_load_api(microvm_factory):
16191632
)
16201633

16211634
# API request without `mem_backend` or `mem_file_path` should fail.
1622-
err_msg = "missing field: either `mem_backend` or " "`mem_file_path` is required"
1635+
err_msg = "missing field: either `mem_backend` or `mem_file_path` is required"
16231636
with pytest.raises(RuntimeError, match=err_msg):
16241637
vm.api.snapshot_load.put(snapshot_path="foo")
16251638

tests/integration_tests/functional/test_snapshot_basic.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@ def test_cycled_snapshot_restore(
140140
)
141141
vm.set_cpu_template(cpu_template_any)
142142
vm.add_net_iface()
143-
vm.api.vsock.put(vsock_id="vsock0", guest_cid=3, uds_path=VSOCK_UDS_PATH)
143+
vm.api.vsock.put(
144+
vsock_id="vsock0", guest_cid=3, uds_path=VSOCK_UDS_PATH, vsock_type="stream"
145+
)
144146
vm.start()
145147

146148
vm_blob_path = "/tmp/vsock/test.blob"

tests/integration_tests/functional/test_snapshot_phase1.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ def test_snapshot_phase1(
4949
for i in range(4):
5050
vm.add_net_iface()
5151
# Add a vsock device
52-
vm.api.vsock.put(vsock_id="vsock0", guest_cid=3, uds_path="/v.sock")
52+
vm.api.vsock.put(
53+
vsock_id="vsock0", guest_cid=3, uds_path="/v.sock", vsock_type="stream"
54+
)
5355
# Add MMDS
5456
configure_mmds(vm, ["eth3"], version="V2")
5557
# Add a memory balloon.

tests/integration_tests/functional/test_vsock.py

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,20 @@ def test_vsock(uvm_plain_any, bin_vsock_path, test_fc_session_root_path):
5757

5858
vm.basic_config()
5959
vm.add_net_iface()
60-
vm.api.vsock.put(vsock_id="vsock0", guest_cid=3, uds_path=f"/{VSOCK_UDS_PATH}")
60+
vm.api.vsock.put(
61+
vsock_id="vsock0",
62+
guest_cid=3,
63+
uds_path=f"/{VSOCK_UDS_PATH}",
64+
vsock_type="stream",
65+
)
6166
vm.start()
6267

6368
check_vsock_device(vm, bin_vsock_path, test_fc_session_root_path, vm.ssh)
6469
metrics = vm.flush_metrics()
6570
validate_fc_metrics(metrics)
6671

6772

68-
def negative_test_host_connections(vm, blob_path, blob_hash):
73+
def negative_test_host_connections(vm, blob_path, blob_hash, vsock_type):
6974
"""Negative test for host-initiated connections.
7075
7176
This will start a daemonized echo server on the guest VM, and then spawn
@@ -77,7 +82,7 @@ def negative_test_host_connections(vm, blob_path, blob_hash):
7782

7883
workers = []
7984
for _ in range(NEGATIVE_TEST_CONNECTION_COUNT):
80-
worker = HostEchoWorker(uds_path, blob_path)
85+
worker = HostEchoWorker(uds_path, blob_path, vsock_type)
8186
workers.append(worker)
8287
worker.start()
8388

@@ -118,7 +123,12 @@ def test_vsock_epipe(uvm_plain_any, bin_vsock_path, test_fc_session_root_path):
118123
vm.spawn()
119124
vm.basic_config()
120125
vm.add_net_iface()
121-
vm.api.vsock.put(vsock_id="vsock0", guest_cid=3, uds_path=f"/{VSOCK_UDS_PATH}")
126+
vm.api.vsock.put(
127+
vsock_id="vsock0",
128+
guest_cid=3,
129+
uds_path=f"/{VSOCK_UDS_PATH}",
130+
vsock_type="stream",
131+
)
122132
vm.start()
123133

124134
# Generate the random data blob file, 20MB
@@ -131,7 +141,7 @@ def test_vsock_epipe(uvm_plain_any, bin_vsock_path, test_fc_session_root_path):
131141

132142
# Negative test for host-initiated connections that
133143
# are closed with in flight data.
134-
negative_test_host_connections(vm, blob_path, blob_hash)
144+
negative_test_host_connections(vm, blob_path, blob_hash, SOCK_STREAM)
135145
metrics = vm.flush_metrics()
136146
validate_fc_metrics(metrics)
137147

@@ -158,7 +168,12 @@ def test_vsock_transport_reset_h2g(
158168
test_vm.spawn()
159169
test_vm.basic_config(vcpu_count=2, mem_size_mib=256)
160170
test_vm.add_net_iface()
161-
test_vm.api.vsock.put(vsock_id="vsock0", guest_cid=3, uds_path=f"/{VSOCK_UDS_PATH}")
171+
test_vm.api.vsock.put(
172+
vsock_id="vsock0",
173+
guest_cid=3,
174+
uds_path=f"/{VSOCK_UDS_PATH}",
175+
vsock_type="stream",
176+
)
162177
test_vm.start()
163178

164179
# Generate the random data blob file.
@@ -200,6 +215,7 @@ def test_vsock_transport_reset_h2g(
200215
assert (
201216
response == b""
202217
), f"Connection not closed: response received '{response.decode('utf-8')}'"
218+
203219
except (SocketTimeout, ConnectionResetError, BrokenPipeError):
204220
pass
205221

@@ -231,7 +247,12 @@ def test_vsock_transport_reset_g2h(uvm_plain_any, microvm_factory):
231247
test_vm.spawn()
232248
test_vm.basic_config(vcpu_count=2, mem_size_mib=256)
233249
test_vm.add_net_iface()
234-
test_vm.api.vsock.put(vsock_id="vsock0", guest_cid=3, uds_path=f"/{VSOCK_UDS_PATH}")
250+
test_vm.api.vsock.put(
251+
vsock_id="vsock0",
252+
guest_cid=3,
253+
uds_path=f"/{VSOCK_UDS_PATH}",
254+
vsock_type="stream",
255+
)
235256
test_vm.start()
236257

237258
# Create snapshot and terminate a VM.

tests/integration_tests/performance/test_snapshot.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ def boot_vm(self, microvm_factory, guest_kernel, rootfs, pci_enabled) -> Microvm
7474
vm.api.balloon.put(
7575
amount_mib=0, deflate_on_oom=True, stats_polling_interval_s=1
7676
)
77-
vm.api.vsock.put(vsock_id="vsock0", guest_cid=3, uds_path="/v.sock")
77+
vm.api.vsock.put(
78+
vsock_id="vsock0", guest_cid=3, uds_path="/v.sock", vsock_type="stream"
79+
)
7880

7981
vm.start()
8082

tests/integration_tests/performance/test_vsock.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,12 @@ def test_vsock_throughput(
9292
vm.basic_config(vcpu_count=vcpus, mem_size_mib=mem_size_mib)
9393
vm.add_net_iface()
9494
# Create a vsock device
95-
vm.api.vsock.put(vsock_id="vsock0", guest_cid=3, uds_path="/" + VSOCK_UDS_PATH)
95+
vm.api.vsock.put(
96+
vsock_id="vsock0",
97+
guest_cid=3,
98+
uds_path="/" + VSOCK_UDS_PATH,
99+
vsock_type="stream",
100+
)
96101
vm.start()
97102

98103
metrics.set_dimensions(

0 commit comments

Comments
 (0)