From 8ecfedc4d5cc454f3a30d3aba618d6ef5a017c5d Mon Sep 17 00:00:00 2001 From: Janine Olear Date: Tue, 11 Oct 2022 08:54:37 +0200 Subject: [PATCH 1/3] add gcp image list command to CLI Signed-off-by: Janine Olear --- .github/workflows/main.yml | 2 ++ src/rhelocator/cli.py | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6f42e690..6d815022 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -88,6 +88,8 @@ jobs: AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }} AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + GCP_APP_CREDENTIALS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS}} + - name: Run pytest with offline tests only if: env.SECRET_CHECK == null diff --git a/src/rhelocator/cli.py b/src/rhelocator/cli.py index 7452cca5..bad43f58 100644 --- a/src/rhelocator/cli.py +++ b/src/rhelocator/cli.py @@ -42,6 +42,11 @@ def aws_regions() -> None: regions = update_images.get_aws_regions() click.echo(json.dumps(regions, indent=2)) +@click.command() +def gcp_images() -> None: + """Dump GCP images for all regions in JSON format""" + images = update_images.get_google_images() + click.echo(json.dumps(images, indent=2)) @click.command() def azure_images() -> None: @@ -53,3 +58,4 @@ def azure_images() -> None: cli.add_command(aws_hourly_images) cli.add_command(aws_regions) cli.add_command(azure_images) +cli.add_command(gcp_images) From 2a7ae17795e4e520b9f7b89d528119c620aaea1e Mon Sep 17 00:00:00 2001 From: Janine Olear Date: Thu, 13 Oct 2022 09:29:09 +0200 Subject: [PATCH 2/3] rename env variable and added tests Signed-off-by: Janine Olear --- .github/workflows/main.yml | 3 +-- tests/conftest.py | 13 +++++++++++++ tests/test_cli.py | 25 ++++++++++++++++++++++++- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6d815022..bcdbe5c3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -88,8 +88,7 @@ jobs: AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }} AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }} - GCP_APP_CREDENTIALS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS}} - + GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS}} - name: Run pytest with offline tests only if: env.SECRET_CHECK == null diff --git a/tests/conftest.py b/tests/conftest.py index 755784ee..782d2af9 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -18,6 +18,11 @@ "9.0.2022090601", ] +MOCKED_GCP_IMAGE_LIST = [ + {"status": "READY"}, + {"status": "DEPRICATED"}, +] + def pytest_configure(config: any) -> None: config.addinivalue_line("markers", "e2e: mark as end-to-end test.") @@ -53,3 +58,11 @@ def mock_azure_image_versions_latest(mocker): mock = mocker.patch("rhelocator.update_images.get_azure_image_versions") mock.return_value = [MOCKED_AZURE_IMAGE_VERSION_LIST[0]] return mock + + +@pytest.fixture +def mock_gcp_images(mocker): + """Provide an offline result for calls to get_google_images.""" + mock = mocker.patch("rhelocator.update_images.get_google_images") + mock.return_value = MOCKED_GCP_IMAGE_LIST + return mock diff --git a/tests/test_cli.py b/tests/test_cli.py index c3ea5840..10e31df5 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -87,7 +87,6 @@ def test_aws_regions_offline(mock_aws_regions, runner): assert "us-east-1" in parsed assert result.exit_code == 0 - @pytest.mark.e2e def test_azure_images_live(runner): """Run a live test against the Azure API to get images via CLI.""" @@ -115,3 +114,27 @@ def test_azure_images_offline(mock_azure_image_versions, runner): assert list(image.keys()) == expected_keys assert result.exit_code == 0 + +@pytest.mark.e2e +def test_gcp_images_live(runner): + """Run a live test against the Google Cloud API to get images via CLI.""" + result = runner.invoke(cli.gcp_images) + parsed = json.loads(result.output) + + assert isinstance(parsed, list) + + assert {image["status"] for image in parsed} != "DEPRICATED" + + assert result.exit_code == 0 + + +def test_gcp_images_offline(mock_gcp_images, runner): + """Run a live test against the Google Cloud API to get images via CLI.""" + result = runner.invoke(cli.gcp_images) + parsed = json.loads(result.output) + + assert isinstance(parsed, list) + + assert {image["status"] for image in parsed} != "DEPRICATED" + + assert result.exit_code == 0 From c2787927d810eb6132c2ba701f51a5c607be7f3d Mon Sep 17 00:00:00 2001 From: Janine Olear Date: Thu, 13 Oct 2022 14:33:34 +0200 Subject: [PATCH 3/3] fix typo Signed-off-by: Janine Olear --- tests/conftest.py | 2 +- tests/test_cli.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 782d2af9..4e7f747b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -20,7 +20,7 @@ MOCKED_GCP_IMAGE_LIST = [ {"status": "READY"}, - {"status": "DEPRICATED"}, + {"status": "DEPRECATED"}, ] diff --git a/tests/test_cli.py b/tests/test_cli.py index 10e31df5..a637774b 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -123,7 +123,7 @@ def test_gcp_images_live(runner): assert isinstance(parsed, list) - assert {image["status"] for image in parsed} != "DEPRICATED" + assert {image["status"] for image in parsed} != "DEPRECATED" assert result.exit_code == 0 @@ -135,6 +135,6 @@ def test_gcp_images_offline(mock_gcp_images, runner): assert isinstance(parsed, list) - assert {image["status"] for image in parsed} != "DEPRICATED" + assert {image["status"] for image in parsed} != "DEPRECATED" assert result.exit_code == 0