diff --git a/gso/workflows/l3_core_service/validate_prefix_list.py b/gso/workflows/l3_core_service/validate_prefix_list.py deleted file mode 100644 index 9c9b6cd4321e07d78ce98524487d880f8b1cfb54..0000000000000000000000000000000000000000 --- a/gso/workflows/l3_core_service/validate_prefix_list.py +++ /dev/null @@ -1,141 +0,0 @@ -"""Prefix Validation workflow for L3 Core Service subscription objects.""" - -from typing import Any - -from orchestrator.config.assignee import Assignee -from orchestrator.forms import SubmitFormPage -from orchestrator.targets import Target -from orchestrator.workflow import StepList, begin, conditional, done, inputstep, step, workflow -from orchestrator.workflows.steps import resync, store_process_subscription, unsync -from orchestrator.workflows.utils import wrap_modify_initial_input_form -from pydantic import Field -from pydantic_forms.types import FormGenerator, State, UUIDstr -from pydantic_forms.validators import Label - -from gso.products.product_types.l3_core_service import L3CoreService, L3CoreServiceType -from gso.services.lso_client import LSOState, anonymous_lso_interaction, lso_interaction -from gso.services.partners import get_partner_by_id -from gso.utils.shared_enums import Vendor - - -@step("Prepare list of all Access Ports") -def build_fqdn_list(subscription_id: UUIDstr) -> State: - """Build the list of all FQDNs in the access ports of L3 Core Service subscription, excluding Juniper devices.""" - subscription = L3CoreService.from_subscription(subscription_id) - ap_fqdn_list = [ - ap.sbp.edge_port.node.router_fqdn - for ap in subscription.l3_core_service.ap_list - if ap.sbp.edge_port.node.vendor != Vendor.JUNIPER - ] - return {"ap_fqdn_list": ap_fqdn_list, "subscription": subscription} - - -@step("[DRY RUN] Validate Prefix-Lists") -def validate_prefix_lists_dry(subscription: dict[str, Any], process_id: UUIDstr, ap_fqdn_list: list[str]) -> LSOState: - """Workflow step for running a playbook that validates prefix-lists in dry run mode.""" - extra_vars = { - "subscription": subscription, - "partner_name": get_partner_by_id(subscription["customer_id"]).name, - "dry_run": True, - "verb": "deploy", - "object": "prefix_list", - "is_verification_workflow": "true", - "commit_comment": f"GSO_PROCESS_ID: {process_id} - Validate prefix-lists for {subscription["description"]}", - } - - return { - "playbook_name": "gap_ansible/playbooks/validate_prefix_list.yaml", - "inventory": {"all": {"hosts": dict.fromkeys(ap_fqdn_list)}}, - "extra_vars": extra_vars, - } - - -@step("Evaluate validation of Prefix-Lists") -def _evaluate_result_has_diff(callback_result: dict) -> State: - return {"callback_result": callback_result, "prefix_list_drift": bool(callback_result["return_code"] != 0)} - - -@inputstep("Await operator confirmation", assignee=Assignee.SYSTEM) -def await_operator() -> FormGenerator: - """Show a form for the operator to start redeploying the prefix list that has drifted.""" - - class AwaitOperatorForm(SubmitFormPage): - info_label_a: Label = Field("A drift has been detected for this prefix list!", exclude=True) - info_label_b: Label = Field("Please continue this workflow to redeploy the drifted prefix list.", exclude=True) - - yield AwaitOperatorForm - - return {} - - -@step("[DRY RUN] Deploy Prefix-Lists") -def deploy_prefix_lists_dry(subscription: dict[str, Any], process_id: UUIDstr, ap_fqdn_list: list[str]) -> LSOState: - """Workflow step for running a playbook that deploys prefix-lists in dry run mode.""" - extra_vars = { - "subscription": subscription, - "partner_name": get_partner_by_id(subscription["customer_id"]).name, - "dry_run": True, - "verb": "deploy", - "object": "prefix_list", - "is_verification_workflow": "false", - "commit_comment": f"GSO_PROCESS_ID: {process_id} - Deploy prefix-lists for {subscription["description"]}", - } - - return { - "playbook_name": "gap_ansible/playbooks/deploy_prefix_list.yaml", - "inventory": {"all": {"hosts": dict.fromkeys(ap_fqdn_list)}}, - "extra_vars": extra_vars, - } - - -@step("[REAL] Deploy Prefix-Lists") -def deploy_prefix_lists_real(subscription: dict[str, Any], process_id: UUIDstr, ap_fqdn_list: list[str]) -> LSOState: - """Workflow step for running a playbook that deploys prefix-lists.""" - extra_vars = { - "subscription": subscription, - "partner_name": get_partner_by_id(subscription["customer_id"]).name, - "dry_run": False, - "verb": "deploy", - "object": "prefix_list", - "is_verification_workflow": "false", - "commit_comment": f"GSO_PROCESS_ID: {process_id} - Deploy prefix-lists for {subscription["description"]}", - } - - return { - "playbook_name": "gap_ansible/playbooks/deploy_prefix_list.yaml", - "inventory": {"all": {"hosts": dict.fromkeys(ap_fqdn_list)}}, - "extra_vars": extra_vars, - } - - -@workflow("Validate Prefix-List", target=Target.SYSTEM, initial_input_form=(wrap_modify_initial_input_form(None))) -def validate_prefix_list() -> StepList: - """Validate prefix-lists for an existing L3 Core Service subscription.""" - prefix_list_should_be_validated = conditional( - lambda state: state["subscription"]["l3_core_service_type"] == L3CoreServiceType.GEANT_IP - ) - fqdn_list_is_empty = conditional(lambda state: state["ap_fqdn_list"] == []) - prefix_list_has_drifted = conditional(lambda state: bool(state["prefix_list_drift"])) - - redeploy_prefix_list_steps = ( - begin - >> unsync - >> await_operator - >> lso_interaction(deploy_prefix_lists_dry) - >> lso_interaction(deploy_prefix_lists_real) - >> resync - ) - prefix_list_validation_steps = ( - begin - >> anonymous_lso_interaction(validate_prefix_lists_dry, _evaluate_result_has_diff) - >> prefix_list_has_drifted(redeploy_prefix_list_steps) - ) - - return ( - begin - >> store_process_subscription(Target.SYSTEM) - >> build_fqdn_list - >> fqdn_list_is_empty(done) - >> prefix_list_should_be_validated(prefix_list_validation_steps) - >> done - )