Skip to content

Commit 3fb0368

Browse files
committed
fix(release): fix some tests to honor --binary-dir
If we specify --binary-dir, we want that binary to be used in all tests where it makes sense. In tests that directly request the Firecracker binary, use the microvm_factory fixture as a way around it. Signed-off-by: Pablo Barbáchano <[email protected]>
1 parent c3ff1b5 commit 3fb0368

File tree

7 files changed

+23
-29
lines changed

7 files changed

+23
-29
lines changed

tests/framework/microvm.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,17 +171,17 @@ def __init__(
171171
self.initrd_file = None
172172
self.boot_args = None
173173

174-
self._fc_binary_path = Path(fc_binary_path)
174+
self.fc_binary_path = Path(fc_binary_path)
175175
assert fc_binary_path.exists()
176-
self._jailer_binary_path = Path(jailer_binary_path)
176+
self.jailer_binary_path = Path(jailer_binary_path)
177177
assert jailer_binary_path.exists()
178178

179179
jailer_kwargs = jailer_kwargs or {}
180180
self.netns = netns
181181
# Create the jailer context associated with this microvm.
182182
self.jailer = JailerContext(
183183
jailer_id=self._microvm_id,
184-
exec_file=self._fc_binary_path,
184+
exec_file=self.fc_binary_path,
185185
netns=netns,
186186
new_pid_ns=True,
187187
**jailer_kwargs,
@@ -329,7 +329,7 @@ def _validate_api_response_times(self):
329329
@property
330330
def firecracker_version(self):
331331
"""Return the version of the Firecracker executable."""
332-
_, stdout, _ = utils.run_cmd(f"{self._fc_binary_path} --version")
332+
_, stdout, _ = utils.run_cmd(f"{self.fc_binary_path} --version")
333333
return re.match(r"^Firecracker v(.+)", stdout.partition("\n")[0]).group(1)
334334

335335
@property
@@ -542,7 +542,7 @@ def spawn(
542542
if not self.jailer.daemonize:
543543
self.jailer.new_pid_ns = False
544544

545-
cmd = [str(self._jailer_binary_path)] + self.jailer.construct_param_list()
545+
cmd = [str(self.jailer_binary_path)] + self.jailer.construct_param_list()
546546
if self._numa_node is not None:
547547
node = str(self._numa_node)
548548
cmd = ["numactl", "-N", node, "-m", node] + cmd

tests/integration_tests/build/test_binary_size.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,27 @@
1111

1212
import pytest
1313

14-
import host_tools.cargo_build as host
15-
1614
MACHINE = platform.machine()
1715

1816

1917
@pytest.mark.timeout(500)
20-
def test_firecracker_binary_size(record_property, metrics):
18+
def test_firecracker_binary_size(record_property, metrics, microvm_factory):
2119
"""
2220
Test if the size of the firecracker binary is within expected ranges.
2321
"""
24-
fc_binary = host.get_binary("firecracker")
22+
fc_binary = microvm_factory.fc_binary_path
2523
result = fc_binary.stat().st_size
2624
record_property("firecracker_binary_size", f"{result}B")
2725
metrics.set_dimensions({"cpu_arch": MACHINE})
2826
metrics.put_metric("firecracker_binary_size", result, unit="Bytes")
2927

3028

3129
@pytest.mark.timeout(500)
32-
def test_jailer_binary_size(record_property, metrics):
30+
def test_jailer_binary_size(record_property, metrics, microvm_factory):
3331
"""
3432
Test if the size of the jailer binary is within expected ranges.
3533
"""
36-
jailer_binary = host.get_binary("jailer")
34+
jailer_binary = microvm_factory.jailer_binary_path
3735
result = jailer_binary.stat().st_size
3836
record_property("jailer_binary_size", f"{result}B")
3937
metrics.set_dimensions({"cpu_arch": MACHINE})

tests/integration_tests/build/test_binary_static_linking.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@
55
"""
66

77
import pytest
8-
import host_tools.cargo_build as host
98
from framework import utils
109

1110

1211
@pytest.mark.timeout(500)
13-
def test_firecracker_binary_static_linking():
12+
def test_firecracker_binary_static_linking(microvm_factory):
1413
"""
1514
Test to make sure the firecracker binary is statically linked.
1615
"""
17-
fc_binary_path = host.get_binary("firecracker")
16+
fc_binary_path = microvm_factory.fc_binary_path
1817
_, stdout, stderr = utils.run_cmd(f"file {fc_binary_path}")
1918
assert "" in stderr
2019
# expected "statically linked" for aarch64 and

tests/integration_tests/functional/test_cmd_line_parameters.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import pytest
99

1010
from framework.utils import run_cmd
11-
from host_tools.cargo_build import get_firecracker_binaries
1211
from host_tools.metrics import validate_fc_metrics
1312

1413

@@ -36,8 +35,8 @@ def test_describe_snapshot_all_versions(
3635
print(vm.log_data)
3736
vm.kill()
3837

39-
# Fetch Firecracker binary for the latest version
40-
fc_binary, _ = get_firecracker_binaries()
38+
# Fetch Firecracker binary
39+
fc_binary = microvm_factory.fc_binary_path
4140
# Verify the output of `--describe-snapshot` command line parameter
4241
cmd = [fc_binary] + ["--describe-snapshot", snapshot.vmstate]
4342
code, stdout, stderr = run_cmd(cmd)
@@ -106,12 +105,12 @@ def test_cli_metrics_if_resume_no_metrics(uvm_plain, microvm_factory):
106105
assert not metrics2.exists()
107106

108107

109-
def test_cli_no_params():
108+
def test_cli_no_params(microvm_factory):
110109
"""
111110
Test running firecracker with no parameters should work
112111
"""
113112

114-
fc_binary, _ = get_firecracker_binaries()
113+
fc_binary = microvm_factory.fc_binary_path
115114
process = subprocess.Popen(fc_binary)
116115
try:
117116
process.communicate(timeout=3)

tests/integration_tests/functional/test_mmds.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
populate_data_store,
1919
run_guest_cmd,
2020
)
21-
from host_tools.cargo_build import get_firecracker_binaries
2221

2322
# Minimum lifetime of token.
2423
MIN_TOKEN_TTL_SECONDS = 1
@@ -88,9 +87,12 @@ def _validate_mmds_snapshot(
8887
basevm.kill()
8988

9089
# Load microVM clone from snapshot.
91-
microvm = microvm_factory.build(
92-
fc_binary_path=fc_binary_path, jailer_binary_path=jailer_binary_path
93-
)
90+
kwargs = {}
91+
if fc_binary_path:
92+
kwargs["fc_binary_path"] = fc_binary_path
93+
if jailer_binary_path:
94+
kwargs["jailer_binary_path"] = jailer_binary_path
95+
microvm = microvm_factory.build(**kwargs)
9496
microvm.spawn()
9597
microvm.restore_from_snapshot(snapshot)
9698
microvm.resume()
@@ -640,7 +642,6 @@ def test_mmds_older_snapshot(
640642
microvm,
641643
microvm_factory,
642644
mmds_version,
643-
*get_firecracker_binaries(),
644645
)
645646

646647

tests/integration_tests/functional/test_snapshot_basic.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
make_host_port_path,
2929
start_guest_echo_server,
3030
)
31-
from host_tools.cargo_build import get_firecracker_binaries
3231

3332

3433
def _get_guest_drive_size(ssh_connection, guest_dev_name="/dev/vdb"):
@@ -59,7 +58,7 @@ def test_snapshot_current_version(uvm_nano):
5958
snapshot = vm.snapshot_full()
6059

6160
# Fetch Firecracker binary for the latest version
62-
fc_binary, _ = get_firecracker_binaries()
61+
fc_binary = uvm_nano.fc_binary_path
6362
# Verify the output of `--describe-snapshot` command line parameter
6463
cmd = [str(fc_binary)] + ["--describe-snapshot", str(snapshot.vmstate)]
6564

tests/integration_tests/security/test_jail.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import requests
1717
import urllib3
1818

19-
import host_tools.cargo_build as build_tools
2019
from framework.defs import FC_BINARY_NAME
2120
from framework.jailer import JailerContext
2221

@@ -60,12 +59,11 @@ def test_empty_jailer_id(test_microvm_with_api):
6059
Test that the jailer ID cannot be empty.
6160
"""
6261
test_microvm = test_microvm_with_api
63-
fc_binary, _ = build_tools.get_firecracker_binaries()
6462

6563
# Set the jailer ID to None.
6664
test_microvm.jailer = JailerContext(
6765
jailer_id="",
68-
exec_file=fc_binary,
66+
exec_file=test_microvm.fc_binary_path,
6967
)
7068

7169
# pylint: disable=W0703

0 commit comments

Comments
 (0)