|
1 | 1 | import os |
2 | 2 | import platform |
| 3 | +import shutil |
| 4 | +import subprocess |
3 | 5 |
|
4 | 6 | import pytest |
5 | 7 | import requests |
|
10 | 12 | from .driver import UbootConsole |
11 | 13 | from jumpstarter.common.utils import serve |
12 | 14 |
|
| 15 | +UBOOT_RPM_URL = "https://kojipkgs.fedoraproject.org/packages/uboot-tools/2025.10/1.fc43/noarch/uboot-images-armv8-2025.10-1.fc43.noarch.rpm" |
| 16 | + |
13 | 17 |
|
14 | 18 | @pytest.fixture(scope="session") |
15 | 19 | def uboot_image(tmpdir_factory): |
16 | 20 | tmp_path = tmpdir_factory.mktemp("uboot-images") |
17 | | - |
18 | | - url = "https://kojipkgs.fedoraproject.org/packages/uboot-tools/2025.10/1.fc43/noarch/uboot-images-armv8-2025.10-1.fc43.noarch.rpm" |
19 | | - |
20 | | - with requests.get(url, stream=True) as r: |
21 | | - r.raise_for_status() |
22 | | - with (tmp_path / "uboot-images-armv8.rpm").open("wb") as f: |
23 | | - for chunk in r.iter_content(chunk_size=8192): |
24 | | - f.write(chunk) |
25 | | - |
26 | | - with rpmfile.open(tmp_path / "uboot-images-armv8.rpm") as rpm: |
27 | | - fd = rpm.extractfile("./usr/share/uboot/qemu_arm64/u-boot.bin") |
28 | | - with (tmp_path / "u-boot.bin").open("wb") as f: |
29 | | - f.write(fd.read()) |
30 | | - |
31 | | - yield tmp_path / "u-boot.bin" |
| 21 | + rpm_path = tmp_path / "uboot-images-armv8.rpm" |
| 22 | + bin_path = tmp_path / "u-boot.bin" |
| 23 | + |
| 24 | + print(f"\nDownloading u-boot RPM from {UBOOT_RPM_URL}") |
| 25 | + try: |
| 26 | + with requests.get(UBOOT_RPM_URL, stream=True, timeout=120) as r: |
| 27 | + r.raise_for_status() |
| 28 | + total = int(r.headers.get("content-length", 0)) |
| 29 | + downloaded = 0 |
| 30 | + with rpm_path.open("wb") as f: |
| 31 | + for chunk in r.iter_content(chunk_size=8192): |
| 32 | + f.write(chunk) |
| 33 | + downloaded += len(chunk) |
| 34 | + print(f"Downloaded {downloaded} bytes (expected {total})") |
| 35 | + except requests.RequestException as e: |
| 36 | + raise AssertionError(f"Failed to download u-boot RPM: {e}") from e |
| 37 | + |
| 38 | + print("Extracting u-boot.bin from RPM...") |
| 39 | + if shutil.which("rpm2cpio") and shutil.which("cpio"): |
| 40 | + subprocess.run( |
| 41 | + f"rpm2cpio {rpm_path} | cpio -idm --quiet ./usr/share/uboot/qemu_arm64/u-boot.bin", |
| 42 | + shell=True, cwd=str(tmp_path), check=True, |
| 43 | + ) |
| 44 | + extracted = tmp_path / "usr" / "share" / "uboot" / "qemu_arm64" / "u-boot.bin" |
| 45 | + extracted.rename(bin_path) |
| 46 | + else: |
| 47 | + with rpmfile.open(rpm_path) as rpm: |
| 48 | + fd = rpm.extractfile("./usr/share/uboot/qemu_arm64/u-boot.bin") |
| 49 | + with bin_path.open("wb") as f: |
| 50 | + f.write(fd.read()) |
| 51 | + print(f"Extracted u-boot.bin ({bin_path.size()} bytes)") |
| 52 | + |
| 53 | + yield bin_path |
32 | 54 |
|
33 | 55 |
|
34 | 56 | @pytest.mark.xfail( |
|
0 commit comments