Skip to content

Commit 706584d

Browse files
author
Kazuyoshi Kato
committed
Add integration tests for #1316
Signed-off-by: Kazuyoshi Kato <[email protected]>
1 parent 877f2f0 commit 706584d

1 file changed

Lines changed: 47 additions & 2 deletions

File tree

tests/integration_tests/functional/test_drives.py

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44

55
import os
66
import platform
7+
from subprocess import run, PIPE
78

89
import pytest
910

1011
import host_tools.drive as drive_tools
1112
import host_tools.network as net_tools # pylint: disable=import-error
1213

1314

14-
def test_rescan(test_microvm_with_ssh, network_config):
15-
"""Verify that a block device rescan has guest seeing changes."""
15+
def test_rescan_file(test_microvm_with_ssh, network_config):
16+
"""Verify that a file-backed virtio device rescan has guest seeing changes."""
1617
test_microvm = test_microvm_with_ssh
1718
test_microvm.spawn()
1819

@@ -57,6 +58,50 @@ def test_rescan(test_microvm_with_ssh, network_config):
5758
)
5859

5960

61+
def test_rescan_dev(test_microvm_with_ssh, network_config):
62+
"""Verify that a device-backed virtio device rescan has guest seeing changes."""
63+
test_microvm = test_microvm_with_ssh
64+
# To access a block device, seccomp_level = 2 is too restrictive
65+
test_microvm.jailer.seccomp_level = 1
66+
test_microvm.spawn()
67+
68+
# Set up the microVM with 1 vCPUs, 256 MiB of RAM, 0 network ifaces and
69+
# a root file system with the rw permission. The network interface is
70+
# added after we get a unique MAC and IP.
71+
test_microvm.basic_config()
72+
73+
_tap, _, _ = test_microvm_with_ssh.ssh_network_config(network_config, '1')
74+
75+
# Add a scratch block device.
76+
fs1 = drive_tools.FilesystemFile(os.path.join(test_microvm.fsfiles, 'fs1'))
77+
response = test_microvm.drive.put(
78+
drive_id='scratch',
79+
path_on_host=test_microvm.create_jailed_resource(fs1.path),
80+
is_root_device=False,
81+
is_read_only=False
82+
)
83+
assert test_microvm.api_session.is_status_no_content(response.status_code)
84+
85+
test_microvm.start()
86+
87+
ssh_connection = net_tools.SSHConnection(test_microvm.ssh_config)
88+
89+
_check_scratch_size(ssh_connection, fs1.size())
90+
91+
fs2 = drive_tools.FilesystemFile(os.path.join(test_microvm.fsfiles, 'fs2'), size = 512)
92+
93+
losetup = run(['losetup', '--find', '--show', fs2.path], stdout=PIPE, stderr=PIPE, check=True)
94+
loopback_device = losetup.stdout.decode('utf-8').rstrip()
95+
96+
response = test_microvm.drive.patch(
97+
drive_id='scratch',
98+
path_on_host=test_microvm.create_jailed_resource(loopback_device),
99+
)
100+
assert test_microvm.api_session.is_status_no_content(response.status_code)
101+
102+
_check_scratch_size(ssh_connection, fs2.size())
103+
104+
60105
def test_non_partuuid_boot(test_microvm_with_ssh, network_config):
61106
"""Test the output reported by blockdev when booting from /dev/vda."""
62107
test_microvm = test_microvm_with_ssh

0 commit comments

Comments
 (0)