From e7aedfdd111324624cfb4721fe7c8efc972a2823 Mon Sep 17 00:00:00 2001 From: Karel van Klink <karel.vanklink@geant.org> Date: Mon, 21 Oct 2024 15:38:44 +0200 Subject: [PATCH] Update validate_router WF_USABLE_MAP * Allow for router validation workflow to be run on those that are still provisioning * Only run validation workflows on the default state "ACTIVE", not all allowed states for a validation workflow to avoid validating provisioning routers --- gso/schedules/validate_subscriptions.py | 8 +++++--- gso/workflows/__init__.py | 1 + test/workflows/router/test_validate_router.py | 7 +++++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/gso/schedules/validate_subscriptions.py b/gso/schedules/validate_subscriptions.py index 4a68b6f0..2e55b05e 100644 --- a/gso/schedules/validate_subscriptions.py +++ b/gso/schedules/validate_subscriptions.py @@ -2,7 +2,7 @@ import structlog from orchestrator.services.processes import get_execution_context -from orchestrator.services.subscriptions import TARGET_DEFAULT_USABLE_MAP, WF_USABLE_MAP +from orchestrator.services.subscriptions import TARGET_DEFAULT_USABLE_MAP from orchestrator.targets import Target from gso.schedules.scheduling import CronScheduleConfig, scheduler @@ -29,8 +29,10 @@ def validate_subscriptions() -> None: validation_workflow = workflow.name if validation_workflow: - default = TARGET_DEFAULT_USABLE_MAP[Target.SYSTEM] - usable_when = WF_USABLE_MAP.get(validation_workflow, default) + # Validation workflows only run on subscriptions that are active, even when they could be run on + # provisioning subscriptions. E.g. for routers, they can manually be validated when provisioning, but are + # not included in this schedule. + usable_when = TARGET_DEFAULT_USABLE_MAP[Target.SYSTEM] if subscription.status in usable_when: json = [{"subscription_id": str(subscription.subscription_id)}] diff --git a/gso/workflows/__init__.py b/gso/workflows/__init__.py index 96638b85..f6a36f9b 100644 --- a/gso/workflows/__init__.py +++ b/gso/workflows/__init__.py @@ -21,6 +21,7 @@ WF_USABLE_MAP.update({ "terminate_router": ALL_ALIVE_STATES, "terminate_iptrunk": ALL_ALIVE_STATES, "promote_p_to_pe": [SubscriptionLifecycle.ACTIVE], + "validate_router": [SubscriptionLifecycle.PROVISIONING, SubscriptionLifecycle.ACTIVE], }) # IP trunk workflows diff --git a/test/workflows/router/test_validate_router.py b/test/workflows/router/test_validate_router.py index 07fc78d7..22e7359a 100644 --- a/test/workflows/router/test_validate_router.py +++ b/test/workflows/router/test_validate_router.py @@ -2,6 +2,7 @@ from unittest.mock import patch import pytest from infoblox_client import objects +from orchestrator.types import SubscriptionLifecycle from gso.products.product_types.router import Router from test.services.conftest import MockedKentikClient @@ -13,6 +14,7 @@ from test.workflows import ( ) +@pytest.mark.parametrize("router_state", [SubscriptionLifecycle.PROVISIONING, SubscriptionLifecycle.ACTIVE]) @pytest.mark.workflow() @patch("gso.services.infoblox.find_host_by_fqdn") @patch("gso.services.lso_client._send_request") @@ -29,11 +31,12 @@ def test_validate_nokia_router_success( faker, data_config_filename, geant_partner, + router_state, ): mock_validate_librenms_device.return_value = None mock_kentik_client.return_value = MockedKentikClient # Run workflow - subscription_id = nokia_router_subscription_factory() + subscription_id = nokia_router_subscription_factory(status=router_state) mock_fqdn = Router.from_subscription(subscription_id).router.router_fqdn mock_v4 = faker.ipv4() mock_find_host_by_fqdn.return_value = objects.HostRecord( @@ -66,7 +69,7 @@ def test_validate_nokia_router_success( state = extract_state(result) subscription = Router.from_subscription(subscription_id) - assert subscription.status == "active" + assert subscription.status == router_state assert mock_execute_playbook.call_count == 2 assert mock_find_host_by_fqdn.call_count == 1 assert mock_get_device_by_name.call_count == 1 -- GitLab