Skip to content

Commit 9884a83

Browse files
committed
Make sure host appears in PXE ARP tables
Detection of host IP till now relies on the fact we download the answerfile from PXE server. Once we generate it this network traffic won't happen so we need some other mechanism to fill the server's ARP tables. Similarly, once installed the host needs the same mechanism so the test can find it. test-pingpxe.service is installed in install.img by iso-remaster, and copied to host using an installer hook. 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. Signed-off-by: Yann Dirson <[email protected]>
1 parent 65a512f commit 9884a83

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

conftest.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ def answerfile(request):
293293
def iso_remaster(answerfile):
294294
SOURCE_ISO = "/home/user/iso/xcp-ng-8.2.1-20231130.iso" # FIXME dict in data.py
295295

296-
from data import ISOSR_SRV, ISOSR_PATH, TEST_SSH_PUBKEY, TOOLS
296+
from data import ISOSR_SRV, ISOSR_PATH, PXE_CONFIG_SERVER, TEST_SSH_PUBKEY, TOOLS
297297
assert "iso-remaster" in TOOLS
298298
iso_remaster = TOOLS["iso-remaster"]
299299
assert os.access(iso_remaster, os.X_OK)
@@ -327,6 +327,32 @@ def iso_remaster(answerfile):
327327
328328
test ! -e "{answerfile_xml}" ||
329329
cp "{answerfile_xml}" "$INSTALLIMG/root/answerfile.xml"
330+
331+
cat > "$INSTALLIMG/etc/systemd/system/test-pingpxe.service" <<EOF
332+
[Unit]
333+
Description=Ping pxe server to populate its ARP table
334+
After=network-online.target
335+
[Service]
336+
Type=oneshot
337+
ExecStart=/bin/sh -c 'while ! ping -c1 {PXE_CONFIG_SERVER}; do : ; done'
338+
[Install]
339+
WantedBy=default.target
340+
EOF
341+
342+
systemctl --root="$INSTALLIMG" enable test-pingpxe.service
343+
344+
cat > "$INSTALLIMG/root/postinstall.sh" <<EOF
345+
#!/bin/sh
346+
set -ex
347+
348+
ROOT="\\$1"
349+
350+
cp /etc/systemd/system/test-pingpxe.service "\\$ROOT/etc/systemd/system/test-pingpxe.service"
351+
systemctl --root="\\$ROOT" enable test-pingpxe.service
352+
353+
mkdir -p "\\$ROOT/.ssh"
354+
echo "{TEST_SSH_PUBKEY}" > "\\$ROOT/.ssh/authorized_keys"
355+
EOF
330356
""",
331357
file=patcher_fd)
332358
os.chmod(patcher_fd.fileno(), 0o755)

0 commit comments

Comments
 (0)