Skip to content

Commit cfa9905

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 ea89189 commit cfa9905

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

conftest.py

Lines changed: 31 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)
@@ -306,6 +306,10 @@ def iso_remaster(answerfile):
306306

307307
if answerfile:
308308
logging.info("generating answerfile %s", answerfile_xml)
309+
import xml.etree.ElementTree as ET
310+
ET.SubElement(answerfile.getroot(), "script",
311+
stage="filesystem-populated",
312+
type="url").text = "file:///root/postinstall.sh"
309313
answerfile.write(answerfile_xml)
310314
else:
311315
logging.info("no answerfile")
@@ -323,6 +327,32 @@ def iso_remaster(answerfile):
323327
324328
test ! -e "{answerfile_xml}" ||
325329
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 sleep 1 ; 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/root/.ssh"
354+
echo "{TEST_SSH_PUBKEY}" >> "\\$ROOT/root/.ssh/authorized_keys"
355+
EOF
326356
""",
327357
file=patcher_fd)
328358
os.chmod(patcher_fd.fileno(), 0o755)

0 commit comments

Comments
 (0)