Skip to content

Commit 126f9e3

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 1a669d8 commit 126f9e3

File tree

2 files changed

+62
-30
lines changed

2 files changed

+62
-30
lines changed

conftest.py

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -403,35 +403,7 @@ def create_vms(request, host):
403403
vdis = []
404404
vbds = []
405405
for vm_def in marker.args:
406-
vm_name = vm_def["name"]
407-
vm_template = vm_def["template"]
408-
409-
logging.info(">> Install VM %r from template %r", vm_name, vm_template)
410-
411-
vm = host.vm_from_template(vm_name, vm_template)
412-
413-
# VM is now created, make sure we clean it up on any subsequent failure
414-
vms.append(vm)
415-
416-
if "vdis" in marker:
417-
for vdi_def in marker["vdis"]:
418-
sr = SR(host.main_sr_uuid(), host.pool)
419-
vdi = sr.create_vdi(vdi_def["name"], vdi_def["size"])
420-
vdis.append(vdi)
421-
# connect to VM
422-
vbd = vm.create_vbd(vdi_def["device"], vdi.uuid)
423-
vbds.append(vbd)
424-
vbd.param_set(param_name="userdevice", value=vdi_def["userdevice"])
425-
426-
if "vifs" in marker:
427-
for vif_def in marker["vifs"]:
428-
vm.create_vif(vif_def["index"], vif_def["network_uuid"])
429-
430-
if "params" in marker:
431-
for param_def in marker["params"]:
432-
logging.info("Setting param %s", param_def)
433-
vm.param_set(**param_def)
434-
406+
_create_vm(vm_def, host, vms, vdis, vbds)
435407
yield vms
436408

437409
except Exception:
@@ -449,6 +421,36 @@ def create_vms(request, host):
449421
logging.info("<< Destroy VM %s", vm.uuid)
450422
vm.destroy(verify=True)
451423

424+
def _create_vm(marker, host, vms, vdis, vbds):
425+
vm_name = marker["name"]
426+
vm_template = marker["template"]
427+
428+
logging.info(">> Install VM %r from template %r", vm_name, vm_template)
429+
430+
vm = host.vm_from_template(vm_name, vm_template)
431+
432+
# VM is now created, make sure we clean it up on any subsequent failure
433+
vms.append(vm)
434+
435+
if "vdis" in marker:
436+
for vdi_def in marker["vdis"]:
437+
sr = SR(host.main_sr_uuid(), host.pool)
438+
vdi = sr.create_vdi(vdi_def["name"], vdi_def["size"])
439+
vdis.append(vdi)
440+
# connect to VM
441+
vbd = vm.create_vbd(vdi_def["device"], vdi.uuid)
442+
vbds.append(vbd)
443+
vbd.param_set(param_name="userdevice", value=vdi_def["userdevice"])
444+
445+
if "vifs" in marker:
446+
for vif_def in marker["vifs"]:
447+
vm.create_vif(vif_def["index"], vif_def["network_uuid"])
448+
449+
if "params" in marker:
450+
for param_def in marker["params"]:
451+
logging.info("Setting param %s", param_def)
452+
vm.param_set(**param_def)
453+
452454
@pytest.fixture(scope="module")
453455
def running_vm(imported_vm):
454456
vm = imported_vm

tests/install/conftest.py

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

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

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

0 commit comments

Comments
 (0)