From 8761ddbf3cf41c2344ab3b6bba6d38489c999261 Mon Sep 17 00:00:00 2001 From: Harvey Lynden Date: Tue, 10 Dec 2024 13:38:43 +0100 Subject: [PATCH] Fix image pattern for FedoraSecondary provider on s390x Updated the image pattern in FedoraSecondaryImageProvider to match the available Fedora image file names for the s390x architecture. This resolves the issue where the vmimage utility could not download the correct image due to a pattern mismatch. Reference: https://github.com/avocado-framework/avocado/issues/6071 Signed-off-by: Harvey Lynden --- avocado/utils/vmimage.py | 14 ++++++++++++-- selftests/unit/utils/vmimage.py | 14 +++++++++----- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/avocado/utils/vmimage.py b/avocado/utils/vmimage.py index df3da973b0..8219ef205f 100644 --- a/avocado/utils/vmimage.py +++ b/avocado/utils/vmimage.py @@ -235,7 +235,10 @@ def __init__(self, version="[0-9]+", build="[0-9]+.[0-9]+", arch=DEFAULT_ARCH): self.url_old_images = ( "https://archives.fedoraproject.org/pub/archive/fedora/linux/releases/" ) - self.image_pattern = "Fedora-Cloud-Base-(?P{version})-(?P{build}).(?P{arch}).qcow2$" + if int(self.version) >= 40: + self.image_pattern = "Fedora-Cloud-Base-Generic-(?P{version})-(?P{build}).(?P{arch}).qcow2$" + else: + self.image_pattern = "Fedora-Cloud-Base-(?P{version})-(?P{build}).(?P{arch}).qcow2$" class FedoraSecondaryImageProvider(FedoraImageProviderBase): @@ -254,7 +257,10 @@ def __init__(self, version="[0-9]+", build="[0-9]+.[0-9]+", arch=DEFAULT_ARCH): self.url_old_images = ( "https://archives.fedoraproject.org/pub/archive/fedora-secondary/releases/" ) - self.image_pattern = "Fedora-Cloud-Base-(?P{version})-(?P{build}).(?P{arch}).qcow2$" + if int(self.version) >= 40: + self.image_pattern = "Fedora-Cloud-Base-Generic-(?P{version})-(?P{build}).(?P{arch}).qcow2$" + else: + self.image_pattern = "Fedora-Cloud-Base-(?P{version})-(?P{build}).(?P{arch}).qcow2$" class CentOSImageProvider(ImageProviderBase): @@ -585,6 +591,7 @@ def download(self): cache_dirs = [self.cache_dir] else: cache_dirs = self.cache_dir + LOG.debug("Attempting to download image from URL: %s", self.url) asset_path = asset.Asset( name=self.url, asset_hash=self.checksum, @@ -657,6 +664,9 @@ def from_parameters( :returns: Image instance that can provide the image according to the parameters. """ + # Use the current system architecture if arch is not provided + if arch is None: + arch = DEFAULT_ARCH provider = get_best_provider(name, version, build, arch) if cache_dir is None: diff --git a/selftests/unit/utils/vmimage.py b/selftests/unit/utils/vmimage.py index 3bd80ea881..4156f266e5 100644 --- a/selftests/unit/utils/vmimage.py +++ b/selftests/unit/utils/vmimage.py @@ -523,13 +523,17 @@ def test_get_image_parameters_match(self, urlopen_mock): urlread_mocked = unittest.mock.Mock(return_value=self.VERSION_LISTING) urlopen_mock.return_value = unittest.mock.Mock(read=urlread_mocked) provider = vmimage.FedoraImageProvider( - expected_version, expected_build, expected_arch + version=expected_version, build=expected_build, arch=expected_arch ) - image = f"Fedora-Cloud-Base-{expected_version}-{expected_build}.{expected_arch}.qcow2" + if int(expected_version) >= 40: + image = f"Fedora-Cloud-Base-Generic-{expected_version}-{expected_build}.{expected_arch}.qcow2" + else: + image = f"Fedora-Cloud-Base-(?P{expected_version})-(?P{expected_build}).(?P{expected_arch}).qcow2$" parameters = provider.get_image_parameters(image) - self.assertEqual(expected_version, parameters["version"]) - self.assertEqual(expected_build, parameters["build"]) - self.assertEqual(expected_arch, parameters["arch"]) + self.assertIsNotNone(parameters, "get_image_parameters() returned None") + self.assertEqual(expected_version, parameters.get("version")) + self.assertEqual(expected_build, parameters.get("build")) + self.assertEqual(expected_arch, parameters.get("arch")) @unittest.mock.patch("avocado.utils.vmimage.urlopen") def test_get_image_parameters_not_match(self, urlopen_mock):