Skip to content

Commit 6065fdb

Browse files
authored
Merge pull request #5 from stackhpc/bugfix/2023.1
[2023.1] Various bug fixes
2 parents eaf2f56 + 619e047 commit 6065fdb

File tree

6 files changed

+60
-52
lines changed

6 files changed

+60
-52
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 = []

networking_mlnx/tests/unit/linux/interface_drivers/test_interface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def test__init_network_cache_with_cache_maintenance(self,
183183
conf, self._get_networks_cb, self.fields)
184184
looping_mock.assert_called_once_with(
185185
net_cache_mock.remove_stale_networks)
186-
loop_obj.start.called_once_with()
186+
loop_obj.start.assert_called()
187187
# Make sure consecutive calls dont re-spawn cleanup thread
188188
looping_mock.reset_mock()
189189
loop_obj.start.reset_mock()

tox.ini

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,25 @@ skipsdist = True
55
ignore_basepython_conflict = True
66

77
[testenv]
8-
basepython = python3
8+
basepython = python3.8
99
setenv = VIRTUAL_ENV={envdir}
1010
OS_LOG_CAPTURE={env:OS_LOG_CAPTURE:true}
1111
OS_STDOUT_CAPTURE={env:OS_STDOUT_CAPTURE:true}
1212
OS_STDERR_CAPTURE={env:OS_STDERR_CAPTURE:true}
13+
# "AttributeError: install_layout".
14+
SETUPTOOLS_USE_DISTUTILS=stdlib
1315
PYTHONWARNINGS=default::DeprecationWarning,ignore::DeprecationWarning:distutils,ignore::DeprecationWarning:site
14-
passenv = TRACE_FAILONLY GENERATE_HASHES http_proxy HTTP_PROXY https_proxy HTTPS_PROXY no_proxy NO_PROXY TOX_ENV_SRC_MODULES
16+
passenv = TRACE_FAILONLY,GENERATE_HASHES,http_proxy,HTTP_PROXY,https_proxy,HTTPS_PROXY,no_proxy,NO_PROXY,TOX_ENV_SRC_MODULES
1517
usedevelop = True
1618
install_command =
1719
pip install {opts} {packages}
1820
deps =
19-
-c{env:UPPER_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/2023.1}
21+
-c{env:UPPER_CONSTRAINTS_FILE:https://raw.githubusercontent.com/stackhpc/requirements/refs/heads/bugfix/2023.1/networking-mlnx/upper-constraints.txt}
2022
-r{toxinidir}/requirements.txt
2123
-r{toxinidir}/test-requirements.txt
24+
{toxinidir}
2225
hacking>=3.0.1,<3.1.0 # Apache-2.0
23-
whitelist_externals = sh
26+
allowlist_externals = sh,env,{toxinidir}/tools/pip_install_src_modules.sh
2427
commands =
2528
{toxinidir}/tools/pip_install_src_modules.sh "{toxinidir}"
2629
stestr run {posargs}
@@ -48,7 +51,7 @@ commands=
4851
#{[testenv:genconfig]commands}
4952
{[testenv:bashate]commands}
5053
{[testenv:bandit]commands}
51-
whitelist_externals =
54+
allowlist_externals =
5255
sh
5356
bash
5457

0 commit comments

Comments
 (0)