Skip to content

Commit df4e3c7

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 12094d1 commit df4e3c7

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
@@ -380,35 +380,7 @@ def create_vms(request, host):
380380
vdis = []
381381
vbds = []
382382
for marker in markers.args:
383-
vm_name = marker["name"]
384-
vm_template = marker["template"]
385-
386-
logging.info(">> Install VM %r from template %r", vm_name, vm_template)
387-
388-
vm = host.vm_from_template(vm_name, vm_template)
389-
390-
# VM is now created, make sure we clean it up on any subsequent failure
391-
vms.append(vm)
392-
393-
if "vdis" in marker:
394-
for vdi_def in marker["vdis"]:
395-
sr = SR(host.main_sr_uuid(), host.pool)
396-
vdi = sr.create_vdi(vdi_def["name"], vdi_def["size"])
397-
vdis.append(vdi)
398-
# connect to VM
399-
vbd = vm.create_vbd(vdi_def["device"], vdi.uuid)
400-
vbds.append(vbd)
401-
vbd.param_set(param_name="userdevice", value=vdi_def["userdevice"])
402-
403-
if "vifs" in marker:
404-
for vif_def in marker["vifs"]:
405-
vm.create_vif(vif_def["index"], vif_def["network_uuid"])
406-
407-
if "params" in marker:
408-
for param_def in marker["params"]:
409-
logging.info("Setting param %s", param_def)
410-
vm.param_set(**param_def)
411-
383+
_create_vm(marker, host, vms, vdis, vbds)
412384
yield vms
413385

414386
except Exception:
@@ -426,6 +398,36 @@ def create_vms(request, host):
426398
logging.info("<< Destroy VM %s", vm.uuid)
427399
vm.destroy(verify=True)
428400

401+
def _create_vm(marker, host, vms, vdis, vbds):
402+
vm_name = marker["name"]
403+
vm_template = marker["template"]
404+
405+
logging.info(">> Install VM %r from template %r", vm_name, vm_template)
406+
407+
vm = host.vm_from_template(vm_name, vm_template)
408+
409+
# VM is now created, make sure we clean it up on any subsequent failure
410+
vms.append(vm)
411+
412+
if "vdis" in marker:
413+
for vdi_def in marker["vdis"]:
414+
sr = SR(host.main_sr_uuid(), host.pool)
415+
vdi = sr.create_vdi(vdi_def["name"], vdi_def["size"])
416+
vdis.append(vdi)
417+
# connect to VM
418+
vbd = vm.create_vbd(vdi_def["device"], vdi.uuid)
419+
vbds.append(vbd)
420+
vbd.param_set(param_name="userdevice", value=vdi_def["userdevice"])
421+
422+
if "vifs" in marker:
423+
for vif_def in marker["vifs"]:
424+
vm.create_vif(vif_def["index"], vif_def["network_uuid"])
425+
426+
if "params" in marker:
427+
for param_def in marker["params"]:
428+
logging.info("Setting param %s", param_def)
429+
vm.param_set(**param_def)
430+
429431
@pytest.fixture(scope="module")
430432
def running_vm(imported_vm):
431433
vm = imported_vm

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)