Skip to content

Commit 6403a03

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 24d4202 commit 6403a03

File tree

3 files changed

+69
-2
lines changed

3 files changed

+69
-2
lines changed

conftest.py

Lines changed: 58 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,62 @@ 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+
from data import ISOSR_SRV, ISOSR_PATH, TOOLS
270+
assert "iso-remaster" in TOOLS
271+
iso_remaster = TOOLS["iso-remaster"]
272+
assert os.access(iso_remaster, os.X_OK)
273+
274+
with tempfile.TemporaryDirectory() as isotmp:
275+
remastered_iso = os.path.join(isotmp, "image.iso")
276+
patcher_script = os.path.join(isotmp, "iso-patcher")
277+
278+
logging.info("Remastering %s to %s", SOURCE_ISO, remastered_iso)
279+
280+
# generate iso-patcher script
281+
with open(patcher_script, "xt") as patcher_fd:
282+
passwd = "passw0rd" # FIXME hash
283+
print(f"""#!/bin/bash
284+
set -ex
285+
ISODIR="$1"
286+
SED_COMMANDS=(-e "s@/vmlinuz@/vmlinuz sshpassword={passwd}@")
287+
SED_COMMANDS+=(-e "s@/vmlinuz@/vmlinuz install answerfile=http://pxe/configs/custom/ydi/install-8.2-uefi-iso-ext.xml@")
288+
289+
sed -i "${{SED_COMMANDS[@]}}" \
290+
"$ISODIR"/*/*/grub*.cfg \
291+
"$ISODIR"/boot/isolinux/isolinux.cfg
292+
""",
293+
file=patcher_fd)
294+
os.chmod(patcher_fd.fileno(), 0o755)
295+
296+
# do remaster
297+
local_cmd([iso_remaster,
298+
"--iso-patcher", patcher_script,
299+
SOURCE_ISO, remastered_iso
300+
])
301+
302+
# hopefully-unique filename on server (FIXME)
303+
remote_iso = os.path.join(ISOSR_PATH, os.path.basename(isotmp)) + ".iso"
304+
logging.info("Uploading to ISO-SR server remastered %s as %s",
305+
remastered_iso, os.path.basename(remote_iso))
306+
scp(ISOSR_SRV, remastered_iso, remote_iso)
307+
# FIXME: is sr-scan ever needed?
308+
309+
try:
310+
yield os.path.basename(remote_iso)
311+
finally:
312+
logging.info("Removing %s from ISO-SR server", os.path.basename(remote_iso))
313+
ssh(ISOSR_SRV, ["rm", remote_iso])
314+
257315
@pytest.fixture(scope='module')
258316
def vm_ref(request):
259317
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
@@ -9,9 +9,9 @@
99
network_uuid="eabc1038-e40f-2ae5-0781-a3adbec1cae8")],
1010
))
1111
class TestInstallNested:
12-
def test_install_nested_821(self, create_vms):
12+
def test_install_nested_821(self, create_vms, iso_remaster):
1313
assert len(create_vms) == 1
1414
host_vm = create_vms[0]
1515

1616
host_vm.create_cd_vbd("sdd")
17-
host_vm.insert_cd("xcp-ng-8.2.1-20231130.iso")
17+
host_vm.insert_cd(iso_remaster)

0 commit comments

Comments
 (0)