|
| 1 | +import re |
| 2 | +import logging |
| 3 | +from urllib.request import urlopen |
| 4 | + |
1 | 5 | from virttest import virsh |
2 | 6 | from virttest import libvirt_version |
3 | 7 |
|
|
7 | 11 | from virttest.utils_libvirtd import Libvirtd |
8 | 12 | from virttest.utils_config import LibvirtQemuConfig |
9 | 13 |
|
| 14 | +LOG = logging.getLogger('avocado.' + __name__) |
| 15 | + |
| 16 | + |
| 17 | +def get_latest_fedora_version(base_url): |
| 18 | + """ |
| 19 | + Get the latest Fedora version from the releases directory. |
| 20 | +
|
| 21 | + :param base_url: Base URL of Fedora releases directory |
| 22 | + :return: Latest version number as string |
| 23 | + """ |
| 24 | + try: |
| 25 | + html = urlopen(base_url, timeout=10).read().decode('utf-8') |
| 26 | + vers = re.findall(r'>(\d+)/<', html) |
| 27 | + if not vers: |
| 28 | + raise RuntimeError(f"No version directories found at {base_url}") |
| 29 | + LOG.info(f"Found the latest Fedora version: {max(vers, key=int)}") |
| 30 | + return max(vers, key=int) |
| 31 | + except Exception as e: |
| 32 | + raise Exception(f"Failed to get latest version from {base_url}: {str(e)}") |
| 33 | + |
| 34 | + |
| 35 | +def get_fedora_iso_build(base_url, version, arch="x86_64", server_type="Server"): |
| 36 | + """ |
| 37 | + Get the exact build number from the ISO directory listing. |
| 38 | +
|
| 39 | + :param base_url: Base URL of Fedora releases directory |
| 40 | + :param version: Fedora version number |
| 41 | + :param arch: System architecture, default is "x86_64" |
| 42 | + :param server_type: Server type, default is "Server" |
| 43 | + :return: Build number as string (e.g., "1.6") |
| 44 | + """ |
| 45 | + iso_dir_url = f"{base_url}{version}/{server_type}/{arch}/iso/" |
| 46 | + try: |
| 47 | + html = urlopen(iso_dir_url, timeout=10).read().decode('utf-8') |
| 48 | + pattern = rf"Fedora-{server_type}-netinst-{arch}-{version}-([\d.]+)\.iso" |
| 49 | + match = re.search(pattern, html) |
| 50 | + if not match: |
| 51 | + raise RuntimeError(f"Cannot find netinst ISO filename in directory listing at {iso_dir_url}") |
| 52 | + LOG.info(f"Found the Fedora build number: {match.group(1)}") |
| 53 | + return match.group(1) |
| 54 | + except Exception as e: |
| 55 | + raise Exception(f"Failed to get build number from {iso_dir_url}: {str(e)}") |
| 56 | + |
| 57 | + |
| 58 | +def get_latest_fedora_iso_url(base_url, arch="x86_64", server_type="Server"): |
| 59 | + """ |
| 60 | + Get the latest Fedora Server netinst ISO path or URL. |
| 61 | +
|
| 62 | + :param base_url: Base URL of Fedora releases |
| 63 | + :param arch: System architecture, default is "x86_64" |
| 64 | + :param server_type: Server type, default is "Server" |
| 65 | + :return: ISO path |
| 66 | + """ |
| 67 | + version = get_latest_fedora_version(base_url) |
| 68 | + build = get_fedora_iso_build(base_url, version, arch, server_type) |
| 69 | + |
| 70 | + iso_path = ( |
| 71 | + f"/fedora/linux/releases/{version}/{server_type}/{arch}/iso/" |
| 72 | + f"Fedora-{server_type}-netinst-{arch}-{version}-{build}.iso" |
| 73 | + ) |
| 74 | + return iso_path |
| 75 | + |
10 | 76 |
|
11 | 77 | def run(test, params, env): |
12 | 78 | """ |
@@ -34,7 +100,8 @@ def prepare_disk(): |
34 | 100 | :param disk_obj: return the disk object. |
35 | 101 | """ |
36 | 102 | network_device = params.get("network_device") |
37 | | - disk_dict = eval(params.get("disk_dict", "{}") % network_device) |
| 103 | + iso_path = get_latest_fedora_iso_url(base_url, arch="x86_64", server_type="Server") |
| 104 | + disk_dict = eval(params.get("disk_dict", "{}") % (network_device, iso_path)) |
38 | 105 | disk_obj = libvirt_vmxml.create_vm_device_by_type("disk", disk_dict) |
39 | 106 | if not with_hotplug: |
40 | 107 | libvirt.add_vm_device(vmxml, disk_obj) |
@@ -64,6 +131,7 @@ def check_result(disk_in_vm=True): |
64 | 131 | expected_xpaths = eval(params.get("expected_xpaths")) |
65 | 132 | cookie_in_dumpxml = params.get("cookie_in_dumpxml") |
66 | 133 | with_hotplug = "yes" == params.get("with_hotplug", "no") |
| 134 | + base_url = params.get("base_url") |
67 | 135 |
|
68 | 136 | vmxml = vm_xml.VMXML.new_from_inactive_dumpxml(vm_name) |
69 | 137 | backup_vmxml = vmxml.copy() |
|
0 commit comments