|
1 | 1 | import logging
|
| 2 | +import os |
2 | 3 | import pytest
|
3 | 4 | import tempfile
|
4 | 5 |
|
5 | 6 | from packaging import version
|
6 | 7 |
|
7 | 8 | import lib.config as global_config
|
8 | 9 |
|
| 10 | +from lib.commands import local_cmd, scp, ssh |
9 | 11 | from lib.common import wait_for, vm_image, is_uuid
|
10 | 12 | from lib.common import setup_formatted_and_mounted_disk, teardown_formatted_and_mounted_disk
|
11 | 13 | from lib.netutil import is_ipv6
|
@@ -254,6 +256,62 @@ def sr_disk_for_all_hosts(request, host):
|
254 | 256 | logging.info(f">> Disk or block device {disk} is present and free on all pool members")
|
255 | 257 | yield candidates[0]
|
256 | 258 |
|
| 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 | + |
257 | 315 | @pytest.fixture(scope='module')
|
258 | 316 | def vm_ref(request):
|
259 | 317 | ref = request.param
|
|
0 commit comments