8
8
import pytest
9
9
from test_balloon import _test_rss_memory_lower
10
10
from 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
+ )
12
16
from framework .builder import MicrovmBuilder , SnapshotBuilder , SnapshotType
13
17
from framework .utils import get_firecracker_version_from_toml
14
18
import host_tools .network as net_tools # pylint: disable=import-error
21
25
scratch_drives = ["vdb" , "vdc" , "vdd" , "vde" , "vdf" ]
22
26
23
27
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 ):
25
48
"""
26
49
Restore from snapshots obtained with previous versions of Firecracker.
27
50
@@ -31,106 +54,100 @@ def test_restore_old_snapshot(bin_cloner_path):
31
54
logger = logging .getLogger ("old_snapshot_many_devices" )
32
55
builder = MicrovmBuilder (bin_cloner_path )
33
56
34
- artifacts = ArtifactCollection (_test_images_s3_bucket ())
35
- # Fetch all firecracker binaries.
36
57
# With each binary create a snapshot and try to restore in current
37
58
# version.
38
- firecracker_artifacts = artifacts .firecrackers (
39
- max_version = get_firecracker_version_from_toml ()
40
- )
41
59
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 ()
67
63
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 )
77
92
78
93
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 ):
80
103
"""
81
104
Restore current snapshot with previous versions of Firecracker.
82
105
106
+ Current snapshot (i.e a machine snapshotted with current build) is
107
+ incompatible with any past release due to notification suppression.
108
+
83
109
@type: functional
84
110
"""
85
111
# Microvm: 2vCPU 256MB RAM, balloon, 4 disks and 4 net devices.
86
112
logger = logging .getLogger ("old_snapshot_version_many_devices" )
87
113
builder = MicrovmBuilder (bin_cloner_path )
88
114
89
- artifacts = ArtifactCollection (_test_images_s3_bucket ())
90
- # Fetch all firecracker binaries.
91
115
# Create a snapshot with current build and restore with each FC binary
92
116
# 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 ,
98
135
)
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
- )
119
136
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 ())
122
139
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 )
134
151
135
152
136
153
@pytest .mark .skipif (platform .machine () != "x86_64" , reason = "TSC is x86_64 specific." )
0 commit comments