From 03de2b9ea09ddf835ab1a7d238b26f5908fa2feb Mon Sep 17 00:00:00 2001 From: Karel van Klink <karel.vanklink@geant.org> Date: Fri, 1 Nov 2024 10:13:24 +0100 Subject: [PATCH] Add summary pages to switch and lan switch interconnect creation --- gso/utils/types/ip_address.py | 2 +- .../create_lan_switch_interconnect.py | 29 +++++++++++++++---- gso/workflows/switch/create_switch.py | 9 ++++-- .../test_create_lan_switch_interconnect.py | 1 + test/workflows/switch/test_create_switch.py | 1 + 5 files changed, 33 insertions(+), 9 deletions(-) diff --git a/gso/utils/types/ip_address.py b/gso/utils/types/ip_address.py index 14e00bb2..3b91167f 100644 --- a/gso/utils/types/ip_address.py +++ b/gso/utils/types/ip_address.py @@ -59,4 +59,4 @@ class AddressSpace(strEnum): """Types of address space. Can be private or public.""" PRIVATE = "PRIVATE" - PUBLIC = "PRIVATE" + PUBLIC = "PUBLIC" diff --git a/gso/workflows/lan_switch_interconnect/create_lan_switch_interconnect.py b/gso/workflows/lan_switch_interconnect/create_lan_switch_interconnect.py index 44f4f811..eeec84e1 100644 --- a/gso/workflows/lan_switch_interconnect/create_lan_switch_interconnect.py +++ b/gso/workflows/lan_switch_interconnect/create_lan_switch_interconnect.py @@ -37,6 +37,7 @@ from gso.utils.types.interfaces import ( ) from gso.utils.types.ip_address import AddressSpace from gso.utils.types.tt_number import TTNumber +from gso.workflows.shared import create_summary_form def _initial_input_form(product_name: str) -> FormGenerator: @@ -53,8 +54,8 @@ def _initial_input_form(product_name: str) -> FormGenerator: divider: Divider vlan_id: ReadOnlyField(111, default_type=int) # type: ignore[valid-type] - user_input = yield CreateLANSwitchInterconnectForm - router = Router.from_subscription(user_input.router_side) + initial_input = yield CreateLANSwitchInterconnectForm + router = Router.from_subscription(initial_input.router_side) if router.router.vendor == Vendor.NOKIA: @@ -67,19 +68,19 @@ def _initial_input_form(product_name: str) -> FormGenerator: router_side_ae_member_list = Annotated[ list[NokiaLAGMemberA], AfterValidator(validate_interface_names_are_unique), - Len(min_length=user_input.minimum_link_count), + Len(min_length=initial_input.minimum_link_count), ] else: router_side_ae_member_list = Annotated[ # type: ignore[assignment, misc] list[JuniperLAGMember], AfterValidator(validate_interface_names_are_unique), - Len(min_length=user_input.minimum_link_count), + Len(min_length=initial_input.minimum_link_count), ] class InterconnectRouterSideForm(FormPage): model_config = ConfigDict(title="Please enter interface names and descriptions for the router side.") - router_side_iface: available_lags_choices(user_input.router_side) or JuniperAEInterface or str # type: ignore[valid-type] + router_side_iface: available_lags_choices(initial_input.router_side) or JuniperAEInterface or str # type: ignore[valid-type] router_side_ae_members: router_side_ae_member_list router_side_input = yield InterconnectRouterSideForm @@ -100,8 +101,24 @@ def _initial_input_form(product_name: str) -> FormGenerator: switch_side_ae_members: switch_side_ae_member_list switch_side_input = yield InterconnectSwitchSideForm + user_input = initial_input.model_dump() | router_side_input.model_dump() | switch_side_input.model_dump() + summary_fields = [ + "tt_number", + "partner", + "router_side", + "switch_side", + "address_space", + "description", + "minimum_link_count", + "vlan_id", + "router_side_iface", + "router_side_ae_members", + "switch_side_iface", + "switch_side_ae_members", + ] + yield from create_summary_form(user_input, product_name, summary_fields) - return user_input.model_dump() | router_side_input.model_dump() | switch_side_input.model_dump() + return user_input @step("Create subscription") diff --git a/gso/workflows/switch/create_switch.py b/gso/workflows/switch/create_switch.py index 220773af..0074c8e4 100644 --- a/gso/workflows/switch/create_switch.py +++ b/gso/workflows/switch/create_switch.py @@ -25,6 +25,7 @@ from gso.utils.shared_enums import Vendor from gso.utils.types.ip_address import PortNumber from gso.utils.types.tt_number import TTNumber from gso.utils.workflow_steps import prompt_sharepoint_checklist_url +from gso.workflows.shared import create_summary_form def _initial_input_form_generator(product_name: str) -> FormGenerator: @@ -55,8 +56,12 @@ def _initial_input_form_generator(product_name: str) -> FormGenerator: return self - user_input = yield CreateSwitchForm - return user_input.model_dump() + input_form = yield CreateSwitchForm + user_input = input_form.model_dump() + summary_fields = ["tt_number", "partner", "switch_site", "hostname", "ts_port", "vendor", "model"] + yield from create_summary_form(user_input, product_name, summary_fields) + + return user_input @step("Create subscription") diff --git a/test/workflows/lan_switch_interconnect/test_create_lan_switch_interconnect.py b/test/workflows/lan_switch_interconnect/test_create_lan_switch_interconnect.py index 7c28828f..2c6657d2 100644 --- a/test/workflows/lan_switch_interconnect/test_create_lan_switch_interconnect.py +++ b/test/workflows/lan_switch_interconnect/test_create_lan_switch_interconnect.py @@ -50,6 +50,7 @@ def input_form_data(faker, router_subscription_factory, switch_subscription_fact "switch_side_iface": faker.network_interface(), "switch_side_ae_members": faker.link_members_juniper()[:2], }, + {}, ] return _generate_form_data diff --git a/test/workflows/switch/test_create_switch.py b/test/workflows/switch/test_create_switch.py index f4f3fc23..c11edf80 100644 --- a/test/workflows/switch/test_create_switch.py +++ b/test/workflows/switch/test_create_switch.py @@ -33,6 +33,7 @@ def test_create_switch_success( "hostname": faker.domain_word(), "ts_port": faker.port_number(is_user=True), }, + {}, ] mock_hostname_available.return_value = True mock_sharepoint_client.return_value = MockedSharePointClient -- GitLab