Fix Bug 1607 Interface position is not taken into account 06/12206/4
authoraticig <gulsum.atici@canonical.com>
Wed, 15 Jun 2022 22:28:29 +0000 (01:28 +0300)
committeraticig <gulsum.atici@canonical.com>
Mon, 20 Jun 2022 09:00:39 +0000 (11:00 +0200)
This fix provides to attach interfaces to VNF according to the position order
which is defined in the VNFD.

Change-Id: Ibe17d63548c8b753f791de2440fec4c763fd8fe2
Signed-off-by: aticig <gulsum.atici@canonical.com>
NG-RO/osm_ng_ro/ns.py
releasenotes/notes/fix_bug_1607-9b1d5abe67535a04.yaml [new file with mode: 0644]

index 2b53f19..d2dc46b 100644 (file)
@@ -958,6 +958,37 @@ class Ns(object):
         extra_dict = {"depends_on": [image_text, flavor_text]}
         net_list = []
 
+        # If the position info is provided for all the interfaces, it will be sorted
+        # according to position number ascendingly.
+        if all(i.get("position") for i in target_vdu["interfaces"]):
+            sorted_interfaces = sorted(
+                target_vdu["interfaces"],
+                key=lambda x: (x.get("position") is None, x.get("position")),
+            )
+            target_vdu["interfaces"] = sorted_interfaces
+
+        # If the position info is provided for some interfaces but not all of them, the interfaces
+        # which has specific position numbers will be placed and others' positions will not be taken care.
+        else:
+            if any(i.get("position") for i in target_vdu["interfaces"]):
+                n = len(target_vdu["interfaces"])
+                sorted_interfaces = [-1] * n
+                k, m = 0, 0
+                while k < n:
+                    if target_vdu["interfaces"][k].get("position"):
+                        idx = target_vdu["interfaces"][k]["position"]
+                        sorted_interfaces[idx - 1] = target_vdu["interfaces"][k]
+                    k += 1
+                while m < n:
+                    if not target_vdu["interfaces"][m].get("position"):
+                        idy = sorted_interfaces.index(-1)
+                        sorted_interfaces[idy] = target_vdu["interfaces"][m]
+                    m += 1
+
+                target_vdu["interfaces"] = sorted_interfaces
+
+        # If the position info is not provided for the interfaces, interfaces will be attached
+        # according to the order in the VNFD.
         for iface_index, interface in enumerate(target_vdu["interfaces"]):
             if interface.get("ns-vld-id"):
                 net_text = ns_preffix + ":vld." + interface["ns-vld-id"]
diff --git a/releasenotes/notes/fix_bug_1607-9b1d5abe67535a04.yaml b/releasenotes/notes/fix_bug_1607-9b1d5abe67535a04.yaml
new file mode 100644 (file)
index 0000000..a65a7e1
--- /dev/null
@@ -0,0 +1,23 @@
+#######################################################################################
+# Copyright ETSI Contributors and Others.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#######################################################################################
+---
+fixes:
+  - |
+    Fix Bug 1607 Interface position is not taken into account
+    This fix provides to attach interfaces to VNF according to the position order
+    which is defined in the VNFD.
+