Skip to content

Commit 3342c82

Browse files
committed
ci: move create_snapshot_artifact to a test
It's more hassle to keep this as a separate tool than including it in the tests, and we avoid having to treat it specially. Also this way we can run it in parallel easily. Signed-off-by: Pablo Barbáchano <[email protected]>
1 parent 8f883c0 commit 3342c82

File tree

4 files changed

+123
-175
lines changed

4 files changed

+123
-175
lines changed

.buildkite/pipeline_cross.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,9 @@
2121
instances_x86_64 = ["c5n.metal", "m5n.metal", "m6i.metal", "m6a.metal"]
2222
instances_aarch64 = ["m7g.metal"]
2323
commands = [
24-
# we run 0 tests for the side effect of downloading the artifacts. We
25-
# should convert create_snapshot_artifact to a proper test/
26-
"./tools/devtool test -- integration_tests/performance/test_benchmarks.py",
27-
"./tools/devtool -y sh ./tools/create_snapshot_artifact/main.py",
24+
"./tools/devtool test -- -m nonci -n4 integration_tests/functional/test_snapshot_phase1.py",
2825
"mkdir -pv snapshots/{instance}_{kv}",
29-
"sudo chown -Rc $USER: snapshot_artifacts",
30-
"mv -v snapshot_artifacts/* snapshots/{instance}_{kv}",
26+
"mv -v test_results/test_snapshot_phase1/* snapshots/{instance}_{kv}",
3127
]
3228
pipeline.build_group(
3329
"📸 create snapshots",
@@ -86,7 +82,7 @@
8682
f"buildkite-agent artifact download snapshots/{src_instance}_{src_kv}/* .",
8783
f"mv -v snapshots/{src_instance}_{src_kv} snapshot_artifacts",
8884
*pipeline.devtool_test(
89-
pytest_opts=f"-m nonci {k_val} integration_tests/functional/test_snapshot_restore_cross_kernel.py",
85+
pytest_opts=f"-m nonci -n4 {k_val} integration_tests/functional/test_snapshot_restore_cross_kernel.py",
9086
),
9187
],
9288
"label": f"🎬 {src_instance} {src_kv} ➡️ {dst_instance} {dst_kv}",

tests/conftest.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -319,14 +319,20 @@ def custom_cpu_template(request, record_property):
319319

320320

321321
@pytest.fixture(
322-
params=list(static_cpu_templates_params()) + list(custom_cpu_templates_params())
322+
params=[
323+
pytest.param(None, id="NO_CPU_TMPL"),
324+
*static_cpu_templates_params(),
325+
*custom_cpu_templates_params(),
326+
],
323327
)
324328
def cpu_template_any(request, record_property):
325329
"""This fixture combines static and custom CPU templates"""
326-
if "name" in request.param:
327-
record_property("custom_cpu_template", request.param["name"])
328-
else:
329-
record_property("static_cpu_template", request.param)
330+
cpu_template_name = request.param
331+
if request.param is None:
332+
cpu_template_name = "None"
333+
elif "name" in request.param:
334+
cpu_template_name = request.param["name"]
335+
record_property("cpu_template", cpu_template_name)
330336
return request.param
331337

332338

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
import json
2+
import platform
3+
import re
4+
5+
import pytest
6+
7+
from framework.utils import (
8+
configure_mmds,
9+
generate_mmds_get_request,
10+
generate_mmds_session_token,
11+
)
12+
13+
"""
14+
./tools/devtool test -- -n4 -m nonci integration_tests/functional/test_snapshot_phase1.py
15+
"""
16+
17+
if platform.machine() != "x86_64":
18+
pytestmark = pytest.mark.skip("only x86_64 architecture supported")
19+
20+
# Default IPv4 address to route MMDS requests.
21+
IPV4_ADDRESS = "169.254.169.254"
22+
NET_IFACE_FOR_MMDS = "eth3"
23+
24+
25+
@pytest.mark.timeout(900)
26+
@pytest.mark.nonci
27+
def test_snapshot_phase1(
28+
microvm_factory, guest_kernel, rootfs_ubuntu_24, cpu_template_any, results_dir
29+
):
30+
"""
31+
This test only creates snapshots for other tests like test_snapshot_restore_cross_kernel.py
32+
"""
33+
34+
vm = microvm_factory.build(guest_kernel, rootfs_ubuntu_24, monitor_memory=False)
35+
vm.spawn(log_level="Info")
36+
vm.add_net_iface()
37+
38+
static_cpu_template = None
39+
if cpu_template_any is None:
40+
cpu_template_name = "None"
41+
elif isinstance(cpu_template_any, str):
42+
static_cpu_template = cpu_template_any
43+
cpu_template_name = f"static_{cpu_template_any}"
44+
elif isinstance(cpu_template_any, dict):
45+
vm.api.cpu_config.put(**cpu_template_any["template"])
46+
cpu_template_name = f"custom_{cpu_template_any['name']}"
47+
vm.basic_config(
48+
vcpu_count=2,
49+
mem_size_mib=1024,
50+
cpu_template=static_cpu_template,
51+
)
52+
53+
guest_kernel_version = re.search("vmlinux-(.*)", vm.kernel_file.name)
54+
snapshot_artifacts_dir = (
55+
results_dir
56+
/ f"{guest_kernel_version.group(1)}_{cpu_template_name}_guest_snapshot"
57+
)
58+
59+
# Add 4 network devices
60+
for i in range(4):
61+
vm.add_net_iface()
62+
# Add a vsock device
63+
vm.api.vsock.put(vsock_id="vsock0", guest_cid=3, uds_path="/v.sock")
64+
# Add MMDS
65+
configure_mmds(vm, ["eth3"], version="V2")
66+
# Add a memory balloon.
67+
vm.api.balloon.put(amount_mib=0, deflate_on_oom=True, stats_polling_interval_s=1)
68+
69+
vm.start()
70+
71+
# Populate MMDS.
72+
data_store = {
73+
"latest": {
74+
"meta-data": {
75+
"ami-id": "ami-12345678",
76+
"reservation-id": "r-fea54097",
77+
"local-hostname": "ip-10-251-50-12.ec2.internal",
78+
"public-hostname": "ec2-203-0-113-25.compute-1.amazonaws.com",
79+
}
80+
}
81+
}
82+
83+
# MMDS should be empty.
84+
assert vm.api.mmds.get().json() == {}
85+
# Populate MMDS with data.
86+
vm.api.mmds.put(**data_store)
87+
# Ensure data is persistent inside the data store.
88+
assert vm.api.mmds.get().json() == data_store
89+
90+
# Iterate and validate connectivity on all ifaces after boot.
91+
for i in range(4):
92+
exit_code, _, _ = vm.ssh_iface(i).run("sync")
93+
assert exit_code == 0
94+
95+
# Validate MMDS.
96+
# Configure interface to route MMDS requests
97+
vm.ssh.check_output(f"ip route add {IPV4_ADDRESS} dev {NET_IFACE_FOR_MMDS}")
98+
99+
# Fetch metadata to ensure MMDS is accessible.
100+
token = generate_mmds_session_token(vm.ssh, IPV4_ADDRESS, token_ttl=60)
101+
cmd = generate_mmds_get_request(IPV4_ADDRESS, token=token)
102+
_, stdout, _ = vm.ssh.run(cmd)
103+
assert json.loads(stdout) == data_store
104+
105+
# Copy snapshot files to be published to S3 for the 2nd part of the test
106+
# Create snapshot artifacts directory specific for the kernel version used.
107+
snapshot = vm.snapshot_full()
108+
snapshot_artifacts_dir.mkdir(parents=True)
109+
snapshot.save_to(snapshot_artifacts_dir)

tools/create_snapshot_artifact/main.py

Lines changed: 0 additions & 163 deletions
This file was deleted.

0 commit comments

Comments
 (0)