Skip to content

Commit 8afc130

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 c24f68d commit 8afc130

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
@@ -231,7 +231,7 @@ def test_spectre_meltdown_checker_on_guest(spectre_meltdown_checker, build_micro
231231
Test with the spectre / meltdown checker on guest.
232232
"""
233233

234-
status = git_ab_test_guest_command_if_pr(
234+
status = precompiled_ab_test_guest_command_if_pr(
235235
with_checker(build_microvm, spectre_meltdown_checker),
236236
REMOTE_CHECKER_COMMAND,
237237
comparator=set_did_not_grow_comparator(
@@ -249,7 +249,7 @@ def test_spectre_meltdown_checker_on_restored_guest(
249249
"""
250250
Test with the spectre / meltdown checker on a restored guest.
251251
"""
252-
status = git_ab_test_guest_command_if_pr(
252+
status = precompiled_ab_test_guest_command_if_pr(
253253
with_checker(
254254
with_restore(build_microvm, microvm_factory), spectre_meltdown_checker
255255
),
@@ -270,7 +270,7 @@ def test_spectre_meltdown_checker_on_guest_with_template(
270270
Test with the spectre / meltdown checker on guest with CPU template.
271271
"""
272272

273-
git_ab_test_guest_command_if_pr(
273+
precompiled_ab_test_guest_command_if_pr(
274274
with_checker(build_microvm_with_template, spectre_meltdown_checker),
275275
REMOTE_CHECKER_COMMAND,
276276
comparator=set_did_not_grow_comparator(
@@ -285,7 +285,7 @@ def test_spectre_meltdown_checker_on_guest_with_custom_template(
285285
"""
286286
Test with the spectre / meltdown checker on guest with a custom CPU template.
287287
"""
288-
git_ab_test_guest_command_if_pr(
288+
precompiled_ab_test_guest_command_if_pr(
289289
with_checker(build_microvm_with_custom_template, spectre_meltdown_checker),
290290
REMOTE_CHECKER_COMMAND,
291291
comparator=set_did_not_grow_comparator(
@@ -300,7 +300,7 @@ def test_spectre_meltdown_checker_on_restored_guest_with_template(
300300
"""
301301
Test with the spectre / meltdown checker on a restored guest with a CPU template.
302302
"""
303-
git_ab_test_guest_command_if_pr(
303+
precompiled_ab_test_guest_command_if_pr(
304304
with_checker(
305305
with_restore(build_microvm_with_template, microvm_factory),
306306
spectre_meltdown_checker,
@@ -320,7 +320,7 @@ def test_spectre_meltdown_checker_on_restored_guest_with_custom_template(
320320
"""
321321
Test with the spectre / meltdown checker on a restored guest with a custom CPU template.
322322
"""
323-
git_ab_test_guest_command_if_pr(
323+
precompiled_ab_test_guest_command_if_pr(
324324
with_checker(
325325
with_restore(build_microvm_with_custom_template, microvm_factory),
326326
spectre_meltdown_checker,
@@ -420,7 +420,7 @@ def check_vulnerabilities_files_ab(builder):
420420
running in a PR pipeline, and otherwise calls `check_vulnerabilities_files_on_guest`
421421
"""
422422
if is_pr():
423-
git_ab_test_guest_command(
423+
precompiled_ab_test_guest_command(
424424
builder,
425425
f"! grep -r Vulnerable {VULN_DIR}",
426426
comparator=set_did_not_grow_comparator(

0 commit comments

Comments
 (0)