Skip to content

Commit

Permalink
Fix image pattern for FedoraSecondary provider on s390x
Browse files Browse the repository at this point in the history
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: #6071
Signed-off-by: Harvey Lynden <hlynden@redhat.com>
  • Loading branch information
harvey0100 committed Dec 10, 2024
1 parent 91752d4 commit b7baffa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
22 changes: 15 additions & 7 deletions avocado/utils/vmimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (

Check warning on line 221 in avocado/utils/vmimage.py

View check run for this annotation

Codecov / codecov/patch

avocado/utils/vmimage.py#L221

Added line #L221 was not covered by tests
self.url_versions + f"{self.version}/" + cloud + f"/{self.arch}/images/"
)
image_url = super().get_image_url()
return image_url

Check warning on line 225 in avocado/utils/vmimage.py

View check run for this annotation

Codecov / codecov/patch

avocado/utils/vmimage.py#L224-L225

Added lines #L224 - L225 were not covered by tests


class FedoraImageProvider(FedoraImageProviderBase):
Expand All @@ -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>{version})-(?P<build>{build}).(?P<arch>{arch}).qcow2$"
self.image_pattern = "Fedora-Cloud-Base-Generic-(?P<version>{version})-(?P<build>{build}).(?P<arch>{arch}).qcow2$"


class FedoraSecondaryImageProvider(FedoraImageProviderBase):
Expand All @@ -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>{version})-(?P<build>{build}).(?P<arch>{arch}).qcow2$"
self.image_pattern = "Fedora-Cloud-Base-Generic-(?P<version>{version})-(?P<build>{build}).(?P<arch>{arch}).qcow2$"


class CentOSImageProvider(ImageProviderBase):
Expand Down Expand Up @@ -585,6 +588,7 @@ def download(self):
cache_dirs = [self.cache_dir]
else:
cache_dirs = self.cache_dir
print(f"Attempting to download image from URL: {self.url}")

Check warning on line 591 in avocado/utils/vmimage.py

View check run for this annotation

Codecov / codecov/patch

avocado/utils/vmimage.py#L591

Added line #L591 was not covered by tests
asset_path = asset.Asset(
name=self.url,
asset_hash=self.checksum,
Expand Down Expand Up @@ -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

Check warning on line 666 in avocado/utils/vmimage.py

View check run for this annotation

Codecov / codecov/patch

avocado/utils/vmimage.py#L665-L666

Added lines #L665 - L666 were not covered by tests
provider = get_best_provider(name, version, build, arch)

if cache_dir is None:
Expand Down Expand Up @@ -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

Check warning on line 739 in avocado/utils/vmimage.py

View check run for this annotation

Codecov / codecov/patch

avocado/utils/vmimage.py#L738-L739

Added lines #L738 - L739 were not covered by tests
except ImageProviderError as e:
LOG.debug(e)
print(f"Error instantiating provider {provider.name}: {e}")

Check warning on line 741 in avocado/utils/vmimage.py

View check run for this annotation

Codecov / codecov/patch

avocado/utils/vmimage.py#L741

Added line #L741 was not covered by tests

LOG.debug("Provider for %s not available", name)
print(f"Provider for {name} not available")

Check warning on line 743 in avocado/utils/vmimage.py

View check run for this annotation

Codecov / codecov/patch

avocado/utils/vmimage.py#L743

Added line #L743 was not covered by tests
raise AttributeError("Provider not available")


Expand Down
11 changes: 6 additions & 5 deletions selftests/unit/utils/vmimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit b7baffa

Please sign in to comment.