Path: blob/main/tests/integration_tests/functional/test_cmd_line_parameters.py
1958 views
# Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.1# SPDX-License-Identifier: Apache-2.02"""Tests that ensure the correctness of the command line parameters."""34import logging5import platform67from host_tools.cargo_build import get_firecracker_binaries8from conftest import _test_images_s3_bucket9from framework.artifacts import ArtifactCollection10from framework.builder import MicrovmBuilder, SnapshotBuilder, SnapshotType11from framework.utils import get_firecracker_version_from_toml, run_cmd121314def test_describe_snapshot_all_versions(bin_cloner_path):15"""Test `--describe-snapshot` correctness for all snapshot versions."""16logger = logging.getLogger("describe_snapshot")17builder = MicrovmBuilder(bin_cloner_path)18artifacts = ArtifactCollection(_test_images_s3_bucket())19# Fetch all firecracker binaries.20# For each binary create a snapshot and verify the data version21# of the snapshot state file.22firecracker_artifacts = artifacts.firecrackers(23older_than=get_firecracker_version_from_toml())2425for firecracker in firecracker_artifacts:26firecracker.download()27jailer = firecracker.jailer()28jailer.download()2930target_version = firecracker.base_name()[1:]31# Skip for aarch64, since the snapshotting feature32# was introduced in v0.24.0.33if platform.machine() == "aarch64" and "v0.23" in target_version:34continue3536logger.info("Creating snapshot with Firecracker: %s",37firecracker.local_path())38logger.info("Using Jailer: %s", jailer.local_path())39logger.info("Using target version: %s", target_version)4041# v0.23 does not support creating diff snapshots.42diff_snapshots = "0.23" not in target_version43vm_instance = builder.build_vm_nano(fc_binary=firecracker.local_path(),44jailer_binary=jailer.local_path(),45diff_snapshots=diff_snapshots)46vm = vm_instance.vm47vm.start()4849# Create a snapshot builder from a microvm.50snapshot_builder = SnapshotBuilder(vm)51disks = [vm_instance.disks[0].local_path()]5253# Version 0.24 and greater have Diff support.54snap_type = SnapshotType.DIFF if diff_snapshots else SnapshotType.FULL5556snapshot = snapshot_builder.create(disks,57vm_instance.ssh_key,58target_version=target_version,59snapshot_type=snap_type)60logger.debug("========== Firecracker create snapshot log ==========")61logger.debug(vm.log_data)62vm.kill()6364# Fetch Firecracker binary for the latest version65fc_binary, _ = get_firecracker_binaries()66# Verify the output of `--describe-snapshot` command line parameter67cmd = [fc_binary] + ["--describe-snapshot", snapshot.vmstate]6869code, stdout, stderr = run_cmd(cmd)70assert code == 071assert stderr == ''72assert target_version in stdout737475