Skip to content

Commit 8381766

Browse files
committed
test: stop compiling firecracker inside A/B-tests
In the pre-PR A/B-tests we were compiling Firecracker. Instead, explicitly rely on the precompiled binaries that we set up in the shared buildkite build step. This has the slight downside that it makes it harder to run these tests locally, as now you need to explicitly pre-compile the binaries, but arguably running these vulnerability A/B-tests locally doesnt make sense anyway, because they specifically test the security configuration on our supported .metals. Signed-off-by: Patrick Roy <[email protected]>
1 parent 10f0054 commit 8381766

File tree

2 files changed

+43
-22
lines changed

2 files changed

+43
-22
lines changed

tests/framework/ab_test.py

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,33 @@ def git_ab_test(
9797
return result_a, result_b, comparison
9898

9999

100+
def precompiled_binary_ab_test(
101+
test_runner: Callable[[Path, bool], T],
102+
comparator: Callable[[T, T], U] = default_comparator,
103+
*,
104+
a_revision: str = DEFAULT_A_REVISION,
105+
b_revision: Optional[str] = None,
106+
) -> (T, T, U):
107+
"""
108+
Similar to `git_ab_test`, except that it does not check out the specified revisions,
109+
but instead expect that they match names of subdirectories of ../build which contain
110+
firecracker and jailer binaries
111+
"""
112+
113+
dir_a = Path("../build") / a_revision
114+
dir_b = (
115+
Path("../build") / b_revision
116+
if b_revision
117+
else get_binary("firecracker").parent
118+
)
119+
120+
result_a = test_runner(dir_a, True)
121+
result_b = test_runner(dir_b, False)
122+
123+
comparison = comparator(result_a, result_b)
124+
return result_a, result_b, comparison
125+
126+
100127
def is_pr() -> bool:
101128
"""Returns `True` iff we are executing in the context of a build kite run on a pull request"""
102129
return os.environ.get("BUILDKITE_PULL_REQUEST", "false") != "false"
@@ -153,7 +180,7 @@ def set_did_not_grow_comparator(
153180
)
154181

155182

156-
def git_ab_test_guest_command(
183+
def precompiled_ab_test_guest_command(
157184
microvm_factory: Callable[[Path, Path], Microvm],
158185
command: str,
159186
*,
@@ -164,20 +191,12 @@ def git_ab_test_guest_command(
164191
"""The same as git_ab_test_command, but via SSH. The closure argument should setup a microvm using the passed
165192
paths to firecracker and jailer binaries."""
166193

167-
@with_filelock
168-
def build_firecracker(workspace_dir):
169-
utils.check_output("./tools/release.sh --profile release", cwd=workspace_dir)
170-
171-
def test_runner(workspace_dir, _is_a: bool):
172-
firecracker = get_binary("firecracker", workspace_dir=workspace_dir)
173-
if not firecracker.exists():
174-
build_firecracker(workspace_dir)
175-
bin_dir = firecracker.parent.resolve()
194+
def test_runner(bin_dir, _is_a: bool):
176195
firecracker, jailer = bin_dir / "firecracker", bin_dir / "jailer"
177196
microvm = microvm_factory(firecracker, jailer)
178197
return microvm.ssh.run(command)
179198

180-
(_, old_out, old_err), (_, new_out, new_err), the_same = git_ab_test(
199+
(_, old_out, old_err), (_, new_out, new_err), the_same = precompiled_binary_ab_test(
181200
test_runner, comparator, a_revision=a_revision, b_revision=b_revision
182201
)
183202

@@ -186,7 +205,7 @@ def test_runner(workspace_dir, _is_a: bool):
186205
), f"The output of running command `{command}` changed:\nOld:\nstdout:\n{old_out}\nstderr\n{old_err}\n\nNew:\nstdout:\n{new_out}\nstderr:\n{new_err}"
187206

188207

189-
def git_ab_test_guest_command_if_pr(
208+
def precompiled_ab_test_guest_command_if_pr(
190209
microvm_factory: Callable[[Path, Path], Microvm],
191210
command: str,
192211
*,
@@ -195,7 +214,9 @@ def git_ab_test_guest_command_if_pr(
195214
):
196215
"""The same as git_ab_test_command_if_pr, but via SSH"""
197216
if is_pr():
198-
git_ab_test_guest_command(microvm_factory, command, comparator=comparator)
217+
precompiled_ab_test_guest_command(
218+
microvm_factory, command, comparator=comparator
219+
)
199220
return None
200221

201222
microvm = microvm_factory(*get_firecracker_binaries())

tests/integration_tests/security/test_vulnerabilities.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313

1414
from framework import utils
1515
from framework.ab_test import (
16-
git_ab_test_guest_command,
17-
git_ab_test_guest_command_if_pr,
1816
is_pr,
17+
precompiled_ab_test_guest_command,
18+
precompiled_ab_test_guest_command_if_pr,
1919
set_did_not_grow_comparator,
2020
)
2121
from framework.properties import global_props
@@ -233,7 +233,7 @@ def test_spectre_meltdown_checker_on_guest(spectre_meltdown_checker, build_micro
233233
Test with the spectre / meltdown checker on guest.
234234
"""
235235

236-
status = git_ab_test_guest_command_if_pr(
236+
status = precompiled_ab_test_guest_command_if_pr(
237237
with_checker(build_microvm, spectre_meltdown_checker),
238238
REMOTE_CHECKER_COMMAND,
239239
comparator=set_did_not_grow_comparator(
@@ -251,7 +251,7 @@ def test_spectre_meltdown_checker_on_restored_guest(
251251
"""
252252
Test with the spectre / meltdown checker on a restored guest.
253253
"""
254-
status = git_ab_test_guest_command_if_pr(
254+
status = precompiled_ab_test_guest_command_if_pr(
255255
with_checker(
256256
with_restore(build_microvm, microvm_factory), spectre_meltdown_checker
257257
),
@@ -272,7 +272,7 @@ def test_spectre_meltdown_checker_on_guest_with_template(
272272
Test with the spectre / meltdown checker on guest with CPU template.
273273
"""
274274

275-
git_ab_test_guest_command_if_pr(
275+
precompiled_ab_test_guest_command_if_pr(
276276
with_checker(build_microvm_with_template, spectre_meltdown_checker),
277277
REMOTE_CHECKER_COMMAND,
278278
comparator=set_did_not_grow_comparator(
@@ -287,7 +287,7 @@ def test_spectre_meltdown_checker_on_guest_with_custom_template(
287287
"""
288288
Test with the spectre / meltdown checker on guest with a custom CPU template.
289289
"""
290-
git_ab_test_guest_command_if_pr(
290+
precompiled_ab_test_guest_command_if_pr(
291291
with_checker(build_microvm_with_custom_template, spectre_meltdown_checker),
292292
REMOTE_CHECKER_COMMAND,
293293
comparator=set_did_not_grow_comparator(
@@ -302,7 +302,7 @@ def test_spectre_meltdown_checker_on_restored_guest_with_template(
302302
"""
303303
Test with the spectre / meltdown checker on a restored guest with a CPU template.
304304
"""
305-
git_ab_test_guest_command_if_pr(
305+
precompiled_ab_test_guest_command_if_pr(
306306
with_checker(
307307
with_restore(build_microvm_with_template, microvm_factory),
308308
spectre_meltdown_checker,
@@ -322,7 +322,7 @@ def test_spectre_meltdown_checker_on_restored_guest_with_custom_template(
322322
"""
323323
Test with the spectre / meltdown checker on a restored guest with a custom CPU template.
324324
"""
325-
git_ab_test_guest_command_if_pr(
325+
precompiled_ab_test_guest_command_if_pr(
326326
with_checker(
327327
with_restore(build_microvm_with_custom_template, microvm_factory),
328328
spectre_meltdown_checker,
@@ -424,7 +424,7 @@ def check_vulnerabilities_files_ab(builder):
424424
running in a PR pipeline, and otherwise calls `check_vulnerabilities_files_on_guest`
425425
"""
426426
if is_pr():
427-
git_ab_test_guest_command(
427+
precompiled_ab_test_guest_command(
428428
builder,
429429
f"! grep -r Vulnerable {VULN_DIR}",
430430
comparator=set_did_not_grow_comparator(

0 commit comments

Comments
 (0)