|
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 |
13 | 14 |
|
14 | 15 | PARTUUID = {"x86_64": "0eaa91a0-01", "aarch64": "7bf14469-01"}
|
15 | 16 | MB = 1024 * 1024
|
@@ -337,6 +338,134 @@ def test_patch_drive(test_microvm_with_ssh, network_config):
|
337 | 338 | assert stdout.readline().strip() == size_bytes_str
|
338 | 339 |
|
339 | 340 |
|
| 341 | +def test_no_flush(test_microvm_with_ssh, network_config): |
| 342 | + """Verify default block ignores flush.""" |
| 343 | + test_microvm = test_microvm_with_ssh |
| 344 | + test_microvm.spawn() |
| 345 | + |
| 346 | + test_microvm.basic_config( |
| 347 | + vcpu_count=1, |
| 348 | + add_root_device=False |
| 349 | + ) |
| 350 | + |
| 351 | + _tap, _, _ = test_microvm.ssh_network_config(network_config, '1') |
| 352 | + |
| 353 | + # Add the block device |
| 354 | + test_microvm.add_drive( |
| 355 | + 'rootfs', |
| 356 | + test_microvm.rootfs_file, |
| 357 | + root_device=True, |
| 358 | + ) |
| 359 | + |
| 360 | + # Configure the metrics. |
| 361 | + metrics_fifo_path = os.path.join(test_microvm.path, 'metrics_fifo') |
| 362 | + metrics_fifo = log_tools.Fifo(metrics_fifo_path) |
| 363 | + response = test_microvm.metrics.put( |
| 364 | + metrics_path=test_microvm.create_jailed_resource(metrics_fifo.path) |
| 365 | + ) |
| 366 | + assert test_microvm.api_session.is_status_no_content(response.status_code) |
| 367 | + |
| 368 | + test_microvm.start() |
| 369 | + |
| 370 | + # Verify all flush commands were ignored during boot. |
| 371 | + fc_metrics = test_microvm.flush_metrics(metrics_fifo) |
| 372 | + assert fc_metrics['block']['flush_count'] == 0 |
| 373 | + |
| 374 | + # Have the guest drop the caches to generate flush requests. |
| 375 | + ssh_connection = net_tools.SSHConnection(test_microvm.ssh_config) |
| 376 | + cmd = "sync; echo 1 > /proc/sys/vm/drop_caches" |
| 377 | + _, _, stderr = ssh_connection.execute_command(cmd) |
| 378 | + assert stderr.read() == '' |
| 379 | + |
| 380 | + # Verify all flush commands were ignored even after |
| 381 | + # dropping the caches. |
| 382 | + fc_metrics = test_microvm.flush_metrics(metrics_fifo) |
| 383 | + assert fc_metrics['block']['flush_count'] == 0 |
| 384 | + |
| 385 | + |
| 386 | +def test_flush(test_microvm_with_ssh, network_config): |
| 387 | + """Verify block with flush actually flushes.""" |
| 388 | + test_microvm = test_microvm_with_ssh |
| 389 | + test_microvm.spawn() |
| 390 | + |
| 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 block device with explicitly enabling flush. |
| 399 | + test_microvm.add_drive( |
| 400 | + 'rootfs', |
| 401 | + test_microvm.rootfs_file, |
| 402 | + root_device=True, |
| 403 | + cache_type="Writeback", |
| 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 | + # Have the guest drop the caches to generate flush requests. |
| 417 | + ssh_connection = net_tools.SSHConnection(test_microvm.ssh_config) |
| 418 | + cmd = "sync; echo 1 > /proc/sys/vm/drop_caches" |
| 419 | + _, _, stderr = ssh_connection.execute_command(cmd) |
| 420 | + assert stderr.read() == '' |
| 421 | + |
| 422 | + # On average, dropping the caches right after boot generates |
| 423 | + # about 6 block flush requests. |
| 424 | + fc_metrics = test_microvm.flush_metrics(metrics_fifo) |
| 425 | + assert fc_metrics['block']['flush_count'] > 0 |
| 426 | + |
| 427 | + |
| 428 | +def test_block_default_cache_old_version(test_microvm_with_ssh): |
| 429 | + """Verify that saving a snapshot for old versions works correctly.""" |
| 430 | + test_microvm = test_microvm_with_ssh |
| 431 | + test_microvm.spawn() |
| 432 | + |
| 433 | + test_microvm.basic_config( |
| 434 | + vcpu_count=1, |
| 435 | + add_root_device=False |
| 436 | + ) |
| 437 | + |
| 438 | + # Add the block device with explicitly enabling flush. |
| 439 | + test_microvm.add_drive( |
| 440 | + 'rootfs', |
| 441 | + test_microvm.rootfs_file, |
| 442 | + root_device=True, |
| 443 | + cache_type="Writeback", |
| 444 | + ) |
| 445 | + |
| 446 | + test_microvm.start() |
| 447 | + |
| 448 | + # Pause the VM to create the snapshot. |
| 449 | + response = test_microvm.vm.patch(state='Paused') |
| 450 | + assert test_microvm.api_session.is_status_no_content(response.status_code) |
| 451 | + |
| 452 | + # Create the snapshot for a version without block cache type. |
| 453 | + response = test_microvm.snapshot.create( |
| 454 | + mem_file_path='memfile', |
| 455 | + snapshot_path='snapsfile', |
| 456 | + diff=False, |
| 457 | + version='0.24.0' |
| 458 | + ) |
| 459 | + assert test_microvm.api_session.is_status_no_content(response.status_code) |
| 460 | + |
| 461 | + # We should find a warning in the logs for this case as this |
| 462 | + # cache type was not supported in 0.24.0 and we should default |
| 463 | + # to "Unsafe" mode. |
| 464 | + log_data = test_microvm.log_data |
| 465 | + assert "Target version does not implement the current cache type. "\ |
| 466 | + "Defaulting to \"unsafe\" mode." in log_data |
| 467 | + |
| 468 | + |
340 | 469 | def check_iops_limit(ssh_connection, block_size, count, min_time, max_time):
|
341 | 470 | """Verify if the rate limiter throttles block iops using dd."""
|
342 | 471 | byte_count = block_size * count
|
|
0 commit comments