-
Notifications
You must be signed in to change notification settings - Fork 6
Add mirror fallback for Debian cloud image downloads #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
thrix
wants to merge
1
commit into
main
Choose a base branch
from
debian-mirror-fallback
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| # -*- coding: utf-8 -*- | ||
| # Copyright 2025, Red Hat, Inc. | ||
| # License: GPL-2.0+ <http://spdx.org/licenses/GPL-2.0+> | ||
| # See the LICENSE file for more details on Licensing | ||
|
|
||
| """Tests for Debian cloud image URL generation.""" | ||
|
|
||
| import pytest | ||
|
|
||
| from testcloud import config, exceptions | ||
| from testcloud.distro_utils import debian | ||
| from testcloud.distro_utils.debian import get_debian_image_url | ||
|
|
||
|
|
||
| PRIMARY = "https://cdimage.debian.org/images/cloud" | ||
| FALLBACK = "https://cloud.debian.org/images/cloud" | ||
|
|
||
|
|
||
| class TestGetDebianImageUrl(object): | ||
|
|
||
| def setup_method(self, method): | ||
| config._config = None | ||
|
|
||
| def teardown_method(self, method): | ||
| config._config = None | ||
|
|
||
| def test_latest(self, monkeypatch): | ||
| monkeypatch.setattr(config, "CONF_DIRS", []) | ||
| urls = get_debian_image_url(version="latest", arch="x86_64") | ||
| assert len(urls) == 2 | ||
| assert "bookworm" in urls[0] | ||
| assert "genericcloud-amd64" in urls[0] | ||
| assert urls[0].startswith(PRIMARY) | ||
| assert urls[1].startswith(FALLBACK) | ||
|
|
||
| def test_version_number(self, monkeypatch): | ||
| monkeypatch.setattr(config, "CONF_DIRS", []) | ||
| urls = get_debian_image_url(version="12", arch="x86_64") | ||
| assert "bookworm" in urls[0] | ||
| assert "debian-12-genericcloud" in urls[0] | ||
|
|
||
| def test_codename(self, monkeypatch): | ||
| monkeypatch.setattr(config, "CONF_DIRS", []) | ||
| urls = get_debian_image_url(version="bookworm", arch="x86_64") | ||
| assert "bookworm" in urls[0] | ||
| assert "debian-12-genericcloud" in urls[0] | ||
|
|
||
| def test_sid(self, monkeypatch): | ||
| monkeypatch.setattr(config, "CONF_DIRS", []) | ||
| urls = get_debian_image_url(version="sid", arch="x86_64") | ||
| assert "sid/daily/latest/debian-sid-genericcloud-amd64-daily.qcow2" in urls[0] | ||
|
|
||
| def test_invalid_version(self, monkeypatch): | ||
| monkeypatch.setattr(config, "CONF_DIRS", []) | ||
| with pytest.raises(exceptions.TestcloudImageError): | ||
| get_debian_image_url(version="99", arch="x86_64") | ||
|
|
||
| def test_unsupported_arch(self, monkeypatch): | ||
| monkeypatch.setattr(config, "CONF_DIRS", []) | ||
| with pytest.raises(exceptions.TestcloudImageError): | ||
| get_debian_image_url(version="latest", arch="s390x") | ||
|
|
||
| def test_aarch64_uses_generic(self, monkeypatch): | ||
| monkeypatch.setattr(config, "CONF_DIRS", []) | ||
| urls = get_debian_image_url(version="12", arch="aarch64") | ||
| for url in urls: | ||
| assert "generic-arm64" in url | ||
| assert "genericcloud" not in url | ||
|
|
||
| def test_str_config_compat(self, monkeypatch): | ||
| monkeypatch.setattr(config, "CONF_DIRS", []) | ||
| monkeypatch.setattr(debian.config_data, "DEBIAN_IMG_URL", | ||
| "https://example.com/%s/%s/%s.qcow2") | ||
| urls = get_debian_image_url(version="12", arch="x86_64") | ||
| assert len(urls) == 1 | ||
| assert urls[0].startswith("https://example.com/") | ||
|
|
||
| def test_list_config(self, monkeypatch): | ||
| monkeypatch.setattr(config, "CONF_DIRS", []) | ||
| monkeypatch.setattr(debian.config_data, "DEBIAN_IMG_URL", [ | ||
| "https://mirror1.example.com/%s/%s/%s.qcow2", | ||
| "https://mirror2.example.com/%s/%s/%s.qcow2", | ||
| "https://mirror3.example.com/%s/%s/%s.qcow2", | ||
| ]) | ||
| urls = get_debian_image_url(version="12", arch="x86_64") | ||
| assert len(urls) == 3 | ||
| assert urls[0].startswith("https://mirror1") | ||
| assert urls[2].startswith("https://mirror3") | ||
|
|
||
| def test_no_config_mutation(self, monkeypatch): | ||
| monkeypatch.setattr(config, "CONF_DIRS", []) | ||
| cfg = config.get_config() | ||
| original = list(cfg.DEBIAN_IMG_URL) if isinstance(cfg.DEBIAN_IMG_URL, list) else cfg.DEBIAN_IMG_URL | ||
|
|
||
| get_debian_image_url(version="12", arch="aarch64") | ||
|
|
||
| if isinstance(original, list): | ||
| assert cfg.DEBIAN_IMG_URL == original | ||
| for template in cfg.DEBIAN_IMG_URL: | ||
| assert "genericcloud" in template | ||
| else: | ||
| assert cfg.DEBIAN_IMG_URL == original | ||
| assert "genericcloud" in cfg.DEBIAN_IMG_URL |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it worth it to have fallback mechanism though? What exactly is it meant to catch during the fallback, that it the cdn is slow, that it is unreachable?
And on top of that we only treat Debian as such a special snowflake?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
felt like a more safer approach, just in case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also it might be more sources in the future for images would be needed, so decided to go this way, it is up for dicussion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would want a clear definition of what issues are being caught for the fallback and a generalization for the others as well.
For example, if a connection is slow but still responsive, then we do not address the original issue for this, we just introduce a more niche way that it could fail that is harder to find out or debug.