Skip to content

Commit

Permalink
Fix linting.
Browse files Browse the repository at this point in the history
  • Loading branch information
marrobi committed Feb 7, 2025
1 parent c2ccb3b commit 841d775
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@
"extensions": [
"ms-python.python",
"ms-python.pylance",
"ms-python.flake8",
"hashicorp.terraform",
"github.vscode-pull-request-github",
"gitHub.copilot",
Expand Down
8 changes: 8 additions & 0 deletions resource_processor/tests_rp/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
from unittest.mock import patch, AsyncMock
from helpers.commands import azure_login_command, apply_porter_credentials_sets_command, azure_acr_login_command, build_porter_command, build_porter_command_for_outputs, get_porter_parameter_keys


@pytest.fixture
def mock_get_porter_parameter_keys():
with patch("helpers.commands.get_porter_parameter_keys", new_callable=AsyncMock) as mock:
yield mock


@pytest.mark.parametrize("config, expected_command", [
({"azure_environment": "AzureCloud", "vmss_msi_id": "msi_id"}, "az cloud set --name AzureCloud >/dev/null && az login --identity -u msi_id >/dev/null "),
({"azure_environment": "AzureCloud", "arm_client_id": "client_id", "arm_client_secret": "client_secret", "arm_tenant_id": "tenant_id"}, "az cloud set --name AzureCloud >/dev/null && az login --service-principal --username client_id --password client_secret --tenant tenant_id >/dev/null")
Expand All @@ -16,6 +18,7 @@ def test_azure_login_command(config, expected_command):
"""Test azure_login_command function."""
assert azure_login_command(config) == expected_command


@pytest.mark.parametrize("config, expected_command", [
({"vmss_msi_id": "msi_id"}, "porter credentials apply vmss_porter/arm_auth_local_debugging.json >/dev/null 2>&1 && porter credentials apply vmss_porter/aad_auth.json >/dev/null 2>&1"),
({}, "porter credentials apply vmss_porter/arm_auth_local_debugging.json >/dev/null 2>&1 && porter credentials apply vmss_porter/aad_auth_local_debugging.json >/dev/null 2>&1")
Expand All @@ -24,13 +27,15 @@ def test_apply_porter_credentials_sets_command(config, expected_command):
"""Test apply_porter_credentials_sets_command function."""
assert apply_porter_credentials_sets_command(config) == expected_command


@pytest.mark.parametrize("config, expected_command", [
({"registry_server": "myregistry.azurecr.io"}, "az acr login --name myregistry >/dev/null ")
])
def test_azure_acr_login_command(config, expected_command):
"""Test azure_acr_login_command function."""
assert azure_acr_login_command(config) == expected_command


@pytest.mark.asyncio
async def test_build_porter_command(mock_get_porter_parameter_keys):
"""Test build_porter_command function."""
Expand All @@ -45,6 +50,7 @@ async def test_build_porter_command(mock_get_porter_parameter_keys):
command = await build_porter_command(config, msg_body)
assert command == expected_command


@pytest.mark.asyncio
async def test_build_porter_command_for_upgrade(mock_get_porter_parameter_keys):
"""Test build_porter_command function for upgrade action."""
Expand All @@ -59,6 +65,7 @@ async def test_build_porter_command_for_upgrade(mock_get_porter_parameter_keys):
command = await build_porter_command(config, msg_body)
assert command == expected_command


@pytest.mark.asyncio
async def test_build_porter_command_for_outputs():
"""Test build_porter_command_for_outputs function."""
Expand All @@ -68,6 +75,7 @@ async def test_build_porter_command_for_outputs():
command = await build_porter_command_for_outputs(msg_body)
assert command == expected_command


@pytest.mark.asyncio
@patch("helpers.commands.azure_login_command", return_value="az login command")
@patch("helpers.commands.azure_acr_login_command", return_value="az acr login command")
Expand Down
6 changes: 2 additions & 4 deletions resource_processor/tests_rp/test_runner.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import json
from unittest.mock import patch, AsyncMock, Mock
import pytest
import asyncio
from resource_processor.vmss_porter.runner import (
set_up_config, receive_message, run_porter, invoke_porter_action, get_porter_outputs, check_runners, runner, default_credentials
set_up_config, receive_message, invoke_porter_action, get_porter_outputs, check_runners, runner
)
from azure.servicebus.aio import ServiceBusClient
from azure.servicebus import ServiceBusMessage, ServiceBusSessionFilter
from azure.servicebus.exceptions import OperationTimeoutError, ServiceBusConnectionError
from azure.servicebus import ServiceBusSessionFilter


@pytest.fixture
Expand Down
4 changes: 2 additions & 2 deletions resource_processor/vmss_porter/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ async def invoke_porter_action(msg_body: dict, sb_client: ServiceBusClient, conf
if returncode == 0:
action_completed_without_error = True


if "uninstall" == action and "could not find installation" in err:
logger.warning("The installation doesn't exist. Treating as a successful action to allow the flow to proceed.")
action_completed_without_error = True
Expand Down Expand Up @@ -240,7 +239,8 @@ async def get_porter_outputs(msg_body: dict, config: dict):

if returncode != 0:
error_message = "Error context message = " + " ".join(err.split('\n'))
logger.info(f"{msg_body["id"]}: Failed to get outputs with error = {error_message}")
installation_id = msg_body["id"]
logger.info(f"{installation_id}: Failed to get outputs with error = {error_message}")
return False, {}
else:
outputs_json = {}
Expand Down

0 comments on commit 841d775

Please sign in to comment.