Skip to content

Commit

Permalink
install 4/n: make sure host appears in PXE ARP tables
Browse files Browse the repository at this point in the history
Detection of host IP till now relies on the fact we download the
answerfile from PXE server.  Once we take this file from the ISO this
network traffic won't happen so we need some other mechanism to fill the
server's ARP tables.

test-pingpxe.service is installed in install.img by iso-remaster.

Since it is difficult to wait until the IP has been assigned before
launching the service, make it ping continuously until we can reach
the PXE server.

Similarly, once installed the host needs the same mechanism so the test
can find it.  We prepare an installer hook to install the service on the
host, which the generated answerfile will use in later commit.

This also takes into account xapi-project/xen-api#5799: we must avoid
sending out any traffic while the XAPI bridge has an obsolete MAC
attached, or the peer and network equipment in between get confused.

Signed-off-by: Yann Dirson <[email protected]>
  • Loading branch information
ydirson committed Jul 26, 2024
1 parent b596178 commit 4d27b64
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion tests/install/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def iso_remaster(request):
param_mapping = marker.kwargs.get("param_mapping", {})
iso_key = callable_marker(marker.args[0], request, param_mapping=param_mapping)

from data import ANSWERFILE_URL, ISO_IMAGES, ISOSR_SRV, ISOSR_PATH, TEST_SSH_PUBKEY, TOOLS
from data import ANSWERFILE_URL, ISO_IMAGES, ISOSR_SRV, ISOSR_PATH, PXE_CONFIG_SERVER, TEST_SSH_PUBKEY, TOOLS
assert "iso-remaster" in TOOLS
iso_remaster = TOOLS["iso-remaster"]
assert os.access(iso_remaster, os.X_OK)
Expand All @@ -36,6 +36,55 @@ def iso_remaster(request):
mkdir -p "$INSTALLIMG/root/.ssh"
echo "{TEST_SSH_PUBKEY}" > "$INSTALLIMG/root/.ssh/authorized_keys"
cat > "$INSTALLIMG/usr/local/sbin/test-pingpxe.sh" << 'EOF'
#! /bin/bash
set -eE
set -o pipefail
ether_of () {{
ifconfig "$1" | grep ether | sed 's/.*ether \\([^ ]*\\).*/\\1/'
}}
# on installed system, avoid xapi-project/xen-api#5799
if ! [ -e /opt/xensource/installer ]; then
eth_mac=$(ether_of eth0)
br_mac=$(ether_of xenbr0)
# wait for bridge MAC to be fixed
test "$eth_mac" = "$br_mac"
fi
ping -c1 "$1"
EOF
chmod +x "$INSTALLIMG/usr/local/sbin/test-pingpxe.sh"
cat > "$INSTALLIMG/etc/systemd/system/test-pingpxe.service" <<EOF
[Unit]
Description=Ping pxe server to populate its ARP table
After=network-online.target
[Service]
Type=oneshot
ExecStart=/bin/sh -c 'while ! /usr/local/sbin/test-pingpxe.sh "{PXE_CONFIG_SERVER}"; do sleep 1 ; done'
[Install]
WantedBy=default.target
EOF
systemctl --root="$INSTALLIMG" enable test-pingpxe.service
cat > "$INSTALLIMG/root/postinstall.sh" <<EOF
#!/bin/sh
set -ex
ROOT="\\$1"
cp /etc/systemd/system/test-pingpxe.service "\\$ROOT/etc/systemd/system/test-pingpxe.service"
cp /usr/local/sbin/test-pingpxe.sh "\\$ROOT/usr/local/sbin/test-pingpxe.sh"
systemctl --root="\\$ROOT" enable test-pingpxe.service
mkdir -p "\\$ROOT/root/.ssh"
echo "{TEST_SSH_PUBKEY}" >> "\\$ROOT/root/.ssh/authorized_keys"
EOF
""",
file=patcher_fd)
os.chmod(patcher_fd.fileno(), 0o755)
Expand Down

0 comments on commit 4d27b64

Please sign in to comment.