提交 6274e641 编写于 作者: L Lukáš Doktor

Rename inner_runner to external_runner

This patch doesn't change any functionality, it only renames the
inner_runner to external_runner (the plugin is called simply external)
Signed-off-by: NLukáš Doktor <ldoktor@redhat.com>
上级 da1ddfdb
......@@ -111,12 +111,12 @@ class TestLoaderProxy(object):
# Add (default) file loader if not already registered
if FileLoader not in self.registered_plugins:
self.register_plugin(FileLoader)
if InnerRunner not in self.registered_plugins:
self.register_plugin(InnerRunner)
# Register inner runner when --inner-runner is used
if getattr(args, "inner_runner", None):
self.register_plugin(InnerRunner)
args.loaders = ["inner_runner:%s" % args.inner_runner]
if ExternalLoader not in self.registered_plugins:
self.register_plugin(ExternalLoader)
# Register external runner when --external-runner is used
if getattr(args, "external_runner", None):
self.register_plugin(ExternalLoader)
args.loaders = ["external:%s" % args.external_runner]
supported_loaders = [_.name for _ in self.registered_plugins]
supported_types = []
for plugin in self.registered_plugins:
......@@ -317,35 +317,35 @@ def add_loader_options(parser):
"@loader_name or TEST_TYPE. By default it tries all "
"available loaders according to priority set in "
"settings->plugins.loaders.")
loader.add_argument('--inner-runner', default=None,
loader.add_argument('--external-runner', default=None,
metavar='EXECUTABLE',
help=('Path to an specific test runner that '
'allows the use of its own tests. This '
'should be used for running tests that '
'do not conform to Avocado\' SIMPLE test'
'interface and can not run standalone. Note: '
'the use of --inner-runner overwrites the --'
'loaders to "inner_runner"'))
'the use of --external-runner overwrites the --'
'loaders to "external_runner"'))
chdir_help = ('Change directory before executing tests. This option '
'may be necessary because of requirements and/or '
'limitations of the inner test runner. If the inner '
'limitations of the external test runner. If the external '
'runner requires to be run from its own base directory,'
'use "runner" here. If the inner runner runs tests based'
'use "runner" here. If the external runner runs tests based'
' on files and requires to be run from the directory '
'where those files are located, use "test" here and '
'specify the test directory with the option '
'"--inner-runner-testdir". Defaults to "%(default)s"')
loader.add_argument('--inner-runner-chdir', default='off',
'"--external-runner-testdir". Defaults to "%(default)s"')
loader.add_argument('--external-runner-chdir', default='off',
choices=('runner', 'test', 'off'),
help=chdir_help)
loader.add_argument('--inner-runner-testdir', metavar='DIRECTORY',
loader.add_argument('--external-runner-testdir', metavar='DIRECTORY',
default=None,
help=('Where test files understood by the inner'
help=('Where test files understood by the external'
' test runner are located in the '
'filesystem. Obviously this assumes and '
'only applies to inner test runners that '
'only applies to external test runners that '
'run tests from files'))
......@@ -672,79 +672,80 @@ class FileLoader(TestLoader):
return make_broken(test.MissingTest, test_name)
class InnerRunner(TestLoader):
class ExternalLoader(TestLoader):
"""
Inner-runner loader class
External-runner loader class
"""
name = 'inner_runner'
name = 'external'
def __init__(self, args, extra_params):
super(InnerRunner, self).__init__(args, extra_params)
super(ExternalLoader, self).__init__(args, extra_params)
loader_options = extra_params.get('loader_options')
if loader_options == '?':
raise LoaderError("File loader accepts an option to set the "
"inner-runner executable.")
self._inner_runner = self._process_inner_runner(args, loader_options)
"external-runner executable.")
self._external_runner = self._process_external_runner(
args, loader_options)
@staticmethod
def _process_inner_runner(args, runner):
""" Enables the inner_runner when asked for """
chdir = getattr(args, 'inner_runner_chdir', 'off')
test_dir = getattr(args, 'inner_runner_testdir', None)
def _process_external_runner(args, runner):
""" Enables the external_runner when asked for """
chdir = getattr(args, 'external_runner_chdir', 'off')
test_dir = getattr(args, 'external_runner_testdir', None)
if runner:
inner_runner_and_args = shlex.split(runner)
if len(inner_runner_and_args) > 1:
executable = inner_runner_and_args[0]
external_runner_and_args = shlex.split(runner)
if len(external_runner_and_args) > 1:
executable = external_runner_and_args[0]
else:
executable = runner
if not os.path.exists(executable):
msg = ('Could not find the inner runner executable "%s"'
msg = ('Could not find the external runner executable "%s"'
% executable)
raise LoaderError(msg)
if chdir == 'test':
if not test_dir:
msg = ('Option "--inner-runner-chdir=test" requires '
'"--inner-runner-testdir" to be set.')
msg = ('Option "--external-runner-chdir=test" requires '
'"--external-runner-testdir" to be set.')
raise LoaderError(msg)
elif test_dir:
msg = ('Option "--inner-runner-testdir" requires '
'"--inner-runner-chdir=test".')
msg = ('Option "--external-runner-testdir" requires '
'"--external-runner-chdir=test".')
raise LoaderError(msg)
cls_inner_runner = collections.namedtuple('InnerRunner',
['runner', 'chdir',
'test_dir'])
return cls_inner_runner(runner, chdir, test_dir)
cls_external_runner = collections.namedtuple('ExternalLoader',
['runner', 'chdir',
'test_dir'])
return cls_external_runner(runner, chdir, test_dir)
elif chdir != "off":
msg = ('Option "--inner-runner-chdir" requires '
'"--inner-runner" to be set.')
msg = ('Option "--external-runner-chdir" requires '
'"--external-runner" to be set.')
raise LoaderError(msg)
elif test_dir:
msg = ('Option "--inner-runner-testdir" requires '
'"--inner-runner" to be set.')
msg = ('Option "--external-runner-testdir" requires '
'"--external-runner" to be set.')
raise LoaderError(msg)
return None # Skip inner runner
return None # Skip external runner
def discover(self, url, list_tests=DEFAULT):
"""
:param url: arguments passed to the inner_runner
:param url: arguments passed to the external_runner
:param list_tests: list corrupted/invalid tests too
:return: list of matching tests
"""
if not self._inner_runner:
if not self._external_runner:
return None
return [(test.InnerRunnerTest, {'name': url, 'params': {'id': url},
'inner_runner': self._inner_runner})]
return [(test.ExternalRunnerTest, {'name': url, 'params': {'id': url},
'external_runner': self._external_runner})]
@staticmethod
def get_type_label_mapping():
return {test.InnerRunnerTest: 'INNER_RUNNER'}
return {test.ExternalRunnerTest: 'EXTERNAL'}
@staticmethod
def get_decorator_mapping():
return {test.InnerRunnerTest: output.term_support.healthy_str}
return {test.ExternalRunnerTest: output.term_support.healthy_str}
loader = TestLoaderProxy()
......@@ -614,39 +614,39 @@ class SimpleTest(Test):
"the log for details.")
class InnerRunnerTest(SimpleTest):
class ExternalRunnerTest(SimpleTest):
def __init__(self, name, params=None, base_logdir=None, tag=None, job=None,
inner_runner=None):
self.assertIsNotNone(inner_runner, "Inner runner test requires "
"inner_runner parameter, got None instead.")
self.inner_runner = inner_runner
super(InnerRunnerTest, self).__init__(name, params, base_logdir, tag,
job)
external_runner=None):
self.assertIsNotNone(external_runner, "External runner test requires "
"external_runner parameter, got None instead.")
self.external_runner = external_runner
super(ExternalRunnerTest, self).__init__(name, params, base_logdir,
tag, job)
def test(self):
pre_cwd = os.getcwd()
new_cwd = None
try:
self.log.info('Running test with the inner level test '
'runner: "%s"', self.inner_runner.runner)
# Change work directory if needed by the inner runner
if self.inner_runner.chdir == 'runner':
new_cwd = os.path.dirname(self.inner_runner.runner)
elif self.inner_runner.chdir == 'test':
new_cwd = self.inner_runner.test_dir
self.log.info('Running test with the external level test '
'runner: "%s"', self.external_runner.runner)
# Change work directory if needed by the external runner
if self.external_runner.chdir == 'runner':
new_cwd = os.path.dirname(self.external_runner.runner)
elif self.external_runner.chdir == 'test':
new_cwd = self.external_runner.test_dir
else:
new_cwd = None
if new_cwd is not None:
self.log.debug('Changing working directory to "%s" '
'because of inner runner requirements ',
'because of external runner requirements ',
new_cwd)
os.chdir(new_cwd)
command = "%s %s" % (self.inner_runner.runner, self.path)
command = "%s %s" % (self.external_runner.runner, self.path)
return super(InnerRunnerTest, self).test(command)
return super(ExternalRunnerTest, self).test(command)
finally:
if new_cwd is not None:
os.chdir(pre_cwd)
......
......@@ -178,10 +178,10 @@ instrumented and simple tests::
JOB HTML : $HOME/avocado/job-results/job-2014-08-12T15.42-86911e49/html/results.html
TIME : 1.04 s
.. _running-inner-runner:
.. _running-external-runner:
Running Tests With An Inner Runner
==================================
Running Tests With An External Runner
=====================================
It's quite common to have organically grown test suites in most
software projects. These usually include a custom built, very specific
......@@ -193,25 +193,25 @@ human and machine readable formats, collecting system information
alongside those tests (the Avocado's `sysinfo` functionality), and
more.
Avocado makes that possible by means of its "inner runner" feature. The
Avocado makes that possible by means of its "external runner" feature. The
most basic way of using it is::
$ avocado run --inner-runner=/path/to/inner_runner foo bar baz
$ avocado run --external-runner=/path/to/external_runner foo bar baz
In this example, Avocado will report individual test results for tests
`foo`, `bar` and `baz`. The actual results will be based on the return
code of individual executions of `/path/to/inner_runner foo`,
`/path/to/inner_runner bar` and finally `/path/to/inner_runner baz`.
code of individual executions of `/path/to/external_runner foo`,
`/path/to/external_runner bar` and finally `/path/to/external_runner baz`.
As another way to explain an show how this feature works, think of the
"inner runner" as some kind of interpreter and the individual tests as
"external runner" as some kind of interpreter and the individual tests as
anything that this interpreter recognizes and is able to execute. A
UNIX shell, say `/bin/sh` could be considered an inner runner, and
UNIX shell, say `/bin/sh` could be considered an external runner, and
files with shell code could be considered tests::
$ echo "exit 0" > /tmp/pass
$ echo "exit 1" > /tmp/fail
$ avocado run --inner-runner=/bin/sh /tmp/pass /tmp/fail
$ avocado run --external-runner=/bin/sh /tmp/pass /tmp/fail
JOB ID : 4a2a1d259690cc7b226e33facdde4f628ab30741
JOB LOG : /home/<user>/avocado/job-results/job-<date>-<shortid>/job.log
JOB HTML : /home/<user>/avocado/job-results/job-<date>-<shortid>/html/results.html
......@@ -228,7 +228,7 @@ them executable (`chmod +x /tmp/pass /tmp/fail)`, and running them as
But now consider the following example::
$ avocado run --inner-runner=/bin/curl http://local-avocado-server:9405/jobs/ \
$ avocado run --external-runner=/bin/curl http://local-avocado-server:9405/jobs/ \
http://remote-avocado-server:9405/jobs/
JOB ID : 56016a1ffffaba02492fdbd5662ac0b958f51e11
JOB LOG : /home/<user>/avocado/job-results/job-<date>-<shortid>/job.log
......@@ -239,7 +239,7 @@ But now consider the following example::
RESULTS : PASS 1 | ERROR 0 | FAIL 1 | SKIP 0 | WARN 0 | INTERRUPT 0
TIME : 3.04 s
This effectively makes `/bin/curl` an "inner test runner", responsible for
This effectively makes `/bin/curl` an "external test runner", responsible for
trying to fetch those URLs, and reporting PASS or FAIL for each of them.
Debugging tests
......
......@@ -24,14 +24,14 @@ settings (``/etc/avocado/``), or temporarily using ``--loaders``
This option allows you to specify order and some params of the available test
loaders. You can specify either loader_name (``file``), loader_name +
TEST_TYPE (``file.SIMPLE``) and for some loaders even additional params
passed after ``:`` (``inner_runner:/bin/echo -e``. You can also supply
passed after ``:`` (``external:/bin/echo -e``. You can also supply
``@DEFAULT``, which injects into that position all the remaining unused
loaders.
To get help about ``--loaders``::
$ avocado run --loaders ?
$ avocado run --loaders inner_runner:?
$ avocado run --loaders external:?
Example of how ``--loaders`` affects the produced tests (manually gathered
as some of them result in error)::
......@@ -41,14 +41,14 @@ as some of them result in error)::
> VT io-github-autotest-qemu.boot
> MISSING this_does_not_exist
> SIMPLE /bin/echo
$ avocado run passtest boot this_does_not_exist /bin/echo --loaders @DEFAULT "inner_runner:/bin/echo -e"
$ avocado run passtest boot this_does_not_exist /bin/echo --loaders @DEFAULT "external:/bin/echo -e"
> INSTRUMENTED passtest.py:PassTest.test
> VT io-github-autotest-qemu.boot
> INNER_RUNNER this_does_not_exist
> EXTERNAL this_does_not_exist
> SIMPLE /bin/echo
$ avocado run passtest boot this_does_not_exist /bin/echo --loaders file.SIMPLE file.INSTRUMENTED @DEFAULT inner_runner.INNER_RUNNER:/bin/echo
$ avocado run passtest boot this_does_not_exist /bin/echo --loaders file.SIMPLE file.INSTRUMENTED @DEFAULT external.EXTERNAL:/bin/echo
> INSTRUMENTED passtest.py:PassTest.test
> VT io-github-autotest-qemu.boot
> INNER_RUNNER this_does_not_exist
> EXTERNAL this_does_not_exist
> SIMPLE /bin/echo
......@@ -58,7 +58,7 @@ password =
skip_broken_plugin_notification = []
# Optionally you can specify the priority of test loaders (file) or test
# types (file.SIMPLE). Some of the plugins even support extra params
# (inner_runner:/bin/echo -e). Plugins will be used accordingly to the plugin
# (external:/bin/echo -e). Plugins will be used accordingly to the plugin
# priorities. It's possible to list plugins multiple times (with different
# options or test types).
# The keyword "@DEFAULT" will be replaced with all available unused loaders.
......
......@@ -451,8 +451,8 @@ the execution of ``perf.sh``. ::
Note that it is not possible to use ``--gdb-run-bin`` together
with ``--wrapper``, they are incompatible.
RUNNING TESTS WITH AN INNER RUNNER
==================================
RUNNING TESTS WITH AN EXTERNAL RUNNER
=====================================
It's quite common to have organically grown test suites in most
software projects. These usually include a custom built, very specific
......@@ -464,25 +464,25 @@ human and machine readable formats, collecting system information
alongside those tests (the Avocado's `sysinfo` functionality), and
more.
Avocado makes that possible by means of its "inner runner" feature. The
Avocado makes that possible by means of its "external runner" feature. The
most basic way of using it is::
$ avocado run --inner-runner=/path/to/inner_runner foo bar baz
$ avocado run --external-runner=/path/to/external_runner foo bar baz
In this example, Avocado will report individual test results for tests
`foo`, `bar` and `baz`. The actual results will be based on the return
code of individual executions of `/path/to/inner_runner foo`,
`/path/to/inner_runner bar` and finally `/path/to/inner_runner baz`.
code of individual executions of `/path/to/external_runner foo`,
`/path/to/external_runner bar` and finally `/path/to/external_runner baz`.
As another way to explain an show how this feature works, think of the
"inner runner" as some kind of interpreter and the individual tests as
"external runner" as some kind of interpreter and the individual tests as
anything that this interpreter recognizes and is able to execute. A
UNIX shell, say `/bin/sh` could be considered an inner runner, and
UNIX shell, say `/bin/sh` could be considered an external runner, and
files with shell code could be considered tests::
$ echo "exit 0" > /tmp/pass
$ echo "exit 1" > /tmp/fail
$ avocado run --inner-runner=/bin/sh /tmp/pass /tmp/fail
$ avocado run --external-runner=/bin/sh /tmp/pass /tmp/fail
JOB ID : 4a2a1d259690cc7b226e33facdde4f628ab30741
JOB LOG : /home/<user>/avocado/job-results/job-<date>-<shortid>/job.log
JOB HTML : /home/<user>/avocado/job-results/job-<date>-<shortid>/html/results.html
......@@ -499,7 +499,7 @@ them executable (`chmod +x /tmp/pass /tmp/fail)`, and running them as
But now consider the following example::
$ avocado run --inner-runner=/bin/curl http://local-avocado-server:9405/jobs/ \
$ avocado run --external-runner=/bin/curl http://local-avocado-server:9405/jobs/ \
http://remote-avocado-server:9405/jobs/
JOB ID : 56016a1ffffaba02492fdbd5662ac0b958f51e11
JOB LOG : /home/<user>/avocado/job-results/job-<date>-<shortid>/job.log
......@@ -510,7 +510,7 @@ But now consider the following example::
RESULTS : PASS 1 | ERROR 0 | FAIL 1 | SKIP 0 | WARN 0 | INTERRUPT 0
TIME : 3.04 s
This effectively makes `/bin/curl` an "inner test runner", responsible for
This effectively makes `/bin/curl` an "external test runner", responsible for
trying to fetch those URLs, and reporting PASS or FAIL for each of them.
RECORDING TEST REFERENCE OUTPUT
......
......@@ -408,24 +408,24 @@ class RunnerSimpleTest(unittest.TestCase):
shutil.rmtree(self.tmpdir)
class InnerRunnerTest(unittest.TestCase):
class ExternalRunnerTest(unittest.TestCase):
def setUp(self):
self.tmpdir = tempfile.mkdtemp(prefix='avocado_' + __name__)
self.pass_script = script.TemporaryScript(
'pass',
PASS_SHELL_CONTENTS,
'avocado_innerrunner_functional')
'avocado_externalrunner_functional')
self.pass_script.save()
self.fail_script = script.TemporaryScript(
'fail',
FAIL_SHELL_CONTENTS,
'avocado_innerrunner_functional')
'avocado_externalrunner_functional')
self.fail_script.save()
def test_innerrunner_pass(self):
def test_externalrunner_pass(self):
os.chdir(basedir)
cmd_line = './scripts/avocado run --job-results-dir %s --sysinfo=off --inner-runner=/bin/sh %s'
cmd_line = './scripts/avocado run --job-results-dir %s --sysinfo=off --external-runner=/bin/sh %s'
cmd_line %= (self.tmpdir, self.pass_script.path)
result = process.run(cmd_line, ignore_status=True)
expected_rc = 0
......@@ -433,9 +433,9 @@ class InnerRunnerTest(unittest.TestCase):
"Avocado did not return rc %d:\n%s" %
(expected_rc, result))
def test_innerrunner_fail(self):
def test_externalrunner_fail(self):
os.chdir(basedir)
cmd_line = './scripts/avocado run --job-results-dir %s --sysinfo=off --inner-runner=/bin/sh %s'
cmd_line = './scripts/avocado run --job-results-dir %s --sysinfo=off --external-runner=/bin/sh %s'
cmd_line %= (self.tmpdir, self.fail_script.path)
result = process.run(cmd_line, ignore_status=True)
expected_rc = 1
......@@ -443,14 +443,14 @@ class InnerRunnerTest(unittest.TestCase):
"Avocado did not return rc %d:\n%s" %
(expected_rc, result))
def test_innerrunner_chdir_no_testdir(self):
def test_externalrunner_chdir_no_testdir(self):
os.chdir(basedir)
cmd_line = ('./scripts/avocado run --job-results-dir %s --sysinfo=off --inner-runner=/bin/sh '
'--inner-runner-chdir=test %s')
cmd_line = ('./scripts/avocado run --job-results-dir %s --sysinfo=off --external-runner=/bin/sh '
'--external-runner-chdir=test %s')
cmd_line %= (self.tmpdir, self.pass_script.path)
result = process.run(cmd_line, ignore_status=True)
expected_output = ('Option "--inner-runner-chdir=test" requires '
'"--inner-runner-testdir" to be set')
expected_output = ('Option "--external-runner-chdir=test" requires '
'"--external-runner-testdir" to be set')
self.assertIn(expected_output, result.stderr)
expected_rc = 2
self.assertEqual(result.exit_status, expected_rc,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册