diff --git a/avocado/utils/vmimage.py b/avocado/utils/vmimage.py index df3da973b0..dfd979d310 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,11 +735,12 @@ 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) - LOG.debug("Provider for %s not available", name) + LOG.debug(f"Provider for {name} not available") raise AttributeError("Provider not available") 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):