1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-03 05:18:29 +03:00

lvmdbustest.py: Ensure we exit non-zero on fail

If you run multiple runs of unittest.main, unless you don't pass exit=true
the test case always ends with a 0 exit code.  Add ability to store the
result of each invocation of the test and exit with a non-zero exit code
if anyone of them fail.
This commit is contained in:
Tony Asleson 2016-10-07 14:55:36 -05:00
parent 9f0195ec1e
commit cb4e26dcb3

View File

@ -1294,8 +1294,25 @@ class TestDbusService(unittest.TestCase):
self.assertTrue(tag in vg_proxy.Vg.Tags, "%s not in %s" %
(tag, str(vg_proxy.Vg.Tags)))
class AggregateResults(object):
def __init__(self):
self.no_errors = True
def register_result(self, result):
if not result.result.wasSuccessful():
self.no_errors = False
def exit_run(self):
if self.no_errors:
sys.exit(0)
sys.exit(1)
if __name__ == '__main__':
r = AggregateResults()
# Test forking & exec new each time
test_shell = os.getenv('LVM_DBUS_TEST_SHELL', 1)
@ -1304,19 +1321,21 @@ if __name__ == '__main__':
if int(test_shell) == 0:
print('\n Shortened fork & exec test ***\n')
unittest.main(exit=True)
r.register_result(unittest.main(exit=False))
else:
print('\n *** Testing fork & exec *** \n')
unittest.main(exit=False)
r.register_result(unittest.main(exit=False))
g_tmo = 15
unittest.main(exit=False)
r.register_result(unittest.main(exit=False))
# Test lvm shell
print('\n *** Testing lvm shell *** \n')
if set_execution(True):
g_tmo = 0
unittest.main(exit=False)
r.register_result(unittest.main(exit=False))
g_tmo = 15
unittest.main()
r.register_result(unittest.main(exit=False))
else:
print("WARNING: Unable to dynamically configure "
"service to use lvm shell!")
r.exit_run()