Skip to content

Commit

Permalink
WIP install 6/n: use iso-remaster to plug an answerfile
Browse files Browse the repository at this point in the history
FIXME:
- hardcoded config values
- hardcoded HTTP answerfile, not generated
  • Loading branch information
ydirson committed May 14, 2024
1 parent 24d4202 commit 6403a03
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 2 deletions.
58 changes: 58 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import logging
import os
import pytest
import tempfile

from packaging import version

import lib.config as global_config

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

@pytest.fixture(scope='session')
def iso_remaster():
#markers = request.node.get_closest_marker("iso_remaster")
#if markers is None:
# raise Exception("No iso_remaster marker specified.")
#assert len(markers) == 1

#markers = request.node.get_closest_marker("answerfile")

SOURCE_ISO = "/home/user/iso/xcp-ng-8.2.1-20231130.iso" # FIXME dict in data.py
from data import ISOSR_SRV, ISOSR_PATH, TOOLS
assert "iso-remaster" in TOOLS
iso_remaster = TOOLS["iso-remaster"]
assert os.access(iso_remaster, os.X_OK)

with tempfile.TemporaryDirectory() as isotmp:
remastered_iso = os.path.join(isotmp, "image.iso")
patcher_script = os.path.join(isotmp, "iso-patcher")

logging.info("Remastering %s to %s", SOURCE_ISO, remastered_iso)

# generate iso-patcher script
with open(patcher_script, "xt") as patcher_fd:
passwd = "passw0rd" # FIXME hash
print(f"""#!/bin/bash
set -ex
ISODIR="$1"
SED_COMMANDS=(-e "s@/vmlinuz@/vmlinuz sshpassword={passwd}@")
SED_COMMANDS+=(-e "s@/vmlinuz@/vmlinuz install answerfile=http://pxe/configs/custom/ydi/install-8.2-uefi-iso-ext.xml@")
sed -i "${{SED_COMMANDS[@]}}" \
"$ISODIR"/*/*/grub*.cfg \
"$ISODIR"/boot/isolinux/isolinux.cfg
""",
file=patcher_fd)
os.chmod(patcher_fd.fileno(), 0o755)

# do remaster
local_cmd([iso_remaster,
"--iso-patcher", patcher_script,
SOURCE_ISO, remastered_iso
])

# hopefully-unique filename on server (FIXME)
remote_iso = os.path.join(ISOSR_PATH, os.path.basename(isotmp)) + ".iso"
logging.info("Uploading to ISO-SR server remastered %s as %s",
remastered_iso, os.path.basename(remote_iso))
scp(ISOSR_SRV, remastered_iso, remote_iso)
# FIXME: is sr-scan ever needed?

try:
yield os.path.basename(remote_iso)
finally:
logging.info("Removing %s from ISO-SR server", os.path.basename(remote_iso))
ssh(ISOSR_SRV, ["rm", remote_iso])

@pytest.fixture(scope='module')
def vm_ref(request):
ref = request.param
Expand Down
9 changes: 9 additions & 0 deletions data.py-dist
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ PXE_CONFIG_SERVER = 'pxe'
# Default VM images location
DEF_VM_URL = 'http://pxe/images/'

# Default shared ISO SR
ISOSR_SRV = "nfs-server"
ISOSR_PATH = "/srv/iso-sr"

# Tools
TOOLS = {
# "iso-remaster": "/home/user/src/xcpng/xcp/scripts/iso-remaster/iso-remaster.sh",
}

# Values can be either full URLs or only partial URLs that will be automatically appended to DEF_VM_URL
VM_IMAGES = {
'mini-linux-x86_64-bios': 'alpine-minimal-3.12.0.xva',
Expand Down
4 changes: 2 additions & 2 deletions tests/install/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
network_uuid="eabc1038-e40f-2ae5-0781-a3adbec1cae8")],
))
class TestInstallNested:
def test_install_nested_821(self, create_vms):
def test_install_nested_821(self, create_vms, iso_remaster):
assert len(create_vms) == 1
host_vm = create_vms[0]

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

0 comments on commit 6403a03

Please sign in to comment.