Skip to content

Commit f37f9fd

Browse files
committed
WIP install 7/n: use iso-remaster to plug an answerfile
FIXME: - hardcoded config values - hardcoded HTTP answerfile, not generated
1 parent a14dfa1 commit f37f9fd

File tree

4 files changed

+104
-2
lines changed

4 files changed

+104
-2
lines changed

data.py-dist

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,30 @@ PXE_CONFIG_SERVER = 'pxe'
2626
# Default VM images location
2727
DEF_VM_URL = 'http://pxe/images/'
2828

29+
# Default shared ISO SR
30+
ISOSR_SRV = "nfs-server"
31+
ISOSR_PATH = "/srv/iso-sr"
32+
33+
# Tools
34+
TOOLS = {
35+
# "iso-remaster": "/home/user/src/xcpng/xcp/scripts/iso-remaster/iso-remaster.sh",
36+
}
37+
2938
# Values can be either full URLs or only partial URLs that will be automatically appended to DEF_VM_URL
3039
VM_IMAGES = {
3140
'mini-linux-x86_64-bios': 'alpine-minimal-3.12.0.xva',
3241
'mini-linux-x86_64-uefi': 'alpine-uefi-minimal-3.12.0.xva'
3342
}
3443

44+
# FIXME: use URLs and an optional cache?
45+
ISO_IMAGES = {
46+
# 'xcpng-8.2.0': "/home/user/iso/xcp-ng-8.2.0.iso",
47+
# 'xcpng-8.2.1': "/home/user/iso/xcp-ng-8.2.1.iso",
48+
# 'xcpng-8.2.1-2023': "/home/user/iso/xcp-ng-8.2.1-20231130.iso",
49+
# 'xcpng-8.3-beta2': "/home/user/iso/xcp-ng-8.3.0-beta2.iso",
50+
# 'xcpng-8.3-beta2-net': "/home/user/iso/xcp-ng-8.3.0-beta2-netinstall.iso",
51+
}
52+
3553
# In some cases, we may prefer to favour a local SR to store test VM disks,
3654
# to avoid latency or unstabilities related to network or shared file servers.
3755
# However it's not good practice to make a local SR the default SR for a pool of several hosts.

pytest.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ markers =
2222
# * VM-related markers to give parameters to fixtures
2323
vm_definitions: dicts of VM defs for create_vms fixture.
2424

25+
# * installation-related markers to customize installer run
26+
installer_iso: key of data.ISO_IMAGES identifying an installer ISO
27+
2528
# * Test targets related to VMs
2629
small_vm: tests that it is enough to run just once, using the smallest possible VM.
2730
big_vm: tests that it would be good to run with a big VM.

tests/install/conftest.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import logging
2+
import os
3+
import pytest
4+
import tempfile
5+
6+
from lib.commands import local_cmd, scp, ssh
7+
8+
@pytest.fixture(scope='function')
9+
def iso_remaster(request, answerfile):
10+
marker = request.node.get_closest_marker("installer_iso")
11+
assert marker is not None, "iso_remaster fixture requires 'installer_iso' marker"
12+
iso_key = marker.args[0]
13+
ANSWERFILE_URL = "http://pxe/configs/custom/ydi/install-8.2-uefi-iso-ext.xml" # FIXME
14+
15+
from data import ISO_IMAGES, ISOSR_SRV, ISOSR_PATH, TOOLS
16+
assert "iso-remaster" in TOOLS
17+
iso_remaster = TOOLS["iso-remaster"]
18+
assert os.access(iso_remaster, os.X_OK)
19+
20+
assert iso_key in ISO_IMAGES, f"ISO_IMAGES does not have a value for {iso_key}"
21+
SOURCE_ISO = ISO_IMAGES[iso_key]
22+
23+
with tempfile.TemporaryDirectory() as isotmp:
24+
remastered_iso = os.path.join(isotmp, "image.iso")
25+
iso_patcher_script = os.path.join(isotmp, "iso-patcher")
26+
27+
logging.info("Remastering %s to %s", SOURCE_ISO, remastered_iso)
28+
29+
# generate install.img-patcher script
30+
with open(img_patcher_script, "xt") as patcher_fd:
31+
print(f"""#!/bin/bash
32+
set -ex
33+
INSTALLIMG="$1"
34+
35+
curl {ANSWERFILE_URL} -o "$INSTALLIMG/root/answerfile.xml"
36+
""",
37+
file=patcher_fd)
38+
os.chmod(patcher_fd.fileno(), 0o755)
39+
40+
# generate iso-patcher script
41+
with open(iso_patcher_script, "xt") as patcher_fd:
42+
passwd = "passw0rd" # FIXME hash
43+
print(f"""#!/bin/bash
44+
set -ex
45+
ISODIR="$1"
46+
SED_COMMANDS=(-e "s@/vmlinuz@/vmlinuz sshpassword={passwd} atexit=shell@")
47+
SED_COMMANDS+=(-e "s@/vmlinuz@/vmlinuz install answerfile=file:///root/answerfile.xml network_device=all@")
48+
49+
sed -i "${{SED_COMMANDS[@]}}" \
50+
"$ISODIR"/*/*/grub*.cfg \
51+
"$ISODIR"/boot/isolinux/isolinux.cfg
52+
""",
53+
file=patcher_fd)
54+
os.chmod(patcher_fd.fileno(), 0o755)
55+
56+
# do remaster
57+
local_cmd([iso_remaster,
58+
"--iso-patcher", iso_patcher_script,
59+
SOURCE_ISO, remastered_iso
60+
])
61+
62+
# unique filename on server, has to work on FreeBSD-based NAS
63+
# too, and even v14 has no tool allowing mktemp suffixes
64+
remote_iso = ssh(ISOSR_SRV,
65+
["python3", "-c",
66+
'"import os, tempfile; '
67+
f"f = tempfile.mkstemp(suffix='.iso', dir='{ISOSR_PATH}')[1];"
68+
"os.chmod(f, 0o644);"
69+
'print(f);"'
70+
])
71+
logging.info("Uploading to ISO-SR server remastered %s as %s",
72+
remastered_iso, os.path.basename(remote_iso))
73+
scp(ISOSR_SRV, remastered_iso, remote_iso)
74+
# FIXME: is sr-scan ever needed?
75+
76+
try:
77+
yield os.path.basename(remote_iso)
78+
finally:
79+
logging.info("Removing %s from ISO-SR server", os.path.basename(remote_iso))
80+
ssh(ISOSR_SRV, ["rm", remote_iso])

tests/install/test.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ class TestNested:
1818
vdis=[dict(name="vm 1 system disk", size="100GiB", device="xvda", userdevice="0")],
1919
vifs=[dict(index=0, network_uuid="eabc1038-e40f-2ae5-0781-a3adbec1cae8")], # FIXME
2020
))
21-
def test_nested_821_uefi(self, create_vms):
21+
@pytest.mark.installer_iso("xcpng-8.2.1-2023")
22+
def test_install_821_uefi(self, iso_remaster, create_vms):
2223
assert len(create_vms) == 1
2324
host_vm = create_vms[0]
2425
# FIXME should be part of vm def
2526
host_vm.create_cd_vbd(device="xvdd", userdevice="3")
2627

27-
host_vm.insert_cd("xcp-ng-8.2.1-20231130.iso")
28+
host_vm.insert_cd(iso_remaster)

0 commit comments

Comments
 (0)