|
4 | 4 |
|
5 | 5 | import os
|
6 | 6 | import platform
|
| 7 | +from subprocess import run, CalledProcessError, 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 rescan works with a file-backed virtio device.""" |
16 | 17 | test_microvm = test_microvm_with_ssh
|
17 | 18 | test_microvm.spawn()
|
18 | 19 |
|
@@ -57,6 +58,62 @@ 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 rescan works with a device-backed virtio device.""" |
| 63 | + test_microvm = test_microvm_with_ssh |
| 64 | + test_microvm.spawn() |
| 65 | + session = test_microvm.api_session |
| 66 | + |
| 67 | + # Set up the microVM with 1 vCPUs, 256 MiB of RAM, 0 network ifaces and |
| 68 | + # a root file system with the rw permission. The network interface is |
| 69 | + # added after we get a unique MAC and IP. |
| 70 | + test_microvm.basic_config() |
| 71 | + |
| 72 | + _tap, _, _ = test_microvm_with_ssh.ssh_network_config(network_config, '1') |
| 73 | + |
| 74 | + # Add a scratch block device. |
| 75 | + fs1 = drive_tools.FilesystemFile(os.path.join(test_microvm.fsfiles, 'fs1')) |
| 76 | + response = test_microvm.drive.put( |
| 77 | + drive_id='scratch', |
| 78 | + path_on_host=test_microvm.create_jailed_resource(fs1.path), |
| 79 | + is_root_device=False, |
| 80 | + is_read_only=False |
| 81 | + ) |
| 82 | + assert session.is_status_no_content(response.status_code) |
| 83 | + |
| 84 | + test_microvm.start() |
| 85 | + |
| 86 | + ssh_connection = net_tools.SSHConnection(test_microvm.ssh_config) |
| 87 | + |
| 88 | + _check_scratch_size(ssh_connection, fs1.size()) |
| 89 | + |
| 90 | + fs2 = drive_tools.FilesystemFile( |
| 91 | + os.path.join(test_microvm.fsfiles, 'fs2'), |
| 92 | + size=512 |
| 93 | + ) |
| 94 | + |
| 95 | + losetup = ['losetup', '--find', '--show', fs2.path] |
| 96 | + loopback_device = None |
| 97 | + try: |
| 98 | + result = run(losetup, check=True, stdout=PIPE, stderr=PIPE) |
| 99 | + loopback_device = result.stdout.decode('utf-8').rstrip() |
| 100 | + except CalledProcessError as error: |
| 101 | + pytest.skip('failed to create a lookback device: ' + |
| 102 | + f'stdout={error.stdout}, stderr={error.stderr}') |
| 103 | + |
| 104 | + try: |
| 105 | + response = test_microvm.drive.patch( |
| 106 | + drive_id='scratch', |
| 107 | + path_on_host=test_microvm.create_jailed_resource(loopback_device), |
| 108 | + ) |
| 109 | + assert session.is_status_no_content(response.status_code) |
| 110 | + |
| 111 | + _check_scratch_size(ssh_connection, fs2.size()) |
| 112 | + finally: |
| 113 | + if loopback_device: |
| 114 | + run(['losetup', '--detach', loopback_device], check=True) |
| 115 | + |
| 116 | + |
60 | 117 | def test_non_partuuid_boot(test_microvm_with_ssh, network_config):
|
61 | 118 | """Test the output reported by blockdev when booting from /dev/vda."""
|
62 | 119 | test_microvm = test_microvm_with_ssh
|
|
0 commit comments