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 12, 2024
1 parent 91752d4 commit 8761ddb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
14 changes: 12 additions & 2 deletions avocado/utils/vmimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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>{version})-(?P<build>{build}).(?P<arch>{arch}).qcow2$"
if int(self.version) >= 40:
self.image_pattern = "Fedora-Cloud-Base-Generic-(?P<version>{version})-(?P<build>{build}).(?P<arch>{arch}).qcow2$"
else:
self.image_pattern = "Fedora-Cloud-Base-(?P<version>{version})-(?P<build>{build}).(?P<arch>{arch}).qcow2$"


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


class CentOSImageProvider(ImageProviderBase):
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down
14 changes: 9 additions & 5 deletions selftests/unit/utils/vmimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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<version>{expected_version})-(?P<build>{expected_build}).(?P<arch>{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 8761ddb

Please sign in to comment.