Fix bug 2019 to delete ONOS hosts associated to a VPLS service 87/13887/7
authorgarciadeblas <gerardo.garciadeblas@telefonica.com>
Tue, 19 Sep 2023 15:09:11 +0000 (17:09 +0200)
committergarciadeblas <gerardo.garciadeblas@telefonica.com>
Mon, 29 Jan 2024 17:00:05 +0000 (18:00 +0100)
Change-Id: Ibb7d39cca4189e4f7ea4f997f80fef165294f7f0
Signed-off-by: garciadeblas <gerardo.garciadeblas@telefonica.com>
RO-SDN-onos_vpls/osm_rosdn_onos_vpls/sdn_assist_onos_vpls.py
releasenotes/notes/fix_bug_2019-5f170b3442a16687.yaml [new file with mode: 0644]

index c02ee15..b659d92 100644 (file)
@@ -54,6 +54,7 @@ class OnosVpls(SdnConnectorBase):
             url = url + "/"
 
         self.url = url + "onos/v1/network/configuration"
+        self.hosts_url = url + "onos/v1/hosts"
         self.logger.info("ONOS VPLS Connector Initialized.")
 
     def check_credentials(self):
@@ -152,6 +153,35 @@ class OnosVpls(SdnConnectorBase):
                 "Exception posting onos network config: {}".format(e)
             )
 
+    def _delete_onos_hosts(self, onos_host_list):
+        try:
+            for host_id in onos_host_list:
+                url = f"{self.hosts_url}/{host_id}"
+                onos_resp = requests.delete(
+                    url, auth=HTTPBasicAuth(self.user, self.password)
+                )
+                status_code = onos_resp.status_code
+
+                if status_code != requests.codes.ok:
+                    self.logger.info(
+                        "Error deleting ONOS host, status code: {}".format(status_code)
+                    )
+
+                    raise SdnConnectorError(
+                        "Error deleting ONOS host, status code: {}".format(status_code),
+                        http_code=status_code,
+                    )
+        except requests.exceptions.ConnectionError as e:
+            self.logger.info("Exception connecting to onos: %s", e)
+
+            raise SdnConnectorError("Error connecting to onos: {}".format(e))
+        except Exception as e:
+            self.logger.info("Exception posting onos network config: %s", e)
+
+            raise SdnConnectorError(
+                "Exception posting onos network config: {}".format(e)
+            )
+
     def create_connectivity_service(self, service_type, connection_points, **kwargs):
         self.logger.debug(
             "create_connectivity_service, service_type: {}, connection_points: {}".format(
@@ -414,9 +444,12 @@ class OnosVpls(SdnConnectorBase):
         created_ifs = conn_info.get("interfaces", [])
         # Obtain current config
         onos_config = self._get_onos_netconfig()
+        conn_service_host_list = []
 
         try:
             # Removes ports used by network from onos config
+            # In addition, it  stores host identifiers (e.g. "FA:16:3E:43:9F:4A/1001")
+            # in conn_service_host_list to be deleted by self._delete_onos_hosts
             for vpls in (
                 onos_config.get("apps", {})
                 .get("org.onosproject.vpls", {})
@@ -424,6 +457,7 @@ class OnosVpls(SdnConnectorBase):
                 .get("vplsList", {})
             ):
                 if vpls["name"] == service_uuid:
+                    self.logger.debug(f"vpls service to be deleted: {vpls}")
                     # iterate interfaces to check if must delete them
                     for interface in vpls["interfaces"]:
                         for port in onos_config["ports"].values():
@@ -437,6 +471,9 @@ class OnosVpls(SdnConnectorBase):
                                             )
                                         )
                                         port["interfaces"].remove(port_interface)
+                                        # TODO: store host_id
+                                        # host_id = ""
+                                        # conn_service_host_list.append(f"{host_id}")
                     onos_config["apps"]["org.onosproject.vpls"]["vpls"][
                         "vplsList"
                     ].remove(vpls)
@@ -448,6 +485,7 @@ class OnosVpls(SdnConnectorBase):
 
             self._pop_last_update_time(onos_config)
             self._post_onos_netconfig(onos_config)
+            self._delete_onos_hosts(conn_service_host_list)
             self.logger.debug(
                 "deleted connectivity service uuid: {}".format(service_uuid)
             )
diff --git a/releasenotes/notes/fix_bug_2019-5f170b3442a16687.yaml b/releasenotes/notes/fix_bug_2019-5f170b3442a16687.yaml
new file mode 100644 (file)
index 0000000..a0e3194
--- /dev/null
@@ -0,0 +1,21 @@
+#######################################################################################
+# 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:
+  - |
+    Fixing Bug 2019: This patch deletes the hosts in ONOS associated to a VPLS service.
+    Hosts are identified by its MAC and VLAN.