88import pytest
99from test_balloon import _test_rss_memory_lower
1010from conftest import _test_images_s3_bucket
11- from framework .artifacts import ArtifactCollection , create_net_devices_configuration
11+ from framework .artifacts import (
12+ ArtifactCollection ,
13+ FirecrackerArtifact ,
14+ create_net_devices_configuration ,
15+ )
1216from framework .builder import MicrovmBuilder , SnapshotBuilder , SnapshotType
1317from framework .utils import get_firecracker_version_from_toml
1418import host_tools .network as net_tools # pylint: disable=import-error
2125scratch_drives = ["vdb" , "vdc" , "vdd" , "vde" , "vdf" ]
2226
2327
24- def test_restore_old_snapshot (bin_cloner_path ):
28+ def firecracker_artifacts (* args , ** kwargs ):
29+ """Return all available firecracker binaries."""
30+ artifacts = ArtifactCollection (_test_images_s3_bucket ())
31+ # Fetch all firecracker binaries.
32+ return artifacts .firecrackers (* args , ** kwargs )
33+
34+
35+ def firecracker_id (fc ):
36+ """Render a nice ID for pytest parametrize."""
37+ if isinstance (fc , FirecrackerArtifact ):
38+ return f"firecracker-{ fc .version } "
39+ return None
40+
41+
42+ @pytest .mark .parametrize (
43+ "firecracker" ,
44+ firecracker_artifacts (max_version = get_firecracker_version_from_toml ()),
45+ ids = firecracker_id ,
46+ )
47+ def test_restore_old_snapshot (bin_cloner_path , firecracker ):
2548 """
2649 Restore from snapshots obtained with previous versions of Firecracker.
2750
@@ -31,106 +54,100 @@ def test_restore_old_snapshot(bin_cloner_path):
3154 logger = logging .getLogger ("old_snapshot_many_devices" )
3255 builder = MicrovmBuilder (bin_cloner_path )
3356
34- artifacts = ArtifactCollection (_test_images_s3_bucket ())
35- # Fetch all firecracker binaries.
3657 # With each binary create a snapshot and try to restore in current
3758 # version.
38- firecracker_artifacts = artifacts .firecrackers (
39- max_version = get_firecracker_version_from_toml ()
40- )
4159
42- for firecracker in firecracker_artifacts :
43- firecracker .download ()
44- jailer = firecracker .jailer ()
45- jailer .download ()
46-
47- logger .info ("Creating snapshot with Firecracker: %s" , firecracker .local_path ())
48- logger .info ("Using Jailer: %s" , jailer .local_path ())
49-
50- target_version = firecracker .base_name ()[1 :]
51-
52- # v0.23 does not support creating diff snapshots.
53- # v0.23 does not support balloon.
54- diff_snapshots = "0.23" not in target_version
55-
56- # Create a snapshot.
57- snapshot = create_snapshot_helper (
58- builder ,
59- logger ,
60- drives = scratch_drives ,
61- ifaces = net_ifaces ,
62- fc_binary = firecracker .local_path (),
63- jailer_binary = jailer .local_path (),
64- diff_snapshots = diff_snapshots ,
65- balloon = diff_snapshots ,
66- )
60+ firecracker .download ()
61+ jailer = firecracker .jailer ()
62+ jailer .download ()
6763
68- # Resume microvm using current build of FC/Jailer.
69- microvm , _ = builder .build_from_snapshot (
70- snapshot , resume = True , diff_snapshots = False
71- )
72- validate_all_devices (
73- logger , microvm , net_ifaces , scratch_drives , diff_snapshots
74- )
75- logger .debug ("========== Firecracker restore snapshot log ==========" )
76- logger .debug (microvm .log_data )
64+ logger .info ("Creating snapshot with Firecracker: %s" , firecracker .local_path ())
65+ logger .info ("Using Jailer: %s" , jailer .local_path ())
66+
67+ target_version = firecracker .base_name ()[1 :]
68+
69+ # v0.23 does not support creating diff snapshots.
70+ # v0.23 does not support balloon.
71+ diff_snapshots = "0.23" not in target_version
72+
73+ # Create a snapshot.
74+ snapshot = create_snapshot_helper (
75+ builder ,
76+ logger ,
77+ drives = scratch_drives ,
78+ ifaces = net_ifaces ,
79+ fc_binary = firecracker .local_path (),
80+ jailer_binary = jailer .local_path (),
81+ diff_snapshots = diff_snapshots ,
82+ balloon = diff_snapshots ,
83+ )
84+
85+ # Resume microvm using current build of FC/Jailer.
86+ microvm , _ = builder .build_from_snapshot (
87+ snapshot , resume = True , diff_snapshots = False
88+ )
89+ validate_all_devices (logger , microvm , net_ifaces , scratch_drives , diff_snapshots )
90+ logger .debug ("========== Firecracker restore snapshot log ==========" )
91+ logger .debug (microvm .log_data )
7792
7893
79- def test_restore_old_version (bin_cloner_path ):
94+ @pytest .mark .parametrize (
95+ "firecracker" ,
96+ firecracker_artifacts (
97+ min_version = "1.2.0" ,
98+ max_version = get_firecracker_version_from_toml (),
99+ ),
100+ ids = firecracker_id ,
101+ )
102+ def test_restore_old_version (bin_cloner_path , firecracker ):
80103 """
81104 Restore current snapshot with previous versions of Firecracker.
82105
106+ Current snapshot (i.e a machine snapshotted with current build) is
107+ incompatible with any past release due to notification suppression.
108+
83109 @type: functional
84110 """
85111 # Microvm: 2vCPU 256MB RAM, balloon, 4 disks and 4 net devices.
86112 logger = logging .getLogger ("old_snapshot_version_many_devices" )
87113 builder = MicrovmBuilder (bin_cloner_path )
88114
89- artifacts = ArtifactCollection (_test_images_s3_bucket ())
90- # Fetch all firecracker binaries.
91115 # Create a snapshot with current build and restore with each FC binary
92116 # artifact.
93- firecracker_artifacts = artifacts .firecrackers (
94- # current snapshot (i.e a machine snapshotted with current build)
95- # is incompatible with any past release due to notification suppression.
96- min_version = "1.2.0" ,
97- max_version = get_firecracker_version_from_toml (),
117+ firecracker .download ()
118+ jailer = firecracker .jailer ()
119+ jailer .download ()
120+
121+ logger .info ("Creating snapshot with local build" )
122+
123+ # Old version from artifact.
124+ target_version = firecracker .base_name ()[1 :]
125+
126+ # Create a snapshot with current FC version targeting the old version.
127+ snapshot = create_snapshot_helper (
128+ builder ,
129+ logger ,
130+ target_version = target_version ,
131+ drives = scratch_drives ,
132+ ifaces = net_ifaces ,
133+ balloon = True ,
134+ diff_snapshots = True ,
98135 )
99- for firecracker in firecracker_artifacts :
100- firecracker .download ()
101- jailer = firecracker .jailer ()
102- jailer .download ()
103-
104- logger .info ("Creating snapshot with local build" )
105-
106- # Old version from artifact.
107- target_version = firecracker .base_name ()[1 :]
108-
109- # Create a snapshot with current FC version targeting the old version.
110- snapshot = create_snapshot_helper (
111- builder ,
112- logger ,
113- target_version = target_version ,
114- drives = scratch_drives ,
115- ifaces = net_ifaces ,
116- balloon = True ,
117- diff_snapshots = True ,
118- )
119136
120- logger .info ("Restoring snapshot with Firecracker: %s" , firecracker .local_path ())
121- logger .info ("Using Jailer: %s" , jailer .local_path ())
137+ logger .info ("Restoring snapshot with Firecracker: %s" , firecracker .local_path ())
138+ logger .info ("Using Jailer: %s" , jailer .local_path ())
122139
123- # Resume microvm using FC/Jailer binary artifacts.
124- vm , _ = builder .build_from_snapshot (
125- snapshot ,
126- resume = True ,
127- diff_snapshots = False ,
128- fc_binary = firecracker .local_path (),
129- jailer_binary = jailer .local_path (),
130- )
131- validate_all_devices (logger , vm , net_ifaces , scratch_drives , True )
132- logger .debug ("========== Firecracker restore snapshot log ==========" )
133- logger .debug (vm .log_data )
140+ # Resume microvm using FC/Jailer binary artifacts.
141+ vm , _ = builder .build_from_snapshot (
142+ snapshot ,
143+ resume = True ,
144+ diff_snapshots = False ,
145+ fc_binary = firecracker .local_path (),
146+ jailer_binary = jailer .local_path (),
147+ )
148+ validate_all_devices (logger , vm , net_ifaces , scratch_drives , True )
149+ logger .debug ("========== Firecracker restore snapshot log ==========" )
150+ logger .debug (vm .log_data )
134151
135152
136153@pytest .mark .skipif (platform .machine () != "x86_64" , reason = "TSC is x86_64 specific." )
0 commit comments