Skip to content

Commit 620b6e8

Browse files
committed
tests: microvm: drop create_jailed_resource
Now the function always tries to do the right thing. Signed-off-by: Pablo Barbáchano <[email protected]>
1 parent 0808731 commit 620b6e8

File tree

11 files changed

+34
-40
lines changed

11 files changed

+34
-40
lines changed

tests/framework/jailer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def api_socket_path(self):
127127
"""Return the MicroVM API socket path."""
128128
return self.chroot / self.api_socket_name
129129

130-
def jailed_path(self, file_path, create=False, subdir="."):
130+
def jailed_path(self, file_path, subdir="."):
131131
"""Create a hard link or block special device owned by uid:gid.
132132
133133
Create a hard link or block special device from the specified file,
@@ -138,7 +138,7 @@ def jailed_path(self, file_path, create=False, subdir="."):
138138
global_p = self.chroot / subdir / file_path.name
139139
global_p.parent.mkdir(parents=True, exist_ok=True)
140140
jailed_p = Path("/") / subdir / file_path.name
141-
if create and not global_p.exists():
141+
if not global_p.exists():
142142
stat_src = file_path.stat()
143143
if file_path.is_block_device():
144144
perms = stat.S_IRUSR | stat.S_IWUSR
@@ -160,7 +160,7 @@ def setup(self):
160160
"""Set up this jailer context."""
161161
os.makedirs(self.chroot, exist_ok=True)
162162
# Copy the /etc/localtime file in the jailer root
163-
self.jailed_path("/etc/localtime", create=True, subdir="etc")
163+
self.jailed_path("/etc/localtime", subdir="etc")
164164

165165
def cleanup(self):
166166
"""Clean up this jailer context."""

tests/framework/microvm.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -450,15 +450,12 @@ def flush_metrics(self):
450450
# get the latest metrics
451451
return self.get_all_metrics()[-1]
452452

453-
def create_jailed_resource(self, path):
454-
"""Create a hard link to some resource inside this microvm."""
455-
return self.jailer.jailed_path(path, create=True)
456-
457453
def jail_path(self, path):
458-
"""Get the relative jailed path to a resource.
454+
"""Return a path relative to the chroot
459455
460-
Also fix permissions if needed"""
461-
return self.jailer.jailed_path(path, create=False)
456+
Copies/hardlinks and fixes permissions as needed.
457+
"""
458+
return self.jailer.jailed_path(path)
462459

463460
@property
464461
def chroot(self):
@@ -562,7 +559,7 @@ def spawn(
562559
if self.metadata_file:
563560
if os.path.exists(self.metadata_file):
564561
LOG.debug("metadata file exists, adding as a jailed resource")
565-
self.create_jailed_resource(self.metadata_file)
562+
self.jail_path(self.metadata_file)
566563
self.jailer.extra_args.update(
567564
{"metadata": os.path.basename(self.metadata_file)}
568565
)
@@ -676,14 +673,12 @@ def basic_config(
676673
if boot_args is not None:
677674
self.boot_args = boot_args
678675
boot_source_args = {
679-
"kernel_image_path": self.create_jailed_resource(self.kernel_file),
676+
"kernel_image_path": self.jail_path(self.kernel_file),
680677
"boot_args": self.boot_args,
681678
}
682679

683680
if use_initrd and self.initrd_file is not None:
684-
boot_source_args.update(
685-
initrd_path=self.create_jailed_resource(self.initrd_file)
686-
)
681+
boot_source_args.update(initrd_path=self.jail_path(self.initrd_file))
687682

688683
self.api.boot.put(**boot_source_args)
689684

@@ -727,10 +722,9 @@ def add_drive(
727722
):
728723
"""Add a block device."""
729724

730-
path_on_jail = self.create_jailed_resource(path_on_host)
731725
self.api.drive.put(
732726
drive_id=drive_id,
733-
path_on_host=path_on_jail,
727+
path_on_host=self.jail_path(path_on_host),
734728
is_root_device=is_root_device,
735729
is_read_only=is_read_only,
736730
partuuid=partuuid,
@@ -779,7 +773,7 @@ def patch_drive(self, drive_id, file=None):
779773
if file:
780774
self.api.drive.patch(
781775
drive_id=drive_id,
782-
path_on_host=self.create_jailed_resource(file),
776+
path_on_host=self.jail_path(file),
783777
)
784778
self.disks[drive_id] = Path(file)
785779
else:
@@ -891,7 +885,7 @@ def restore_from_snapshot(
891885
assert len(snapshot_disks) > 0, "Snapshot requires at least one disk."
892886
jailed_disks = []
893887
for disk in snapshot_disks:
894-
jailed_disks.append(self.create_jailed_resource(disk))
888+
jailed_disks.append(self.jail_path(disk))
895889
self.disks = snapshot.disks
896890
self.ssh_key = snapshot.ssh_key
897891

tests/integration_tests/functional/test_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def test_drive_io_engine(uvm_plain):
6060

6161
kwargs = {
6262
"drive_id": "rootfs",
63-
"path_on_host": test_microvm.create_jailed_resource(test_microvm.rootfs_file),
63+
"path_on_host": test_microvm.jail_path(test_microvm.rootfs_file),
6464
"is_root_device": True,
6565
"is_read_only": True,
6666
}

tests/integration_tests/functional/test_cmd_line_start.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ def _configure_vm_from_json(test_microvm, vm_config_file):
2727
parameter to this helper function.
2828
"""
2929
# since we don't use basic-config, we do it by hand
30-
test_microvm.create_jailed_resource(test_microvm.kernel_file)
31-
test_microvm.create_jailed_resource(test_microvm.rootfs_file)
30+
test_microvm.jail_path(test_microvm.kernel_file)
31+
test_microvm.jail_path(test_microvm.rootfs_file)
3232

3333
vm_config_file = Path(vm_config_file)
3434
obj = json.load(vm_config_file.open(encoding="UTF-8"))

tests/integration_tests/functional/test_drive_virtio.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def test_rescan_file(uvm_plain_any, io_engine):
5454

5555
test_microvm.api.drive.patch(
5656
drive_id="scratch",
57-
path_on_host=test_microvm.create_jailed_resource(fs.path),
57+
path_on_host=test_microvm.jail_path(fs.path),
5858
)
5959

6060
_check_block_size(test_microvm.ssh, "/dev/vdb", fs.size())
@@ -132,7 +132,7 @@ def test_rescan_dev(uvm_plain_any, io_engine):
132132
try:
133133
test_microvm.api.drive.patch(
134134
drive_id="scratch",
135-
path_on_host=test_microvm.create_jailed_resource(loopback_device),
135+
path_on_host=test_microvm.jail_path(loopback_device),
136136
)
137137

138138
_check_block_size(test_microvm.ssh, "/dev/vdb", fs2.size())
@@ -262,7 +262,7 @@ def test_patch_drive(uvm_plain_any, io_engine):
262262
# Updates to `path_on_host` with a valid path are allowed.
263263
fs2 = drive_tools.FilesystemFile(test_microvm.chroot / "otherscratch", size=512)
264264
test_microvm.api.drive.patch(
265-
drive_id="scratch", path_on_host=test_microvm.create_jailed_resource(fs2.path)
265+
drive_id="scratch", path_on_host=test_microvm.jail_path(fs2.path)
266266
)
267267

268268
_check_mount(test_microvm.ssh, "/dev/vdb")

tests/integration_tests/functional/test_snapshot_basic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ def test_load_snapshot_failure_handling(uvm_plain):
239239
snapshot_vmstate.touch()
240240

241241
# Hardlink the snapshot files into the microvm jail.
242-
jailed_mem = vm.create_jailed_resource(snapshot_mem)
243-
jailed_vmstate = vm.create_jailed_resource(snapshot_vmstate)
242+
jailed_mem = vm.jail_path(snapshot_mem)
243+
jailed_vmstate = vm.jail_path(snapshot_vmstate)
244244

245245
# Load the snapshot
246246
expected_msg = (

tests/integration_tests/functional/test_uffd.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
# SPDX-License-Identifier: Apache-2.0
33
"""Test UFFD related functionality when resuming from snapshot."""
44

5-
import os
65
import re
6+
from pathlib import Path
77

88
import pytest
99
import requests
@@ -39,10 +39,10 @@ def snapshot_fxt(microvm_factory, guest_kernel_linux_5_10, rootfs):
3939
def spawn_pf_handler(vm, handler_path, mem_path):
4040
"""Spawn page fault handler process."""
4141
# Copy snapshot memory file into chroot of microVM.
42-
jailed_mem = vm.create_jailed_resource(mem_path)
42+
jailed_mem = vm.jail_path(mem_path)
4343
# Copy the valid page fault binary into chroot of microVM.
44-
jailed_handler = vm.create_jailed_resource(handler_path)
45-
handler_name = os.path.basename(jailed_handler)
44+
jailed_handler = Path(vm.jail_path(handler_path))
45+
handler_name = jailed_handler.name
4646

4747
uffd_handler = UffdHandler(
4848
handler_name, SOCKET_PATH, jailed_mem, vm.chroot, "uffd.log"
@@ -58,7 +58,7 @@ def test_bad_socket_path(uvm_plain, snapshot):
5858
"""
5959
vm = uvm_plain
6060
vm.spawn()
61-
jailed_vmstate = vm.create_jailed_resource(snapshot.vmstate)
61+
jailed_vmstate = vm.jail_path(snapshot.vmstate)
6262

6363
expected_msg = re.escape(
6464
"Load snapshot error: Failed to restore from snapshot: Failed to load guest "
@@ -81,7 +81,7 @@ def test_unbinded_socket(uvm_plain, snapshot):
8181
vm = uvm_plain
8282
vm.spawn()
8383

84-
jailed_vmstate = vm.create_jailed_resource(snapshot.vmstate)
84+
jailed_vmstate = vm.jail_path(snapshot.vmstate)
8585
socket_path = vm.chroot / "firecracker-uffd.sock"
8686
socket_path.touch()
8787
jailed_sock_path = vm.jail_path(socket_path)

tests/integration_tests/functional/test_vsock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ def test_vsock_transport_reset_g2h(uvm_nano, microvm_factory):
250250
# Give some time for host socat to create socket
251251
time.sleep(0.5)
252252
assert Path(host_socket_path).exists()
253-
new_vm.create_jailed_resource(host_socket_path)
253+
new_vm.jail_path(host_socket_path)
254254

255255
# Create a socat process in the guest which will connect to the host socat
256256
guest_socat_commmand = (

tests/integration_tests/performance/test_process_startup_time.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,5 @@ def _test_startup_time(microvm, metrics, test_suffix: str):
8080
def _custom_filter_setup(test_microvm):
8181
bpf_path = test_microvm.chroot / "bpf.out"
8282
run_seccompiler_bin(bpf_path)
83-
test_microvm.create_jailed_resource(bpf_path)
83+
test_microvm.jail_path(bpf_path)
8484
test_microvm.jailer.extra_args.update({"seccomp-filter": "bpf.out"})

tests/integration_tests/performance/test_vsock_ab.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def spawn_iperf3_client(self, client_idx, client_mode_flag):
5252
uds_path = self._microvm.chroot / make_host_port_path(
5353
VSOCK_UDS_PATH, self._base_port + client_idx
5454
)
55-
self._microvm.create_jailed_resource(uds_path)
55+
self._microvm.jail_path(uds_path)
5656
# The rootfs does not have iperf3-vsock
5757
iperf3_guest = "/tmp/iperf3-vsock"
5858

0 commit comments

Comments
 (0)