Skip to content
Snippets Groups Projects
Commit 8c894742 authored by garciadeblas's avatar garciadeblas
Browse files

Fix bug 2019 to delete ONOS hosts associated to a VPLS service


Change-Id: Ibb7d39cca4189e4f7ea4f997f80fef165294f7f0
Signed-off-by: default avatargarciadeblas <gerardo.garciadeblas@telefonica.com>
parent aca8cb5e
No related branches found
No related tags found
No related merge requests found
Pipeline #14733 passed with warnings with stage
......@@ -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)
)
......
#######################################################################################
# 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.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment