From f566bb3216dfc7a14bec45d79387cee00ea7841e Mon Sep 17 00:00:00 2001 From: Karel van Klink <karel.vanklink@geant.org> Date: Thu, 17 Oct 2024 11:14:54 +0200 Subject: [PATCH] Update Edge Port workflows --- gso/workflows/edge_port/create_edge_port.py | 7 +-- .../edge_port/create_imported_edge_port.py | 20 +++---- gso/workflows/edge_port/modify_edge_port.py | 60 +++++++++---------- .../edge_port/terminate_edge_port.py | 8 +-- gso/workflows/edge_port/validate_edge_port.py | 6 +- .../create_nren_l3_core_service.py | 2 +- test/fixtures/edge_port_fixtures.py | 19 +++--- test/fixtures/geant_ip_fixtures.py | 6 +- .../edge_port/test_modify_edge_port.py | 4 +- 9 files changed, 64 insertions(+), 68 deletions(-) diff --git a/gso/workflows/edge_port/create_edge_port.py b/gso/workflows/edge_port/create_edge_port.py index 1580de71..0cd6127f 100644 --- a/gso/workflows/edge_port/create_edge_port.py +++ b/gso/workflows/edge_port/create_edge_port.py @@ -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, } diff --git a/gso/workflows/edge_port/create_imported_edge_port.py b/gso/workflows/edge_port/create_imported_edge_port.py index f6fb84fd..5f9fe262 100644 --- a/gso/workflows/edge_port/create_imported_edge_port.py +++ b/gso/workflows/edge_port/create_imported_edge_port.py @@ -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) diff --git a/gso/workflows/edge_port/modify_edge_port.py b/gso/workflows/edge_port/modify_edge_port.py index 48ab064f..42be6db5 100644 --- a/gso/workflows/edge_port/modify_edge_port.py +++ b/gso/workflows/edge_port/modify_edge_port.py @@ -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 ) diff --git a/gso/workflows/edge_port/terminate_edge_port.py b/gso/workflows/edge_port/terminate_edge_port.py index 9aecae20..257440de 100644 --- a/gso/workflows/edge_port/terminate_edge_port.py +++ b/gso/workflows/edge_port/terminate_edge_port.py @@ -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( diff --git a/gso/workflows/edge_port/validate_edge_port.py b/gso/workflows/edge_port/validate_edge_port.py index b9561d4c..654d1e7b 100644 --- a/gso/workflows/edge_port/validate_edge_port.py +++ b/gso/workflows/edge_port/validate_edge_port.py @@ -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, diff --git a/gso/workflows/nren_l3_core_service/create_nren_l3_core_service.py b/gso/workflows/nren_l3_core_service/create_nren_l3_core_service.py index f390b8b1..bba6a51e 100644 --- a/gso/workflows/nren_l3_core_service/create_nren_l3_core_service.py +++ b/gso/workflows/nren_l3_core_service/create_nren_l3_core_service.py @@ -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" diff --git a/test/fixtures/edge_port_fixtures.py b/test/fixtures/edge_port_fixtures.py index 274f4052..c8e73f09 100644 --- a/test/fixtures/edge_port_fixtures.py +++ b/test/fixtures/edge_port_fixtures.py @@ -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(), diff --git a/test/fixtures/geant_ip_fixtures.py b/test/fixtures/geant_ip_fixtures.py index 95c275f8..cf7a8384 100644 --- a/test/fixtures/geant_ip_fixtures.py +++ b/test/fixtures/geant_ip_fixtures.py @@ -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 ) diff --git a/test/workflows/edge_port/test_modify_edge_port.py b/test/workflows/edge_port/test_modify_edge_port.py index 6b57c4c9..68635d14 100644 --- a/test/workflows/edge_port/test_modify_edge_port.py +++ b/test/workflows/edge_port/test_modify_edge_port.py @@ -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"] -- GitLab