From b2a7961650fcd1417a471f1c1fdb629716c9923e Mon Sep 17 00:00:00 2001 From: Russell Date: Wed, 23 Feb 2022 11:09:38 -0500 Subject: [PATCH] temporary work-around to #129 (#130) --- foodx_devops_tools/deploy_me/_deployment.py | 11 ++++++++++- .../deploy_me/application_steps/_deploy.py | 2 -- .../deployment/application_steps/test_deploy_step.py | 7 +------ tests/ci/unit_tests/deploy_me/deployment/conftest.py | 3 +-- .../unit_tests/deploy_me/deployment/test_do_deploy.py | 7 ++++++- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/foodx_devops_tools/deploy_me/_deployment.py b/foodx_devops_tools/deploy_me/_deployment.py index da846fa..3782039 100644 --- a/foodx_devops_tools/deploy_me/_deployment.py +++ b/foodx_devops_tools/deploy_me/_deployment.py @@ -12,7 +12,10 @@ import click -from foodx_devops_tools.azure.cloud.auth import AzureAuthenticationError +from foodx_devops_tools.azure.cloud.auth import ( + AzureAuthenticationError, + login_service_principal, +) from foodx_devops_tools.pipeline_config import ( ApplicationDefinition, ApplicationDeploymentSteps, @@ -358,6 +361,12 @@ async def do_deploy( timeout_seconds=pipeline_parameters.wait_timeout_seconds, ) try: + # this is a temporary work-around to the login concurrency problem - + # it works provided there is no more than a single subscription per + # deployment at a time. + # https://github.com/Food-X-Technologies/foodx_devops_tools/issues/129 + await login_service_principal(deployment_data.data.azure_credentials) + wait_task = asyncio.create_task( frame_deployment_status.wait_for_all_completed() ) diff --git a/foodx_devops_tools/deploy_me/application_steps/_deploy.py b/foodx_devops_tools/deploy_me/application_steps/_deploy.py index d9ed0aa..e49c7f3 100644 --- a/foodx_devops_tools/deploy_me/application_steps/_deploy.py +++ b/foodx_devops_tools/deploy_me/application_steps/_deploy.py @@ -11,7 +11,6 @@ import click -from foodx_devops_tools.azure.cloud.auth import login_service_principal from foodx_devops_tools.azure.cloud.resource_group import ( AzureSubscriptionConfiguration, ) @@ -118,7 +117,6 @@ async def _do_step_deployment( this_step.resource_group, ) - await login_service_principal(deployment_data.data.azure_credentials) if enable_validation: log.info(f"validation deployment enabled, {step_context}") resource_group = _mangle_validation_resource_group( diff --git a/tests/ci/unit_tests/deploy_me/deployment/application_steps/test_deploy_step.py b/tests/ci/unit_tests/deploy_me/deployment/application_steps/test_deploy_step.py index facdac8..4cb85cf 100644 --- a/tests/ci/unit_tests/deploy_me/deployment/application_steps/test_deploy_step.py +++ b/tests/ci/unit_tests/deploy_me/deployment/application_steps/test_deploy_step.py @@ -18,7 +18,6 @@ async def test_clean( mock_apply_template, mock_deploystep_context, - mock_login, mock_rg_deploy, mock_run_puff, mock_verify_puff_target, @@ -33,7 +32,6 @@ async def test_default_override_parameters( default_override_parameters, mock_apply_template, mock_deploystep_context, - mock_login, mock_rg_deploy, mock_run_puff, mock_verify_puff_target, @@ -65,7 +63,6 @@ async def test_secrets_enabled( default_override_parameters, mock_apply_template, mock_deploystep_context, - mock_login, mock_rg_deploy, mock_run_puff, mock_verify_puff_target, @@ -114,9 +111,7 @@ async def test_secrets_enabled( @pytest.mark.asyncio -async def test_step_skip( - caplog, mock_deploystep_context, mock_login, mock_rg_deploy -): +async def test_step_skip(caplog, mock_deploystep_context, mock_rg_deploy): with caplog.at_level(logging.DEBUG): mock_deploystep_context["deployment_data"].data.to = StructuredTo( frame="f1", application="a1", step="other_step" diff --git a/tests/ci/unit_tests/deploy_me/deployment/conftest.py b/tests/ci/unit_tests/deploy_me/deployment/conftest.py index a7678f1..c97416c 100644 --- a/tests/ci/unit_tests/deploy_me/deployment/conftest.py +++ b/tests/ci/unit_tests/deploy_me/deployment/conftest.py @@ -28,8 +28,7 @@ @pytest.fixture() def mock_login(mock_async_method): mock_async_method( - "foodx_devops_tools.deploy_me.application_steps" - "._deploy.login_service_principal" + "foodx_devops_tools.deploy_me._deployment.login_service_principal" ) diff --git a/tests/ci/unit_tests/deploy_me/deployment/test_do_deploy.py b/tests/ci/unit_tests/deploy_me/deployment/test_do_deploy.py index bc1c0a7..d395698 100644 --- a/tests/ci/unit_tests/deploy_me/deployment/test_do_deploy.py +++ b/tests/ci/unit_tests/deploy_me/deployment/test_do_deploy.py @@ -33,7 +33,12 @@ def prep_data(mock_async_method, mock_flattened_deployment, mock_run_puff): class TestDoDeploy: @pytest.mark.asyncio async def test_validation_clean( - self, mocker, prep_data, mock_completion_event, pipeline_parameters + self, + mocker, + prep_data, + mock_completion_event, + mock_login, + pipeline_parameters, ): cli_options = pipeline_parameters() mock_frame, deployment_data, pipeline_config = prep_data