From 792b6f2576f602b1e1dd7442488a231f2d802a0b 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 | 18 +++++++++++++----- selftests/unit/utils/vmimage.py | 11 ++++++----- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/avocado/utils/vmimage.py b/avocado/utils/vmimage.py index df3da973b0..1b69c9ff8d 100644 --- a/avocado/utils/vmimage.py +++ b/avocado/utils/vmimage.py @@ -218,8 +218,11 @@ def get_image_url(self): if self.url_old_images and int(self.version) <= 38: self.url_versions = self.url_old_images - self.url_images = self.url_versions + "{version}/" + cloud + "/{arch}/images/" - return super().get_image_url() + self.url_images = ( + self.url_versions + f"{self.version}/" + cloud + f"/{self.arch}/images/" + ) + image_url = super().get_image_url() + return image_url class FedoraImageProvider(FedoraImageProviderBase): @@ -235,7 +238,7 @@ 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$" + self.image_pattern = "Fedora-Cloud-Base-Generic-(?P{version})-(?P{build}).(?P{arch}).qcow2$" class FedoraSecondaryImageProvider(FedoraImageProviderBase): @@ -254,7 +257,7 @@ 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$" + self.image_pattern = "Fedora-Cloud-Base-Generic-(?P{version})-(?P{build}).(?P{arch}).qcow2$" class CentOSImageProvider(ImageProviderBase): @@ -585,6 +588,7 @@ def download(self): cache_dirs = [self.cache_dir] else: cache_dirs = self.cache_dir + LOG.debug(f"Attempting to download image from URL: {self.url}") asset_path = asset.Asset( name=self.url, asset_hash=self.checksum, @@ -657,6 +661,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: @@ -728,7 +735,8 @@ def get_best_provider(name=None, version=None, build=None, arch=None): for provider in IMAGE_PROVIDERS: if name is None or name == provider.name.lower(): try: - return provider(**provider_args) + selected_provider = provider(**provider_args) + return selected_provider except ImageProviderError as e: LOG.debug(e) diff --git a/selftests/unit/utils/vmimage.py b/selftests/unit/utils/vmimage.py index 3bd80ea881..28527723a8 100644 --- a/selftests/unit/utils/vmimage.py +++ b/selftests/unit/utils/vmimage.py @@ -523,13 +523,14 @@ 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" + image = f"Fedora-Cloud-Base-Generic-{expected_version}-{expected_build}.{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):