Skip to content

Commit

Permalink
vmctl: Add Host Aliases
Browse files Browse the repository at this point in the history
Instead of duplicating the IP addresses in tests, add host aliases in
/etc/hosts.
  • Loading branch information
holesch committed Apr 12, 2024
1 parent ab12093 commit bfbce04
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
28 changes: 25 additions & 3 deletions scripts/_vmctl/configure-vm.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/bin/sh

ip_hub=192.168.200.1
ip_exporter=192.168.200.2
ip_client=192.168.200.3

main() {
vm="${1:?}"
PS4=">>> "
Expand Down Expand Up @@ -32,18 +36,36 @@ setup_network_hub() {
ip link set eth2 up
ip link set dev eth2 master br0

ip addr add 192.168.200.1/24 dev br0
ip addr add "$ip_hub/24" dev br0
ip link set br0 up

cat >> /etc/hosts << EOF
127.0.0.1 hub.local
$ip_exporter exporter.local
$ip_client client.local
EOF
}

setup_network_exporter() {
ip addr add 192.168.200.2/24 dev eth1
ip addr add "$ip_exporter/24" dev eth1
ip link set eth1 up

cat >> /etc/hosts << EOF
$ip_hub hub.local
127.0.0.1 exporter.local
$ip_client client.local
EOF
}

setup_network_client() {
ip addr add 192.168.200.3/24 dev eth1
ip addr add "$ip_client/24" dev eth1
ip link set eth1 up

cat >> /etc/hosts << EOF
$ip_hub hub.local
$ip_exporter exporter.local
127.0.0.1 client.local
EOF
}

install_project() {
Expand Down
6 changes: 3 additions & 3 deletions tests/test_usbip.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ async def test_raw_usb_forwarding(vms):
await vms.exporter.ssh_poll("nc -z 127.0.0.1 3240")

async with vms.client.ssh_task_root(
f"python3 -m not_my_board._usbip import {vms.exporter.ip} 2-1 0",
"python3 -m not_my_board._usbip import exporter.local 2-1 0",
"usbip import",
):
# wait for USB device to appear
Expand All @@ -31,12 +31,12 @@ async def test_usb_forwarding(vms):
await vms.hub.ssh_poll("nc -z 127.0.0.1 2092")

async with vms.exporter.ssh_task_root(
f"not-my-board export http://{vms.hub.ip}:2092 ./src/tests/qemu-usb-place.toml",
"not-my-board export http://hub.local:2092 ./src/tests/qemu-usb-place.toml",
"export",
):
await vms.client.ssh("""'doas rm -f "/run/not-my-board-agent.sock"'""")
async with vms.client.ssh_task_root(
f"not-my-board agent http://{vms.hub.ip}:2092", "agent"
"not-my-board agent http://hub.local:2092", "agent"
):
# wait until exported place is registered
await vms.client.ssh_poll(
Expand Down
3 changes: 0 additions & 3 deletions tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,10 @@ async def ssh_poll(self, cmd, timeout=None):

class HubVM(_VM):
_name = "hub"
ip = "192.168.200.1"


class ExporterVM(_VM):
_name = "exporter"
ip = "192.168.200.2"

async def usb_attach(self):
await sh("./scripts/vmctl usb attach")
Expand All @@ -64,7 +62,6 @@ async def usb_detach(self):

class ClientVM(_VM):
_name = "client"
ip = "192.168.200.3"


async def sh(cmd, check=True, strip=True, prefix=None):
Expand Down

0 comments on commit bfbce04

Please sign in to comment.