From 798e7afc523c53b9b198047fe03c0e14c9931f60 Mon Sep 17 00:00:00 2001
From: Bjarke Madsen <bjarke@nordu.net>
Date: Thu, 13 Apr 2023 16:00:37 +0200
Subject: [PATCH] Add fix for assigning correct port SIDs to circuits

---
 inventory_provider/tasks/worker.py | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/inventory_provider/tasks/worker.py b/inventory_provider/tasks/worker.py
index f9b1e36b..c695e646 100644
--- a/inventory_provider/tasks/worker.py
+++ b/inventory_provider/tasks/worker.py
@@ -1110,16 +1110,25 @@ def transform_ims_data(data):
                     node_pair_services[
                         f"{circ['equipment']}/{circ['other_end_equipment']}"
                     ][circ['id']] = circ
+                try:
+                    # get the physical port circuit, if it exists
+                    # https://jira.software.geant.org/browse/POL1-687
+                    port_circuit = next(
+                        c for c in circuits if c.get('port_type') == 'ports')
+                except StopIteration:
+                    port_circuit = None
 
                 sid = None
                 if circ['id'] in circuit_ids_and_sids:
                     sid = circuit_ids_and_sids[circ['id']]
-
                 elif 'sid' in details:
                     if len(circuits) > 1:
-                        # we don't know which circuit
-                        # to give the SID in this case, so skip
-                        continue
+                        if port_circuit != circ:
+                            # we don't know which circuit
+                            # to give the SID in this case, so skip
+                            continue
+
+                    # assign the SID from the port to this circuit
                     sid = details['sid']
 
                 if sid is None:
-- 
GitLab