diff --git a/networking_mlnx/eswitchd/eswitch_daemon.py b/networking_mlnx/eswitchd/eswitch_daemon.py index c0b527c..f68c3ae 100644 --- a/networking_mlnx/eswitchd/eswitch_daemon.py +++ b/networking_mlnx/eswitchd/eswitch_daemon.py @@ -64,14 +64,13 @@ def _parse_physical_mapping(self): def _init_connections(self): context = zmq.Context() self.socket_os = context.socket(zmq.REP) + self.socket.setsockopt(zmq.LINGER, 0) os_transport = constants.SOCKET_OS_TRANSPORT os_port = constants.SOCKET_OS_PORT os_addr = constants.SOCKET_OS_ADDR self.conn_os_url = set_conn_url(os_transport, os_addr, os_port) self.socket_os.bind(self.conn_os_url) - self.poller = zmq.Poller() - self.poller.register(self.socket_os, zmq.POLLIN) def _handle_msg(self): data = None @@ -81,15 +80,20 @@ def _handle_msg(self): if msg: data = jsonutils.loads(msg) - msg = None + result = { + "status": "FAIL", + "action": data.get("action", "UNKNOWN"), + "reason": "UNKNOWN" + } if data: try: result = self.dispatcher.handle_msg(data) - msg = jsonutils.dumps(result) except Exception as e: LOG.exception("Exception during message handling - %s", e) - msg = jsonutils.dumps(str(e)) - sender.send_string(msg) + result["reason"] = str(e) + + msg = jsonutils.dumps(result) + sender.send_string(msg) def daemon_loop(self): LOG.info("Daemon Started!") diff --git a/networking_mlnx/eswitchd/utils/pci_utils.py b/networking_mlnx/eswitchd/utils/pci_utils.py index 8214300..a9bb74c 100644 --- a/networking_mlnx/eswitchd/utils/pci_utils.py +++ b/networking_mlnx/eswitchd/utils/pci_utils.py @@ -71,8 +71,8 @@ def get_vfs_info(self, pf): def get_dev_attr(self, attr_path): try: - fd = open(attr_path) - return fd.readline().strip() + with open(attr_path) as fd: + return fd.readline().strip() except IOError: return diff --git a/networking_mlnx/internal/netdev_ops/impl_pyroute2.py b/networking_mlnx/internal/netdev_ops/impl_pyroute2.py index 9255796..31233f8 100644 --- a/networking_mlnx/internal/netdev_ops/impl_pyroute2.py +++ b/networking_mlnx/internal/netdev_ops/impl_pyroute2.py @@ -33,16 +33,16 @@ def set_vf_admin_state(self, pf_ifname, vf_idx, state): :param state: desired admin state as defined in networking_mlnx.internal.netdev_ops.constants """ - try: - ip = pyroute2.IPRoute() - link_idx = ip.link_lookup(ifname=pf_ifname)[0] - ip.link( - 'set', index=link_idx, vf={'vf': int(vf_idx), - 'link_state': state}) - except IndexError: - raise exceptions.NetworkInterfaceNotFound(pf_ifname) - except pyroute2.NetlinkError as e: - raise exceptions.NetlinkRuntimeError(e) + with pyroute2.IPRoute() as ip: + try: + link_idx = ip.link_lookup(ifname=pf_ifname)[0] + ip.link( + 'set', index=link_idx, vf={'vf': int(vf_idx), + 'link_state': state}) + except IndexError: + raise exceptions.NetworkInterfaceNotFound(pf_ifname) + except pyroute2.NetlinkError as e: + raise exceptions.NetlinkRuntimeError(e) def set_link_state(self, ifname, state): """Set net device link state @@ -51,14 +51,14 @@ def set_link_state(self, ifname, state): :param state: desired link state as defined in networking_mlnx.internal.netdev_ops.constants """ - try: - ip = pyroute2.IPRoute() - link_idx = ip.link_lookup(ifname=ifname)[0] - ip.link('set', index=link_idx, state=state) - except IndexError: - raise exceptions.NetworkInterfaceNotFound(ifname) - except pyroute2.NetlinkError as e: - raise exceptions.NetlinkRuntimeError(e) + with pyroute2.IPRoute() as ip: + try: + link_idx = ip.link_lookup(ifname=ifname)[0] + ip.link('set', index=link_idx, state=state) + except IndexError: + raise exceptions.NetworkInterfaceNotFound(ifname) + except pyroute2.NetlinkError as e: + raise exceptions.NetlinkRuntimeError(e) def set_vf_guid(self, pf_ifname, vf_idx, guid): """Set vf administrative port and node GUID @@ -68,17 +68,17 @@ def set_vf_guid(self, pf_ifname, vf_idx, guid): :param guid: 64bit guid str in xx:xx:xx:xx:xx:xx:xx:xx format where x is a hexadecimal digit. """ - try: - ip = pyroute2.IPRoute() - link_idx = ip.link_lookup(ifname=pf_ifname)[0] - ip.link('set', index=link_idx, vf={'vf': int(vf_idx), - 'ib_port_guid': guid}) - ip.link('set', index=link_idx, - vf={'vf': int(vf_idx), 'ib_node_guid': guid}) - except IndexError: - raise exceptions.NetworkInterfaceNotFound(pf_ifname) - except pyroute2.NetlinkError as e: - raise exceptions.NetlinkRuntimeError(e) + with pyroute2.IPRoute() as ip: + try: + link_idx = ip.link_lookup(ifname=pf_ifname)[0] + ip.link('set', index=link_idx, vf={'vf': int(vf_idx), + 'ib_port_guid': guid}) + ip.link('set', index=link_idx, + vf={'vf': int(vf_idx), 'ib_node_guid': guid}) + except IndexError: + raise exceptions.NetworkInterfaceNotFound(pf_ifname) + except pyroute2.NetlinkError as e: + raise exceptions.NetlinkRuntimeError(e) def get_vf_guid(self, pf_ifname, vf_idx): """Get vf administrative GUID @@ -91,14 +91,14 @@ def get_vf_guid(self, pf_ifname, vf_idx): NOTE: while there are two GUIDs assigned per VF (port and node GUID) we assume they are the same and return just one value. """ - try: - ip = pyroute2.IPRoute() - link_idx = ip.link_lookup(ifname=pf_ifname)[0] - attrs = ip.link('get', index=link_idx, ext_mask=1)[0] - except IndexError: - raise exceptions.NetworkInterfaceNotFound(pf_ifname) - except pyroute2.NetlinkError as e: - raise exceptions.NetlinkRuntimeError(e) + with pyroute2.IPRoute() as ip: + try: + link_idx = ip.link_lookup(ifname=pf_ifname)[0] + attrs = ip.link('get', index=link_idx, ext_mask=1)[0] + except IndexError: + raise exceptions.NetworkInterfaceNotFound(pf_ifname) + except pyroute2.NetlinkError as e: + raise exceptions.NetlinkRuntimeError(e) vf_attr = (attrs.get_attr('IFLA_VFINFO_LIST'). get_attrs("IFLA_VF_INFO"))[int(vf_idx)] diff --git a/networking_mlnx/plugins/ml2/drivers/mlnx/mech_mlnx.py b/networking_mlnx/plugins/ml2/drivers/mlnx/mech_mlnx.py index e85dd78..95e08f3 100644 --- a/networking_mlnx/plugins/ml2/drivers/mlnx/mech_mlnx.py +++ b/networking_mlnx/plugins/ml2/drivers/mlnx/mech_mlnx.py @@ -86,7 +86,8 @@ def _gen_client_id_with_prefix(self, port, prefix): def _gen_client_id_opt(self, port): client_id = self._gen_client_id(port) return [{"opt_name": edo_ext.DHCP_OPT_CLIENT_ID, - "opt_value": client_id}] + "opt_value": client_id, + "ip_version": 4}] def _gen_none_client_id_opt(self, port): updated_extra_dhcp_opts = []