Skip to content
Snippets Groups Projects
Verified Commit 245ef7e0 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 17b77238
No related branches found
No related tags found
No related merge requests found
This commit is part of merge request !126. Comments created here will be created in the context of that merge request.
......@@ -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
......
......@@ -36,7 +36,7 @@ def migrate_form_input(
old_subscription = Iptrunk.from_subscription(product_id)
new_router = juniper_router_subscription_factory()
replace_side = str(old_subscription.iptrunk.iptrunk_sides[0].iptrunk_side_node.subscription.subscription_id)
new_side_ae_members = faker.generate_juniper_members_list()[0:2]
new_side_ae_members = faker.link_members_juniper()[0:2]
lag_name = "ae1"
elif use_juniper == UseJuniperSide.SIDE_B:
# Juniper -> Nokia
......@@ -48,7 +48,7 @@ def migrate_form_input(
old_subscription = Iptrunk.from_subscription(product_id)
new_router = nokia_router_subscription_factory()
replace_side = str(old_subscription.iptrunk.iptrunk_sides[0].iptrunk_side_node.subscription.subscription_id)
new_side_ae_members = faker.generate_nokia_members_list()[0:2]
new_side_ae_members = faker.link_members_nokia()[0:2]
lag_name = "LAG1"
elif use_juniper == UseJuniperSide.SIDE_BOTH:
# Juniper -> Juniper
......@@ -60,7 +60,7 @@ def migrate_form_input(
old_subscription = Iptrunk.from_subscription(product_id)
new_router = juniper_router_subscription_factory()
replace_side = str(old_subscription.iptrunk.iptrunk_sides[0].iptrunk_side_node.subscription.subscription_id)
new_side_ae_members = faker.generate_juniper_members_list()[0:2]
new_side_ae_members = faker.link_members_juniper()[0:2]
lag_name = "ae1"
else:
# Nokia -> Nokia
......@@ -68,7 +68,7 @@ def migrate_form_input(
old_subscription = Iptrunk.from_subscription(product_id)
new_router = nokia_router_subscription_factory()
replace_side = str(old_subscription.iptrunk.iptrunk_sides[0].iptrunk_side_node.subscription.subscription_id)
new_side_ae_members = faker.generate_nokia_members_list()[0:2]
new_side_ae_members = faker.link_members_nokia()[0:2]
lag_name = "LAG1"
return [
......
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment