1
0
Fork 0

Adding upstream version 2.4.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-03-17 07:17:42 +01:00
parent b76282b820
commit 7422bc4c2f
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
35 changed files with 364 additions and 122 deletions

View file

@ -9,6 +9,8 @@
srce_dir = meson.current_source_dir()
test_env = environment({'MALLOC_PERTURB_': '0'})
test_env.append('PYTHONMALLOC', 'malloc')
test_list = modules_to_lint + packages_to_lint
libnvme_location = '?'
@ -23,9 +25,9 @@ if get_option('libnvme-sel') == 'pre-installed'
rr = run_command(python3, '-c', 'import libnvme; print(f"{libnvme.__path__[0]}")', check: false, env: test_env)
if rr.returncode() == 0
libnvme_location = rr.stdout().strip()
pythonpath = fs.parent(libnvme_location)
test_env.prepend('PYTHONPATH', pythonpath) # Look in standard location first
test_env.append('PYTHONPATH', PYTHONPATH) # Look in the build directory second
libnvme_path = fs.parent(libnvme_location)
PYTHONPATH = ':'.join([libnvme_path, PYTHONPATH])
test_env.prepend('PYTHONPATH', PYTHONPATH)
endif
endif
@ -46,13 +48,7 @@ if libnvme_location == '?'
else
#---------------------------------------------------------------------------
# pylint and pyflakes
# There's a bug with pylint 3.X. Tests should be run with pylint
# 2.17.7 (or less), which can be installed with:
# python3 -m pip install --upgrade pylint==2.17.7
if modules_to_lint.length() != 0
if test_list.length() != 0
pylint = find_program('pylint', required: false)
pyflakes = find_program('pyflakes3', required: false)
if not pyflakes.found()
@ -65,12 +61,12 @@ else
rcfile = srce_dir / 'pylint.rc'
if pylint.found()
test('pylint', pylint, args: ['--rcfile=' + rcfile] + modules_to_lint + packages_to_lint, env: test_env)
test('pylint', pylint, args: ['--rcfile=' + rcfile] + test_list, env: test_env)
else
warning('Skiping some of the tests because "pylint" is missing.')
endif
if pyflakes.found()
test('pyflakes', pyflakes, args: modules_to_lint, env: test_env)
test('pyflakes', pyflakes, args: test_list, env: test_env)
else
warning('Skiping some of the tests because "pyflakes" is missing.')
endif
@ -156,8 +152,8 @@ tools = [
]
vermin = find_program('vermin', required: false)
if vermin.found()
if modules_to_lint.length() != 0
test('vermin code', vermin, args: ['--config-file', srce_dir / 'vermin.conf'] + modules_to_lint, env: test_env)
if test_list.length() != 0
test('vermin code', vermin, args: ['--config-file', srce_dir / 'vermin.conf'] + test_list, env: test_env)
endif
test('vermin tools', vermin, args: ['--config-file', srce_dir / 'vermin-tools.conf'] + tools, env: test_env)
else

View file

@ -43,11 +43,40 @@ class Test(unittest.TestCase):
self.assertEqual('', iputil.get_interface(ifaces, ''))
self.assertEqual('', iputil.get_interface(ifaces, None))
@staticmethod
def _is_ok_for_mac2iface(iface) -> bool:
'''mac2iface can only work with interfaces that have a proper MAC
address. One can use this function to filter out other interfaces
configured on the system.'''
if iface['link_type'] != 'ether':
# Some esoteric interface types (e.g., gre) use the address
# field to store something that is not a MAC address. Skip
# them.
return False
if 'address' not in iface:
return False
if iface['address'] == '00:00:00:00:00:00':
# All 0's is an invalid MAC address so do not bother.
# In practice, it often appears as the address of the loopback
# interface but it can also appear for other things like a gretap
# or erspan interface.
return False
return True
def test_mac2iface(self):
for iface in self.ifaces:
address = iface.get('address', None)
if address:
self.assertEqual(iface['ifname'], iputil.mac2iface(address))
# We only test the interfaces that have a MAC address, and a valid one.
candidate_ifaces = [iface for iface in self.ifaces if self._is_ok_for_mac2iface(iface)]
for iface in candidate_ifaces:
if len([x for x in candidate_ifaces if x['address'] == iface['address']]) >= 2:
# We need to be careful, sometimes we can have the same MAC address
# on multiple interfaces. This happens with VLAN interfaces for
# instance. mac2iface will obviously be confused when dealing with
# those so let's skip the interfaces that have duplicate MAC.
logging.warning('[%s] is not the only interface with address [%s]', iface['ifname'], iface['address'])
continue
self.assertEqual(iface['ifname'], iputil.mac2iface(iface['address']))
def test_remove_invalid_addresses(self):
good_tcp = trid.TID({'transport': 'tcp', 'traddr': '1.1.1.1', 'subsysnqn': '', 'trsvcid': '8009'})

View file

@ -200,8 +200,7 @@ def get_tids_to_test(family, src_ip, ifname):
]
class DummyDevice:
...
class DummyDevice: ...
class Test(unittest.TestCase):
@ -295,6 +294,11 @@ class Test(unittest.TestCase):
def test__cid_matches_tid(self):
ifaces = iputil.net_if_addrs()
for ifname, addrs in self.ifaces.items():
# <ifaces> contains a subset of the interfaces found in <self.ifaces>.
# So, let's make sure that we only test with the interfaces found in both.
if ifname not in ifaces:
continue
##############################################
# IPV4