summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rwxr-xr-xtest/test-iputil.py11
-rwxr-xr-xtest/test-nbft_conf.py11
-rwxr-xr-xtest/test-nvme_options.py4
-rwxr-xr-xtest/test-udev.py100
4 files changed, 86 insertions, 40 deletions
diff --git a/test/test-iputil.py b/test/test-iputil.py
index 3af734f..b0a5448 100755
--- a/test/test-iputil.py
+++ b/test/test-iputil.py
@@ -31,14 +31,17 @@ class Test(unittest.TestCase):
def test_get_interface(self):
'''Check that get_interface() returns the right info'''
+ ifaces = iputil.net_if_addrs()
for iface in self.ifaces:
for addr_entry in iface['addr_info']:
addr = ipaddress.ip_address(addr_entry['local'])
# Link local addresses may appear on more than one interface and therefore cannot be used.
if not addr.is_link_local:
- self.assertEqual(iface['ifname'], iputil.get_interface(str(addr)))
+ self.assertEqual(iface['ifname'], iputil.get_interface(ifaces, addr))
- self.assertEqual('', iputil.get_interface('255.255.255.255'))
+ self.assertEqual('', iputil.get_interface(ifaces, iputil.get_ipaddress_obj('255.255.255.255')))
+ self.assertEqual('', iputil.get_interface(ifaces, ''))
+ self.assertEqual('', iputil.get_interface(ifaces, None))
def test_mac2iface(self):
for iface in self.ifaces:
@@ -69,9 +72,7 @@ class Test(unittest.TestCase):
self.assertNotIn(bad_trtype, l2)
def test__data_matches_ip(self):
- self.assertFalse(iputil._data_matches_ip(None, None, None))
- self.assertFalse(iputil._data_matches_ip(socket.AF_INET, None, None))
- self.assertFalse(iputil._data_matches_ip(socket.AF_INET6, None, None))
+ self.assertFalse(iputil.ip_equal(None, None))
if __name__ == "__main__":
diff --git a/test/test-nbft_conf.py b/test/test-nbft_conf.py
index 072c3db..fa499e6 100755
--- a/test/test-nbft_conf.py
+++ b/test/test-nbft_conf.py
@@ -48,11 +48,12 @@ class Test(unittest.TestCase):
self.assertEqual(nbft_conf.iocs, EXPECTED_IOCS)
def test_dir_without_nbft_files(self):
- conf.NbftConf.destroy() # Make sure singleton does not exist
- with self.assertNoLogs(logger=logging.getLogger(), level='DEBUG'):
- nbft_conf = conf.NbftConf('/tmp')
- self.assertEqual(nbft_conf.dcs, [])
- self.assertEqual(nbft_conf.iocs, [])
+ if hasattr(self, 'assertNoLogs'): # assertNoLogs only in Python 3.10 or later
+ conf.NbftConf.destroy() # Make sure singleton does not exist
+ with self.assertNoLogs(logger=logging.getLogger(), level='DEBUG'):
+ nbft_conf = conf.NbftConf('/tmp')
+ self.assertEqual(nbft_conf.dcs, [])
+ self.assertEqual(nbft_conf.iocs, [])
if __name__ == "__main__":
diff --git a/test/test-nvme_options.py b/test/test-nvme_options.py
index adfba5f..91afc2c 100755
--- a/test/test-nvme_options.py
+++ b/test/test-nvme_options.py
@@ -2,7 +2,7 @@
import os
import logging
import unittest
-from staslib import conf, log
+from staslib import defs, conf, log
from pyfakefs.fake_filesystem_unittest import TestCase
@@ -10,7 +10,7 @@ class TestStandardNvmeFabricsFile(unittest.TestCase):
def test_regular_user(self):
conf.NvmeOptions.destroy() # Make sure singleton does not exist
if os.path.exists('/dev/nvme-fabrics'):
- if os.geteuid() != 0:
+ if os.geteuid() != 0 and defs.KERNEL_VERSION < defs.KERNEL_ALL_MIN_VERSION:
with self.assertRaises(PermissionError):
nvme_options = conf.NvmeOptions()
else:
diff --git a/test/test-udev.py b/test/test-udev.py
index 9508de4..be257d9 100755
--- a/test/test-udev.py
+++ b/test/test-udev.py
@@ -3,7 +3,6 @@ import json
import shutil
import logging
import unittest
-import ipaddress
import subprocess
from staslib import defs, iputil, log, trid, udev
@@ -294,6 +293,7 @@ class Test(unittest.TestCase):
self.assertTrue(udev.UDEV.is_ioc_device(device))
def test__cid_matches_tid(self):
+ ifaces = iputil.net_if_addrs()
for ifname, addrs in self.ifaces.items():
##############################################
# IPV4
@@ -321,10 +321,14 @@ class Test(unittest.TestCase):
'host-nqn': '',
}
for case_id, tid, match in get_tids_to_test(4, src_ipv4, ifname):
- self.assertEqual(match, udev.UDEV._cid_matches_tid(tid, cid), msg=f'Test Case {case_id} failed')
+ self.assertEqual(
+ match, udev.UDEV._cid_matches_tid(tid, cid, ifaces), msg=f'Test Case {case_id} failed'
+ )
if case_id != 8:
self.assertEqual(
- match, udev.UDEV._cid_matches_tid(tid, cid_legacy), msg=f'Legacy Test Case {case_id} failed'
+ match,
+ udev.UDEV._cid_matches_tid(tid, cid_legacy, ifaces),
+ msg=f'Legacy Test Case {case_id} failed',
)
cid_legacy = {
@@ -347,7 +351,9 @@ class Test(unittest.TestCase):
'host-nqn': '',
}
)
- self.assertEqual(True, udev.UDEV._cid_matches_tid(tid, cid_legacy), msg=f'Legacy Test Case A4.1 failed')
+ self.assertEqual(
+ True, udev.UDEV._cid_matches_tid(tid, cid_legacy, ifaces), msg=f'Legacy Test Case A4.1 failed'
+ )
cid_legacy = {
'transport': 'tcp',
@@ -368,9 +374,13 @@ class Test(unittest.TestCase):
'host-nqn': '',
}
)
- self.assertEqual(True, udev.UDEV._cid_matches_tid(tid, cid_legacy), msg=f'Legacy Test Case A4.2 failed')
self.assertEqual(
- True, udev.UDEV._cid_matches_tcp_tid_legacy(tid, cid_legacy), msg=f'Legacy Test Case A4.3 failed'
+ True, udev.UDEV._cid_matches_tid(tid, cid_legacy, ifaces), msg=f'Legacy Test Case A4.2 failed'
+ )
+ self.assertEqual(
+ True,
+ udev.UDEV._cid_matches_tcp_tid_legacy(tid, cid_legacy, ifaces),
+ msg=f'Legacy Test Case A4.3 failed',
)
cid_legacy = {
@@ -393,7 +403,9 @@ class Test(unittest.TestCase):
'host-nqn': '',
}
)
- self.assertEqual(False, udev.UDEV._cid_matches_tid(tid, cid_legacy), msg=f'Legacy Test Case B4 failed')
+ self.assertEqual(
+ False, udev.UDEV._cid_matches_tid(tid, cid_legacy, ifaces), msg=f'Legacy Test Case B4 failed'
+ )
tid = trid.TID(
{
@@ -405,7 +417,9 @@ class Test(unittest.TestCase):
'host-nqn': '',
}
)
- self.assertEqual(False, udev.UDEV._cid_matches_tid(tid, cid_legacy), msg=f'Legacy Test Case C4 failed')
+ self.assertEqual(
+ False, udev.UDEV._cid_matches_tid(tid, cid_legacy, ifaces), msg=f'Legacy Test Case C4 failed'
+ )
tid = trid.TID(
{
@@ -417,7 +431,9 @@ class Test(unittest.TestCase):
'host-nqn': '',
}
)
- self.assertEqual(True, udev.UDEV._cid_matches_tid(tid, cid_legacy), msg=f'Legacy Test Case D4 failed')
+ self.assertEqual(
+ True, udev.UDEV._cid_matches_tid(tid, cid_legacy, ifaces), msg=f'Legacy Test Case D4 failed'
+ )
cid_legacy = {
'transport': 'tcp',
@@ -440,7 +456,9 @@ class Test(unittest.TestCase):
'host-nqn': '',
}
)
- self.assertEqual(False, udev.UDEV._cid_matches_tid(tid, cid_legacy), msg=f'Legacy Test Case E4 failed')
+ self.assertEqual(
+ False, udev.UDEV._cid_matches_tid(tid, cid_legacy, ifaces), msg=f'Legacy Test Case E4 failed'
+ )
tid = trid.TID(
{
@@ -452,7 +470,9 @@ class Test(unittest.TestCase):
'host-nqn': '',
}
)
- self.assertEqual(False, udev.UDEV._cid_matches_tid(tid, cid_legacy), msg=f'Legacy Test Case F4 failed')
+ self.assertEqual(
+ False, udev.UDEV._cid_matches_tid(tid, cid_legacy, ifaces), msg=f'Legacy Test Case F4 failed'
+ )
tid = trid.TID(
{
@@ -467,7 +487,9 @@ class Test(unittest.TestCase):
match = len(ipv4_addrs) == 1 and iputil.get_ipaddress_obj(
ipv4_addrs[0], ipv4_mapped_convert=True
) == iputil.get_ipaddress_obj(tid.host_traddr, ipv4_mapped_convert=True)
- self.assertEqual(match, udev.UDEV._cid_matches_tid(tid, cid_legacy), msg=f'Legacy Test Case G4 failed')
+ self.assertEqual(
+ match, udev.UDEV._cid_matches_tid(tid, cid_legacy, ifaces), msg=f'Legacy Test Case G4 failed'
+ )
##############################################
# IPV6
@@ -495,9 +517,13 @@ class Test(unittest.TestCase):
'host-nqn': '',
}
for case_id, tid, match in get_tids_to_test(6, src_ipv6, ifname):
- self.assertEqual(match, udev.UDEV._cid_matches_tid(tid, cid), msg=f'Test Case {case_id} failed')
self.assertEqual(
- match, udev.UDEV._cid_matches_tid(tid, cid_legacy), msg=f'Legacy Test Case {case_id} failed'
+ match, udev.UDEV._cid_matches_tid(tid, cid, ifaces), msg=f'Test Case {case_id} failed'
+ )
+ self.assertEqual(
+ match,
+ udev.UDEV._cid_matches_tid(tid, cid_legacy, ifaces),
+ msg=f'Legacy Test Case {case_id} failed',
)
cid_legacy = {
@@ -520,7 +546,9 @@ class Test(unittest.TestCase):
'host-nqn': '',
}
)
- self.assertEqual(True, udev.UDEV._cid_matches_tid(tid, cid_legacy), msg=f'Legacy Test Case A6.1 failed')
+ self.assertEqual(
+ True, udev.UDEV._cid_matches_tid(tid, cid_legacy, ifaces), msg=f'Legacy Test Case A6.1 failed'
+ )
cid_legacy = {
'transport': 'tcp',
@@ -541,9 +569,13 @@ class Test(unittest.TestCase):
'host-nqn': '',
}
)
- self.assertEqual(True, udev.UDEV._cid_matches_tid(tid, cid_legacy), msg=f'Legacy Test Case A6.2 failed')
self.assertEqual(
- True, udev.UDEV._cid_matches_tcp_tid_legacy(tid, cid_legacy), msg=f'Legacy Test Case A6.3 failed'
+ True, udev.UDEV._cid_matches_tid(tid, cid_legacy, ifaces), msg=f'Legacy Test Case A6.2 failed'
+ )
+ self.assertEqual(
+ True,
+ udev.UDEV._cid_matches_tcp_tid_legacy(tid, cid_legacy, ifaces),
+ msg=f'Legacy Test Case A6.3 failed',
)
cid_legacy = {
@@ -566,7 +598,9 @@ class Test(unittest.TestCase):
'host-nqn': '',
}
)
- self.assertEqual(False, udev.UDEV._cid_matches_tid(tid, cid_legacy), msg=f'Legacy Test Case B6 failed')
+ self.assertEqual(
+ False, udev.UDEV._cid_matches_tid(tid, cid_legacy, ifaces), msg=f'Legacy Test Case B6 failed'
+ )
tid = trid.TID(
{
@@ -578,7 +612,9 @@ class Test(unittest.TestCase):
'host-nqn': '',
}
)
- self.assertEqual(False, udev.UDEV._cid_matches_tid(tid, cid_legacy), msg=f'Legacy Test Case C6 failed')
+ self.assertEqual(
+ False, udev.UDEV._cid_matches_tid(tid, cid_legacy, ifaces), msg=f'Legacy Test Case C6 failed'
+ )
tid = trid.TID(
{
@@ -590,7 +626,9 @@ class Test(unittest.TestCase):
'host-nqn': '',
}
)
- self.assertEqual(True, udev.UDEV._cid_matches_tid(tid, cid_legacy), msg=f'Legacy Test Case D6 failed')
+ self.assertEqual(
+ True, udev.UDEV._cid_matches_tid(tid, cid_legacy, ifaces), msg=f'Legacy Test Case D6 failed'
+ )
cid_legacy = {
'transport': 'tcp',
@@ -613,7 +651,9 @@ class Test(unittest.TestCase):
'host-nqn': '',
}
)
- self.assertEqual(False, udev.UDEV._cid_matches_tid(tid, cid_legacy), msg=f'Legacy Test Case E6 failed')
+ self.assertEqual(
+ False, udev.UDEV._cid_matches_tid(tid, cid_legacy, ifaces), msg=f'Legacy Test Case E6 failed'
+ )
tid = trid.TID(
{
@@ -625,7 +665,9 @@ class Test(unittest.TestCase):
'host-nqn': '',
}
)
- self.assertEqual(False, udev.UDEV._cid_matches_tid(tid, cid_legacy), msg=f'Legacy Test Case F6 failed')
+ self.assertEqual(
+ False, udev.UDEV._cid_matches_tid(tid, cid_legacy, ifaces), msg=f'Legacy Test Case F6 failed'
+ )
tid = trid.TID(
{
@@ -640,7 +682,9 @@ class Test(unittest.TestCase):
match = len(ipv6_addrs) == 1 and iputil.get_ipaddress_obj(
ipv6_addrs[0], ipv4_mapped_convert=True
) == iputil.get_ipaddress_obj(tid.host_traddr, ipv4_mapped_convert=True)
- self.assertEqual(match, udev.UDEV._cid_matches_tid(tid, cid_legacy), msg=f'Legacy Test Case G6 failed')
+ self.assertEqual(
+ match, udev.UDEV._cid_matches_tid(tid, cid_legacy, ifaces), msg=f'Legacy Test Case G6 failed'
+ )
##############################################
# FC
@@ -664,7 +708,7 @@ class Test(unittest.TestCase):
'host-nqn': '',
}
)
- self.assertEqual(True, udev.UDEV._cid_matches_tid(tid, cid), msg=f'Test Case FC-1 failed')
+ self.assertEqual(True, udev.UDEV._cid_matches_tid(tid, cid, ifaces), msg=f'Test Case FC-1 failed')
tid = trid.TID(
{
@@ -676,7 +720,7 @@ class Test(unittest.TestCase):
'host-nqn': '',
}
)
- self.assertEqual(False, udev.UDEV._cid_matches_tid(tid, cid), msg=f'Test Case FC-2 failed')
+ self.assertEqual(False, udev.UDEV._cid_matches_tid(tid, cid, ifaces), msg=f'Test Case FC-2 failed')
##############################################
# RDMA
@@ -700,7 +744,7 @@ class Test(unittest.TestCase):
'host-nqn': '',
}
)
- self.assertEqual(True, udev.UDEV._cid_matches_tid(tid, cid), msg=f'Test Case RDMA-1 failed')
+ self.assertEqual(True, udev.UDEV._cid_matches_tid(tid, cid, ifaces), msg=f'Test Case RDMA-1 failed')
tid = trid.TID(
{
@@ -712,7 +756,7 @@ class Test(unittest.TestCase):
'host-nqn': '',
}
)
- self.assertEqual(False, udev.UDEV._cid_matches_tid(tid, cid), msg=f'Test Case RDMA-2 failed')
+ self.assertEqual(False, udev.UDEV._cid_matches_tid(tid, cid, ifaces), msg=f'Test Case RDMA-2 failed')
tid = trid.TID(
{
@@ -723,7 +767,7 @@ class Test(unittest.TestCase):
'host-nqn': '',
}
)
- self.assertEqual(True, udev.UDEV._cid_matches_tid(tid, cid), msg=f'Test Case RDMA-3 failed')
+ self.assertEqual(True, udev.UDEV._cid_matches_tid(tid, cid, ifaces), msg=f'Test Case RDMA-3 failed')
if __name__ == '__main__':