|
7 | 7 | import pytest
|
8 | 8 |
|
9 | 9 | from framework.artifacts import NetIfaceConfig
|
10 |
| -from framework.builder import MicrovmBuilder, SnapshotBuilder |
| 10 | +from framework.builder import MicrovmBuilder, SnapshotBuilder, SnapshotType |
| 11 | +from framework.utils import get_firecracker_version_from_toml, run_cmd |
| 12 | +from host_tools.cargo_build import get_firecracker_binaries |
11 | 13 |
|
12 | 14 | # Firecracker v0.23 used 16 IRQ lines. For virtio devices,
|
13 | 15 | # IRQs are available from 5 to 23, so the maximum number
|
@@ -116,6 +118,47 @@ def test_create_invalid_version(bin_cloner_path):
|
116 | 118 | assert False, "Negative test failed"
|
117 | 119 |
|
118 | 120 |
|
| 121 | +def test_snapshot_current_version(bin_cloner_path): |
| 122 | + """Tests taking a snapshot at the version specified in Cargo.toml |
| 123 | +
|
| 124 | + Check that it is possible to take a snapshot at the version of the upcoming |
| 125 | + release (during the release process this ensures that if we release version |
| 126 | + x.y, then taking a snapshot at version x.y works - something we'd otherwise |
| 127 | + only be able to test once the x.y binary has been uploaded to S3, at which |
| 128 | + point it is too late, see also the 1.3 release). |
| 129 | +
|
| 130 | + @type: functional |
| 131 | + """ |
| 132 | + builder = MicrovmBuilder(bin_cloner_path) |
| 133 | + vm_instance = builder.build_vm_nano(diff_snapshots=True) |
| 134 | + vm = vm_instance.vm |
| 135 | + vm.start() |
| 136 | + |
| 137 | + version = get_firecracker_version_from_toml() |
| 138 | + # normalize to a snapshot version |
| 139 | + (major, minor, _) = version.split(".", maxsplit=3) |
| 140 | + target_version = f"{major}.{minor}.0" |
| 141 | + # Create a snapshot builder from a microvm. |
| 142 | + snapshot_builder = SnapshotBuilder(vm) |
| 143 | + disks = [vm_instance.disks[0].local_path()] |
| 144 | + snapshot = snapshot_builder.create( |
| 145 | + disks, |
| 146 | + vm_instance.ssh_key, |
| 147 | + snapshot_type=SnapshotType.FULL, |
| 148 | + target_version=target_version, |
| 149 | + ) |
| 150 | + |
| 151 | + # Fetch Firecracker binary for the latest version |
| 152 | + fc_binary, _ = get_firecracker_binaries() |
| 153 | + # Verify the output of `--describe-snapshot` command line parameter |
| 154 | + cmd = [fc_binary] + ["--describe-snapshot", snapshot.vmstate] |
| 155 | + |
| 156 | + code, stdout, stderr = run_cmd(cmd) |
| 157 | + assert code == 0, stderr |
| 158 | + assert stderr == "" |
| 159 | + assert target_version in stdout |
| 160 | + |
| 161 | + |
119 | 162 | def test_create_with_newer_virtio_features(bin_cloner_path):
|
120 | 163 | """
|
121 | 164 | Attempt to create a snapshot with newer virtio features.
|
|
0 commit comments