From 4ef56d2647c2bf1750c0e6941428b2dc5b387965 Mon Sep 17 00:00:00 2001
From: Karel van Klink <karel.vanklink@geant.org>
Date: Thu, 14 Mar 2024 17:52:25 +0100
Subject: [PATCH] Update IPtrunk migration IPAM step behaviour

---
 gso/workflows/iptrunk/migrate_iptrunk.py       | 13 ++++++-------
 test/workflows/iptrunk/test_migrate_iptrunk.py | 12 +++---------
 2 files changed, 9 insertions(+), 16 deletions(-)

diff --git a/gso/workflows/iptrunk/migrate_iptrunk.py b/gso/workflows/iptrunk/migrate_iptrunk.py
index 04ae9af5..a6428491 100644
--- a/gso/workflows/iptrunk/migrate_iptrunk.py
+++ b/gso/workflows/iptrunk/migrate_iptrunk.py
@@ -542,26 +542,25 @@ def delete_old_config_real(
 
 
 @step("Update IP records in IPAM")
-def update_ipam(subscription: Iptrunk, old_side_data: dict, new_node: Router, new_lag_interface: str) -> State:
+def update_ipam(subscription: Iptrunk, replace_index: int, new_node: Router, new_lag_interface: str) -> State:
     """Update :term:`IPAM` resources.
 
     Move the DNS record pointing to the old side of the trunk, to the new side.
     """
-    old_fqdn = f"{old_side_data['iptrunk_side_ae_iface']}.{old_side_data['iptrunk_side_node']['router_fqdn']}"
-    trunk_v4 = infoblox.find_host_by_fqdn(old_fqdn)
-    trunk_v6 = infoblox.find_v6_host_by_fqdn(old_fqdn)
+    v4_addr = subscription.iptrunk.iptrunk_ipv4_network[replace_index]
+    v6_addr = subscription.iptrunk.iptrunk_ipv6_network[replace_index]
 
     #  Out with the old
     try:
-        infoblox.delete_host_by_fqdn(old_fqdn)
+        infoblox.delete_host_by_ip(subscription.iptrunk.iptrunk_ipv4_network[replace_index])
     except DeletionError as e:
         msg = "Failed to delete record from Infoblox."
         raise ProcessFailureError(msg) from e
 
     #  And in with the new
-    new_fqdn = f"{new_lag_interface}.{new_node.router.router_fqdn}"
+    new_fqdn = f"{new_lag_interface}-0.{new_node.router.router_fqdn}"
     comment = str(subscription.subscription_id)
-    infoblox.create_host_by_ip(new_fqdn, trunk_v4.ipv4addr, trunk_v6.ipv6addr, service_type="TRUNK", comment=comment)
+    infoblox.create_host_by_ip(new_fqdn, v4_addr, v6_addr, "TRUNK", comment)
 
     return {"subscription": subscription}
 
diff --git a/test/workflows/iptrunk/test_migrate_iptrunk.py b/test/workflows/iptrunk/test_migrate_iptrunk.py
index 825b9e7c..be971b2b 100644
--- a/test/workflows/iptrunk/test_migrate_iptrunk.py
+++ b/test/workflows/iptrunk/test_migrate_iptrunk.py
@@ -109,9 +109,7 @@ def interface_lists_are_equal(list1, list2):
 )
 @pytest.mark.workflow()
 @patch("gso.services.infoblox.create_host_by_ip")
-@patch("gso.services.infoblox.find_v6_host_by_fqdn")
-@patch("gso.services.infoblox.find_host_by_fqdn")
-@patch("gso.services.infoblox.delete_host_by_fqdn")
+@patch("gso.services.infoblox.delete_host_by_ip")
 @patch("gso.services.provisioning_proxy._send_request")
 @patch("gso.services.netbox_client.NetboxClient.get_available_interfaces")
 @patch("gso.services.netbox_client.NetboxClient.get_available_lags")
@@ -131,9 +129,7 @@ def test_migrate_iptrunk_success(
     mocked_get_available_lags,
     mocked_get_available_interfaces,
     mock_execute_playbook,
-    mock_delete_host_by_fqdn,
-    mock_find_host_by_fqdn,
-    mock_find_v6_host_by_fqdn,
+    mock_delete_host_by_ip,
     mock_create_host_by_ip,
     migrate_form_input,
     data_config_filename: PathLike,
@@ -173,10 +169,8 @@ def test_migrate_iptrunk_success(
 
     assert subscription.status == "active"
     assert mock_execute_playbook.call_count == 9
-    assert mock_find_host_by_fqdn.call_count == 1
-    assert mock_find_v6_host_by_fqdn.call_count == 1
     assert mock_create_host_by_ip.call_count == 1
-    assert mock_delete_host_by_fqdn.call_count == 1
+    assert mock_delete_host_by_ip.call_count == 1
 
     # get some values from form
     new_router = migrate_form_input[2]["new_node"]
-- 
GitLab