|
10 | 10 |
|
11 | 11 | import host_tools.drive as drive_tools
|
12 | 12 | import host_tools.network as net_tools # pylint: disable=import-error
|
| 13 | +import host_tools.logging as log_tools # metrics |
13 | 14 |
|
14 | 15 |
|
15 | 16 | def test_rescan_file(test_microvm_with_ssh, network_config):
|
@@ -329,6 +330,108 @@ def test_patch_drive(test_microvm_with_ssh, network_config):
|
329 | 330 | assert stdout.readline().strip() == size_bytes_str
|
330 | 331 |
|
331 | 332 |
|
| 333 | +def test_rootfs_rw_noflush(test_microvm_with_ssh, network_config): |
| 334 | + """Verify default rootfs does not invoke flush.""" |
| 335 | + test_microvm = test_microvm_with_ssh |
| 336 | + test_microvm.spawn() |
| 337 | + |
| 338 | + # Set up the microVM with 1 vCPUs, 256 MiB of RAM, no network ifaces and |
| 339 | + # a root file system with the rw permission. The network interfaces is |
| 340 | + # added after we get a unique MAC and IP. |
| 341 | + test_microvm.basic_config( |
| 342 | + vcpu_count=1, |
| 343 | + add_root_device=False |
| 344 | + ) |
| 345 | + |
| 346 | + _tap, _, _ = test_microvm.ssh_network_config(network_config, '1') |
| 347 | + |
| 348 | + # Add the root block device |
| 349 | + test_microvm.add_drive( |
| 350 | + 'rootfs', |
| 351 | + test_microvm.rootfs_file, |
| 352 | + root_device=True, |
| 353 | + ) |
| 354 | + |
| 355 | + # Configure metrics, to get later the `flush_count`. |
| 356 | + metrics_fifo_path = os.path.join(test_microvm.path, 'metrics_fifo') |
| 357 | + metrics_fifo = log_tools.Fifo(metrics_fifo_path) |
| 358 | + response = test_microvm.metrics.put( |
| 359 | + metrics_path=test_microvm.create_jailed_resource(metrics_fifo.path) |
| 360 | + ) |
| 361 | + assert test_microvm.api_session.is_status_no_content(response.status_code) |
| 362 | + |
| 363 | + test_microvm.start() |
| 364 | + |
| 365 | + # From spec: pub const VIRTIO_F_VERSION_1: u32 = 32; |
| 366 | + lo32 = "00000000000000000000000000000000" |
| 367 | + hi32 = "10000000000000000000000000000000" |
| 368 | + default_features = lo32 + hi32 |
| 369 | + |
| 370 | + ssh_connection = net_tools.SSHConnection(test_microvm.ssh_config) |
| 371 | + cmd = "cat /sys/block/vda/device/features" |
| 372 | + _, stdout, stderr = ssh_connection.execute_command(cmd) |
| 373 | + assert stderr.read() == '' |
| 374 | + assert stdout.readline().strip() == default_features |
| 375 | + |
| 376 | + # Verify no flush commands were generated during boot. By |
| 377 | + # default, on a RW device with flush enabled, there will be |
| 378 | + # +- six virtio flush commands |
| 379 | + fc_metrics = test_microvm.flush_metrics(metrics_fifo) |
| 380 | + assert fc_metrics['block']['flush_count'] == 0 |
| 381 | + |
| 382 | + |
| 383 | +def test_rootfs_rw_flush(test_microvm_with_ssh, network_config): |
| 384 | + """Verify rootfs with flush does invoke flush.""" |
| 385 | + test_microvm = test_microvm_with_ssh |
| 386 | + test_microvm.spawn() |
| 387 | + |
| 388 | + # Set up the microVM with 1 vCPUs, 256 MiB of RAM, no network ifaces and |
| 389 | + # a root file system with the rw permission. The network interfaces is |
| 390 | + # added after we get a unique MAC and IP. |
| 391 | + test_microvm.basic_config( |
| 392 | + vcpu_count=1, |
| 393 | + add_root_device=False |
| 394 | + ) |
| 395 | + |
| 396 | + _tap, _, _ = test_microvm.ssh_network_config(network_config, '1') |
| 397 | + |
| 398 | + # Add the root block device |
| 399 | + test_microvm.add_drive( |
| 400 | + 'rootfs', |
| 401 | + test_microvm.rootfs_file, |
| 402 | + root_device=True, |
| 403 | + want_flush=True, |
| 404 | + ) |
| 405 | + |
| 406 | + # Configure metrics, to get later the `flush_count`. |
| 407 | + metrics_fifo_path = os.path.join(test_microvm.path, 'metrics_fifo') |
| 408 | + metrics_fifo = log_tools.Fifo(metrics_fifo_path) |
| 409 | + response = test_microvm.metrics.put( |
| 410 | + metrics_path=test_microvm.create_jailed_resource(metrics_fifo.path) |
| 411 | + ) |
| 412 | + assert test_microvm.api_session.is_status_no_content(response.status_code) |
| 413 | + |
| 414 | + test_microvm.start() |
| 415 | + |
| 416 | + # From spec: pub const VIRTIO_F_VERSION_1: u32 = 32; |
| 417 | + # pub const VIRTIO_BLK_F_FLUSH: u32 = 9; |
| 418 | + lo32 = "00000000010000000000000000000000" |
| 419 | + hi32 = "10000000000000000000000000000000" |
| 420 | + default_features = lo32 + hi32 |
| 421 | + |
| 422 | + ssh_connection = net_tools.SSHConnection(test_microvm.ssh_config) |
| 423 | + cmd = "cat /sys/block/vda/device/features" |
| 424 | + _, stdout, stderr = ssh_connection.execute_command(cmd) |
| 425 | + assert stderr.read() == '' |
| 426 | + assert stdout.readline().strip() == default_features |
| 427 | + |
| 428 | + # Verify no flush commands were generated during boot. By |
| 429 | + # default, on a RW device with flush enabled, there will be |
| 430 | + # +- six virtio flush commands |
| 431 | + fc_metrics = test_microvm.flush_metrics(metrics_fifo) |
| 432 | + assert fc_metrics['block']['flush_count'] > 0 |
| 433 | + |
| 434 | + |
332 | 435 | def _check_block_size(ssh_connection, dev_path, size):
|
333 | 436 | _, stdout, stderr = ssh_connection.execute_command(
|
334 | 437 | 'blockdev --getsize64 {}'.format(dev_path)
|
|
0 commit comments