|
| 1 | +test_network_dhcp_routes() { |
| 2 | + ensure_import_testimage |
| 3 | + ensure_has_localhost_remote "${INCUS_ADDR}" |
| 4 | + |
| 5 | + # bridge network |
| 6 | + incus network create inct$$ |
| 7 | + incus network set inct$$ ipv4.address 10.13.37.1/24 |
| 8 | + incus network set inct$$ ipv4.dhcp.routes 1.2.0.0/16,10.13.37.5,2.3.0.0/16,10.13.37.7 |
| 9 | + |
| 10 | + incus launch testimage nettest -n inct$$ |
| 11 | + |
| 12 | + cat > "${TEST_DIR}"/udhcpc.sh <<EOL |
| 13 | +#!/bin/sh |
| 14 | +[ "\$1" = "bound" ] && echo "STATICROUTES: \$staticroutes" |
| 15 | +EOL |
| 16 | + |
| 17 | + incus file push "${TEST_DIR}/udhcpc.sh" nettest/udhcpc.sh |
| 18 | + incus exec nettest -- chmod a+rx /udhcpc.sh |
| 19 | + |
| 20 | + staticroutes_output=$(incus exec nettest -- udhcpc -s /udhcpc.sh 2>/dev/null | grep STATICROUTES) |
| 21 | + |
| 22 | + echo "$staticroutes_output" | grep -q "1.2.0.0/16 10.13.37.5" |
| 23 | + echo "$staticroutes_output" | grep -q "2.3.0.0/16 10.13.37.7" |
| 24 | + |
| 25 | + incus delete nettest -f |
| 26 | + |
| 27 | + if [ -n "${INCUS_OFFLINE:-}" ]; then |
| 28 | + echo "==> SKIP: Skipping OCI tests as running offline" |
| 29 | + else |
| 30 | + ensure_has_localhost_remote "${INCUS_ADDR}" |
| 31 | + |
| 32 | + incus remote add docker https://docker.io --protocol=oci |
| 33 | + incus launch docker:alpine nettest --network=inct$$ |
| 34 | + |
| 35 | + incus exec nettest -- ip route list | grep -q "1.2.0.0/16 via 10.13.37.5" |
| 36 | + incus exec nettest -- ip route list | grep -q "2.3.0.0/16 via 10.13.37.7" |
| 37 | + |
| 38 | + incus delete -f nettest |
| 39 | + incus remote remove docker |
| 40 | + fi |
| 41 | + |
| 42 | + incus network delete inct$$ |
| 43 | + |
| 44 | + |
| 45 | + # ovn network |
| 46 | + if incus network create inct$$ -t ovn network=none; then |
| 47 | + incus network set inct$$ ipv4.address 10.13.37.1/24 |
| 48 | + incus network set inct$$ ipv4.dhcp.routes 1.2.0.0/16,10.13.37.5,2.3.0.0/16,10.13.37.7 |
| 49 | + |
| 50 | + incus launch testimage nettest -n inct$$ |
| 51 | + |
| 52 | + incus exec nettest -- ip route list | grep -q "1.2.0.0/16 via 10.13.37.5" |
| 53 | + incus exec nettest -- ip route list | grep -q "2.3.0.0/16 via 10.13.37.7" |
| 54 | + |
| 55 | + incus delete nettest -f |
| 56 | + incus network delete inct$$ |
| 57 | + else |
| 58 | + echo "==> SKIP: Skipping OVN tests" |
| 59 | + fi |
| 60 | +} |
0 commit comments