diff --git a/src/rhelocator/api/routes/gcp.py b/src/rhelocator/api/routes/google.py similarity index 80% rename from src/rhelocator/api/routes/gcp.py rename to src/rhelocator/api/routes/google.py index c6f13a91..6b8fca9a 100644 --- a/src/rhelocator/api/routes/gcp.py +++ b/src/rhelocator/api/routes/google.py @@ -5,7 +5,7 @@ from flask import request -def gcp_blueprint(data: list[dict[str, str]]) -> Blueprint: +def google_blueprint(data: list[dict[str, str]]) -> Blueprint: """Creates and returns a Flask blueprint based that serves the provided image data. @@ -15,13 +15,13 @@ def gcp_blueprint(data: list[dict[str, str]]) -> Blueprint: Returns: Flask blueprint serving the provided data. """ - gcp_endpoint = Blueprint("gcp_api", __name__) + google_endpoint = Blueprint("google_api", __name__) - @gcp_endpoint.route("/gcp", methods=["GET"]) - @swag_from("../schema/gcp.yml") + @google_endpoint.route("/google", methods=["GET"]) + @swag_from("../schema/google.yml") def endpoint() -> list[dict[str, str]]: - """Cloud Image Locator GCP Endpoint Provides RHEL image data for Google - Cloud.""" + """Cloud Image Locator GOOGLE Endpoint Provides RHEL image data for + Google Cloud.""" query: dict[str, str] = {} name: Optional[str] = request.args.get("name") @@ -55,4 +55,4 @@ def endpoint() -> list[dict[str, str]]: response.append(image) return response - return gcp_endpoint + return google_endpoint diff --git a/src/rhelocator/api/schema/gcp.yml b/src/rhelocator/api/schema/google.yml similarity index 100% rename from src/rhelocator/api/schema/gcp.yml rename to src/rhelocator/api/schema/google.yml diff --git a/src/rhelocator/api/server.py b/src/rhelocator/api/server.py index 0dd05c7e..274cc73c 100644 --- a/src/rhelocator/api/server.py +++ b/src/rhelocator/api/server.py @@ -6,7 +6,7 @@ from rhelocator.api.routes.aws import aws_blueprint from rhelocator.api.routes.azure import azure_blueprint -from rhelocator.api.routes.gcp import gcp_blueprint +from rhelocator.api.routes.google import google_blueprint from rhelocator.update_images import schema @@ -40,7 +40,7 @@ def create_app(file_path: str) -> Flask: ) app.register_blueprint( - gcp_blueprint(image_data["images"]["google"]), url_prefix="/api" + google_blueprint(image_data["images"]["google"]), url_prefix="/api" ) app.register_blueprint( diff --git a/src/rhelocator/cli.py b/src/rhelocator/cli.py index 82b16882..5509a348 100644 --- a/src/rhelocator/cli.py +++ b/src/rhelocator/cli.py @@ -10,7 +10,7 @@ from rhelocator.api import server from rhelocator.update_images import aws from rhelocator.update_images import azure -from rhelocator.update_images import gcp +from rhelocator.update_images import google from rhelocator.update_images import schema @@ -54,9 +54,9 @@ def aws_regions() -> None: @click.command() -def gcp_images() -> None: - """Dump GCP images for all regions in JSON format.""" - images = gcp.format_all_images() +def google_images() -> None: + """Dump GOOGLE images for all regions in JSON format.""" + images = google.format_all_images() dump_images(images) @@ -106,5 +106,5 @@ def serve(file_path: str, port: int, host: str, dev: bool) -> None: cli.add_command(aws_hourly_images) cli.add_command(aws_regions) cli.add_command(azure_images) -cli.add_command(gcp_images) +cli.add_command(google_images) cli.add_command(serve) diff --git a/src/rhelocator/config.py b/src/rhelocator/config.py index 0efcf7ac..d0f93392 100644 --- a/src/rhelocator/config.py +++ b/src/rhelocator/config.py @@ -52,4 +52,4 @@ # \____/\____/_/ # Defines project name. -GCP_PROJECTNAME = "rhel-cloud" +GOOGLE_PROJECTNAME = "rhel-cloud" diff --git a/src/rhelocator/update_images/gcp.py b/src/rhelocator/update_images/google.py similarity index 91% rename from src/rhelocator/update_images/gcp.py rename to src/rhelocator/update_images/google.py index c903d8dc..b9e63641 100644 --- a/src/rhelocator/update_images/gcp.py +++ b/src/rhelocator/update_images/google.py @@ -21,7 +21,9 @@ def get_images() -> list[dict[str, str]]: # NOTE(mhayden): Google's examples suggest using a filter here for "deprecated.state # != DEPRECATED" but it returns no images when I tried it. # https://github.com/googleapis/python-compute/blob/main/samples/recipes/images/pagination.py - images_list_request = compute_v1.ListImagesRequest(project=config.GCP_PROJECTNAME) + images_list_request = compute_v1.ListImagesRequest( + project=config.GOOGLE_PROJECTNAME + ) # Normalize the data first. @@ -37,9 +39,9 @@ def get_images() -> list[dict[str, str]]: def normalize_google_images(image_list: list[Any]) -> list[dict[str, str]]: """Normalize the data returned from Google's image listing. - The GCP SDK returns an unusual object with repeated attributes and some attributes - lead to other interesting objects. The goal here is to normalize this data so that - it's dict-like, similar to the Azure and AWS functions. + The GOOGLE SDK returns an unusual object with repeated attributes and some + attributes lead to other interesting objects. The goal here is to normalize + this data so that it's dict-like, similar to the Azure and AWS functions. Args: image_list: A Google image listing from the ImagesClient class. diff --git a/tests/api/test_server.py b/tests/api/test_server.py index 04fee0f0..7d3544ae 100644 --- a/tests/api/test_server.py +++ b/tests/api/test_server.py @@ -30,15 +30,15 @@ def runner(app): return app.test_cli_runner() -def test_request_gcp(client): - response = client.get("/api/gcp") +def test_request_google(client): + response = client.get("/api/google") assert len(response.data) > 0 assert response.status_code == 200 -def test_request_gcp_with_query(client): +def test_request_google_with_query(client): response = client.get( - "/api/gcp", + "/api/google", query_string={ "version": "9", }, @@ -48,7 +48,7 @@ def test_request_gcp_with_query(client): assert response.status_code == 200 -def test_request_gcp_with_multi_query(client): +def test_request_google_with_multi_query(client): test_query = { "name": "RHEL 9", "arch": "arm64", @@ -56,7 +56,7 @@ def test_request_gcp_with_multi_query(client): "imageId": "rhel-9", "date": "2022-11-02", } - response = client.get("/api/gcp", query_string=test_query) + response = client.get("/api/google", query_string=test_query) for image in json.loads(response.data): assert test_query["name"] in image["name"] assert test_query["arch"] in image["arch"] diff --git a/tests/conftest.py b/tests/conftest.py index 6b042292..144ba81f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -132,9 +132,9 @@ def mock_azure_images(mocker): @pytest.fixture -def mock_gcp_images(mocker): +def mock_google_images(mocker): """Provide an offline result for calls to get_google_images.""" - mock = mocker.patch("rhelocator.update_images.gcp.get_images") + mock = mocker.patch("rhelocator.update_images.google.get_images") mocked_image = { "id": "rhel-7-9-sap-v20220719", @@ -151,7 +151,7 @@ def mock_gcp_images(mocker): @pytest.fixture def mock_normalize_google_images(mocker): """Provide an offline result for calls to normalize_google_images.""" - mock = mocker.patch("rhelocator.update_images.gcp.normalize_google_images") + mock = mocker.patch("rhelocator.update_images.google.normalize_google_images") # Fake a Google image listing. mocked_image = MagicMock() diff --git a/tests/test_cli.py b/tests/test_cli.py index 7c6f41dc..93f0a161 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -132,9 +132,9 @@ def test_azure_images_offline( @pytest.mark.e2e -def test_gcp_images_live(runner): +def test_google_images_live(runner): """Run a live test against the Google Cloud API to get images via CLI.""" - result = runner.invoke(cli.gcp_images) + result = runner.invoke(cli.google_images) parsed = json.loads(result.output) assert isinstance(parsed["images"]["google"], list) @@ -146,9 +146,9 @@ def test_gcp_images_live(runner): assert result.exit_code == 0 -def test_gcp_images_offline(mock_gcp_images, runner): +def test_google_images_offline(mock_google_images, runner): """Run a live test against the Google Cloud API to get images via CLI.""" - result = runner.invoke(cli.gcp_images) + result = runner.invoke(cli.google_images) parsed = json.loads(result.output) assert isinstance(parsed["images"]["google"], list) diff --git a/tests/update_images/test_gcp.py b/tests/update_images/test_google.py similarity index 81% rename from tests/update_images/test_gcp.py rename to tests/update_images/test_google.py index eab12e69..3aa32ce8 100644 --- a/tests/update_images/test_gcp.py +++ b/tests/update_images/test_google.py @@ -8,15 +8,15 @@ from jsonschema import ValidationError -from rhelocator.update_images import gcp +from rhelocator.update_images import google from rhelocator.update_images import schema -@patch("rhelocator.update_images.gcp.compute_v1.ImagesClient") -def test_get_images(mock_gcp: MagicMock) -> None: +@patch("rhelocator.update_images.google.compute_v1.ImagesClient") +def test_get_images(mock_google: MagicMock) -> None: """Test getting Google images.""" fam_rhel_images = [] - with open("tests/update_images/testdata/gcp_list_images.json") as json_file: + with open("tests/update_images/testdata/google_list_images.json") as json_file: list = json.load(json_file) for entry in list: if entry["family"].__contains__("rhel"): @@ -47,9 +47,9 @@ def test_get_images(mock_gcp: MagicMock) -> None: # Connect the mock to the ImagesClient return value. mock_response = MagicMock() mock_response.list.return_value = mocked_list - mock_gcp.return_value = mock_response + mock_google.return_value = mock_response - images = gcp.get_images() + images = google.get_images() assert len(images) == len(mocked_list) / 2 @@ -62,7 +62,7 @@ def test_normalize_google_images() -> None: mocked_image.description = "RHEL" mocked_image.name = "rhel-9-20221018" - images = gcp.normalize_google_images([mocked_image]) + images = google.normalize_google_images([mocked_image]) assert isinstance(images, list) assert images[0] == { @@ -76,25 +76,25 @@ def test_normalize_google_images() -> None: def test_parse_image_version_from_name(): """Test parsing a google image name with a basic image.""" image_name = "rhel-7-9-sap-v20220719" - version = gcp.parse_image_version_from_name(image_name) + version = google.parse_image_version_from_name(image_name) assert version == "7.9" """Test parsing a google image name with a basic image.""" image_name = "rhel-7-sap-v20220719" - version = gcp.parse_image_version_from_name(image_name) + version = google.parse_image_version_from_name(image_name) assert version == "7" """Test parsing a google image name with a basic image.""" image_name = "rhel-7-1-2-sap-v20220719" - version = gcp.parse_image_version_from_name(image_name) + version = google.parse_image_version_from_name(image_name) assert version == "7.1.2" """Test parsing a google image name with a basic image.""" image_name = "rhel-sap-v20220719" - version = gcp.parse_image_version_from_name(image_name) + version = google.parse_image_version_from_name(image_name) assert version == "unknown" @@ -110,7 +110,7 @@ def test_format_image(): "name": "rhel-7-v20220920", } - data = {"images": {"google": [gcp.format_image(mocked_image)]}} + data = {"images": {"google": [google.format_image(mocked_image)]}} try: schema.validate_json(data) @@ -118,10 +118,10 @@ def test_format_image(): raise AssertionError(f"Formatted data does not expect schema: {exc}") -def test_format_all_images(mock_gcp_images): +def test_format_all_images(mock_google_images): """Test transforming a list of google images into a schema approved format.""" - data = gcp.format_all_images() + data = google.format_all_images() try: schema.validate_json(data) diff --git a/tests/update_images/testdata/gcp_list_images.json b/tests/update_images/testdata/google_list_images.json similarity index 100% rename from tests/update_images/testdata/gcp_list_images.json rename to tests/update_images/testdata/google_list_images.json diff --git a/tests/update_images/testdata/update.sh b/tests/update_images/testdata/update.sh index c9b1ef08..c38d4267 100755 --- a/tests/update_images/testdata/update.sh +++ b/tests/update_images/testdata/update.sh @@ -1,5 +1,5 @@ #!/bin/bash # az vm image list -f RHEL -l eastus --all > azure_list_images.json gcloud config set account rhel-cloud -gcloud compute images list --format="json" > gcp_list_images.json +gcloud compute images list --format="json" > google_list_images.json aws --region=us-east-1 ec2 describe-images --owner 309956199498 --filter "Name=is-public,Values=true" > aws_list_images.json