1616# pylint: disable=wrong-import-position
1717# The test infra assumes it is running from the `tests` directory.
1818os .chdir ("tests" )
19- import host_tools .network as net_tools # pylint: disable=import-error
20- from conftest import _gcc_compile
21- from framework .artifacts import (
22- ArtifactCollection ,
23- ArtifactSet ,
24- create_net_devices_configuration ,
25- )
19+ from conftest import ARTIFACTS_COLLECTION as ARTIFACTS , _gcc_compile
20+ from framework .artifacts import create_net_devices_configuration
2621from framework .builder import MicrovmBuilder , SnapshotBuilder , SnapshotType
27- from framework .defs import DEFAULT_TEST_SESSION_ROOT_PATH , _test_images_s3_bucket
28- from framework .matrix import TestContext , TestMatrix
22+ from framework .defs import DEFAULT_TEST_SESSION_ROOT_PATH
2923from framework .microvm import Microvm
3024from framework .utils import (
3125 generate_mmds_get_request ,
3428)
3529from framework .utils_cpuid import CpuVendor , get_cpu_vendor
3630from integration_tests .functional .test_cmd_line_start import _configure_vm_from_json
37-
3831# restore directory
3932os .chdir (".." )
4033
@@ -86,14 +79,11 @@ def populate_mmds(microvm, data_store):
8679 assert response .json () == data_store
8780
8881
89- def setup_vm (context ):
82+ def setup_vm (root_path , bin_cloner_path , kernel , disk ):
9083 """Init microVM using context provided."""
91- root_path = context .custom ["session_root_path" ]
92- bin_cloner_path = context .custom ["bin_cloner_path" ]
93-
9484 print (
95- f"Creating snapshot of microVM with kernel { context . kernel .name ()} "
96- f" and disk { context . disk .name ()} ."
85+ f"Creating snapshot of microVM with kernel { kernel .name ()} "
86+ f" and disk { disk .name ()} ."
9787 )
9888 vm = Microvm (
9989 resource_path = root_path ,
@@ -102,11 +92,11 @@ def setup_vm(context):
10292
10393 # Change kernel name to match the one in the config file.
10494 kernel_full_path = os .path .join (vm .path , DEST_KERNEL_NAME )
105- shutil .copyfile (context . kernel .local_path (), kernel_full_path )
95+ shutil .copyfile (kernel .local_path (), kernel_full_path )
10696 vm .kernel_file = kernel_full_path
10797
108- rootfs_full_path = os .path .join (vm .path , context . disk .name ())
109- shutil .copyfile (context . disk .local_path (), rootfs_full_path )
98+ rootfs_full_path = os .path .join (vm .path , disk .name ())
99+ shutil .copyfile (disk .local_path (), rootfs_full_path )
110100 vm .rootfs_file = rootfs_full_path
111101
112102 return vm
@@ -191,6 +181,7 @@ def main():
191181 """
192182 # Create directory dedicated to store snapshot artifacts for
193183 # each guest kernel version.
184+ print ("Cleanup" )
194185 shutil .rmtree (SNAPSHOT_ARTIFACTS_ROOT_DIR , ignore_errors = True )
195186 os .mkdir (SNAPSHOT_ARTIFACTS_ROOT_DIR )
196187
@@ -204,29 +195,21 @@ def main():
204195 )
205196
206197 # Fetch kernel and rootfs artifacts from S3 bucket.
207- artifacts = ArtifactCollection (_test_images_s3_bucket ())
208- kernel_artifacts = ArtifactSet (artifacts .kernels ())
209- disk_artifacts = ArtifactSet (artifacts .disks (keyword = "ubuntu" ))
198+ kernels = ARTIFACTS .kernels ()
199+ disks = ARTIFACTS .disks (keyword = "ubuntu" )
210200
211201 cpu_templates = ["None" ]
212202 if get_cpu_vendor () == CpuVendor .INTEL :
213203 cpu_templates .extend (["C3" , "T2" , "T2S" ])
214204
215205 for cpu_template in cpu_templates :
216- # Create a test context.
217- test_context = TestContext ()
218- test_context .custom = {
219- "bin_cloner_path" : bin_cloner_path ,
220- "session_root_path" : root_path ,
221- "cpu_template" : cpu_template ,
222- }
223-
224- # Create the test matrix.
225- test_matrix = TestMatrix (
226- context = test_context , artifact_sets = [kernel_artifacts , disk_artifacts ]
227- )
228-
229- test_matrix .run_test (create_snapshots )
206+ for kernel in kernels :
207+ kernel .download ()
208+ for rootfs in disks :
209+ rootfs .download ()
210+ print (kernel , rootfs , cpu_template )
211+ vm = setup_vm (root_path , bin_cloner_path , kernel , rootfs )
212+ create_snapshots (vm , rootfs , kernel , cpu_template )
230213
231214
232215def add_cpu_template (template , json_data ):
@@ -235,16 +218,13 @@ def add_cpu_template(template, json_data):
235218 return json_data
236219
237220
238- def create_snapshots (context ):
221+ def create_snapshots (vm , rootfs , kernel , cpu_template ):
239222 """Snapshot microVM built from vm configuration file."""
240- vm = setup_vm (context )
241-
242223 # Get ssh key from read-only artifact.
243- ssh_key = context . disk .ssh_key ()
224+ ssh_key = rootfs .ssh_key ()
244225 ssh_key .download (vm .path )
245226 vm .ssh_config ["ssh_key_path" ] = ssh_key .local_path ()
246227 os .chmod (vm .ssh_config ["ssh_key_path" ], 0o400 )
247- cpu_template = context .custom ["cpu_template" ]
248228
249229 fn = partial (add_cpu_template , cpu_template )
250230 _configure_vm_from_json (vm , VM_CONFIG_FILE , json_xform = fn )
@@ -272,12 +252,11 @@ def create_snapshots(context):
272252 # Iterate and validate connectivity on all ifaces after boot.
273253 for iface in net_ifaces :
274254 vm .ssh_config ["hostname" ] = iface .guest_ip
275- ssh_connection = net_tools .SSHConnection (vm .ssh_config )
276- exit_code , _ , _ = ssh_connection .execute_command ("sync" )
255+ exit_code , _ , _ = vm .ssh .execute_command ("sync" )
277256 assert exit_code == 0
278257
279258 # Validate MMDS.
280- validate_mmds (ssh_connection , data_store )
259+ validate_mmds (vm . ssh , data_store )
281260
282261 # Create a snapshot builder from a microVM.
283262 snapshot_builder = SnapshotBuilder (vm )
@@ -288,7 +267,7 @@ def create_snapshots(context):
288267 )
289268
290269 copy_snapshot_artifacts (
291- snapshot , vm .rootfs_file , context . kernel .name (), ssh_key , cpu_template
270+ snapshot , vm .rootfs_file , kernel .name (), ssh_key , cpu_template
292271 )
293272
294273 vm .kill ()
0 commit comments