Skip to content

Commit 2d96732

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 d3f5e3d commit 2d96732

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

tests/install/conftest.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def iso_remaster(request, answerfile):
4747
assert marker is not None, "iso_remaster fixture requires 'installer_iso' marker"
4848
iso_key = marker.args[0]
4949

50-
from data import ISO_IMAGES, ISOSR_SRV, ISOSR_PATH, TEST_SSH_PUBKEY, TOOLS
50+
from data import ISO_IMAGES, ISOSR_SRV, ISOSR_PATH, PXE_CONFIG_SERVER, TEST_SSH_PUBKEY, TOOLS
5151
assert "iso-remaster" in TOOLS
5252
iso_remaster = TOOLS["iso-remaster"]
5353
assert os.access(iso_remaster, os.X_OK)
@@ -63,6 +63,10 @@ def iso_remaster(request, answerfile):
6363

6464
if answerfile:
6565
logging.info("generating answerfile %s", answerfile_xml)
66+
import xml.etree.ElementTree as ET
67+
ET.SubElement(answerfile.getroot(), "script",
68+
stage="filesystem-populated",
69+
type="url").text = "file:///root/postinstall.sh"
6670
answerfile.write(answerfile_xml)
6771
else:
6872
logging.info("no answerfile")
@@ -80,6 +84,32 @@ def iso_remaster(request, answerfile):
8084
8185
test ! -e "{answerfile_xml}" ||
8286
cp "{answerfile_xml}" "$INSTALLIMG/root/answerfile.xml"
87+
88+
cat > "$INSTALLIMG/etc/systemd/system/test-pingpxe.service" <<EOF
89+
[Unit]
90+
Description=Ping pxe server to populate its ARP table
91+
After=network-online.target
92+
[Service]
93+
Type=oneshot
94+
ExecStart=/bin/sh -c 'while ! ping -c1 {PXE_CONFIG_SERVER}; do sleep 1 ; done'
95+
[Install]
96+
WantedBy=default.target
97+
EOF
98+
99+
systemctl --root="$INSTALLIMG" enable test-pingpxe.service
100+
101+
cat > "$INSTALLIMG/root/postinstall.sh" <<EOF
102+
#!/bin/sh
103+
set -ex
104+
105+
ROOT="\\$1"
106+
107+
cp /etc/systemd/system/test-pingpxe.service "\\$ROOT/etc/systemd/system/test-pingpxe.service"
108+
systemctl --root="\\$ROOT" enable test-pingpxe.service
109+
110+
mkdir -p "\\$ROOT/root/.ssh"
111+
echo "{TEST_SSH_PUBKEY}" >> "\\$ROOT/root/.ssh/authorized_keys"
112+
EOF
83113
""",
84114
file=patcher_fd)
85115
os.chmod(patcher_fd.fileno(), 0o755)

0 commit comments

Comments
 (0)