Skip to content

Commit ea90d53

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 d8c157a commit ea90d53

File tree

2 files changed

+54
-22
lines changed

2 files changed

+54
-22
lines changed

tests/framework/ab_test.py

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,44 @@ 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+
assert (
121+
dir_a.exists()
122+
and (dir_a / "firecracker").exists()
123+
and (dir_a / "jailer").exists()
124+
)
125+
assert (
126+
dir_b.exists()
127+
and (dir_b / "firecracker").exists()
128+
and (dir_b / "jailer").exists()
129+
)
130+
131+
result_a = test_runner(dir_a, True)
132+
result_b = test_runner(dir_b, False)
133+
134+
comparison = comparator(result_a, result_b)
135+
return result_a, result_b, comparison
136+
137+
100138
def is_pr() -> bool:
101139
"""Returns `True` iff we are executing in the context of a build kite run on a pull request"""
102140
return os.environ.get("BUILDKITE_PULL_REQUEST", "false") != "false"
@@ -153,7 +191,7 @@ def set_did_not_grow_comparator(
153191
)
154192

155193

156-
def git_ab_test_guest_command(
194+
def precompiled_ab_test_guest_command(
157195
microvm_factory: Callable[[Path, Path], Microvm],
158196
command: str,
159197
*,
@@ -164,20 +202,12 @@ def git_ab_test_guest_command(
164202
"""The same as git_ab_test_command, but via SSH. The closure argument should setup a microvm using the passed
165203
paths to firecracker and jailer binaries."""
166204

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()
205+
def test_runner(bin_dir, _is_a: bool):
176206
firecracker, jailer = bin_dir / "firecracker", bin_dir / "jailer"
177207
microvm = microvm_factory(firecracker, jailer)
178208
return microvm.ssh.run(command)
179209

180-
(_, old_out, old_err), (_, new_out, new_err), the_same = git_ab_test(
210+
(_, old_out, old_err), (_, new_out, new_err), the_same = precompiled_binary_ab_test(
181211
test_runner, comparator, a_revision=a_revision, b_revision=b_revision
182212
)
183213

@@ -186,7 +216,7 @@ def test_runner(workspace_dir, _is_a: bool):
186216
), 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}"
187217

188218

189-
def git_ab_test_guest_command_if_pr(
219+
def precompiled_ab_test_guest_command_if_pr(
190220
microvm_factory: Callable[[Path, Path], Microvm],
191221
command: str,
192222
*,
@@ -195,7 +225,9 @@ def git_ab_test_guest_command_if_pr(
195225
):
196226
"""The same as git_ab_test_command_if_pr, but via SSH"""
197227
if is_pr():
198-
git_ab_test_guest_command(microvm_factory, command, comparator=comparator)
228+
precompiled_ab_test_guest_command(
229+
microvm_factory, command, comparator=comparator
230+
)
199231
return None
200232

201233
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)