Skip to content
Snippets Groups Projects
Verified Commit 989d58d6 authored by Karel van Klink's avatar Karel van Klink :smiley_cat:
Browse files

updates to iBGP workflow

only target P routers in relevant steps
add TT number and commit comments to playbook executions
update unit tests
parent c73ae298
No related branches found
No related tags found
1 merge request!126Add iBGP workflow and LibreNMS client
...@@ -13,7 +13,7 @@ from pydantic import root_validator ...@@ -13,7 +13,7 @@ from pydantic import root_validator
from gso.products.product_blocks.router import RouterRole from gso.products.product_blocks.router import RouterRole
from gso.products.product_types.router import Router from gso.products.product_types.router import Router
from gso.services import librenms_client, provisioning_proxy, subscriptions 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.services.subscriptions import get_active_trunks_that_terminate_on_router
from gso.utils.helpers import SNMPVersion from gso.utils.helpers import SNMPVersion
...@@ -30,6 +30,8 @@ def initial_input_form_generator(subscription_id: UUIDstr) -> FormGenerator: ...@@ -30,6 +30,8 @@ def initial_input_form_generator(subscription_id: UUIDstr) -> FormGenerator:
class Config: class Config:
title = f"Add {subscription.router.router_fqdn} to the iBGP mesh?" title = f"Add {subscription.router.router_fqdn} to the iBGP mesh?"
tt_number: str
@root_validator(allow_reuse=True) @root_validator(allow_reuse=True)
def router_has_a_trunk(cls, values: dict[str, Any]) -> dict[str, Any]: 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: 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: ...@@ -38,9 +40,9 @@ def initial_input_form_generator(subscription_id: UUIDstr) -> FormGenerator:
return values return values
yield AddBGPSessionForm user_input = yield AddBGPSessionForm
return {"subscription": subscription} return user_input.dict()
@step("Calculate list of all active PE routers") @step("Calculate list of all active PE routers")
...@@ -65,20 +67,21 @@ def _generate_pe_inventory(pe_router_list: list[Router]) -> dict[str, Any]: ...@@ -65,20 +67,21 @@ def _generate_pe_inventory(pe_router_list: list[Router]) -> dict[str, Any]:
"vendor": router.router.vendor, "vendor": router.router.vendor,
} }
for router in pe_router_list 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") @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.""" """Perform a dry run of adding the new P router to the PE router mesh."""
extra_vars = { extra_vars = {
"dry_run": True, "dry_run": True,
"subscription": subscription, "subscription": subscription,
"commit_comment": f"GSO_PROCESS_ID: {process_id} - TT_NUMBER: {tt_number} - Update iBGP mesh",
} }
provisioning_proxy.execute_playbook( provisioning_proxy.execute_playbook(
...@@ -88,15 +91,16 @@ def add_p_to_mesh_dry(subscription: Router, callback_route: str, pe_router_list: ...@@ -88,15 +91,16 @@ def add_p_to_mesh_dry(subscription: Router, callback_route: str, pe_router_list:
extra_vars=extra_vars, extra_vars=extra_vars,
) )
return {"subscription": subscription}
@step("[FOR REAL] Add P router to iBGP mesh") @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.""" """Add the P router to the mesh of PE routers."""
extra_vars = { extra_vars = {
"dry_run": False, "dry_run": False,
"subscription": subscription, "subscription": subscription,
"commit_comment": f"GSO_PROCESS_ID: {process_id} - TT_NUMBER: {tt_number} - Update iBGP mesh",
} }
provisioning_proxy.execute_playbook( provisioning_proxy.execute_playbook(
...@@ -106,11 +110,11 @@ def add_p_to_mesh_real(subscription: Router, callback_route: str, pe_router_list ...@@ -106,11 +110,11 @@ def add_p_to_mesh_real(subscription: Router, callback_route: str, pe_router_list
extra_vars=extra_vars, extra_vars=extra_vars,
) )
return {"subscription": subscription}
@step("[DRY RUN] Add all PE routers to P router iBGP table") @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.""" """Perform a dry run of adding the list of all PE routers to the new P router."""
extra_vars = { extra_vars = {
"dry_run": True, "dry_run": True,
...@@ -122,26 +126,21 @@ def add_all_pe_to_p_dry(subscription: Router, pe_router_list: list[Router], call ...@@ -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 for router in pe_router_list
}, },
} "commit_comment": f"GSO_PROCESS_ID: {process_id} - TT_NUMBER: {tt_number} - Update iBGP mesh",
inventory = {
"all": {
"hosts": {router.router.router_fqdn: None for router in pe_router_list},
},
} }
provisioning_proxy.execute_playbook( provisioning_proxy.execute_playbook(
playbook_name="update_ibgp_mesh.yaml", playbook_name="update_ibgp_mesh.yaml",
callback_route=callback_route, callback_route=callback_route,
inventory=inventory, inventory=subscription.router.router_fqdn,
extra_vars=extra_vars, extra_vars=extra_vars,
) )
return {"subscription": subscription}
@step("[FOR REAL] Add all PE routers to P router iBGP table") @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.""" """Add the list of all PE routers to the new P router."""
extra_vars = { extra_vars = {
"dry_run": False, "dry_run": False,
...@@ -153,44 +152,27 @@ def add_all_pe_to_p_real(subscription: Router, pe_router_list: list[Router], cal ...@@ -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 for router in pe_router_list
}, },
} "commit_comment": f"GSO_PROCESS_ID: {process_id} - TT_NUMBER: {tt_number} - Update iBGP mesh",
inventory = {
"all": {
"hosts": {router.router.router_fqdn: None for router in pe_router_list},
},
} }
provisioning_proxy.execute_playbook( provisioning_proxy.execute_playbook(
playbook_name="update_ibgp_mesh.yaml", playbook_name="update_ibgp_mesh.yaml",
callback_route=callback_route, callback_route=callback_route,
inventory=inventory, inventory=subscription.router.router_fqdn,
extra_vars=extra_vars, extra_vars=extra_vars,
) )
return {"subscription": subscription}
@step("Verify iBGP session health") @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.""" """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( provisioning_proxy.execute_playbook(
playbook_name="check_ibgp.yaml", playbook_name="check_ibgp.yaml",
callback_route=callback_route, callback_route=callback_route,
inventory=inventory, inventory=subscription.router.router_fqdn,
extra_vars={}, extra_vars={},
) )
return {"subscription": subscription}
@step("Add the router to LibreNMS") @step("Add the router to LibreNMS")
def add_device_to_librenms(subscription: Router) -> State: def add_device_to_librenms(subscription: Router) -> State:
...@@ -232,7 +214,7 @@ def update_ibgp_mesh() -> StepList: ...@@ -232,7 +214,7 @@ def update_ibgp_mesh() -> StepList:
>> pp_interaction(add_p_to_mesh_real) >> pp_interaction(add_p_to_mesh_real)
>> pp_interaction(add_all_pe_to_p_dry) >> pp_interaction(add_all_pe_to_p_dry)
>> pp_interaction(add_all_pe_to_p_real) >> pp_interaction(add_all_pe_to_p_real)
>> indifferent_pp_interaction(check_ibgp_session) >> pp_interaction(check_ibgp_session)
>> add_device_to_librenms >> add_device_to_librenms
>> update_subscription_model >> update_subscription_model
>> resync >> resync
......
...@@ -24,8 +24,11 @@ def test_update_ibgp_mesh_success( ...@@ -24,8 +24,11 @@ def test_update_ibgp_mesh_success(
mock_execute_playbook, mock_execute_playbook,
ibgp_mesh_input_form_data, ibgp_mesh_input_form_data,
data_config_filename, 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): for _ in range(5):
result, step_log = assert_pp_interaction_success(result, process_stat, step_log) result, step_log = assert_pp_interaction_success(result, process_stat, step_log)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment