diff --git a/gso/workflows/iptrunk/create_iptrunk.py b/gso/workflows/iptrunk/create_iptrunk.py index ac482121a172741bb619985dbc1da2cd6f913d69..7c4be562318211bf118980c17af9bc800597c5c4 100644 --- a/gso/workflows/iptrunk/create_iptrunk.py +++ b/gso/workflows/iptrunk/create_iptrunk.py @@ -400,6 +400,22 @@ def check_ip_trunk_isis( return {"subscription": subscription} +@step("Register DNS records for both sides of the trunk") +def register_dns_records(subscription: IptrunkInactive) -> State: + """Register DNS records for both sides of the newly created IPtrunk.""" + for index, side in enumerate(subscription.iptrunk.iptrunk_sides): + fqdn = f"{side.iptrunk_side_ae_iface}-0.{side.iptrunk_side_node.router_fqdn}" + if not (subscription.iptrunk.iptrunk_ipv4_network and subscription.iptrunk.iptrunk_ipv6_network): + msg = f"Missing IP resources in trunk, cannot allocate DNS record for side {fqdn}!" + raise ValueError(msg) + ipv4_addr = subscription.iptrunk.iptrunk_ipv4_network[index] + ipv6_addr = subscription.iptrunk.iptrunk_ipv6_network[index] + + infoblox.create_host_by_ip(fqdn, ipv4_addr, ipv6_addr, "TRUNK", str(subscription.subscription_id)) + + return {"subscription": subscription} + + @step("NextBox integration") def reserve_interfaces_in_netbox(subscription: IptrunkInactive) -> State: """Create the :term:`LAG` interfaces in NetBox and attach the lag interfaces to the physical interfaces.""" @@ -490,6 +506,7 @@ def create_iptrunk() -> StepList: >> pp_interaction(provision_ip_trunk_isis_iface_dry) >> pp_interaction(provision_ip_trunk_isis_iface_real) >> pp_interaction(check_ip_trunk_isis) + >> register_dns_records >> side_a_is_nokia(netbox_allocate_side_a_interfaces) >> side_b_is_nokia(netbox_allocate_side_b_interfaces) >> set_status(SubscriptionLifecycle.PROVISIONING) diff --git a/test/workflows/iptrunk/test_create_iptrunk.py b/test/workflows/iptrunk/test_create_iptrunk.py index b85f6d3fc586949dd07d53f5694e23d251eb69f5..3aad9ae13e7132fdcd62b3acd31f1047c32ad8c3 100644 --- a/test/workflows/iptrunk/test_create_iptrunk.py +++ b/test/workflows/iptrunk/test_create_iptrunk.py @@ -97,7 +97,9 @@ def input_form_wizard_data(request, juniper_router_subscription_factory, nokia_r @patch("gso.workflows.iptrunk.create_iptrunk.execute_playbook") @patch("gso.workflows.iptrunk.create_iptrunk.infoblox.allocate_v6_network") @patch("gso.workflows.iptrunk.create_iptrunk.infoblox.allocate_v4_network") +@patch("gso.workflows.iptrunk.create_iptrunk.infoblox.create_host_by_ip") def test_successful_iptrunk_creation_with_standard_lso_result( + mock_create_host, mock_allocate_v4_network, mock_allocate_v6_network, mock_execute_playbook, @@ -108,6 +110,7 @@ def test_successful_iptrunk_creation_with_standard_lso_result( data_config_filename: PathLike, test_client, ): + mock_create_host.return_value = None mock_allocate_v4_network.return_value = faker.ipv4(network=True) mock_allocate_v6_network.return_value = faker.ipv6(network=True) product_id = get_product_id_by_name(ProductType.IP_TRUNK) @@ -170,7 +173,9 @@ def test_iptrunk_creation_fails_when_lso_return_code_is_one( @patch("gso.workflows.iptrunk.create_iptrunk.execute_playbook") @patch("gso.workflows.iptrunk.create_iptrunk.infoblox.allocate_v6_network") @patch("gso.workflows.iptrunk.create_iptrunk.infoblox.allocate_v4_network") +@patch("gso.workflows.iptrunk.create_iptrunk.infoblox.create_host_by_ip") def test_successful_iptrunk_creation_with_juniper_interface_names( + mock_create_host, mock_allocate_v4_network, mock_allocate_v6_network, mock_execute_playbook, @@ -181,8 +186,9 @@ def test_successful_iptrunk_creation_with_juniper_interface_names( _netbox_client_mock, # noqa: PT019 test_client, ): - mock_allocate_v4_network.return_value = faker.ipv4(network=True) - mock_allocate_v6_network.return_value = faker.ipv6(network=True) + mock_create_host.return_value = None + mock_allocate_v4_network.return_value = faker.ipv4_network(max_subnet=31) + mock_allocate_v6_network.return_value = faker.ipv6_network(max_subnet=127) product_id = get_product_id_by_name(ProductType.IP_TRUNK) initial_site_data = [{"product": product_id}, *input_form_wizard_data] result, process_stat, step_log = run_workflow("create_iptrunk", initial_site_data)