From: tierno Date: Thu, 5 Mar 2020 16:45:48 +0000 (+0000) Subject: fix SDN: port mapping, switch_id, sdnconn logging X-Git-Tag: v7.1.0rc1~1^2~21 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F62%2F8662%2F2;p=osm%2FRO.git fix SDN: port mapping, switch_id, sdnconn logging Change-Id: I3160b7705e9acea83d3cf2a22beebafc32d4ef4a Signed-off-by: tierno --- diff --git a/RO-SDN-floodlight_openflow/osm_rosdn_floodlightof/sdnconn_floodlightof.py b/RO-SDN-floodlight_openflow/osm_rosdn_floodlightof/sdnconn_floodlightof.py index 395b18d8..6d90fe93 100644 --- a/RO-SDN-floodlight_openflow/osm_rosdn_floodlightof/sdnconn_floodlightof.py +++ b/RO-SDN-floodlight_openflow/osm_rosdn_floodlightof/sdnconn_floodlightof.py @@ -33,7 +33,7 @@ class SdnConnectorFloodLightOf(SdnConnectorOpenFlow): super().__init__(wim, wim_account, config, logger) of_params = { "of_url": wim["wim_url"], - "of_dpid": config.get("dpid"), + "of_dpid": config.get("dpid") or config.get("switch_id"), "of_user": wim_account["user"], "of_password": wim_account["password"], } diff --git a/RO-SDN-onos_openflow/osm_rosdn_onosof/onos_of.py b/RO-SDN-onos_openflow/osm_rosdn_onosof/onos_of.py index 373b4e0a..139f7a01 100644 --- a/RO-SDN-onos_openflow/osm_rosdn_onosof/onos_of.py +++ b/RO-SDN-onos_openflow/osm_rosdn_onosof/onos_of.py @@ -49,7 +49,7 @@ class OfConnOnos(OpenflowConn): """ Constructor. :param params: dictionary with the following keys: of_dpid: DPID to use for this controller ?? Does a controller have a dpid? - url: must be [http://HOST:PORT/] + of_url: must be [http://HOST:PORT/] of_user: user credentials, can be missing or None of_password: password credentials of_debug: debug level for logging. Default to ERROR @@ -87,7 +87,7 @@ class OfConnOnos(OpenflowConn): self.auth = self.auth.decode() self.headers['authorization'] = 'Basic ' + self.auth - self.logger = logging.getLogger('openmano.sdn.onosof') + self.logger = logging.getLogger('openmano.sdnconn.onosof') #self.logger.setLevel( getattr(logging, params.get("of_debug", "ERROR")) ) self.logger.debug("onosof plugin initialized") self.ip_address = None @@ -164,7 +164,7 @@ class OfConnOnos(OpenflowConn): try: self.headers['content-type'] = 'text/plain' of_response = requests.get(self.url + "devices/" + self.id + "/ports", headers=self.headers) - error_text = "Openflow response %d: %s" % (of_response.status_code, of_response.text) + error_text = "Openflow response {}: {}".format(of_response.status_code, of_response.text) if of_response.status_code != 200: self.logger.warning("obtain_port_correspondence " + error_text) raise OpenflowConnUnexpectedResponse(error_text) @@ -220,7 +220,7 @@ class OfConnOnos(OpenflowConn): (vlan, None/int): for stripping/setting a vlan tag (out, port): send to this port switch: DPID, all - Raise a openflowconnUnexpectedResponse expection in case of failure + Raise a openflowconnUnexpectedResponse exception in case of failure """ try: @@ -235,7 +235,7 @@ class OfConnOnos(OpenflowConn): # The configured page does not exist if there are no rules installed. In that case we return an empty dict if of_response.status_code == 404: - return {} + return [] elif of_response.status_code != 200: self.logger.warning("get_of_rules " + error_text) @@ -252,8 +252,7 @@ class OfConnOnos(OpenflowConn): flow_list = info.get('flows') if flow_list is None: - return {} - + return [] if type(flow_list) is not list: self.logger.error( "get_of_rules. Unexpected response at 'flows', not a list: %s", @@ -261,7 +260,7 @@ class OfConnOnos(OpenflowConn): raise OpenflowConnUnexpectedResponse("Unexpected response at 'flows', not a list. " "Wrong version?") - rules = [] # Response list + rules = [] # Response list for flow in flow_list: if not ('id' in flow and 'selector' in flow and 'treatment' in flow and \ 'instructions' in flow['treatment'] and 'criteria' in \ @@ -362,7 +361,7 @@ class OfConnOnos(OpenflowConn): actions: list of actions, composed by a pair tuples with these posibilities: ('vlan', None/int): for stripping/setting a vlan tag ('out', port): send to this port - :return: Raise a openflowconnUnexpectedResponse expection in case of failure + :return: Raise a openflowconnUnexpectedResponse exception in case of failure """ try: self.logger.debug("new_flow data: {}".format(data)) diff --git a/RO-SDN-onos_openflow/osm_rosdn_onosof/sdnconn_onosof.py b/RO-SDN-onos_openflow/osm_rosdn_onosof/sdnconn_onosof.py index 3a4e39b0..e33994a3 100644 --- a/RO-SDN-onos_openflow/osm_rosdn_onosof/sdnconn_onosof.py +++ b/RO-SDN-onos_openflow/osm_rosdn_onosof/sdnconn_onosof.py @@ -29,13 +29,15 @@ class SdnConnectorOnosOf(SdnConnectorOpenFlow): def __init__(self, wim, wim_account, config=None, logger=None): """Creates a connectivity based on pro-active openflow rules """ - self.logger = logging.getLogger('openmano.sdn.onosof') + self.logger = logging.getLogger('openmano.sdnconn.onosof') super().__init__(wim, wim_account, config, logger) of_params = { "of_url": wim["wim_url"], - "of_dpid": config.get("dpid"), + "of_dpid": config.get("dpid") or config.get("switch_id"), "of_user": wim_account["user"], "of_password": wim_account["password"], } self.openflow_conn = OfConnOnos(of_params) super().__init__(wim, wim_account, config, logger, self.openflow_conn) + self.logger.debug("Init sdn plugin '{}' dpid={} user={}".format(of_params["of_url"], of_params["of_dpid"], + of_params["of_user"])) diff --git a/RO-SDN-onos_vpls/osm_rosdn_onos_vpls/sdn_assist_onos_vpls.py b/RO-SDN-onos_vpls/osm_rosdn_onos_vpls/sdn_assist_onos_vpls.py index e6ac2b7e..120c40fe 100644 --- a/RO-SDN-onos_vpls/osm_rosdn_onos_vpls/sdn_assist_onos_vpls.py +++ b/RO-SDN-onos_vpls/osm_rosdn_onos_vpls/sdn_assist_onos_vpls.py @@ -34,7 +34,7 @@ class OnosVpls(SdnConnectorBase): """ https://wiki.onosproject.org/display/ONOS/VPLS+User+Guide """ - _WIM_LOGGER = "sdn.assist.onos.vpls" + _WIM_LOGGER = "openmano.sdnconn.onosvpls" def __init__(self, wim, wim_account, config=None, logger=None): self.logger = logger or logging.getLogger(self._WIM_LOGGER) diff --git a/RO-VIM-openstack/osm_rovim_openstack/vimconn_openstack.py b/RO-VIM-openstack/osm_rovim_openstack/vimconn_openstack.py index ff433460..b3b3fcb6 100644 --- a/RO-VIM-openstack/osm_rovim_openstack/vimconn_openstack.py +++ b/RO-VIM-openstack/osm_rovim_openstack/vimconn_openstack.py @@ -395,17 +395,17 @@ class vimconnector(vimconn.vimconnector): # method before the implemented VIM connectors are called. def _format_exception(self, exception): - '''Transform a keystone, nova, neutron exception into a vimconn exception''' + """Transform a keystone, nova, neutron exception into a vimconn exception discovering the cause""" - message_error = exception.message + message_error = str(exception) if isinstance(exception, (neExceptions.NetworkNotFoundClient, nvExceptions.NotFound, ksExceptions.NotFound, gl1Exceptions.HTTPNotFound)): raise vimconn.vimconnNotFoundException(type(exception).__name__ + ": " + message_error) elif isinstance(exception, (HTTPException, gl1Exceptions.HTTPException, gl1Exceptions.CommunicationError, - ConnectionError, ksExceptions.ConnectionError, neExceptions.ConnectionFailed)): + ConnectionError, ksExceptions.ConnectionError, neExceptions.ConnectionFailed)): raise vimconn.vimconnConnectionException(type(exception).__name__ + ": " + message_error) - elif isinstance(exception, (KeyError, nvExceptions.BadRequest, ksExceptions.BadRequest)): + elif isinstance(exception, (KeyError, nvExceptions.BadRequest, ksExceptions.BadRequest)): raise vimconn.vimconnException(type(exception).__name__ + ": " + message_error) elif isinstance(exception, (nvExceptions.ClientException, ksExceptions.ClientException, neExceptions.NeutronException)): diff --git a/RO/osm_ro/openmano_schemas.py b/RO/osm_ro/openmano_schemas.py index dda608f0..3b077dbe 100644 --- a/RO/osm_ro/openmano_schemas.py +++ b/RO/osm_ro/openmano_schemas.py @@ -121,6 +121,7 @@ config_schema = { "log_level_console": log_level_schema, "log_level_ovim": log_level_schema, "log_level_sdn": log_level_schema, + "log_level_sdnconn": log_level_schema, "log_file_db": path_schema, "log_file_vim": path_schema, "log_file_wim": path_schema, @@ -129,6 +130,7 @@ config_schema = { "log_file_console": path_schema, "log_file_ovim": path_schema, "log_file_sdn": path_schema, + "log_file_sdnconn": path_schema, "log_socket_host": nameshort_schema, "log_socket_port": port_schema, "log_file": path_schema, @@ -1229,7 +1231,7 @@ sdn_controller_edit_schema = { "additionalProperties": False } -sdn_port_mapping_schema = { +sdn_port_mapping_schema = { "$schema": "http://json-schema.org/draft-04/schema#", "title":"sdn port mapping information schema", "type": "object", @@ -1247,6 +1249,8 @@ sdn_port_mapping_schema = { "properties": { "pci": {"OneOf": [null_schema, pci_extended_schema]}, # pci_schema, "switch_port": nameshort_schema, + "switch_id": nameshort_schema, + "switch_dpid": nameshort_schema, "switch_mac": mac_schema }, "required": ["pci"] diff --git a/RO/osm_ro/openmanod.cfg b/RO/osm_ro/openmanod.cfg index ce53ba95..f7e56d93 100644 --- a/RO/osm_ro/openmanod.cfg +++ b/RO/osm_ro/openmanod.cfg @@ -75,7 +75,7 @@ log_level_db: ERROR #database log levels #log_file_wim: /opt/openmano/logs/openmano_wimconn.log #log_level_nfvo: DEBUG #Main engine log levels #log_file_nfvo: /opt/openmano/logs/openmano_nfvo.log -log_level_http: DEBUG #Main engine log levels +#log_level_http: DEBUG #Main engine log levels #log_file_http: /opt/openmano/logs/openmano_http.log #log_level_console: DEBUG #proxy console log levels #log_file_console: /opt/openmano/logs/openmano_console.log @@ -83,6 +83,8 @@ log_level_http: DEBUG #Main engine log levels #log_file_ovim: /opt/openmano/logs/openmano_ovim.log #log_level_sdn: DEBUG #log_file_sdn: /opt/openmano/logs/openmano_sdn.log +#log_level_sdnconn: DEBUG +#log_file_sdnconn: /opt/openmano/logs/openmano_sdnconn.log #Uncomment to send logs via IP to an external host #log_socket_host: localhost diff --git a/RO/osm_ro/openmanod.py b/RO/osm_ro/openmanod.py index 81ea96f1..e5a5ae1b 100755 --- a/RO/osm_ro/openmanod.py +++ b/RO/osm_ro/openmanod.py @@ -292,7 +292,7 @@ if __name__ == "__main__": logger.critical("Starting openmano server version: '%s %s' command: '%s'", ro_version, version_date, " ".join(sys.argv)) - for log_module in ("nfvo", "http", "vim", "wim", "db", "console", "ovim","sdn"): + for log_module in ("nfvo", "http", "vim", "wim", "db", "console", "ovim", "sdn", "sdnconn"): log_level_module = "log_level_" + log_module log_file_module = "log_file_" + log_module logger_module = logging.getLogger('openmano.' + log_module) diff --git a/RO/osm_ro/sdn.py b/RO/osm_ro/sdn.py index 290882cf..636be552 100755 --- a/RO/osm_ro/sdn.py +++ b/RO/osm_ro/sdn.py @@ -257,7 +257,7 @@ class Sdn: of_data = {x: wim_account[x] for x in ("uuid", "name", "user")} if isinstance(wim_account["config"], str): config = yaml.load(wim_account["config"], Loader=yaml.Loader) - of_data["dpid"] = config.get("dpid") + of_data["dpid"] = config.get("switch_id") or config.get("dpid") of_data["version"] = config.get("version") if wim: of_data["url"] = wim["wim_url"] @@ -300,13 +300,14 @@ class Sdn: wim_id = wim_account["wim_id"] db_wim_port_mappings = [] for map in maps: + _switch_dpid = map.get("switch_id") or map.get("switch_dpid") or switch_dpid new_map = { 'wim_id': wim_id, - 'switch_dpid': switch_dpid, + 'switch_dpid': _switch_dpid, "switch_port": map.get("switch_port"), 'datacenter_id': vim_id, "device_id": map.get("compute_node"), - "service_endpoint_id": switch_dpid + "-" + str(uuid4()) + "service_endpoint_id": _switch_dpid + "-" + str(uuid4()) } if map.get("pci"): new_map["device_interface_id"] = map["pci"].lower() diff --git a/RO/osm_ro/vim_thread.py b/RO/osm_ro/vim_thread.py index f4849f48..d0b8dc91 100644 --- a/RO/osm_ro/vim_thread.py +++ b/RO/osm_ro/vim_thread.py @@ -1141,6 +1141,8 @@ class vim_thread(threading.Thread): ports = self.db.get_rows(FROM='instance_interfaces', WHERE={'instance_wim_net_id': task["item_id"]}) sdn_need_update = False + if len(ports) != len(connected_ports): + sdn_need_update = True for port in ports: # TODO. Do not connect if already done if port.get("compute_node") and port.get("pci"): diff --git a/RO/osm_ro/wim/sdnconn.py b/RO/osm_ro/wim/sdnconn.py index 46649ce4..f24cedcc 100644 --- a/RO/osm_ro/wim/sdnconn.py +++ b/RO/osm_ro/wim/sdnconn.py @@ -90,7 +90,7 @@ class SdnConnectorBase(object): wim_id: (internal, do not use) :param logger (logging.Logger): optional logger object. If none is passed 'openmano.sdn.sdnconn' is used. """ - self.logger = logger or logging.getLogger('openmano.sdn.sdnconn') + self.logger = logger or logging.getLogger('openmano.sdnconn') self.wim = wim self.wim_account = wim_account