Skip to content

Commit 6011393

Browse files
authored
Merge pull request #6767 from meinaLi/fix_https
Virtual disk: fix URL returned error issue for https network disk
2 parents 6855b50 + 847ff81 commit 6011393

2 files changed

Lines changed: 71 additions & 3 deletions

File tree

libvirt/tests/cfg/virtual_disks/virtual_disks_https.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
target_disk = "sdb"
55
disk_format = "raw"
66
source_host_name = "insect.mm.fcix.net"
7-
source_iso_name = "/fedora/linux/releases/41/Server/x86_64/iso/Fedora-Server-netinst-x86_64-41-1.4.iso"
7+
base_url = "https://insect.mm.fcix.net/fedora/linux/releases/"
88
cookie_name = "vmware_soap_session"
99
cookie_value = "314455dbd2eaafd7d76b3b7828f0a3e3956450f9"
1010
expected_xpaths = [{'element_attrs': [".//ssl[@verify='yes']"]}, {'element_attrs': [".//readahead[@size='1024']"]}, {'element_attrs': [".//timeout[@seconds='60']"]}]
1111
cookie_in_dumpxml = "${cookie_name}.*${cookie_value}"
1212
driver_dict = "'driver': {'name': 'qemu', 'type': '${disk_format}'}"
1313
source_extra_dict = "'cookies': {'cookie_name': '${cookie_name}', 'cookie': '${cookie_value}'}, 'readahead': '1024', 'timeout': '60', 'ssl': 'yes'"
14-
source_dict = "'source': {'hosts': [{'name': '${source_host_name}'}], 'attrs': {'protocol': 'https', 'name': '${source_iso_name}'}, ${source_extra_dict}}"
14+
source_dict = "'source': {'hosts': [{'name': '${source_host_name}'}], 'attrs': {'protocol': 'https', 'name': '%s'}, ${source_extra_dict}}"
1515
disk_dict = {'type_name': 'network', 'readonly': True, 'device': '%s', ${driver_dict}, ${source_dict}, 'target': {'dev': '${target_disk}', 'bus': 'scsi'}}
1616
func_supported_since_libvirt_ver = (10, 10, 0)
1717
variants:

libvirt/tests/src/virtual_disks/virtual_disks_https.py

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import re
2+
import logging
3+
from urllib.request import urlopen
4+
15
from virttest import virsh
26
from virttest import libvirt_version
37

@@ -7,6 +11,68 @@
711
from virttest.utils_libvirtd import Libvirtd
812
from virttest.utils_config import LibvirtQemuConfig
913

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+
1076

1177
def run(test, params, env):
1278
"""
@@ -34,7 +100,8 @@ def prepare_disk():
34100
:param disk_obj: return the disk object.
35101
"""
36102
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))
38105
disk_obj = libvirt_vmxml.create_vm_device_by_type("disk", disk_dict)
39106
if not with_hotplug:
40107
libvirt.add_vm_device(vmxml, disk_obj)
@@ -64,6 +131,7 @@ def check_result(disk_in_vm=True):
64131
expected_xpaths = eval(params.get("expected_xpaths"))
65132
cookie_in_dumpxml = params.get("cookie_in_dumpxml")
66133
with_hotplug = "yes" == params.get("with_hotplug", "no")
134+
base_url = params.get("base_url")
67135

68136
vmxml = vm_xml.VMXML.new_from_inactive_dumpxml(vm_name)
69137
backup_vmxml = vmxml.copy()

0 commit comments

Comments
 (0)