|
4 | 4 |
|
5 | 5 | import os |
6 | 6 | import platform |
| 7 | +from subprocess import run, PIPE |
7 | 8 |
|
8 | 9 | import pytest |
9 | 10 |
|
10 | 11 | import host_tools.drive as drive_tools |
11 | 12 | import host_tools.network as net_tools # pylint: disable=import-error |
12 | 13 |
|
13 | 14 |
|
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.""" |
16 | 17 | test_microvm = test_microvm_with_ssh |
17 | 18 | test_microvm.spawn() |
18 | 19 |
|
@@ -57,6 +58,50 @@ def test_rescan(test_microvm_with_ssh, network_config): |
57 | 58 | ) |
58 | 59 |
|
59 | 60 |
|
| 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 | + |
60 | 105 | def test_non_partuuid_boot(test_microvm_with_ssh, network_config): |
61 | 106 | """Test the output reported by blockdev when booting from /dev/vda.""" |
62 | 107 | test_microvm = test_microvm_with_ssh |
|
0 commit comments