Skip to content

Commit

Permalink
Update instructions on build a new test image
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusPettersson98 committed Oct 16, 2023
1 parent b0574cc commit 063d7f3
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 6 deletions.
94 changes: 89 additions & 5 deletions test/BUILD_OS_IMAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ This document explains how to create base OS images and run test runners on them

For macOS, the host machine must be macOS. All other platforms assume that the host is Linux.

# Configuring a user in the image

`test-manager` assumes that a dedicated user named `test` (with password `test`) is configured in any guest system which it should control.
Also, it is strongly recommended that a new image should have passwordless `sudo` set up and `sshd` running on boot,
since this will greatly simplify the bootstrapping of `test-runner` and all needed binary artifacts (MullvadVPN App, GUI tests ..).
The legacy method of pre-building a test-runner image is detailed [further down in this document](#).

# Creating a base Linux image

These instructions use Debian, but the process is pretty much the same for any other distribution.
Expand All @@ -15,12 +22,22 @@ qemu-img create -f qcow2 ./os-images/debian.qcow2 5G
qemu-system-x86_64 -cpu host -accel kvm -m 4096 -smp 2 -cdrom debian-11.5.0-amd64-netinst.iso -drive file=./os-images/debian.qcow2
```

`xvfb` must be installed on the guest system. On Fedora, this package is called `xorg-x11-server-Xvfb`.
On Debian/Ubuntu, the package is called `xvfb`. You will also need `wireguard-tools` and some
additional libraries. They are likely already installed if gnome is installed. On Debian:
## Dependencies to install in the image

`xvfb` must be installed on the guest system. You will also need
`wireguard-tools` and some additional libraries. They are likely already
installed if gnome is installed.

### Debian/Ubuntu

```bash
apt install libnss3 libgbm1 libasound2 libatk1.0-0 libatk-bridge2.0-0 libcups2 libgtk-3-0 wireguard-tools xvfb
```

### Fedora

```bash
apt install libnss3 libgbm1 libasound2 libatk1.0-0 libatk-bridge2.0-0 libcups2 libgtk-3-0 wireguard-tools
dnf install libnss3 libgbm1 libasound2 libatk1.0-0 libatk-bridge2.0-0 libcups2 libgtk-3-0 wireguard-tools xorg-x11-server-Xvfb
```

# Creating a base Windows image
Expand Down Expand Up @@ -93,7 +110,74 @@ do the following:
1. Press shift-F10 to open a command prompt.
1. Type `oobe\BypassNRO` and press enter.
## Bootstrapping test runner
# Creating a testrunner image (Legacy method)
The [build-runner-image.sh](./scripts/build-runner-image.sh) script produces a
virtual disk containing the test runner binaries, which must be mounted when
starting the guest OS. They are used `build-runner-image.sh` assumes that an environment
variable `$TARGET` is set to one of the following values:
`x86_64-unknown-linux-gnu`, `x86_64-pc-windows-gnu` depending on which platform
you want to build a testrunner-image for.
## Bootstrapping test runner (Legacy method)
### Linux
The testing image needs to be mounted to `/opt/testing`, and the test runner needs to be started on
boot.
* In the guest, create a mount point for the runner: `mkdir -p /opt/testing`.
* Add an entry to `/etc/fstab`:
```
# Mount testing image
/dev/sdb /opt/testing ext4 defaults 0 1
```
* Create a systemd service that starts the test runner, `/etc/systemd/system/testrunner.service`:
```
[Unit]
Description=Mullvad Test Runner
[Service]
ExecStart=/opt/testing/test-runner /dev/ttyS0 serve
[Install]
WantedBy=multi-user.target
```
* Enable the service: `systemctl enable testrunner.service`.
### Note about SELinux (Fedora)
SELinux prevents services from executing files that do not have the `bin_t` attribute set. Building
the test runner image stripts extended file attributes, and `e2tools` does not yet support setting
these. As a workaround, we currently need to reapply these on each boot.
First, set `bin_t` for all files in `/opt/testing`:
```
semanage fcontext -a -t bin_t "/opt/testing/.*"
```
Secondly, update the systemd unit file to run `restorecon` before the `test-runner`, using the
`ExecStartPre` option:
```
[Unit]
Description=Mullvad Test Runner

[Service]
ExecStartPre=restorecon -v "/opt/testing/*"
ExecStart=/opt/testing/test-runner /dev/ttyS0 serve

[Install]
WantedBy=multi-user.target
```
### Windows
The test runner needs to be started on boot, with the test runner image mounted at `E:`.
This can be achieved as follows:
Expand Down
2 changes: 1 addition & 1 deletion test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ cargo run --bin test-manager set debian11 qemu ./os-images/debian11.qcow2 linux
--disks ./testrunner-images/linux-test-runner.img

# Try it out to see if it works
#cargo run --bin test-manager run-vm debian11
cargo run --bin test-manager run-vm debian11

# Run all tests
cargo run --bin test-manager run-tests debian11 \
Expand Down

0 comments on commit 063d7f3

Please sign in to comment.