From 4560ee8aaabc862e9dd4eef48b38702fea4d2297 Mon Sep 17 00:00:00 2001 From: Lee Duncan Date: Thu, 20 Feb 2020 11:56:33 -0800 Subject: 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. --- test/.gitignore | 3 ++ test/harness/.gitignore | 1 + test/harness/__init__.py | 4 +- test/harness/tests.py | 131 +++++++++++++++++++++++++++++++++++++++++++++++ test/harness/util.py | 15 ++++++ test/test-open-iscsi.py | 124 ++------------------------------------------ 6 files changed, 156 insertions(+), 122 deletions(-) create mode 100644 test/.gitignore create mode 100644 test/harness/tests.py (limited to 'test') diff --git a/test/.gitignore b/test/.gitignore new file mode 100644 index 0000000..8ac4f0c --- /dev/null +++ b/test/.gitignore @@ -0,0 +1,3 @@ +__pycache__ +\#*# +.#* diff --git a/test/harness/.gitignore b/test/harness/.gitignore index bee8a64..8025bc0 100644 --- a/test/harness/.gitignore +++ b/test/harness/.gitignore @@ -1 +1,2 @@ __pycache__ +*~ diff --git a/test/harness/__init__.py b/test/harness/__init__.py index 44fd09e..b93fb7e 100644 --- a/test/harness/__init__.py +++ b/test/harness/__init__.py @@ -2,4 +2,6 @@ Harness functions for the open-iscsi test suite. """ -__version__ = "1.0" +__version__ = '1.0' + +__all__ = ['util', 'iscsi', 'tests'] 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']) + diff --git a/test/harness/util.py b/test/harness/util.py index a2b0173..ff0fc13 100644 --- a/test/harness/util.py +++ b/test/harness/util.py @@ -118,6 +118,18 @@ def new_initArgParsers(self): self._main_parser.add_argument('-V', '--version', dest='version_request', action='store_true', help='Display Version info and exit') + self._main_parser.add_argument('-l', '--list', dest='list_tests', + action='store_true', + help='List test cases and exit') + +def print_suite(suite): + """Print a list of tests from a test suite""" + dprint("print_suite: entering for", suite) + if hasattr(suite, '__iter__'): + for x in suite: + print_suite(x) + else: + print(suite) def new_parseArgs(self, argv): """ @@ -134,6 +146,9 @@ def new_parseArgs(self, argv): sys.exit(0) Global.verbosity = self.verbosity Global.debug = self.debug + if self.list_tests: + print_suite(unittest.defaultTestLoader.discover('.')) + sys.exit(0) for v in ['target', 'ipnr', 'device']: if getattr(self, v) is None: print('Error: "%s" required' % v.upper()) diff --git a/test/test-open-iscsi.py b/test/test-open-iscsi.py index 2c06372..2b8f2b9 100755 --- a/test/test-open-iscsi.py +++ b/test/test-open-iscsi.py @@ -8,133 +8,15 @@ import unittest import os import time from harness import util -from harness.util import Global -from harness.iscsi import IscsiData +#from harness import tests +#from tests import TestRegression __version__ = '1.0' -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(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_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_and_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_and_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']) - if __name__ == '__main__': # do our own hackery first, to get access to verbosity, debug, etc, # as well as add our own command-line options util.setup_testProgram_overrides(__version__, 'test-open-iscsi.py') # now run the tests - unittest.main() + unittest.main(module = 'harness.tests') -- cgit v1.2.1