Skip to content

Commit 879c0c3

Browse files
committed
WIP install 6/n: use iso-remaster to plug an answerfile
FIXME: - hardcoded config values - hardcoded HTTP answerfile, not generated - use mkstemp on server to get a unique name for ISO
1 parent 36277d3 commit 879c0c3

File tree

3 files changed

+71
-2
lines changed

3 files changed

+71
-2
lines changed

conftest.py

Lines changed: 60 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,64 @@ 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+
# markers = request.node.get_closest_marker("iso_remaster")
262+
# if markers is None:
263+
# raise Exception("No iso_remaster marker specified.")
264+
# assert len(markers) == 1
265+
266+
# markers = request.node.get_closest_marker("answerfile")
267+
268+
SOURCE_ISO = "/home/user/iso/xcp-ng-8.2.1-20231130.iso" # FIXME dict in data.py
269+
ANSWERFILE_URL = "http://pxe/configs/custom/ydi/install-8.2-uefi-iso-ext.xml" # FIXME
270+
271+
from data import ISOSR_SRV, ISOSR_PATH, TOOLS
272+
assert "iso-remaster" in TOOLS
273+
iso_remaster = TOOLS["iso-remaster"]
274+
assert os.access(iso_remaster, os.X_OK)
275+
276+
with tempfile.TemporaryDirectory() as isotmp:
277+
remastered_iso = os.path.join(isotmp, "image.iso")
278+
iso_patcher_script = os.path.join(isotmp, "iso-patcher")
279+
280+
logging.info("Remastering %s to %s", SOURCE_ISO, remastered_iso)
281+
282+
# generate iso-patcher script
283+
with open(iso_patcher_script, "xt") as patcher_fd:
284+
passwd = "passw0rd" # FIXME hash
285+
print(f"""#!/bin/bash
286+
set -ex
287+
ISODIR="$1"
288+
SED_COMMANDS=(-e "s@/vmlinuz@/vmlinuz sshpassword={passwd} atexit=shell@")
289+
SED_COMMANDS+=(-e "s@/vmlinuz@/vmlinuz install answerfile={ANSWERFILE_URL}@")
290+
291+
sed -i "${{SED_COMMANDS[@]}}" \
292+
"$ISODIR"/*/*/grub*.cfg \
293+
"$ISODIR"/boot/isolinux/isolinux.cfg
294+
""",
295+
file=patcher_fd)
296+
os.chmod(patcher_fd.fileno(), 0o755)
297+
298+
# do remaster
299+
local_cmd([iso_remaster,
300+
"--iso-patcher", iso_patcher_script,
301+
SOURCE_ISO, remastered_iso
302+
])
303+
304+
# hopefully-unique filename on server (FIXME)
305+
remote_iso = os.path.join(ISOSR_PATH, os.path.basename(isotmp)) + ".iso"
306+
logging.info("Uploading to ISO-SR server remastered %s as %s",
307+
remastered_iso, os.path.basename(remote_iso))
308+
scp(ISOSR_SRV, remastered_iso, remote_iso)
309+
# FIXME: is sr-scan ever needed?
310+
311+
try:
312+
yield os.path.basename(remote_iso)
313+
finally:
314+
logging.info("Removing %s from ISO-SR server", os.path.basename(remote_iso))
315+
ssh(ISOSR_SRV, ["rm", remote_iso])
316+
257317
@pytest.fixture(scope='module')
258318
def vm_ref(request):
259319
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
@@ -8,9 +8,9 @@
88
vifs=[dict(index=0, network_uuid="eabc1038-e40f-2ae5-0781-a3adbec1cae8")], # FIXME
99
))
1010
class TestInstallNested:
11-
def test_install_nested_821_uefi(self, create_vms):
11+
def test_install_nested_821_uefi(self, create_vms, iso_remaster):
1212
assert len(create_vms) == 1
1313
host_vm = create_vms[0]
1414

1515
host_vm.create_cd_vbd("xvdd")
16-
host_vm.insert_cd("xcp-ng-8.2.1-20231130.iso")
16+
host_vm.insert_cd(iso_remaster)

0 commit comments

Comments
 (0)