Fix bug 2302: IP ranges management in Azure not working properly 85/13985/4
authoraguilard <e.dah.tid@telefonica.com>
Thu, 2 Nov 2023 16:52:56 +0000 (16:52 +0000)
committeraguilard <e.dah.tid@telefonica.com>
Mon, 6 Nov 2023 07:29:55 +0000 (07:29 +0000)
OSM uses a specific vnet to create NS or VNF subnets when instantiating on
Azure. The vnets allow more than one address prefix, but RO only try to
allocate new subnets in the range defined in first place, ignoring the rest.

Change-Id: I9792caf2a468e60b6762567a9b4a90d0f1646b39
Signed-off-by: aguilard <e.dah.tid@telefonica.com>
RO-VIM-azure/osm_rovim_azure/vimconn_azure.py
releasenotes/notes/fix_bug_2302-3432828f06200186.yaml [new file with mode: 0644]

index 15c3cad..06bc970 100755 (executable)
@@ -203,7 +203,7 @@ class vimconnector(vimconn.VimConnector):
         # Variable that indicates if client must be reloaded or initialized
         self.reload_client = True
 
-        self.vnet_address_space = None
+        self.vnet_address_space = []
 
         # LOGGER
         self.logger = logging.getLogger("ro.vim.azure")
@@ -407,7 +407,7 @@ class vimconnector(vimconn.VimConnector):
             vnet = self.conn_vnet.virtual_networks.get(
                 self.vnet_resource_group or self.resource_group, self.vnet_name
             )
-            self.vnet_address_space = vnet.address_space.address_prefixes[0]
+            self.vnet_address_space = vnet.address_space.address_prefixes
             self.vnet_id = vnet.id
 
             return
@@ -424,7 +424,7 @@ class vimconnector(vimconn.VimConnector):
                 "location": self.region,
                 "address_space": {"address_prefixes": ["10.0.0.0/8"]},
             }
-            self.vnet_address_space = "10.0.0.0/8"
+            self.vnet_address_space = ["10.0.0.0/8"]
 
             self.logger.debug("create base vnet: %s", self.vnet_name)
             self.conn_vnet.virtual_networks.begin_create_or_update(
@@ -485,16 +485,21 @@ class vimconnector(vimconn.VimConnector):
         if ip_profile is None:
             # get a non used vnet ip range /24 and allocate automatically inside the range self.vnet_address_space
             used_subnets = self.get_network_list()
-            for ip_range in netaddr.IPNetwork(self.vnet_address_space).subnet(24):
-                for used_subnet in used_subnets:
-                    subnet_range = netaddr.IPNetwork(used_subnet["cidr_block"])
-
-                    if subnet_range in ip_range or ip_range in subnet_range:
-                        # this range overlaps with an existing subnet ip range. Breaks and look for another
+            for space in self.vnet_address_space:
+                for ip_range in netaddr.IPNetwork(space).subnet(24):
+                    for used_subnet in used_subnets:
+                        subnet_range = netaddr.IPNetwork(used_subnet["cidr_block"])
+
+                        if subnet_range in ip_range or ip_range in subnet_range:
+                            # this range overlaps with an existing subnet ip range. Breaks and look for another
+                            break
+                    else:
+                        ip_profile = {"subnet_address": str(ip_range)}
+                        self.logger.debug(
+                            "dinamically obtained ip_profile: %s", ip_range
+                        )
                         break
-                else:
-                    ip_profile = {"subnet_address": str(ip_range)}
-                    self.logger.debug("dinamically obtained ip_profile: %s", ip_range)
+                if ip_profile is not None:
                     break
             else:
                 raise vimconn.VimConnException(
diff --git a/releasenotes/notes/fix_bug_2302-3432828f06200186.yaml b/releasenotes/notes/fix_bug_2302-3432828f06200186.yaml
new file mode 100644 (file)
index 0000000..0181013
--- /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 2302: RO does not handle properly vnet IP ranges in Azure. 
+    OSM uses a specific vnet to create NS or VNF subnets when instantiating on
+    Azure. The vnets allow more than one address prefix, but RO only try to
+    allocate new subnets in the range defined in first place, ignoring the rest.