Skip to content

Commit e685620

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 4e8082c commit e685620

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
@@ -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)