Skip to content

Commit a7201fb

Browse files
Alexandra Iordachedianpopa
authored andcommitted
integ tests: separate fixtures for building...
...auxiliary binaries. * cloner_bin_path will build the binary that clones into jailer; * vsock_bin_path will build the vsock client/server; * seccomp_bin_paths will build the demo seccomp binaries. This way, tests will only build the auxiliary binaries they need. Fixes #1236 Signed-off-by: Alexandra Iordache <[email protected]>
1 parent f123988 commit a7201fb

File tree

5 files changed

+53
-33
lines changed

5 files changed

+53
-33
lines changed

tests/conftest.py

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,10 @@ def test_images_s3_bucket():
143143
MICROVM_S3_FETCHER = MicrovmImageS3Fetcher(test_images_s3_bucket())
144144

145145

146-
def init_microvm(root_path, aux_binary_paths, features=''):
146+
def init_microvm(root_path, bin_cloner_path, features=''):
147147
"""Auxiliary function for instantiating a microvm and setting it up."""
148+
# pylint: disable=redefined-outer-name
149+
# The fixture pattern causes a pylint false positive for that rule.
148150
microvm_id = str(uuid.uuid4())
149151
fc_binary, jailer_binary = build_tools.get_firecracker_binaries(
150152
root_path,
@@ -156,7 +158,7 @@ def init_microvm(root_path, aux_binary_paths, features=''):
156158
jailer_binary_path=jailer_binary,
157159
build_feature=features,
158160
microvm_id=microvm_id,
159-
aux_bin_paths=aux_binary_paths
161+
bin_cloner_path=bin_cloner_path
160162
)
161163
vm.setup()
162164
return vm
@@ -211,16 +213,11 @@ def _gcc_compile(src_file, output_file):
211213

212214

213215
@pytest.fixture(scope='session')
214-
def aux_bin_paths(test_session_root_path):
215-
"""Build external tools.
216-
217-
They currently consist of:
216+
def bin_cloner_path(test_session_root_path):
217+
"""Build a binary that `clone`s into the jailer.
218218
219-
* a binary that can properly use the `clone()` syscall;
220-
* a jailer with a simple syscall whitelist;
221-
* a jailer with a (syscall, arguments) advanced whitelist;
222-
* a jailed binary that follows the seccomp rules;
223-
* a jailed binary that breaks the seccomp rules.
219+
It's necessary because Python doesn't interface well with the `clone()`
220+
syscall directly.
224221
"""
225222
# pylint: disable=redefined-outer-name
226223
# The fixture pattern causes a pylint false positive for that rule.
@@ -229,7 +226,14 @@ def aux_bin_paths(test_session_root_path):
229226
'host_tools/newpid_cloner.c',
230227
cloner_bin_path
231228
)
229+
yield cloner_bin_path
230+
232231

232+
@pytest.fixture(scope='session')
233+
def bin_vsock_path(test_session_root_path):
234+
"""Build a simple vsock client/server application."""
235+
# pylint: disable=redefined-outer-name
236+
# The fixture pattern causes a pylint false positive for that rule.
233237
vsock_helper_bin_path = os.path.join(
234238
test_session_root_path,
235239
'vsock_helper'
@@ -238,7 +242,22 @@ def aux_bin_paths(test_session_root_path):
238242
'host_tools/vsock_helper.c',
239243
vsock_helper_bin_path
240244
)
245+
yield vsock_helper_bin_path
246+
241247

248+
@pytest.fixture(scope='session')
249+
def bin_seccomp_paths(test_session_root_path):
250+
"""Build jailers and jailed binaries to test seccomp.
251+
252+
They currently consist of:
253+
254+
* a jailer with a simple syscall whitelist;
255+
* a jailer with a (syscall, arguments) advanced whitelist;
256+
* a jailed binary that follows the seccomp rules;
257+
* a jailed binary that breaks the seccomp rules.
258+
"""
259+
# pylint: disable=redefined-outer-name
260+
# The fixture pattern causes a pylint false positive for that rule.
242261
seccomp_build_path = os.path.join(
243262
test_session_root_path,
244263
build_tools.CARGO_RELEASE_REL_PATH
@@ -282,17 +301,15 @@ def aux_bin_paths(test_session_root_path):
282301
)
283302

284303
yield {
285-
'cloner': cloner_bin_path,
286-
'vsock_helper': vsock_helper_bin_path,
287304
'demo_basic_jailer': demo_basic_jailer,
288305
'demo_advanced_jailer': demo_advanced_jailer,
289306
'demo_harmless': demo_harmless,
290307
'demo_malicious': demo_malicious
291308
}
292309

293310

294-
@pytest.fixture
295-
def microvm(test_session_root_path, aux_bin_paths):
311+
@pytest.fixture()
312+
def microvm(test_session_root_path, bin_cloner_path):
296313
"""Instantiate a microvm."""
297314
# pylint: disable=redefined-outer-name
298315
# The fixture pattern causes a pylint false positive for that rule.
@@ -301,7 +318,7 @@ def microvm(test_session_root_path, aux_bin_paths):
301318
# microvm.
302319
vm = init_microvm(
303320
test_session_root_path,
304-
aux_bin_paths,
321+
bin_cloner_path,
305322
features=''
306323
)
307324
yield vm
@@ -345,7 +362,7 @@ def test_microvm_any(request, microvm):
345362
def test_multiple_microvms(
346363
test_session_root_path,
347364
context,
348-
aux_bin_paths
365+
bin_cloner_path
349366
):
350367
"""Yield one or more microvms based on the context provided.
351368
@@ -361,7 +378,7 @@ def test_multiple_microvms(
361378

362379
# When the context specifies multiple microvms, we use the first vm to
363380
# populate the other ones by hardlinking its resources.
364-
first_vm = init_microvm(test_session_root_path, aux_bin_paths)
381+
first_vm = init_microvm(test_session_root_path, bin_cloner_path)
365382
MICROVM_S3_FETCHER.init_vm_resources(
366383
microvm_resources,
367384
first_vm
@@ -372,7 +389,7 @@ def test_multiple_microvms(
372389
# asserts that the `how_many` parameter is always positive
373390
# (i.e strictly greater than 0).
374391
for _ in range(how_many - 1):
375-
vm = init_microvm(test_session_root_path, aux_bin_paths)
392+
vm = init_microvm(test_session_root_path, bin_cloner_path)
376393
MICROVM_S3_FETCHER.hardlink_vm_resources(
377394
microvm_resources,
378395
first_vm,

tests/framework/microvm.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def __init__(
4545
microvm_id,
4646
build_feature='',
4747
monitor_memory=True,
48-
aux_bin_paths=None
48+
bin_cloner_path=None
4949
):
5050
"""Set up microVM attributes, paths, and data structures."""
5151
# Unique identifier for this machine.
@@ -111,7 +111,7 @@ def __init__(
111111
self._memory_events_queue = None
112112

113113
# External clone/exec tool, because Python can't into clone
114-
self.aux_bin_paths = aux_bin_paths
114+
self.bin_cloner_path = bin_cloner_path
115115

116116
def kill(self):
117117
"""All clean up associated with this microVM should go here."""
@@ -272,8 +272,8 @@ def spawn(self):
272272
# 2) Python's ctypes libc interface appears to be broken, causing
273273
# our clone / exec to deadlock at some point.
274274
if self._jailer.daemonize:
275-
if self.aux_bin_paths:
276-
cmd = [self.aux_bin_paths['cloner']] + \
275+
if self.bin_cloner_path:
276+
cmd = [self.bin_cloner_path] + \
277277
[self._jailer_binary_path] + \
278278
jailer_param_list
279279
_p = run(cmd, stdout=PIPE, stderr=PIPE, check=True)

tests/integration_tests/functional/test_vsock.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def _run(self):
159159
def test_vsock(
160160
test_microvm_with_ssh,
161161
network_config,
162-
aux_bin_paths,
162+
bin_vsock_path,
163163
test_session_root_path
164164
):
165165
"""Vsock tests. See the module docstring for a high-level description."""
@@ -191,7 +191,8 @@ def test_vsock(
191191
assert ecode == 0
192192

193193
# Copy `vsock_helper` and the random blob to the guest.
194-
conn.scp_file(aux_bin_paths['vsock_helper'], '/bin/vsock_helper')
194+
vsock_helper = bin_vsock_path
195+
conn.scp_file(vsock_helper, '/bin/vsock_helper')
195196
conn.scp_file(blob_path, vm_blob_path)
196197

197198
# Test guest-initiated connections.

tests/integration_tests/security/demo_seccomp/Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/integration_tests/security/test_seccomp.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
from subprocess import run, PIPE
88

99

10-
def test_seccomp_ls(aux_bin_paths):
10+
def test_seccomp_ls(bin_seccomp_paths):
1111
"""Assert that the seccomp filters deny a blacklisted syscall."""
1212
# pylint: disable=redefined-outer-name
1313
# The fixture pattern causes a pylint false positive for that rule.
1414

1515
# Path to the `ls` binary, which attempts to execute the blacklisted
1616
# `SYS_access`.
1717
ls_command_path = '/bin/ls'
18-
demo_jailer = aux_bin_paths['demo_basic_jailer']
18+
demo_jailer = bin_seccomp_paths['demo_basic_jailer']
1919

2020
assert os.path.exists(demo_jailer)
2121

@@ -27,7 +27,7 @@ def test_seccomp_ls(aux_bin_paths):
2727
assert outcome.returncode != 0
2828

2929

30-
def test_advanced_seccomp_harmless(aux_bin_paths):
30+
def test_advanced_seccomp_harmless(bin_seccomp_paths):
3131
"""
3232
Test `demo_harmless`.
3333
@@ -36,8 +36,8 @@ def test_advanced_seccomp_harmless(aux_bin_paths):
3636
# pylint: disable=redefined-outer-name
3737
# The fixture pattern causes a pylint false positive for that rule.
3838

39-
demo_advanced_jailer = aux_bin_paths['demo_advanced_jailer']
40-
demo_harmless = aux_bin_paths['demo_harmless']
39+
demo_advanced_jailer = bin_seccomp_paths['demo_advanced_jailer']
40+
demo_harmless = bin_seccomp_paths['demo_harmless']
4141

4242
assert os.path.exists(demo_advanced_jailer)
4343
assert os.path.exists(demo_harmless)
@@ -48,7 +48,7 @@ def test_advanced_seccomp_harmless(aux_bin_paths):
4848
assert outcome.returncode == 0
4949

5050

51-
def test_advanced_seccomp_malicious(aux_bin_paths):
51+
def test_advanced_seccomp_malicious(bin_seccomp_paths):
5252
"""
5353
Test `demo_malicious`.
5454
@@ -57,8 +57,8 @@ def test_advanced_seccomp_malicious(aux_bin_paths):
5757
# pylint: disable=redefined-outer-name
5858
# The fixture pattern causes a pylint false positive for that rule.
5959

60-
demo_advanced_jailer = aux_bin_paths['demo_advanced_jailer']
61-
demo_malicious = aux_bin_paths['demo_malicious']
60+
demo_advanced_jailer = bin_seccomp_paths['demo_advanced_jailer']
61+
demo_malicious = bin_seccomp_paths['demo_malicious']
6262

6363
assert os.path.exists(demo_advanced_jailer)
6464
assert os.path.exists(demo_malicious)

0 commit comments

Comments
 (0)