diff options
author | Lee Duncan <lduncan@suse.com> | 2020-02-20 11:56:33 -0800 |
---|---|---|
committer | Lee Duncan <lduncan@suse.com> | 2020-02-20 11:56:33 -0800 |
commit | 4560ee8aaabc862e9dd4eef48b38702fea4d2297 (patch) | |
tree | 759a26c286c6670c643e3df7a60a90f068667263 /test/harness/tests.py | |
parent | 1720aeaeeb1c42cc8ca54c0e8c1fe3a775d2667a (diff) | |
download | open-iscsi-4560ee8aaabc862e9dd4eef48b38702fea4d2297.tar.gz |
Test code rearranged to make discovery work.
Now you can run:
> python3 -m unittest discover
to run all the tests, using discovery, or
> ./test-open-iscsi -l
to list the tests.
Diffstat (limited to 'test/harness/tests.py')
-rw-r--r-- | test/harness/tests.py | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/test/harness/tests.py b/test/harness/tests.py new file mode 100644 index 0000000..7cc960b --- /dev/null +++ b/test/harness/tests.py @@ -0,0 +1,131 @@ +""" +tests -- the actual TestCase (just one) +""" + +import sys +import os +import unittest + +from . import util +from .util import Global +from .iscsi import IscsiData + + +class TestRegression(unittest.TestCase): + """ + Regression testing + """ + + @classmethod + def setUpClass(cls): + util.verify_needed_commands_exist(['parted', 'fio', 'mkfs', 'bonnie++', 'sgdisk', 'iscsiadm']) + util.vprint('*** Starting %s' % cls.__name__) + # XXX validate that target exists? + # an array of first burts, max burst, and max recv values, for testing + cls.param_values = [[4096, 4096, 4096], + [8192, 4096, 4096], + [16384, 4096, 4096], + [32768, 4096, 4096], + [65536, 4096, 4096], + [131972, 4096, 4096], + [4096, 8192, 4096], + [4096, 16384, 4096], + [4096, 32768, 4096], + [4096, 65536, 4096], + [4096, 131072, 4096], + [4096, 4096, 8192], + [4096, 4096, 16384], + [4096, 4096, 32768], + [4096, 4096, 65536], + [4096, 4096, 131072]] + + def setUp(self): + if Global.debug or Global.verbosity > 1: + # this makes debug printing a little more clean + print('', file=sys.stderr) + + def iscsi_logout(self): + res = util.run_cmd(['iscsiadm', '-m', 'node', + '-T', Global.target, + '-p', Global.ipnr, + '--logout']) + if res not in [0, 21]: + self.fail('logout failed') + self.assertFalse(os.path.exists(Global.device), '%s: exists after logout!' % Global.device) + + def test_InitialR2T_on_ImmediateData_off(self): + """Test Initial Request to Transmit on, but Immediate Data off""" + i = 1 + for v in self.param_values: + with self.subTest('Testing FirstBurst={} MaxBurts={} MaxRecv={}'.format(*v), i=i): + util.vprint('Running subtest %d: FirstBurst={} MaxBurts={} MaxRecv={}'.format(*v) % i) + self.iscsi_logout() + iscsi_data = IscsiData('No', 'Yes', 'None', 'None', v[0], v[1], v[2]) + iscsi_data.update_cfg(Global.target, Global.ipnr) + self.run_the_rest() + i += 1 + + def test_InitialR2T_off_ImmediateData_on(self): + """Test Initial Request to Transmit off, Immediate Data on""" + i = 1 + for v in self.param_values: + with self.subTest('Testing FirstBurst={} MaxBurts={} MaxRecv={}'.format(*v), i=i): + self.iscsi_logout() + iscsi_data = IscsiData('Yes', 'No', 'None', 'None', v[0], v[1], v[2]) + iscsi_data.update_cfg(Global.target, Global.ipnr) + self.run_the_rest() + i += 1 + + def test_InitialR2T_on_ImmediateData_on(self): + """Test Initial Request to Transmit and Immediate Data on""" + i = 1 + for v in self.param_values: + with self.subTest('Testing FirstBurst={} MaxBurts={} MaxRecv={}'.format(*v), i=i): + util.vprint('Running subtest %d: FirstBurst={} MaxBurts={} MaxRecv={}'.format(*v) % i) + self.iscsi_logout() + iscsi_data = IscsiData('Yes', 'Yes', 'None', 'None', v[0], v[1], v[2]) + iscsi_data.update_cfg(Global.target, Global.ipnr) + self.run_the_rest() + i += 1 + + def test_InitialR2T_off_ImmediateData_off(self): + """Test Initial Request to Transmit and Immediate Data off""" + i = 1 + for v in self.param_values: + with self.subTest('Testing FirstBurst={} MaxBurts={} MaxRecv={}'.format(*v), i=i): + util.vprint('Running subtest %d: FirstBurst={} MaxBurts={} MaxRecv={}'.format(*v) % i) + self.iscsi_logout() + iscsi_data = IscsiData('No', 'No', 'None', 'None', v[0], v[1], v[2]) + iscsi_data.update_cfg(Global.target, Global.ipnr) + self.run_the_rest() + i += 1 + + def run_the_rest(self): + res = util.run_cmd(['iscsiadm', '-m', 'node', + '-T', Global.target, + '-p', Global.ipnr, + '--login']) + self.assertEqual(res, 0, 'cannot login to device') + # wait a few seconds for the device to show up + if not util.wait_for_path(Global.device): + self.fail('%s: does not exist after login' % Global.device) + (res, reason) = util.run_fio() + self.assertEqual(res, 0, reason) + (res, reason) = util.run_parted() + self.assertEqual(res, 0, reason) + (res, reason) = util.run_mkfs() + self.assertEqual(res, 0, reason) + (res, reason) = util.run_bonnie() + self.assertEqual(res, 0, reason) + + @classmethod + def tearDownClass(cls): + # restore iscsi config + iscsi_data = IscsiData() + iscsi_data.update_cfg(Global.target, Global.ipnr) + # log out of iscsi connection + util.run_cmd(['iscsiadm', '-m', 'node', + '-T', Global.target, + '-p', Global.ipnr, + '--logout']) + |