Skip to content

Commit 60aae69

Browse files
committed
WIP install 6/n: use iso-remaster to plug an answerfile
FIXME: - hardcoded config values - hardcoded HTTP answerfile, not generated
1 parent ca35ddf commit 60aae69

File tree

3 files changed

+82
-2
lines changed

3 files changed

+82
-2
lines changed

conftest.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import logging
2+
import os
23
import pytest
34
import tempfile
45

56
from packaging import version
67

78
import lib.config as global_config
89

10+
from lib.commands import local_cmd, scp, ssh
911
from lib.common import wait_for, vm_image, is_uuid
1012
from lib.common import setup_formatted_and_mounted_disk, teardown_formatted_and_mounted_disk
1113
from lib.netutil import is_ipv6
@@ -254,6 +256,75 @@ def sr_disk_for_all_hosts(request, host):
254256
logging.info(f">> Disk or block device {disk} is present and free on all pool members")
255257
yield candidates[0]
256258

259+
@pytest.fixture(scope='session')
260+
def iso_remaster():
261+
SOURCE_ISO = "/home/user/iso/xcp-ng-8.2.1-20231130.iso" # FIXME dict in data.py
262+
ANSWERFILE_URL = "http://pxe/configs/custom/ydi/install-8.2-uefi-iso-ext.xml" # FIXME
263+
264+
from data import ISOSR_SRV, ISOSR_PATH, TOOLS
265+
assert "iso-remaster" in TOOLS
266+
iso_remaster = TOOLS["iso-remaster"]
267+
assert os.access(iso_remaster, os.X_OK)
268+
269+
with tempfile.TemporaryDirectory() as isotmp:
270+
remastered_iso = os.path.join(isotmp, "image.iso")
271+
iso_patcher_script = os.path.join(isotmp, "iso-patcher")
272+
273+
logging.info("Remastering %s to %s", SOURCE_ISO, remastered_iso)
274+
275+
# generate install.img-patcher script
276+
with open(img_patcher_script, "xt") as patcher_fd:
277+
print(f"""#!/bin/bash
278+
set -ex
279+
INSTALLIMG="$1"
280+
281+
curl {ANSWERFILE_URL} -o "$INSTALLIMG/root/answerfile.xml"
282+
""",
283+
file=patcher_fd)
284+
os.chmod(patcher_fd.fileno(), 0o755)
285+
286+
# generate iso-patcher script
287+
with open(iso_patcher_script, "xt") as patcher_fd:
288+
passwd = "passw0rd" # FIXME hash
289+
print(f"""#!/bin/bash
290+
set -ex
291+
ISODIR="$1"
292+
SED_COMMANDS=(-e "s@/vmlinuz@/vmlinuz sshpassword={passwd} atexit=shell@")
293+
SED_COMMANDS+=(-e "s@/vmlinuz@/vmlinuz install answerfile=file:///root/answerfile.xml network_device=all@")
294+
295+
sed -i "${{SED_COMMANDS[@]}}" \
296+
"$ISODIR"/*/*/grub*.cfg \
297+
"$ISODIR"/boot/isolinux/isolinux.cfg
298+
""",
299+
file=patcher_fd)
300+
os.chmod(patcher_fd.fileno(), 0o755)
301+
302+
# do remaster
303+
local_cmd([iso_remaster,
304+
"--iso-patcher", iso_patcher_script,
305+
SOURCE_ISO, remastered_iso
306+
])
307+
308+
# unique filename on server, has to work on FreeBSD-based NAS
309+
# too, and even v14 has no tool allowing mktemp suffixes
310+
remote_iso = ssh(ISOSR_SRV,
311+
["python3", "-c",
312+
'"import os, tempfile; '
313+
f"f = tempfile.mkstemp(suffix='.iso', dir='{ISOSR_PATH}')[1];"
314+
"os.chmod(f, 0o644);"
315+
'print(f);"'
316+
])
317+
logging.info("Uploading to ISO-SR server remastered %s as %s",
318+
remastered_iso, os.path.basename(remote_iso))
319+
scp(ISOSR_SRV, remastered_iso, remote_iso)
320+
# FIXME: is sr-scan ever needed?
321+
322+
try:
323+
yield os.path.basename(remote_iso)
324+
finally:
325+
logging.info("Removing %s from ISO-SR server", os.path.basename(remote_iso))
326+
ssh(ISOSR_SRV, ["rm", remote_iso])
327+
257328
@pytest.fixture(scope='module')
258329
def vm_ref(request):
259330
ref = request.param

data.py-dist

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ 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',

tests/install/test_install.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ class TestInstallNested:
1717
vdis=[dict(name="vm 1 system disk", size="100GiB", device="xvda", userdevice="0")],
1818
vifs=[dict(index=0, network_uuid="eabc1038-e40f-2ae5-0781-a3adbec1cae8")], # FIXME
1919
))
20-
def test_install_nested_821_uefi(self, create_vms):
20+
def test_install_nested_821_uefi(self, iso_remaster, create_vms):
2121
assert len(create_vms) == 1
2222
host_vm = create_vms[0]
2323

2424
host_vm.create_cd_vbd(device="xvdd", userdevice="3")
25-
host_vm.insert_cd("xcp-ng-8.2.1-20231130.iso")
25+
host_vm.insert_cd(iso_remaster)

0 commit comments

Comments
 (0)