Skip to content

Commit

Permalink
Merge branch 'main' into error-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Woollett-Light authored Oct 19, 2023
2 parents 53e94ae + eb292e3 commit 9b9eefd
Show file tree
Hide file tree
Showing 33 changed files with 219 additions and 362 deletions.
28 changes: 28 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -393,3 +393,31 @@ uvm.ssh.run("ls")
snap = uvm.snapshot_full()
uvm.help.tmux_ssh()
```
It supports a number of options, you can check with `devtool sandbox --
--help`.
### Running outside of Docker
Running without Docker
```
source /etc/os-release
case $ID-$VERSION_ID in
amzn-2)
sudo yum remove -y python3
sudo amazon-linux-extras install -y python3.8
sudo ln -sv /usr/bin/python3.8 /usr/bin/python3
sudo ln -sv /usr/bin/pip3.8 /usr/bin/pip3
esac
sudo pip3 install pytest ipython requests psutil tenacity filelock "urllib3<2.0" requests_unixsocket
sudo env PYTHONPATH=tests HOME=$HOME ~/.local/bin/ipython3 -i ./tools/sandbox.py -- --binary-dir ../repro/v1.4.1
```
> :warning: **Notice this runs as root!**
```python
!id
```
19 changes: 3 additions & 16 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,18 +176,6 @@ def test_fc_session_root_path():
yield fc_session_root_path


@pytest.fixture(scope="session")
def bin_cloner_path(test_fc_session_root_path):
"""Build a binary that `clone`s into the jailer.
It's necessary because Python doesn't interface well with the `clone()`
syscall directly.
"""
cloner_bin_path = os.path.join(test_fc_session_root_path, "newpid_cloner")
build_tools.gcc_compile("host_tools/newpid_cloner.c", cloner_bin_path)
yield cloner_bin_path


@pytest.fixture(scope="session")
def bin_vsock_path(test_fc_session_root_path):
"""Build a simple vsock client/server application."""
Expand Down Expand Up @@ -276,7 +264,7 @@ def fc_tmp_path(test_fc_session_root_path):


@pytest.fixture()
def microvm_factory(fc_tmp_path, bin_cloner_path, request):
def microvm_factory(fc_tmp_path, request, record_property):
"""Fixture to create microvms simply.
In order to avoid running out of space when instantiating many microvms,
Expand All @@ -290,10 +278,9 @@ def microvm_factory(fc_tmp_path, bin_cloner_path, request):
jailer_binary_path = Path(binary_dir) / "jailer"
else:
fc_binary_path, jailer_binary_path = build_tools.get_firecracker_binaries()
record_property("firecracker_bin", str(fc_binary_path))

uvm_factory = MicroVMFactory(
fc_tmp_path, bin_cloner_path, fc_binary_path, jailer_binary_path
)
uvm_factory = MicroVMFactory(fc_tmp_path, fc_binary_path, jailer_binary_path)
yield uvm_factory
uvm_factory.kill()
shutil.rmtree(fc_tmp_path)
Expand Down
7 changes: 0 additions & 7 deletions tests/framework/defs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
# Firecracker's binary name
FC_BINARY_NAME = "firecracker"

# Jailer's binary name
JAILER_BINARY_NAME = "jailer"

# The Firecracker sources workspace dir
FC_WORKSPACE_DIR = Path(__file__).parent.parent.parent.resolve()

Expand All @@ -32,10 +29,6 @@
# Absolute path to the test results folder
TEST_RESULTS_DIR = FC_WORKSPACE_DIR / "test_results"

# Name of the file that stores firecracker's PID when launched by jailer with
# `--new-pid-ns`.
FC_PID_FILE_NAME = "firecracker.pid"

# The minimum required host kernel version for which io_uring is supported in
# Firecracker.
MIN_KERNEL_VERSION_FOR_IO_URING = "5.10.51"
Expand Down
21 changes: 13 additions & 8 deletions tests/framework/jailer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import stat
from pathlib import Path

from retry.api import retry_call
from tenacity import Retrying, retry_if_exception_type, stop_after_delay

from framework import defs, utils
from framework.defs import FC_BINARY_NAME
Expand Down Expand Up @@ -226,13 +226,13 @@ def cleanup(self):
# Obtain the tasks from each cgroup and wait on them before
# removing the microvm's associated cgroup folder.
try:
retry_call(
f=self._kill_cgroup_tasks,
fargs=[controller],
exceptions=TimeoutError,
max_delay=5,
logger=None,
)
for attempt in Retrying(
retry=retry_if_exception_type(TimeoutError),
stop=stop_after_delay(5),
reraise=True,
):
with attempt:
self._kill_cgroup_tasks(controller)
except TimeoutError:
pass

Expand Down Expand Up @@ -271,3 +271,8 @@ def _kill_cgroup_tasks(self, controller):
if os.path.exists("/proc/{}".format(task)):
raise TimeoutError
return True

@property
def pid_file(self):
"""Return the PID file of the jailed process"""
return Path(self.chroot_path()) / (self.exec_file.name + ".pid")
Loading

0 comments on commit 9b9eefd

Please sign in to comment.