Skip to content

Commit 251bdf7

Browse files
authored
Merge pull request #4 from stackhpc/bugfix/2024.1
[2024.1] Various bug fixes
2 parents e530474 + 73273a6 commit 251bdf7

File tree

4 files changed

+51
-46
lines changed

4 files changed

+51
-46
lines changed

networking_mlnx/eswitchd/eswitch_daemon.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,13 @@ def _parse_physical_mapping(self):
6464
def _init_connections(self):
6565
context = zmq.Context()
6666
self.socket_os = context.socket(zmq.REP)
67+
self.socket.setsockopt(zmq.LINGER, 0)
6768
os_transport = constants.SOCKET_OS_TRANSPORT
6869
os_port = constants.SOCKET_OS_PORT
6970
os_addr = constants.SOCKET_OS_ADDR
7071
self.conn_os_url = set_conn_url(os_transport, os_addr, os_port)
7172

7273
self.socket_os.bind(self.conn_os_url)
73-
self.poller = zmq.Poller()
74-
self.poller.register(self.socket_os, zmq.POLLIN)
7574

7675
def _handle_msg(self):
7776
data = None
@@ -81,15 +80,20 @@ def _handle_msg(self):
8180
if msg:
8281
data = jsonutils.loads(msg)
8382

84-
msg = None
83+
result = {
84+
"status": "FAIL",
85+
"action": data.get("action", "UNKNOWN"),
86+
"reason": "UNKNOWN"
87+
}
8588
if data:
8689
try:
8790
result = self.dispatcher.handle_msg(data)
88-
msg = jsonutils.dumps(result)
8991
except Exception as e:
9092
LOG.exception("Exception during message handling - %s", e)
91-
msg = jsonutils.dumps(str(e))
92-
sender.send_string(msg)
93+
result["reason"] = str(e)
94+
95+
msg = jsonutils.dumps(result)
96+
sender.send_string(msg)
9397

9498
def daemon_loop(self):
9599
LOG.info("Daemon Started!")

networking_mlnx/eswitchd/utils/pci_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ def get_vfs_info(self, pf):
7171

7272
def get_dev_attr(self, attr_path):
7373
try:
74-
fd = open(attr_path)
75-
return fd.readline().strip()
74+
with open(attr_path) as fd:
75+
return fd.readline().strip()
7676
except IOError:
7777
return
7878

networking_mlnx/internal/netdev_ops/impl_pyroute2.py

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ def set_vf_admin_state(self, pf_ifname, vf_idx, state):
3333
:param state: desired admin state as defined in
3434
networking_mlnx.internal.netdev_ops.constants
3535
"""
36-
try:
37-
ip = pyroute2.IPRoute()
38-
link_idx = ip.link_lookup(ifname=pf_ifname)[0]
39-
ip.link(
40-
'set', index=link_idx, vf={'vf': int(vf_idx),
41-
'link_state': state})
42-
except IndexError:
43-
raise exceptions.NetworkInterfaceNotFound(pf_ifname)
44-
except pyroute2.NetlinkError as e:
45-
raise exceptions.NetlinkRuntimeError(e)
36+
with pyroute2.IPRoute() as ip:
37+
try:
38+
link_idx = ip.link_lookup(ifname=pf_ifname)[0]
39+
ip.link(
40+
'set', index=link_idx, vf={'vf': int(vf_idx),
41+
'link_state': state})
42+
except IndexError:
43+
raise exceptions.NetworkInterfaceNotFound(pf_ifname)
44+
except pyroute2.NetlinkError as e:
45+
raise exceptions.NetlinkRuntimeError(e)
4646

4747
def set_link_state(self, ifname, state):
4848
"""Set net device link state
@@ -51,14 +51,14 @@ def set_link_state(self, ifname, state):
5151
:param state: desired link state as defined in
5252
networking_mlnx.internal.netdev_ops.constants
5353
"""
54-
try:
55-
ip = pyroute2.IPRoute()
56-
link_idx = ip.link_lookup(ifname=ifname)[0]
57-
ip.link('set', index=link_idx, state=state)
58-
except IndexError:
59-
raise exceptions.NetworkInterfaceNotFound(ifname)
60-
except pyroute2.NetlinkError as e:
61-
raise exceptions.NetlinkRuntimeError(e)
54+
with pyroute2.IPRoute() as ip:
55+
try:
56+
link_idx = ip.link_lookup(ifname=ifname)[0]
57+
ip.link('set', index=link_idx, state=state)
58+
except IndexError:
59+
raise exceptions.NetworkInterfaceNotFound(ifname)
60+
except pyroute2.NetlinkError as e:
61+
raise exceptions.NetlinkRuntimeError(e)
6262

6363
def set_vf_guid(self, pf_ifname, vf_idx, guid):
6464
"""Set vf administrative port and node GUID
@@ -68,17 +68,17 @@ def set_vf_guid(self, pf_ifname, vf_idx, guid):
6868
:param guid: 64bit guid str in xx:xx:xx:xx:xx:xx:xx:xx format
6969
where x is a hexadecimal digit.
7070
"""
71-
try:
72-
ip = pyroute2.IPRoute()
73-
link_idx = ip.link_lookup(ifname=pf_ifname)[0]
74-
ip.link('set', index=link_idx, vf={'vf': int(vf_idx),
75-
'ib_port_guid': guid})
76-
ip.link('set', index=link_idx,
77-
vf={'vf': int(vf_idx), 'ib_node_guid': guid})
78-
except IndexError:
79-
raise exceptions.NetworkInterfaceNotFound(pf_ifname)
80-
except pyroute2.NetlinkError as e:
81-
raise exceptions.NetlinkRuntimeError(e)
71+
with pyroute2.IPRoute() as ip:
72+
try:
73+
link_idx = ip.link_lookup(ifname=pf_ifname)[0]
74+
ip.link('set', index=link_idx, vf={'vf': int(vf_idx),
75+
'ib_port_guid': guid})
76+
ip.link('set', index=link_idx,
77+
vf={'vf': int(vf_idx), 'ib_node_guid': guid})
78+
except IndexError:
79+
raise exceptions.NetworkInterfaceNotFound(pf_ifname)
80+
except pyroute2.NetlinkError as e:
81+
raise exceptions.NetlinkRuntimeError(e)
8282

8383
def get_vf_guid(self, pf_ifname, vf_idx):
8484
"""Get vf administrative GUID
@@ -91,14 +91,14 @@ def get_vf_guid(self, pf_ifname, vf_idx):
9191
NOTE: while there are two GUIDs assigned per VF (port and node GUID)
9292
we assume they are the same and return just one value.
9393
"""
94-
try:
95-
ip = pyroute2.IPRoute()
96-
link_idx = ip.link_lookup(ifname=pf_ifname)[0]
97-
attrs = ip.link('get', index=link_idx, ext_mask=1)[0]
98-
except IndexError:
99-
raise exceptions.NetworkInterfaceNotFound(pf_ifname)
100-
except pyroute2.NetlinkError as e:
101-
raise exceptions.NetlinkRuntimeError(e)
94+
with pyroute2.IPRoute() as ip:
95+
try:
96+
link_idx = ip.link_lookup(ifname=pf_ifname)[0]
97+
attrs = ip.link('get', index=link_idx, ext_mask=1)[0]
98+
except IndexError:
99+
raise exceptions.NetworkInterfaceNotFound(pf_ifname)
100+
except pyroute2.NetlinkError as e:
101+
raise exceptions.NetlinkRuntimeError(e)
102102

103103
vf_attr = (attrs.get_attr('IFLA_VFINFO_LIST').
104104
get_attrs("IFLA_VF_INFO"))[int(vf_idx)]

networking_mlnx/plugins/ml2/drivers/mlnx/mech_mlnx.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ def _gen_client_id_with_prefix(self, port, prefix):
8686
def _gen_client_id_opt(self, port):
8787
client_id = self._gen_client_id(port)
8888
return [{"opt_name": edo_ext.DHCP_OPT_CLIENT_ID,
89-
"opt_value": client_id}]
89+
"opt_value": client_id,
90+
"ip_version": 4}]
9091

9192
def _gen_none_client_id_opt(self, port):
9293
updated_extra_dhcp_opts = []

0 commit comments

Comments
 (0)