diff --git a/gso/workflows/router/update_ibgp_mesh.py b/gso/workflows/router/update_ibgp_mesh.py index a4c4be29cbd4a4fc34e6c4139b7c4823443fe80e..f6208e255e61556d4a5bde25a51570ae8b6a3b48 100644 --- a/gso/workflows/router/update_ibgp_mesh.py +++ b/gso/workflows/router/update_ibgp_mesh.py @@ -13,7 +13,7 @@ from pydantic import root_validator from gso.products.product_blocks.router import RouterRole from gso.products.product_types.router import Router from gso.services import librenms_client, provisioning_proxy, subscriptions -from gso.services.provisioning_proxy import indifferent_pp_interaction, pp_interaction +from gso.services.provisioning_proxy import pp_interaction from gso.services.subscriptions import get_active_trunks_that_terminate_on_router from gso.utils.helpers import SNMPVersion @@ -30,6 +30,8 @@ def initial_input_form_generator(subscription_id: UUIDstr) -> FormGenerator: class Config: title = f"Add {subscription.router.router_fqdn} to the iBGP mesh?" + tt_number: str + @root_validator(allow_reuse=True) def router_has_a_trunk(cls, values: dict[str, Any]) -> dict[str, Any]: if len(get_active_trunks_that_terminate_on_router(subscription_id)) == 0: @@ -38,9 +40,9 @@ def initial_input_form_generator(subscription_id: UUIDstr) -> FormGenerator: return values - yield AddBGPSessionForm + user_input = yield AddBGPSessionForm - return {"subscription": subscription} + return user_input.dict() @step("Calculate list of all active PE routers") @@ -65,20 +67,21 @@ def _generate_pe_inventory(pe_router_list: list[Router]) -> dict[str, Any]: "vendor": router.router.vendor, } for router in pe_router_list - }, - }, - "all": { - "hosts": {router.router.router_fqdn: None for router in pe_router_list}, + } }, + "all": {"hosts": {router.router.router_fqdn: None for router in pe_router_list}}, } @step("[DRY RUN] Add P router to iBGP mesh") -def add_p_to_mesh_dry(subscription: Router, callback_route: str, pe_router_list: list[Router]) -> State: +def add_p_to_mesh_dry( + subscription: Router, callback_route: str, pe_router_list: list[Router], tt_number: str, process_id: UUIDstr +) -> None: """Perform a dry run of adding the new P router to the PE router mesh.""" extra_vars = { "dry_run": True, "subscription": subscription, + "commit_comment": f"GSO_PROCESS_ID: {process_id} - TT_NUMBER: {tt_number} - Update iBGP mesh", } provisioning_proxy.execute_playbook( @@ -88,15 +91,16 @@ def add_p_to_mesh_dry(subscription: Router, callback_route: str, pe_router_list: extra_vars=extra_vars, ) - return {"subscription": subscription} - @step("[FOR REAL] Add P router to iBGP mesh") -def add_p_to_mesh_real(subscription: Router, callback_route: str, pe_router_list: list[Router]) -> State: +def add_p_to_mesh_real( + subscription: Router, callback_route: str, pe_router_list: list[Router], tt_number: str, process_id: UUIDstr +) -> None: """Add the P router to the mesh of PE routers.""" extra_vars = { "dry_run": False, "subscription": subscription, + "commit_comment": f"GSO_PROCESS_ID: {process_id} - TT_NUMBER: {tt_number} - Update iBGP mesh", } provisioning_proxy.execute_playbook( @@ -106,11 +110,11 @@ def add_p_to_mesh_real(subscription: Router, callback_route: str, pe_router_list extra_vars=extra_vars, ) - return {"subscription": subscription} - @step("[DRY RUN] Add all PE routers to P router iBGP table") -def add_all_pe_to_p_dry(subscription: Router, pe_router_list: list[Router], callback_route: str) -> State: +def add_all_pe_to_p_dry( + subscription: Router, pe_router_list: list[Router], callback_route: str, tt_number: str, process_id: UUIDstr +) -> None: """Perform a dry run of adding the list of all PE routers to the new P router.""" extra_vars = { "dry_run": True, @@ -122,26 +126,21 @@ def add_all_pe_to_p_dry(subscription: Router, pe_router_list: list[Router], call } for router in pe_router_list }, - } - - inventory = { - "all": { - "hosts": {router.router.router_fqdn: None for router in pe_router_list}, - }, + "commit_comment": f"GSO_PROCESS_ID: {process_id} - TT_NUMBER: {tt_number} - Update iBGP mesh", } provisioning_proxy.execute_playbook( playbook_name="update_ibgp_mesh.yaml", callback_route=callback_route, - inventory=inventory, + inventory=subscription.router.router_fqdn, extra_vars=extra_vars, ) - return {"subscription": subscription} - @step("[FOR REAL] Add all PE routers to P router iBGP table") -def add_all_pe_to_p_real(subscription: Router, pe_router_list: list[Router], callback_route: str) -> State: +def add_all_pe_to_p_real( + subscription: Router, pe_router_list: list[Router], callback_route: str, tt_number: str, process_id: UUIDstr +) -> None: """Add the list of all PE routers to the new P router.""" extra_vars = { "dry_run": False, @@ -153,44 +152,27 @@ def add_all_pe_to_p_real(subscription: Router, pe_router_list: list[Router], cal } for router in pe_router_list }, - } - - inventory = { - "all": { - "hosts": {router.router.router_fqdn: None for router in pe_router_list}, - }, + "commit_comment": f"GSO_PROCESS_ID: {process_id} - TT_NUMBER: {tt_number} - Update iBGP mesh", } provisioning_proxy.execute_playbook( playbook_name="update_ibgp_mesh.yaml", callback_route=callback_route, - inventory=inventory, + inventory=subscription.router.router_fqdn, extra_vars=extra_vars, ) - return {"subscription": subscription} - @step("Verify iBGP session health") -def check_ibgp_session(subscription: Router, callback_route: str) -> State: +def check_ibgp_session(subscription: Router, callback_route: str) -> None: """Run a playbook using the provisioning proxy, to check the health of the new iBGP session.""" - inventory = { - "all": { - "hosts": { - subscription.router.router_fqdn: None, - }, - }, - } - provisioning_proxy.execute_playbook( playbook_name="check_ibgp.yaml", callback_route=callback_route, - inventory=inventory, + inventory=subscription.router.router_fqdn, extra_vars={}, ) - return {"subscription": subscription} - @step("Add the router to LibreNMS") def add_device_to_librenms(subscription: Router) -> State: @@ -232,7 +214,7 @@ def update_ibgp_mesh() -> StepList: >> pp_interaction(add_p_to_mesh_real) >> pp_interaction(add_all_pe_to_p_dry) >> pp_interaction(add_all_pe_to_p_real) - >> indifferent_pp_interaction(check_ibgp_session) + >> pp_interaction(check_ibgp_session) >> add_device_to_librenms >> update_subscription_model >> resync diff --git a/test/workflows/router/test_update_ibgp_mesh.py b/test/workflows/router/test_update_ibgp_mesh.py index 44b979c6f5d3a79fb65c6eea203776610e118b42..14543066130d06d5d6f5d148b2d126a44d267adc 100644 --- a/test/workflows/router/test_update_ibgp_mesh.py +++ b/test/workflows/router/test_update_ibgp_mesh.py @@ -24,8 +24,11 @@ def test_update_ibgp_mesh_success( mock_execute_playbook, ibgp_mesh_input_form_data, data_config_filename, + faker, ): - result, process_stat, step_log = run_workflow("update_ibgp_mesh", [ibgp_mesh_input_form_data, {}]) + result, process_stat, step_log = run_workflow( + "update_ibgp_mesh", [ibgp_mesh_input_form_data, {"tt_number": faker.tt_number()}] + ) for _ in range(5): result, step_log = assert_pp_interaction_success(result, process_stat, step_log)