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

Update Edge Port workflows

parent bd73fa43
No related branches found
No related tags found
No related merge requests found
This commit is part of merge request !286. Comments created here will be created in the context of that merge request.
......@@ -127,8 +127,7 @@ def initialize_subscription(
subscription.edge_port.geant_ga_id = geant_ga_id
subscription.edge_port.mac_address = mac_address
partner_name = get_partner_by_id(partner).name
subscription.description = (f"Edge Port {name} on {router.router_fqdn}, "
f"{partner_name}, {geant_ga_id or ""}")
subscription.description = f"Edge Port {name} on {router.router_fqdn}, " f"{partner_name}, {geant_ga_id or ""}"
subscription.edge_port.edge_port_description = description
for member in ae_members:
subscription.edge_port.edge_port_ae_members.append(
......@@ -196,7 +195,7 @@ def create_edge_port_dry(subscription: dict[str, Any], tt_number: str, process_i
return {
"playbook_name": "edge_port.yaml",
"inventory": {"all": {"hosts": {subscription["edge_port"]["edge_port_node"]["router_fqdn"]: None}}},
"inventory": {"all": {"hosts": {subscription["edge_port"]["node"]["router_fqdn"]: None}}},
"extra_vars": extra_vars,
}
......@@ -213,7 +212,7 @@ def create_edge_port_real(subscription: dict[str, Any], tt_number: str, process_
return {
"playbook_name": "edge_port.yaml",
"inventory": {"all": {"hosts": {subscription["edge_port"]["edge_port_node"]["router_fqdn"]: None}}},
"inventory": {"all": {"hosts": {subscription["edge_port"]["node"]["router_fqdn"]: None}}},
"extra_vars": extra_vars,
}
......
......@@ -80,18 +80,18 @@ def initialize_subscription(
) -> State:
"""Initialise the subscription object in the service database."""
router = Router.from_subscription(node).router
subscription.edge_port.edge_port_node = router
subscription.edge_port.edge_port_type = service_type
subscription.edge_port.edge_port_enable_lacp = enable_lacp
subscription.edge_port.edge_port_member_speed = speed
subscription.edge_port.edge_port_encapsulation = encapsulation
subscription.edge_port.node = router
subscription.edge_port.edge_port_name = name
subscription.edge_port.edge_port_minimum_links = minimum_links
subscription.edge_port.edge_port_ignore_if_down = ignore_if_down
subscription.edge_port.edge_port_geant_ga_id = geant_ga_id
subscription.edge_port.edge_port_mac_address = mac_address
subscription.description = f"Edge Port {name} on {router.router_fqdn}, {partner}, {geant_ga_id or ""}"
subscription.edge_port.edge_port_description = description
subscription.edge_port.enable_lacp = enable_lacp
subscription.edge_port.encapsulation = encapsulation
subscription.edge_port.mac_address = mac_address
subscription.edge_port.member_speed = speed
subscription.edge_port.minimum_links = minimum_links
subscription.edge_port.edge_port_type = service_type
subscription.edge_port.ignore_if_down = ignore_if_down
subscription.edge_port.geant_ga_id = geant_ga_id
subscription.description = f"Edge Port {name} on {router.router_fqdn}, {partner}, {geant_ga_id or ""}"
for member in ae_members:
subscription.edge_port.edge_port_ae_members.append(
EdgePortAEMemberBlockInactive.new(subscription_id=uuid4(), **member)
......
......@@ -36,14 +36,14 @@ def initial_input_form_generator(subscription_id: UUIDstr) -> FormGenerator:
model_config = ConfigDict(title="Modify Edge Port")
tt_number: TTNumber
enable_lacp: bool = subscription.edge_port.edge_port_enable_lacp
member_speed: PhysicalPortCapacity = subscription.edge_port.edge_port_member_speed
encapsulation: EncapsulationType = subscription.edge_port.edge_port_encapsulation
enable_lacp: bool = subscription.edge_port.enable_lacp
member_speed: PhysicalPortCapacity = subscription.edge_port.member_speed
encapsulation: EncapsulationType = subscription.edge_port.encapsulation
number_of_members: int = len(subscription.edge_port.edge_port_ae_members)
minimum_links: int | None = subscription.edge_port.edge_port_minimum_links or None
mac_address: str | None = subscription.edge_port.edge_port_mac_address or None
ignore_if_down: bool = subscription.edge_port.edge_port_ignore_if_down
geant_ga_id: str | None = subscription.edge_port.edge_port_geant_ga_id or None
minimum_links: int | None = subscription.edge_port.minimum_links or None
mac_address: str | None = subscription.edge_port.mac_address or None
ignore_if_down: bool = subscription.edge_port.ignore_if_down
geant_ga_id: str | None = subscription.edge_port.geant_ga_id or None
@model_validator(mode="after")
def validate_number_of_members(self) -> Self:
......@@ -57,15 +57,13 @@ def initial_input_form_generator(subscription_id: UUIDstr) -> FormGenerator:
class EdgePortLAGMember(LAGMember):
interface_name: ( # type: ignore[valid-type]
available_interfaces_choices_including_current_members(
subscription.edge_port.edge_port_node.owner_subscription_id,
subscription.edge_port.node.owner_subscription_id,
user_input.member_speed,
subscription.edge_port.edge_port_ae_members,
)
if user_input.member_speed == subscription.edge_port.edge_port_member_speed
if user_input.member_speed == subscription.edge_port.member_speed
else (
available_interfaces_choices(
subscription.edge_port.edge_port_node.owner_subscription_id, user_input.member_speed
)
available_interfaces_choices(subscription.edge_port.node.owner_subscription_id, user_input.member_speed)
)
)
......@@ -86,7 +84,7 @@ def initial_input_form_generator(subscription_id: UUIDstr) -> FormGenerator:
)
for iface in subscription.edge_port.edge_port_ae_members
]
if user_input.member_speed == subscription.edge_port.edge_port_member_speed
if user_input.member_speed == subscription.edge_port.member_speed
else []
)
......@@ -100,7 +98,7 @@ def initial_input_form_generator(subscription_id: UUIDstr) -> FormGenerator:
interface_form_input = yield ModifyEdgePortInterfaceForm
capacity_has_changed = (
user_input.member_speed != subscription.edge_port.edge_port_member_speed
user_input.member_speed != subscription.edge_port.member_speed
or user_input.number_of_members != len(subscription.edge_port.edge_port_ae_members)
or any(
old_interface.interface_name
......@@ -134,17 +132,17 @@ def modify_edge_port_subscription(
for member in subscription.edge_port.edge_port_ae_members
]
removed_ae_members = [member for member in previous_ae_members if member not in ae_members]
subscription.edge_port.edge_port_enable_lacp = enable_lacp
subscription.edge_port.edge_port_member_speed = member_speed
subscription.edge_port.edge_port_encapsulation = encapsulation
subscription.edge_port.edge_port_minimum_links = minimum_links
subscription.edge_port.edge_port_mac_address = mac_address
subscription.edge_port.edge_port_ignore_if_down = ignore_if_down
subscription.edge_port.edge_port_geant_ga_id = geant_ga_id
subscription.edge_port.enable_lacp = enable_lacp
subscription.edge_port.member_speed = member_speed
subscription.edge_port.encapsulation = encapsulation
subscription.edge_port.minimum_links = minimum_links
subscription.edge_port.mac_address = mac_address
subscription.edge_port.ignore_if_down = ignore_if_down
subscription.edge_port.geant_ga_id = geant_ga_id
subscription.edge_port.edge_port_description = description
subscription.description = (
f"Edge Port {subscription.edge_port.edge_port_name} on"
f" {subscription.edge_port.edge_port_node.router_fqdn},"
f" {subscription.edge_port.node.router_fqdn},"
f" {get_partner_by_id(subscription.customer_id).name}, {geant_ga_id or ""}"
)
subscription.edge_port.edge_port_ae_members.clear()
......@@ -166,7 +164,7 @@ def update_interfaces_in_netbox(
nbclient = NetboxClient()
# Free removed interfaces
for removed_member in removed_ae_members:
nbclient.free_interface(subscription.edge_port.edge_port_node.router_fqdn, removed_member["interface_name"])
nbclient.free_interface(subscription.edge_port.node.router_fqdn, removed_member["interface_name"])
# Attach physical interfaces to :term:`LAG`
# Update interface description to subscription ID
# Reserve interfaces
......@@ -174,12 +172,12 @@ def update_interfaces_in_netbox(
if any(prev_member["interface_name"] == member.interface_name for prev_member in previous_ae_members):
continue
nbclient.attach_interface_to_lag(
device_name=subscription.edge_port.edge_port_node.router_fqdn,
device_name=subscription.edge_port.node.router_fqdn,
lag_name=subscription.edge_port.edge_port_name,
iface_name=member.interface_name,
description=str(subscription.subscription_id),
)
nbclient.reserve_interface(subscription.edge_port.edge_port_node.router_fqdn, member.interface_name)
nbclient.reserve_interface(subscription.edge_port.node.router_fqdn, member.interface_name)
return {"subscription": subscription}
......@@ -195,13 +193,13 @@ def update_edge_port_dry(
"verb": "update",
"commit_comment": f"GSO_PROCESS_ID: {process_id} - TT_NUMBER: {tt_number} "
f"- Update Edge Port {subscription["edge_port"]["edge_port_name"]}"
f" on {subscription["edge_port"]["edge_port_node"]["router_fqdn"]}",
f" on {subscription["edge_port"]["node"]["router_fqdn"]}",
"removed_ae_members": removed_ae_members,
}
return {
"playbook_name": "edge_ports.yaml",
"inventory": {"all": {"hosts": {subscription["edge_port"]["edge_port_node"]["router_fqdn"]}}},
"inventory": {"all": {"hosts": {subscription["edge_port"]["node"]["router_fqdn"]}}},
"extra_vars": extra_vars,
"subscription": subscription,
}
......@@ -218,14 +216,14 @@ def update_edge_port_real(
"verb": "update",
"commit_comment": f"GSO_PROCESS_ID: {process_id} - TT_NUMBER: {tt_number} "
f"- Update Edge Port {subscription["edge_port"]["edge_port_name"]}"
f" on {subscription["edge_port"]["edge_port_node"]["router_fqdn"]}",
f" on {subscription["edge_port"]["node"]["router_fqdn"]}",
"removed_ae_members": removed_ae_members,
}
return {
"subscription": subscription,
"playbook_name": "edge_ports.yaml",
"inventory": {"all": {"hosts": {subscription["edge_port"]["edge_port_node"]["router_fqdn"]: None}}},
"inventory": {"all": {"hosts": {subscription["edge_port"]["node"]["router_fqdn"]: None}}},
"extra_vars": extra_vars,
}
......@@ -238,13 +236,13 @@ def allocate_interfaces_in_netbox(subscription: EdgePort, previous_ae_members: l
if any(member.interface_name == prev_member["interface_name"] for prev_member in previous_ae_members):
continue
nbclient.allocate_interface(
device_name=subscription.edge_port.edge_port_node.router_fqdn,
device_name=subscription.edge_port.node.router_fqdn,
iface_name=member.interface_name,
)
# detach the old interfaces from lag
nbclient.detach_interfaces_from_lag(
device_name=subscription.edge_port.edge_port_node.router_fqdn, lag_name=subscription.edge_port.edge_port_name
device_name=subscription.edge_port.node.router_fqdn, lag_name=subscription.edge_port.edge_port_name
)
......
......@@ -40,7 +40,7 @@ def remove_edge_port_dry(subscription: dict[str, Any], tt_number: str, process_i
return {
"subscription": subscription,
"playbook_name": "edge_port.yaml",
"inventory": {"all": {"hosts": {subscription["edge_port"]["edge_port_node"]["router_fqdn"]: None}}},
"inventory": {"all": {"hosts": {subscription["edge_port"]["node"]["router_fqdn"]: None}}},
"extra_vars": extra_vars,
}
......@@ -58,7 +58,7 @@ def remove_edge_port_real(subscription: dict[str, Any], tt_number: str, process_
return {
"subscription": subscription,
"playbook_name": "edge_port.yaml",
"inventory": {"all": {"hosts": {subscription["edge_port"]["edge_port_node"]["router_fqdn"]: None}}},
"inventory": {"all": {"hosts": {subscription["edge_port"]["node"]["router_fqdn"]: None}}},
"extra_vars": extra_vars,
}
......@@ -69,9 +69,9 @@ def netbox_clean_up(subscription: EdgePort) -> None:
nbclient = NetboxClient()
for member in subscription.edge_port.edge_port_ae_members:
nbclient.free_interface(subscription.edge_port.edge_port_node.router_fqdn, member.interface_name)
nbclient.free_interface(subscription.edge_port.node.router_fqdn, member.interface_name)
nbclient.delete_interface(subscription.edge_port.edge_port_node.router_fqdn, subscription.edge_port.edge_port_name)
nbclient.delete_interface(subscription.edge_port.node.router_fqdn, subscription.edge_port.edge_port_name)
@workflow(
......
......@@ -30,7 +30,7 @@ def verify_netbox_entries(subscription: EdgePort) -> None:
# Raises en exception when not found.
lag = nbclient.get_interface_by_name_and_device(
subscription.edge_port.edge_port_name, subscription.edge_port.edge_port_node.router_fqdn
subscription.edge_port.edge_port_name, subscription.edge_port.node.router_fqdn
)
if lag.description != str(subscription.subscription_id):
netbox_errors.append(
......@@ -41,7 +41,7 @@ def verify_netbox_entries(subscription: EdgePort) -> None:
netbox_errors.append(f"NetBox interface '{lag}' is not enabled.")
for member in subscription.edge_port.edge_port_ae_members:
interface = nbclient.get_interface_by_name_and_device(
member.interface_name, subscription.edge_port.edge_port_node.router_fqdn
member.interface_name, subscription.edge_port.node.router_fqdn
)
if interface.description != str(subscription.subscription_id):
netbox_errors.append(
......@@ -60,7 +60,7 @@ def verify_base_config(subscription: dict[str, Any]) -> LSOState:
"""Workflow step for running a playbook that checks whether base config has drifted."""
return {
"playbook_name": "edge_port.yaml",
"inventory": {"all": {"hosts": {subscription["edge_port"]["edge_port_node"]["router_fqdn"]: None}}},
"inventory": {"all": {"hosts": {subscription["edge_port"]["node"]["router_fqdn"]: None}}},
"extra_vars": {
"dry_run": True,
"subscription": subscription,
......
......@@ -166,7 +166,7 @@ def initialize_subscription(
geant_ip_sbp=service_binding_port,
)
)
edge_port_fqdn_list.append(edge_port_subscription.edge_port.edge_port_node.router_fqdn)
edge_port_fqdn_list.append(edge_port_subscription.edge_port.node.router_fqdn)
subscription.description = "GEANT IP service"
......
......@@ -39,7 +39,7 @@ def edge_port_subscription_factory(faker, partner_factory, nokia_router_subscrip
is_imported=True,
) -> UUIDstr:
partner = partner or partner_factory()
edge_port_node = Router.from_subscription(nokia_router_subscription_factory()).router
node = Router.from_subscription(nokia_router_subscription_factory()).router
if is_imported:
product_id = subscriptions.get_product_id_by_name(ProductName.EDGE_PORT)
edge_port_subscription = EdgePortInactive.from_product_id(
......@@ -52,18 +52,17 @@ def edge_port_subscription_factory(faker, partner_factory, nokia_router_subscrip
)
edge_port_subscription.edge_port.edge_port_description = description or faker.text(max_nb_chars=30)
edge_port_subscription.edge_port.edge_port_geant_ga_id = geant_ga_id or faker.geant_sid()
edge_port_subscription.edge_port.edge_port_node = node or edge_port_node
edge_port_subscription.edge_port.geant_ga_id = geant_ga_id or faker.geant_sid()
edge_port_subscription.edge_port.node = node or node
edge_port_subscription.edge_port.edge_port_name = name or f"lag-{faker.pyint(21, 50)}"
edge_port_subscription.edge_port.edge_port_description = edge_port_description or faker.sentence()
edge_port_subscription.edge_port.edge_port_enable_lacp = enable_lacp
edge_port_subscription.edge_port.edge_port_encapsulation = encapsulation
edge_port_subscription.edge_port.edge_port_mac_address = mac_address or faker.mac_address()
edge_port_subscription.edge_port.edge_port_member_speed = member_speed
edge_port_subscription.edge_port.edge_port_minimum_links = minimum_links or faker.pyint(1, 2)
edge_port_subscription.edge_port.enable_lacp = enable_lacp
edge_port_subscription.edge_port.encapsulation = encapsulation
edge_port_subscription.edge_port.mac_address = mac_address or faker.mac_address()
edge_port_subscription.edge_port.member_speed = member_speed
edge_port_subscription.edge_port.minimum_links = minimum_links or faker.pyint(1, 2)
edge_port_subscription.edge_port.edge_port_type = edge_port_type
edge_port_subscription.edge_port.edge_port_ignore_if_down = ignore_if_down
edge_port_subscription.edge_port.edge_port_geant_ga_id = geant_ga_id
edge_port_subscription.edge_port.ignore_if_down = ignore_if_down
edge_port_subscription.edge_port.edge_port_ae_members = edge_port_ae_members or [
EdgePortAEMemberBlock.new(
faker.uuid4(),
......
......@@ -10,7 +10,7 @@ from gso.products import EdgePort, ProductName
from gso.products.product_blocks.bgp_session import BGPSession, IPFamily
from gso.products.product_blocks.nren_l3_core_service import NRENAccessPort
from gso.products.product_blocks.service_binding_port import ServiceBindingPort
from gso.products.product_types.nren_l3_core_service import GeantIPInactive, ImportedGeantIP
from gso.products.product_types.nren_l3_core_service import NRENL3CoreServiceInactive, ImportedNRENL3CoreService
from gso.services import subscriptions
from gso.utils.shared_enums import APType, SBPType
from gso.utils.types.ip_address import IPAddress
......@@ -123,12 +123,12 @@ def geant_ip_subscription_factory(
partner = partner or partner_factory()
if is_imported:
product_id = subscriptions.get_product_id_by_name(ProductName.GEANT_IP)
geant_ip_subscription = GeantIPInactive.from_product_id(
geant_ip_subscription = NRENL3CoreServiceInactive.from_product_id(
product_id, customer_id=partner["partner_id"], insync=True
)
else:
product_id = subscriptions.get_product_id_by_name(ProductName.IMPORTED_GEANT_IP)
geant_ip_subscription = ImportedGeantIP.from_product_id(
geant_ip_subscription = ImportedNRENL3CoreService.from_product_id(
product_id, customer_id=partner["partner_id"], insync=True
)
......
......@@ -89,7 +89,7 @@ def test_modify_edge_port_with_changing_capacity(
assert mocked_attach_interface_to_lag.call_count == 1
assert mocked_free_interface.call_count == 2
assert mocked_detach_interfaces_from_lag.call_count == 1
assert subscription.edge_port.edge_port_geant_ga_id == input_form_wizard_data[1]["geant_ga_id"]
assert subscription.edge_port.geant_ga_id == input_form_wizard_data[1]["geant_ga_id"]
assert len(subscription.edge_port.edge_port_ae_members) == 1
......@@ -163,6 +163,6 @@ def test_modify_edge_port_without_changing_capacity(
assert mocked_free_interface.call_count == 0
assert mocked_detach_interfaces_from_lag.call_count == 0
assert subscription.edge_port.edge_port_geant_ga_id == input_form_wizard_without_changing_capacity[1]["geant_ga_id"]
assert subscription.edge_port.geant_ga_id == input_form_wizard_without_changing_capacity[1]["geant_ga_id"]
assert len(subscription.edge_port.edge_port_ae_members) == 2
assert subscription.edge_port.edge_port_description == input_form_wizard_without_changing_capacity[2]["description"]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment