Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/firecracker
Path: blob/main/tests/integration_tests/functional/test_cmd_line_parameters.py
1958 views
1
# Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
# SPDX-License-Identifier: Apache-2.0
3
"""Tests that ensure the correctness of the command line parameters."""
4
5
import logging
6
import platform
7
8
from host_tools.cargo_build import get_firecracker_binaries
9
from conftest import _test_images_s3_bucket
10
from framework.artifacts import ArtifactCollection
11
from framework.builder import MicrovmBuilder, SnapshotBuilder, SnapshotType
12
from framework.utils import get_firecracker_version_from_toml, run_cmd
13
14
15
def test_describe_snapshot_all_versions(bin_cloner_path):
16
"""Test `--describe-snapshot` correctness for all snapshot versions."""
17
logger = logging.getLogger("describe_snapshot")
18
builder = MicrovmBuilder(bin_cloner_path)
19
artifacts = ArtifactCollection(_test_images_s3_bucket())
20
# Fetch all firecracker binaries.
21
# For each binary create a snapshot and verify the data version
22
# of the snapshot state file.
23
firecracker_artifacts = artifacts.firecrackers(
24
older_than=get_firecracker_version_from_toml())
25
26
for firecracker in firecracker_artifacts:
27
firecracker.download()
28
jailer = firecracker.jailer()
29
jailer.download()
30
31
target_version = firecracker.base_name()[1:]
32
# Skip for aarch64, since the snapshotting feature
33
# was introduced in v0.24.0.
34
if platform.machine() == "aarch64" and "v0.23" in target_version:
35
continue
36
37
logger.info("Creating snapshot with Firecracker: %s",
38
firecracker.local_path())
39
logger.info("Using Jailer: %s", jailer.local_path())
40
logger.info("Using target version: %s", target_version)
41
42
# v0.23 does not support creating diff snapshots.
43
diff_snapshots = "0.23" not in target_version
44
vm_instance = builder.build_vm_nano(fc_binary=firecracker.local_path(),
45
jailer_binary=jailer.local_path(),
46
diff_snapshots=diff_snapshots)
47
vm = vm_instance.vm
48
vm.start()
49
50
# Create a snapshot builder from a microvm.
51
snapshot_builder = SnapshotBuilder(vm)
52
disks = [vm_instance.disks[0].local_path()]
53
54
# Version 0.24 and greater have Diff support.
55
snap_type = SnapshotType.DIFF if diff_snapshots else SnapshotType.FULL
56
57
snapshot = snapshot_builder.create(disks,
58
vm_instance.ssh_key,
59
target_version=target_version,
60
snapshot_type=snap_type)
61
logger.debug("========== Firecracker create snapshot log ==========")
62
logger.debug(vm.log_data)
63
vm.kill()
64
65
# Fetch Firecracker binary for the latest version
66
fc_binary, _ = get_firecracker_binaries()
67
# Verify the output of `--describe-snapshot` command line parameter
68
cmd = [fc_binary] + ["--describe-snapshot", snapshot.vmstate]
69
70
code, stdout, stderr = run_cmd(cmd)
71
assert code == 0
72
assert stderr == ''
73
assert target_version in stdout
74
75