提交 f2595633 编写于 作者: A Amador Pahim

Add failfast support for replay

Now replay jobs will respect the original job failfast option, when used. Also,
it is possible to disable failfast option on replay jobs with `--failfast off`.
Signed-off-by: NAmador Pahim <apahim@redhat.com>
上级 b0cf1a57
...@@ -445,7 +445,7 @@ class TestRunner(object): ...@@ -445,7 +445,7 @@ class TestRunner(object):
elif not mapping[test_state['status']]: elif not mapping[test_state['status']]:
summary.add("FAIL") summary.add("FAIL")
if getattr(self.job.args, 'failfast', False): if getattr(self.job.args, 'failfast', 'off') == 'on':
summary.add("INTERRUPTED") summary.add("INTERRUPTED")
self.job.log.debug("Interrupting job (failfast).") self.job.log.debug("Interrupting job (failfast).")
return False return False
......
...@@ -136,14 +136,15 @@ class Replay(CLI): ...@@ -136,14 +136,15 @@ class Replay(CLI):
whitelist = ['loaders', whitelist = ['loaders',
'external_runner', 'external_runner',
'external_runner_testdir', 'external_runner_testdir',
'external_runner_chdir'] 'external_runner_chdir',
'failfast']
if replay_args is None: if replay_args is None:
log.warn('Source job args data not found. These options will not ' log.warn('Source job args data not found. These options will not '
'be loaded in this replay job: %s', ', '.join(whitelist)) 'be loaded in this replay job: %s', ', '.join(whitelist))
else: else:
for option in whitelist: for option in whitelist:
optvalue = getattr(args, option, None) optvalue = getattr(args, option, None)
if optvalue: if optvalue is not None:
log.warn("Overriding the replay %s with the --%s value " log.warn("Overriding the replay %s with the --%s value "
"given on the command line.", "given on the command line.",
option.replace('_', '-'), option.replace('_', '-'),
......
...@@ -77,8 +77,9 @@ class Run(CLICmd): ...@@ -77,8 +77,9 @@ class Run(CLICmd):
'You can also use suffixes, like: ' 'You can also use suffixes, like: '
' s (seconds), m (minutes), h (hours). ')) ' s (seconds), m (minutes), h (hours). '))
parser.add_argument('--failfast', action='store_true', parser.add_argument('--failfast', choices=('on', 'off'),
help='Interrupt job on first failed test.') help='Enable or disable the job interruption on '
'first failed test.')
sysinfo_default = settings.get_value('sysinfo.collect', sysinfo_default = settings.get_value('sysinfo.collect',
'enabled', 'enabled',
......
...@@ -219,10 +219,10 @@ instrumented and simple tests:: ...@@ -219,10 +219,10 @@ instrumented and simple tests::
Interrupting The Job On First Failed Test (failfast) Interrupting The Job On First Failed Test (failfast)
==================================================== ====================================================
The Avocado ``run`` command has the option ``--failfast`` to exit the job on The Avocado ``run`` command has the option ``--failfast on`` to exit the job
first failed test:: on first failed test::
$ avocado run --failfast /bin/true /bin/false /bin/true /bin/true $ avocado run --failfast on /bin/true /bin/false /bin/true /bin/true
JOB ID : eaf51b8c7d6be966bdf5562c9611b1ec2db3f68a JOB ID : eaf51b8c7d6be966bdf5562c9611b1ec2db3f68a
JOB LOG : $HOME/avocado/job-results/job-2016-07-19T09.43-eaf51b8/job.log JOB LOG : $HOME/avocado/job-results/job-2016-07-19T09.43-eaf51b8/job.log
TESTS : 4 TESTS : 4
...@@ -233,6 +233,10 @@ first failed test:: ...@@ -233,6 +233,10 @@ first failed test::
JOB HTML : /home/apahim/avocado/job-results/job-2016-07-19T09.43-eaf51b8/html/results.html JOB HTML : /home/apahim/avocado/job-results/job-2016-07-19T09.43-eaf51b8/html/results.html
TESTS TIME : 0.02 s TESTS TIME : 0.02 s
The ``--failfast`` option accepts the argument ``off``. Since it's disabled
by default, the ``off`` argument only makes sense in replay jobs, when the
original job was executed with ``--failfast on``.
.. _running-external-runner: .. _running-external-runner:
Running Tests With An External Runner Running Tests With An External Runner
......
...@@ -171,6 +171,9 @@ result, using the option ``--replay-test-status``. See the example below:: ...@@ -171,6 +171,9 @@ result, using the option ``--replay-test-status``. See the example below::
JOB HTML : $HOME/avocado/job-results/job-2016-01-12T00.38-2e1dc41/html/results.html JOB HTML : $HOME/avocado/job-results/job-2016-01-12T00.38-2e1dc41/html/results.html
TESTS TIME : 0.19 s TESTS TIME : 0.19 s
When replaying jobs that were executed with the ``--failfast on`` option, you
can disable the ``failfast`` option using ``--failfast off`` in the replay job.
To be able to replay a job, avocado records the job data in the same To be able to replay a job, avocado records the job data in the same
job results directory, inside a subdirectory named ``replay``. If a job results directory, inside a subdirectory named ``replay``. If a
given job has a non-default path to record the logs, when the replay given job has a non-default path to record the logs, when the replay
......
...@@ -151,7 +151,8 @@ class RunnerOperationTest(unittest.TestCase): ...@@ -151,7 +151,8 @@ class RunnerOperationTest(unittest.TestCase):
def test_runner_failfast(self): def test_runner_failfast(self):
os.chdir(basedir) os.chdir(basedir)
cmd_line = ('./scripts/avocado run --sysinfo=off --job-results-dir %s ' cmd_line = ('./scripts/avocado run --sysinfo=off --job-results-dir %s '
'passtest.py failtest.py passtest.py --failfast' % self.tmpdir) 'passtest.py failtest.py passtest.py --failfast on' %
self.tmpdir)
result = process.run(cmd_line, ignore_status=True) result = process.run(cmd_line, ignore_status=True)
self.assertIn('Interrupting job (failfast).', result.stdout) self.assertIn('Interrupting job (failfast).', result.stdout)
self.assertIn('PASS 1 | ERROR 0 | FAIL 1 | SKIP 1', result.stdout) self.assertIn('PASS 1 | ERROR 0 | FAIL 1 | SKIP 1', result.stdout)
......
...@@ -20,7 +20,7 @@ basedir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..') ...@@ -20,7 +20,7 @@ basedir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..')
basedir = os.path.abspath(basedir) basedir = os.path.abspath(basedir)
class ReplayTests(unittest.TestCase): class ReplayExtRunnerTests(unittest.TestCase):
def setUp(self): def setUp(self):
self.tmpdir = tempfile.mkdtemp(prefix='avocado_' + __name__) self.tmpdir = tempfile.mkdtemp(prefix='avocado_' + __name__)
......
#!/usr/bin/env python
import glob
import os
import sys
import tempfile
import shutil
if sys.version_info[:2] == (2, 6):
import unittest2 as unittest
else:
import unittest
from avocado.core import exit_codes
from avocado.utils import process
basedir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..')
basedir = os.path.abspath(basedir)
class ReplayFailfastTests(unittest.TestCase):
def setUp(self):
self.tmpdir = tempfile.mkdtemp(prefix='avocado_' + __name__)
cmd_line = ('./scripts/avocado run passtest.py failtest.py passtest.py '
'--failfast on --job-results-dir %s --sysinfo=off --json -'
% self.tmpdir)
expected_rc = exit_codes.AVOCADO_TESTS_FAIL | exit_codes.AVOCADO_JOB_INTERRUPTED
self.run_and_check(cmd_line, expected_rc)
self.jobdir = ''.join(glob.glob(os.path.join(self.tmpdir, 'job-*')))
idfile = ''.join(os.path.join(self.jobdir, 'id'))
with open(idfile, 'r') as f:
self.jobid = f.read().strip('\n')
def run_and_check(self, cmd_line, expected_rc):
os.chdir(basedir)
result = process.run(cmd_line, ignore_status=True)
self.assertEqual(result.exit_status, expected_rc,
"Command %s did not return rc "
"%d:\n%s" % (cmd_line, expected_rc, result))
return result
def test_run_replay_failfast(self):
cmd_line = ('./scripts/avocado run --replay %s '
'--job-results-dir %s --replay-data-dir %s --sysinfo=off'
% (self.jobid, self.tmpdir, self.jobdir))
expected_rc = exit_codes.AVOCADO_TESTS_FAIL | exit_codes.AVOCADO_JOB_INTERRUPTED
result = self.run_and_check(cmd_line, expected_rc)
def test_run_replay_disable_failfast(self):
cmd_line = ('./scripts/avocado run --replay %s --failfast off '
'--job-results-dir %s --replay-data-dir %s --sysinfo=off'
% (self.jobid, self.tmpdir, self.jobdir))
expected_rc = exit_codes.AVOCADO_TESTS_FAIL
result = self.run_and_check(cmd_line, expected_rc)
msg = 'Overriding the replay failfast with the --failfast value given on the command line.'
self.assertIn(msg, result.stderr)
def tearDown(self):
shutil.rmtree(self.tmpdir)
if __name__ == '__main__':
unittest.main()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册