Skip to content

Commit e2d59d7

Browse files
committed
ci: handle an inactive libvirt network for local runs
Start an inactive libvirt network and restore its reservations, so local runs match the hosted runners. Signed-off-by: Fabian Wiesel <fabian.wiesel@sap.com>
1 parent 57aacdb commit e2d59d7

1 file changed

Lines changed: 29 additions & 5 deletions

File tree

‎.github/actions/test/integration/setup/action.yml‎

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,35 @@ runs:
2626
- name: Configure the default libvirt network
2727
shell: bash
2828
run: |
29-
sudo virsh net-destroy default
30-
sudo virsh net-undefine default
31-
sudo virsh net-define ./.github/actions/test/integration/setup/virbr-hv.xml
32-
sudo virsh net-start default
33-
sudo virsh net-autostart default
29+
NETWORK=${HV_NETWORK:-default}
30+
31+
# virsh net-info also succeeds for a defined network that is inactive,
32+
# so decide on its Active field, not on the exit status alone.
33+
if ! net_info=$(sudo virsh net-info "$NETWORK" 2>/dev/null); then
34+
[ "$NETWORK" = default ] \
35+
|| { echo "the libvirt network $NETWORK does not exist; only default may be defined from virbr-hv.xml" >&2; exit 1; }
36+
sudo virsh net-define ./.github/actions/test/integration/setup/virbr-hv.xml
37+
sudo virsh net-start "$NETWORK"
38+
else
39+
active=$(printf '%s\n' "$net_info" | awk '$1 == "Active:" { print $2 }')
40+
[ -n "$active" ] \
41+
|| { echo "cannot read the Active state of the libvirt network $NETWORK" >&2; exit 1; }
42+
if [ "$active" = no ]; then
43+
sudo virsh net-start "$NETWORK"
44+
elif [ "$active" != yes ]; then
45+
echo "unexpected Active state '$active' for the libvirt network $NETWORK" >&2
46+
exit 1
47+
fi
48+
fi
49+
50+
# virbr-hv.xml carries the two reservations, but a pre-existing network
51+
# was never defined from it. Restore them by MAC, so a rerun adds none.
52+
add_host() {
53+
sudo virsh net-dumpxml "$NETWORK" | grep -q "mac='$1'" \
54+
|| sudo virsh net-update "$NETWORK" add ip-dhcp-host "<host mac='$1' ip='$2' name='$3'/>" --live --config
55+
}
56+
add_host 52:54:00:12:34:56 192.168.122.2 hv1
57+
add_host 52:54:00:65:43:21 192.168.122.3 hv2
3458
3559
- name: Copy ignition file
3660
shell: bash

0 commit comments

Comments
 (0)