Skip to content

Commit

Permalink
fix(release): fix some tests to honor --binary-dir
Browse files Browse the repository at this point in the history
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 <pablob@amazon.com>
  • Loading branch information
pb8o committed Dec 6, 2023
1 parent c3ff1b5 commit 3fb0368
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 29 deletions.
10 changes: 5 additions & 5 deletions tests/framework/microvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,17 @@ def __init__(
self.initrd_file = None
self.boot_args = None

self._fc_binary_path = Path(fc_binary_path)
self.fc_binary_path = Path(fc_binary_path)
assert fc_binary_path.exists()
self._jailer_binary_path = Path(jailer_binary_path)
self.jailer_binary_path = Path(jailer_binary_path)
assert jailer_binary_path.exists()

jailer_kwargs = jailer_kwargs or {}
self.netns = netns
# Create the jailer context associated with this microvm.
self.jailer = JailerContext(
jailer_id=self._microvm_id,
exec_file=self._fc_binary_path,
exec_file=self.fc_binary_path,
netns=netns,
new_pid_ns=True,
**jailer_kwargs,
Expand Down Expand Up @@ -329,7 +329,7 @@ def _validate_api_response_times(self):
@property
def firecracker_version(self):
"""Return the version of the Firecracker executable."""
_, stdout, _ = utils.run_cmd(f"{self._fc_binary_path} --version")
_, stdout, _ = utils.run_cmd(f"{self.fc_binary_path} --version")
return re.match(r"^Firecracker v(.+)", stdout.partition("\n")[0]).group(1)

@property
Expand Down Expand Up @@ -542,7 +542,7 @@ def spawn(
if not self.jailer.daemonize:
self.jailer.new_pid_ns = False

cmd = [str(self._jailer_binary_path)] + self.jailer.construct_param_list()
cmd = [str(self.jailer_binary_path)] + self.jailer.construct_param_list()
if self._numa_node is not None:
node = str(self._numa_node)
cmd = ["numactl", "-N", node, "-m", node] + cmd
Expand Down
10 changes: 4 additions & 6 deletions tests/integration_tests/build/test_binary_size.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,27 @@

import pytest

import host_tools.cargo_build as host

MACHINE = platform.machine()


@pytest.mark.timeout(500)
def test_firecracker_binary_size(record_property, metrics):
def test_firecracker_binary_size(record_property, metrics, microvm_factory):
"""
Test if the size of the firecracker binary is within expected ranges.
"""
fc_binary = host.get_binary("firecracker")
fc_binary = microvm_factory.fc_binary_path
result = fc_binary.stat().st_size
record_property("firecracker_binary_size", f"{result}B")
metrics.set_dimensions({"cpu_arch": MACHINE})
metrics.put_metric("firecracker_binary_size", result, unit="Bytes")


@pytest.mark.timeout(500)
def test_jailer_binary_size(record_property, metrics):
def test_jailer_binary_size(record_property, metrics, microvm_factory):
"""
Test if the size of the jailer binary is within expected ranges.
"""
jailer_binary = host.get_binary("jailer")
jailer_binary = microvm_factory.jailer_binary_path
result = jailer_binary.stat().st_size
record_property("jailer_binary_size", f"{result}B")
metrics.set_dimensions({"cpu_arch": MACHINE})
Expand Down
5 changes: 2 additions & 3 deletions tests/integration_tests/build/test_binary_static_linking.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@
"""

import pytest
import host_tools.cargo_build as host
from framework import utils


@pytest.mark.timeout(500)
def test_firecracker_binary_static_linking():
def test_firecracker_binary_static_linking(microvm_factory):
"""
Test to make sure the firecracker binary is statically linked.
"""
fc_binary_path = host.get_binary("firecracker")
fc_binary_path = microvm_factory.fc_binary_path
_, stdout, stderr = utils.run_cmd(f"file {fc_binary_path}")
assert "" in stderr
# expected "statically linked" for aarch64 and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import pytest

from framework.utils import run_cmd
from host_tools.cargo_build import get_firecracker_binaries
from host_tools.metrics import validate_fc_metrics


Expand Down Expand Up @@ -36,8 +35,8 @@ def test_describe_snapshot_all_versions(
print(vm.log_data)
vm.kill()

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


def test_cli_no_params():
def test_cli_no_params(microvm_factory):
"""
Test running firecracker with no parameters should work
"""

fc_binary, _ = get_firecracker_binaries()
fc_binary = microvm_factory.fc_binary_path
process = subprocess.Popen(fc_binary)
try:
process.communicate(timeout=3)
Expand Down
11 changes: 6 additions & 5 deletions tests/integration_tests/functional/test_mmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
populate_data_store,
run_guest_cmd,
)
from host_tools.cargo_build import get_firecracker_binaries

# Minimum lifetime of token.
MIN_TOKEN_TTL_SECONDS = 1
Expand Down Expand Up @@ -88,9 +87,12 @@ def _validate_mmds_snapshot(
basevm.kill()

# Load microVM clone from snapshot.
microvm = microvm_factory.build(
fc_binary_path=fc_binary_path, jailer_binary_path=jailer_binary_path
)
kwargs = {}
if fc_binary_path:
kwargs["fc_binary_path"] = fc_binary_path
if jailer_binary_path:
kwargs["jailer_binary_path"] = jailer_binary_path
microvm = microvm_factory.build(**kwargs)
microvm.spawn()
microvm.restore_from_snapshot(snapshot)
microvm.resume()
Expand Down Expand Up @@ -640,7 +642,6 @@ def test_mmds_older_snapshot(
microvm,
microvm_factory,
mmds_version,
*get_firecracker_binaries(),
)


Expand Down
3 changes: 1 addition & 2 deletions tests/integration_tests/functional/test_snapshot_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
make_host_port_path,
start_guest_echo_server,
)
from host_tools.cargo_build import get_firecracker_binaries


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

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

Expand Down
4 changes: 1 addition & 3 deletions tests/integration_tests/security/test_jail.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import requests
import urllib3

import host_tools.cargo_build as build_tools
from framework.defs import FC_BINARY_NAME
from framework.jailer import JailerContext

Expand Down Expand Up @@ -60,12 +59,11 @@ def test_empty_jailer_id(test_microvm_with_api):
Test that the jailer ID cannot be empty.
"""
test_microvm = test_microvm_with_api
fc_binary, _ = build_tools.get_firecracker_binaries()

# Set the jailer ID to None.
test_microvm.jailer = JailerContext(
jailer_id="",
exec_file=fc_binary,
exec_file=test_microvm.fc_binary_path,
)

# pylint: disable=W0703
Expand Down

0 comments on commit 3fb0368

Please sign in to comment.