Skip to content

Commit

Permalink
test: remove snapshot forward-compatibility tests
Browse files Browse the repository at this point in the history
We dropped support for Firecracker snapshots forward compatibility.
Clean up the tests related to this functionality. Mainly remove tests
that directly use the removed feature and re-organize some of the code
to adapt to the now missing functionality.

Signed-off-by: Babis Chalios <bchalios@amazon.es>
  • Loading branch information
bchalios committed Oct 25, 2023
1 parent c13b2d1 commit e960d8d
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 330 deletions.
10 changes: 9 additions & 1 deletion tests/framework/artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ def current_release(version):
return binaries


def working_version_as_artifact():
"""
Return working copy of Firecracker as a release artifact
"""
cargo_version = get_firecracker_version_from_toml()
return FirecrackerArtifact(current_release(cargo_version.base_version)[0])


def firecracker_artifacts():
"""Return all supported firecracker binaries."""
cargo_version = get_firecracker_version_from_toml()
Expand All @@ -141,7 +149,7 @@ def firecracker_artifacts():
continue
yield pytest.param(fc, id=fc.name)

fc = FirecrackerArtifact(current_release(cargo_version.base_version)[0])
fc = working_version_as_artifact()
yield pytest.param(fc, id=fc.name)


Expand Down
13 changes: 5 additions & 8 deletions tests/framework/microvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,9 +710,7 @@ def resume(self):
"""Resume the microVM"""
self.api.vm.patch(state="Resumed")

def make_snapshot(
self, snapshot_type: SnapshotType | str, target_version: str = None
):
def make_snapshot(self, snapshot_type: SnapshotType | str):
"""Create a Snapshot object from a microvm.
It pauses the microvm before taking the snapshot.
Expand All @@ -725,7 +723,6 @@ def make_snapshot(
mem_file_path=str(mem_path),
snapshot_path=str(vmstate_path),
snapshot_type=snapshot_type.value,
version=target_version,
)
root = Path(self.chroot())
return Snapshot(
Expand All @@ -737,13 +734,13 @@ def make_snapshot(
snapshot_type=snapshot_type,
)

def snapshot_diff(self, target_version: str = None):
def snapshot_diff(self):
"""Make a Diff snapshot"""
return self.make_snapshot("Diff", target_version)
return self.make_snapshot("Diff")

def snapshot_full(self, target_version: str = None):
def snapshot_full(self):
"""Make a Full snapshot"""
return self.make_snapshot("Full", target_version)
return self.make_snapshot("Full")

def restore_from_snapshot(
self,
Expand Down
22 changes: 0 additions & 22 deletions tests/integration_tests/functional/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1291,28 +1291,6 @@ def test_map_private_seccomp_regression(test_microvm_with_api):
test_microvm.api.mmds.put(**data_store)


def test_negative_snapshot_create_api(microvm_factory, guest_kernel, rootfs):
"""
Test snapshot create API.
"""

vm = microvm_factory.build(guest_kernel, rootfs)
vm.spawn()
vm.basic_config()
vm.start()

# Specifying `version` in the create API is deprecated
vm.pause()
response = vm.api.snapshot_create.put(
mem_file_path="mem",
snapshot_path="vmstate",
snapshot_type="Full",
version="1.4.0",
)
assert response.headers["deprecation"]
assert "PUT /snapshot/create: 'version' field is deprecated." in vm.log_data


# pylint: disable=protected-access
def test_negative_snapshot_load_api(microvm_factory):
"""
Expand Down
40 changes: 0 additions & 40 deletions tests/integration_tests/functional/test_drives.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,46 +361,6 @@ def test_flush(uvm_plain_rw):
assert fc_metrics["block"]["flush_count"] > 0


def test_block_default_cache_old_version(test_microvm_with_api):
"""
Verify that saving a snapshot for old versions works correctly.
"""
test_microvm = test_microvm_with_api
test_microvm.spawn()

test_microvm.basic_config(vcpu_count=1, add_root_device=False)

# Add the block device with explicitly enabling flush.
test_microvm.add_drive(
"rootfs",
test_microvm.rootfs_file,
is_root_device=True,
cache_type="Writeback",
)

test_microvm.start()

# Pause the VM to create the snapshot.
test_microvm.pause()

# Create the snapshot for a version without block cache type.
test_microvm.api.snapshot_create.put(
mem_file_path="memfile",
snapshot_path="snapsfile",
snapshot_type="Full",
version="0.24.0",
)

# We should find a warning in the logs for this case as this
# cache type was not supported in 0.24.0 and we should default
# to "Unsafe" mode.
test_microvm.check_log_message(
"Target version does not implement the"
" current cache type. "
'Defaulting to "unsafe" mode.'
)


def _check_block_size(ssh_connection, dev_path, size):
_, stdout, stderr = ssh_connection.run("blockdev --getsize64 {}".format(dev_path))
assert stderr == ""
Expand Down
13 changes: 6 additions & 7 deletions tests/integration_tests/functional/test_mmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import pytest

from framework.artifacts import working_version_as_artifact
from framework.properties import global_props
from framework.utils import (
configure_mmds,
Expand All @@ -33,7 +34,6 @@ def _validate_mmds_snapshot(
basevm,
microvm_factory,
version,
target_fc_version=None,
fc_binary_path=None,
jailer_binary_path=None,
):
Expand Down Expand Up @@ -76,7 +76,7 @@ def _validate_mmds_snapshot(
run_guest_cmd(ssh_connection, cmd, data_store, use_json=True)

# Create snapshot.
snapshot = basevm.snapshot_full(target_version=target_fc_version)
snapshot = basevm.snapshot_full()

# Resume microVM and ensure session token is still valid on the base.
response = basevm.resume()
Expand Down Expand Up @@ -591,22 +591,22 @@ def test_mmds_limit_scenario(test_microvm_with_api, version):


@pytest.mark.parametrize("version", MMDS_VERSIONS)
def test_mmds_snapshot(uvm_nano, microvm_factory, version, firecracker_release):
def test_mmds_snapshot(uvm_nano, microvm_factory, version):
"""
Test MMDS behavior by restoring a snapshot on current FC versions.
Ensures that the version is persisted or initialised with the default if
the firecracker version does not support it.
"""

current_release = working_version_as_artifact()
uvm_nano.add_net_iface()
_validate_mmds_snapshot(
uvm_nano,
microvm_factory,
version,
target_fc_version=firecracker_release.snapshot_version,
fc_binary_path=firecracker_release.path,
jailer_binary_path=firecracker_release.jailer,
fc_binary_path=current_release.path,
jailer_binary_path=current_release.jailer,
)


Expand Down Expand Up @@ -640,7 +640,6 @@ def test_mmds_older_snapshot(
microvm,
microvm_factory,
mmds_version,
firecracker_release.snapshot_version,
*get_firecracker_binaries(),
)

Expand Down
49 changes: 1 addition & 48 deletions tests/integration_tests/functional/test_snapshot_advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# SPDX-License-Identifier: Apache-2.0
"""Advanced tests scenarios for snapshot save/restore."""

import platform
import tempfile

import pytest
Expand Down Expand Up @@ -55,51 +54,6 @@ def test_restore_old_to_current(
print(vm.log_data)


def test_restore_current_to_old(microvm_factory, uvm_plain, firecracker_release):
"""
Restore current snapshot with previous versions of Firecracker.
For each firecracker release:
1. Snapshot with the current build
2. Restore with the past release
"""

# Microvm: 2vCPU 256MB RAM, balloon, 4 disks and 4 net devices.
vm = uvm_plain
vm.spawn()
vm.basic_config(track_dirty_pages=True)

# Create a snapshot with current FC version targeting the old version.
snapshot = create_snapshot_helper(
vm,
target_version=firecracker_release.snapshot_version,
drives=scratch_drives,
balloon=True,
diff_snapshots=True,
)

# Resume microvm using FC/Jailer binary artifacts.
vm = microvm_factory.build(
fc_binary_path=firecracker_release.path,
jailer_binary_path=firecracker_release.jailer,
)
vm.spawn()
vm.restore_from_snapshot(snapshot, resume=True)
validate_all_devices(vm, True)
print("========== Firecracker restore snapshot log ==========")
print(vm.log_data)


@pytest.mark.skipif(platform.machine() != "x86_64", reason="TSC is x86_64 specific.")
def test_save_tsc_old_version(uvm_nano):
"""
Test TSC warning message when saving old snapshot.
"""
uvm_nano.start()
uvm_nano.snapshot_full(target_version="0.24.0")
uvm_nano.check_log_message("Saving to older snapshot version, TSC freq")


def validate_all_devices(microvm, balloon):
"""Perform a basic validation for all devices of a microvm."""
# Test that net devices have connectivity after restore.
Expand Down Expand Up @@ -139,7 +93,6 @@ def validate_all_devices(microvm, balloon):

def create_snapshot_helper(
vm,
target_version=None,
drives=None,
balloon=False,
diff_snapshots=False,
Expand Down Expand Up @@ -196,7 +149,7 @@ def create_snapshot_helper(
exit_code, _, _ = vm.ssh.run(cmd)
assert exit_code == 0

snapshot = vm.make_snapshot(snapshot_type, target_version=target_version)
snapshot = vm.make_snapshot(snapshot_type)
print("========== Firecracker create snapshot log ==========")
print(vm.log_data)
vm.kill()
Expand Down
34 changes: 33 additions & 1 deletion tests/integration_tests/functional/test_snapshot_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@

import host_tools.drive as drive_tools
from framework.microvm import SnapshotType
from framework.utils import check_filesystem, wait_process_termination
from framework.utils import (
check_filesystem,
get_firecracker_version_from_toml,
run_cmd,
wait_process_termination,
)
from framework.utils_vsock import (
ECHO_SERVER_PORT,
VSOCK_UDS_PATH,
Expand All @@ -23,6 +28,7 @@
make_host_port_path,
start_guest_echo_server,
)
from host_tools.cargo_build import get_firecracker_binaries


def _get_guest_drive_size(ssh_connection, guest_dev_name="/dev/vdb"):
Expand All @@ -35,6 +41,32 @@ def _get_guest_drive_size(ssh_connection, guest_dev_name="/dev/vdb"):
return lines[1].strip()


def test_snapshot_current_version(uvm_nano):
"""Tests taking a snapshot at the version specified in Cargo.toml
Check that it is possible to take a snapshot at the version of the upcoming
release (during the release process this ensures that if we release version
x.y, then taking a snapshot at version x.y works - something we'd otherwise
only be able to test once the x.y binary has been uploaded to S3, at which
point it is too late, see also the 1.3 release).
"""
vm = uvm_nano
vm.start()

version = get_firecracker_version_from_toml()
# normalize to a snapshot version
version = f"{version.major}.{version.minor}.0"
snapshot = vm.snapshot_full()

# Fetch Firecracker binary for the latest version
fc_binary, _ = get_firecracker_binaries()
# Verify the output of `--describe-snapshot` command line parameter
cmd = [str(fc_binary)] + ["--describe-snapshot", str(snapshot.vmstate)]

_, stdout, _ = run_cmd(cmd)
assert version in stdout


# Testing matrix:
# - Guest kernel: All supported ones
# - Rootfs: Ubuntu 18.04
Expand Down
Loading

0 comments on commit e960d8d

Please sign in to comment.