Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Add Google image formatting to CLI #122

Merged
merged 1 commit into from
Nov 17, 2022
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
4 changes: 2 additions & 2 deletions src/rhelocator/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ def aws_regions() -> None:
@click.command()
def gcp_images() -> None:
"""Dump GCP images for all regions in JSON format."""
images = gcp.get_images()
click.echo(json.dumps(images, indent=2))
images = gcp.format_all_images()
dump_images(images)


@click.command()
Expand Down
2 changes: 1 addition & 1 deletion src/rhelocator/update_images/gcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def format_image(image: dict[str, str]) -> dict[str, str]:
"""

arch = image["architecture"]
image_id = image["id"]
image_id = image["name"]
Copy link
Member

Choose a reason for hiding this comment

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

Was id not correct? :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah while the GCP image properties do contain an "ID" tag it's not actually used to create a VM instance. The "name" in a Google image is what we consider the image id in AWS and Azure.. This is once again one of those weird differences between cloud providers.. tbh. I've only noticed when I was running the live CLI tests. Turns out, the "normalize_google_images" method doesn't even parse the id property.

Copy link
Member Author

Choose a reason for hiding this comment

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

Btw. fixed this in the Schema definition for sake of consistency!

date = image["creation_timestamp"]
version = parse_image_version_from_name(image["name"])

Expand Down
20 changes: 8 additions & 12 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,11 @@ def test_gcp_images_live(runner):
result = runner.invoke(cli.gcp_images)
parsed = json.loads(result.output)

assert isinstance(parsed, list)
assert isinstance(parsed["images"]["google"], list)

for img in parsed:
assert img["architecture"] in ["arm64", "x86_64"]
assert "creation_timestamp" in img
assert "Red Hat" in img["description"]
assert "rhel" in img["name"]
for image in parsed["images"]["google"]:
expected_keys = ["name", "arch", "version", "imageId", "date", "selflink"]
assert list(image.keys()) == expected_keys

assert result.exit_code == 0

Expand All @@ -156,12 +154,10 @@ def test_gcp_images_offline(mock_gcp_images, runner):
result = runner.invoke(cli.gcp_images)
parsed = json.loads(result.output)

assert isinstance(parsed, list)
assert isinstance(parsed["images"]["google"], list)

for img in parsed:
assert img["architecture"] in ["arm64", "x86_64"]
assert "creation_timestamp" in img
assert "Red Hat" in img["description"]
assert "rhel" in img["name"]
for image in parsed["images"]["google"]:
expected_keys = ["name", "arch", "version", "imageId", "date", "selflink"]
assert list(image.keys()) == expected_keys

assert result.exit_code == 0