Skip to content

Commit 103c20e

Browse files
committed
tests: fix snapshot tests for older versions
Previously, the snapshot tests that were supposed to retrieve the older Firecracker binaries from S3 were not filtering the artifacts by version number. This results in test failures for patch releases, where the test will use both older and newer binaries. Added support in the testing framework for this and fixed the respective tests. Signed-off-by: alindima <[email protected]>
1 parent ec7b69c commit 103c20e

File tree

4 files changed

+74
-14
lines changed

4 files changed

+74
-14
lines changed

tests/framework/artifacts.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import boto3
1313
import botocore.client
1414
from host_tools.snapshot_helper import merge_memory_bitmaps
15+
from framework.utils import compare_release_versions
1516

1617

1718
ARTIFACTS_LOCAL_ROOT = "/tmp/ci-artifacts"
@@ -316,9 +317,9 @@ def _fetch_artifacts(self,
316317
# Filter by userprovided keyword if any.
317318
and (keyword is None or keyword in file.key)
318319
):
319-
artifacts.append(artifact_class(self.bucket,
320-
file.key,
321-
artifact_type=artifact_type))
320+
artifacts.append(artifact_class(
321+
self.bucket, file.key, artifact_type=artifact_type)
322+
)
322323
return artifacts
323324

324325
def snapshots(self, keyword=None):
@@ -347,7 +348,7 @@ def snapshots(self, keyword=None):
347348
# Filter out the snapshot artifacts root folder.
348349
# Select only files with specified keyword.
349350
if (key[-1] == "/" and key != prefix and
350-
(keyword is None or keyword in snapshot_dir.key)):
351+
(keyword is None or keyword in snapshot_dir.key)):
351352
artifact_type = ArtifactType.SNAPSHOT
352353
artifacts.append(SnapshotArtifact(self.bucket,
353354
key,
@@ -365,16 +366,29 @@ def microvms(self, keyword=None):
365366
keyword=keyword
366367
)
367368

368-
def firecrackers(self, keyword=None):
369+
def firecrackers(self, keyword=None, older_than=None):
369370
"""Return fc/jailer artifacts for the current arch."""
370-
return self._fetch_artifacts(
371+
firecrackers = self._fetch_artifacts(
371372
ArtifactCollection.ARTIFACTS_BINARIES,
372373
ArtifactCollection.FC_EXTENSION,
373374
ArtifactType.FC,
374375
FirecrackerArtifact,
375376
keyword=keyword
376377
)
377378

379+
if older_than is not None:
380+
return filter(
381+
lambda fc:
382+
compare_release_versions(
383+
os.path.basename(fc.key).replace(
384+
ArtifactCollection.FC_EXTENSION, '')[1:],
385+
older_than
386+
) < 0,
387+
firecrackers
388+
)
389+
390+
return firecrackers
391+
378392
def kernels(self, keyword=None):
379393
"""Return kernel artifacts for the current arch."""
380394
return self._fetch_artifacts(

tests/framework/utils.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,44 @@ def get_cpu_vendor():
206206
if 'AuthenticAMD' in brand_str:
207207
return CpuVendor.AMD
208208
return CpuVendor.INTEL
209+
210+
211+
def get_firecracker_version_from_toml():
212+
"""
213+
Return the version of the firecracker crate, from Cargo.toml.
214+
215+
Usually different from the output of `./firecracker --version`, if
216+
the code has not been released.
217+
"""
218+
cmd = "cd ../src/firecracker && cargo pkgid | cut -d# -f2 | cut -d: -f2"
219+
220+
rc, stdout, _ = run_cmd(cmd)
221+
assert rc == 0
222+
223+
return stdout
224+
225+
226+
def compare_release_versions(first, second):
227+
"""
228+
Compare two versions with format `X.Y.Z`.
229+
230+
:param first: first version string
231+
:param second: second version string
232+
:returns: 0 if equal, <0 if first < second, >0 if second < first
233+
"""
234+
first = first.split('.')
235+
second = second.split('.')
236+
237+
first = list(map(int, first))
238+
second = list(map(int, second))
239+
240+
if first[0] == second[0]:
241+
if first[1] == second[1]:
242+
if first[2] == second[2]:
243+
return 0
244+
245+
return first[2] - second[2]
246+
247+
return first[1] - second[1]
248+
249+
return first[0] - second[0]

tests/integration_tests/functional/test_snapshot_version.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from framework.artifacts import ArtifactCollection
1010
from framework.builder import MicrovmBuilder, SnapshotBuilder, SnapshotType
1111
from framework.microvms import C3micro
12+
from framework.utils import get_firecracker_version_from_toml
1213
import host_tools.network as net_tools # pylint: disable=import-error
1314

1415

@@ -24,7 +25,8 @@ def test_restore_from_past_versions(bin_cloner_path):
2425
# Fetch all firecracker binaries.
2526
# With each binary create a snapshot and try to restore in current
2627
# version.
27-
firecracker_artifacts = artifacts.firecrackers()
28+
firecracker_artifacts = artifacts.firecrackers(
29+
older_than=get_firecracker_version_from_toml())
2830
for firecracker in firecracker_artifacts:
2931
firecracker.download()
3032
jailer = firecracker.jailer()
@@ -90,12 +92,13 @@ def test_restore_in_past_versions(bin_cloner_path):
9092
logger = logging.getLogger("snapshot_version")
9193

9294
artifacts = ArtifactCollection(_test_images_s3_bucket())
93-
# Fetch all snapshots artifacts.
95+
# Fetch all snapshots artifacts of past versions.
9496
# "fc_release" is the key that should be used for per release snapshot
9597
# artifacts. Such snapshots are created at release time and target the
9698
# current version. We are going to restore all these snapshots with current
9799
# testing build.
98-
firecracker_artifacts = artifacts.firecrackers()
100+
firecracker_artifacts = artifacts.firecrackers(
101+
older_than=get_firecracker_version_from_toml())
99102
for firecracker in firecracker_artifacts:
100103
firecracker.download()
101104
jailer = firecracker.jailer()

tests/integration_tests/performance/test_snapshot_perf.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
from framework.matrix import TestMatrix, TestContext
1313
from framework.microvms import C3micro
1414
from framework.builder import MicrovmBuilder, SnapshotBuilder, SnapshotType
15-
from framework.utils import CpuVendor, get_cpu_vendor
15+
from framework.utils import CpuVendor, get_cpu_vendor, \
16+
get_firecracker_version_from_toml
1617
import host_tools.network as net_tools # pylint: disable=import-error
1718
import host_tools.logging as log_tools
1819

@@ -147,9 +148,9 @@ def _test_snapshot_resume_latency(context):
147148

148149
for i in range(SAMPLE_COUNT):
149150
microvm, metrics_fifo = vm_builder.build_from_snapshot(
150-
snapshot,
151-
True,
152-
enable_diff_snapshots)
151+
snapshot,
152+
True,
153+
enable_diff_snapshots)
153154

154155
# Attempt to connect to resumed microvm.
155156
ssh_connection = net_tools.SSHConnection(microvm.ssh_config)
@@ -267,7 +268,8 @@ def test_older_snapshot_resume_latency(bin_cloner_path):
267268
# Fetch all firecracker binaries.
268269
# With each binary create a snapshot and try to restore in current
269270
# version.
270-
firecracker_artifacts = artifacts.firecrackers()
271+
firecracker_artifacts = artifacts.firecrackers(
272+
older_than=get_firecracker_version_from_toml())
271273
for firecracker in firecracker_artifacts:
272274
firecracker.download()
273275
jailer = firecracker.jailer()

0 commit comments

Comments
 (0)