Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions core/services/versionchooser/test_versionchooser.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import pytest

from utils.chooser import VersionChooser
from utils.dockerhub import TagFetcher, TagMetadata

# All test coroutines will be treated as marked.
pytestmark = pytest.mark.asyncio
Expand Down Expand Up @@ -236,3 +237,41 @@ async def is_valid_version(image: str) -> Tuple[bool, str]:
result = await chooser.set_version("bluerobotics/blueos-core", "master")
assert result.status == 500
assert len(json_mock.mock_calls) > 0


class TestTagFetcher:
"""Test class for TagFetcher functionality"""

@pytest.mark.asyncio
async def test_fetch_real_blueos_core_tags(self) -> None:
"""Integration test: Fetch real tags from bluerobotics/blueos-core repository"""
fetcher = TagFetcher()

try:
errors, tags = await fetcher.fetch_remote_tags("bluerobotics/blueos-core", [])

# Verify we got some tags back
assert isinstance(tags, list)
assert len(tags) > 0, "Should have found some tags for bluerobotics/blueos-core"

# Verify tag structure
for tag in tags[:3]: # Check first 3 tags
assert isinstance(tag, TagMetadata)
assert tag.repository == "bluerobotics/blueos-core"
assert tag.image == "blueos-core"
assert tag.tag is not None
assert len(tag.tag) > 0
assert tag.last_modified is not None
assert tag.digest is not None

# Should find the 'master' tag
tag_names = [tag.tag for tag in tags]
assert "master" in tag_names, f"Expected to find 'master' tag in tags: {tag_names[:10]}"

# Errors should be empty string if successful
if errors:
print(f"Non-fatal errors during fetch: {errors}")

except Exception as e:
# If this fails due to network issues, skip the test
pytest.skip(f"Could not fetch tags from DockerHub, likely network issue: {e}")
16 changes: 16 additions & 0 deletions core/services/versionchooser/utils/dockerhub.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,22 @@ async def fetch_remote_tags(self, repository: str, local_images: List[str]) -> T
my_architecture = get_current_arch()
valid_images = []
for tag in tags:
images = tag["images"]
if len(images) == 0:
# this is a hack to deal with https://github.com/docker/hub-feedback/issues/2484
# we lost the ability to properly identify the images as we dont have the digest,
# and also the ability to filter for compatible architectures.
# so we just add the tag and hope for the best.
tag = TagMetadata(
repository=repository,
image=repository.split("/")[-1],
tag=tag["name"],
last_modified=tag["last_updated"],
sha=None,
digest="------",
)
valid_images.append(tag)
continue
for image in tag["images"]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for image in tag["images"]:
for image in images:

If they've already been fetched into a variable, it makes sense to use that variable, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a cherry-pick from master, it would be nice to move this change to master not here

if image["architecture"] == my_architecture:
tag = TagMetadata(
Expand Down
Loading