提交 7bbe6c06 编写于 作者: R Rudá Moura

Merge pull request #291 from lmr/plugin-tweaks

Plugin tweaks
......@@ -15,6 +15,7 @@
from avocado.plugins import plugin
from avocado.core import output
from avocado.core import data_dir
from avocado.settings import settings
class DataDirList(plugin.Plugin):
......@@ -34,9 +35,11 @@ class DataDirList(plugin.Plugin):
def run(self, args):
view = output.View()
view.notify(event="message", msg='Config file path: %s' % settings.config_path)
view.notify(event="message", msg='')
view.notify(event="message", msg='Avocado Data Directories:')
view.notify(event="message", msg=' base dir ' + data_dir.get_base_dir())
view.notify(event="message", msg=' tests dir ' + data_dir.get_test_dir())
view.notify(event="message", msg=' data dir ' + data_dir.get_data_dir())
view.notify(event="message", msg=' logs dir ' + data_dir.get_logs_dir())
view.notify(event="message", msg=' tmp dir ' + data_dir.get_tmp_dir())
view.notify(event="minor", msg=' base dir ' + data_dir.get_base_dir())
view.notify(event="minor", msg=' tests dir ' + data_dir.get_test_dir())
view.notify(event="minor", msg=' data dir ' + data_dir.get_data_dir())
view.notify(event="minor", msg=' logs dir ' + data_dir.get_logs_dir())
view.notify(event="minor", msg=' tmp dir ' + data_dir.get_tmp_dir())
......@@ -241,7 +241,6 @@ class HTML(plugin.Plugin):
name = 'htmlresult'
enabled = True
parser = None
def configure(self, parser):
self.parser = parser
......
......@@ -29,6 +29,7 @@ class Plugin(object):
name = 'noname'
enabled = False
priority = 3
parser = None
def __init__(self, name=None, enabled=None):
"""Creates a new plugin instance.
......
......@@ -42,7 +42,7 @@ class PluginsList(plugin.Plugin):
if clength > blength:
blength = clength
format_str = " %-" + str(blength) + "s - %s %s"
format_str = " %-" + str(blength) + "s %s %s"
for plug in sorted(pm.plugins):
if plug.enabled:
status = "(Enabled)"
......
......@@ -16,65 +16,14 @@
Base Test Runner Plugins.
"""
import os
import sys
from avocado.core import error_codes
from avocado.plugins import plugin
from avocado.core import data_dir
from avocado.core import output
from avocado.utils import path
from avocado import sysinfo
from avocado import job
class TestLister(plugin.Plugin):
"""
Implements the avocado 'list' subcommand
"""
name = 'test_lister'
enabled = True
def configure(self, parser):
"""
Add the subparser for the list action.
:param parser: Main test runner parser.
"""
self.parser = parser.subcommands.add_parser(
'list',
help='List available test modules')
super(TestLister, self).configure(self.parser)
def run(self, args):
"""
List available test modules.
:param args: Command line args received from the list subparser.
"""
view = output.View(app_args=args, use_paginator=True)
base_test_dir = data_dir.get_test_dir()
test_files = os.listdir(base_test_dir)
test_dirs = []
blength = 0
for t in test_files:
inspector = path.PathInspector(path=t)
if inspector.is_python():
clength = len((t.split('.')[0]))
if clength > blength:
blength = clength
test_dirs.append((t.split('.')[0], os.path.join(base_test_dir, t)))
format_string = " %-" + str(blength) + "s %s"
view.notify(event='message', msg='Tests dir: %s' % base_test_dir)
if len(test_dirs) > 0:
view.notify(event='message', msg=format_string % ('Alias', 'Path'))
for test_dir in test_dirs:
view.notify(event='minor', msg=format_string % test_dir)
else:
view.notify(event='error', msg='No tests were found on current tests dir')
class TestRunner(plugin.Plugin):
"""
......@@ -165,16 +114,15 @@ class TestRunner(plugin.Plugin):
:param args: Command line args received from the run subparser.
"""
view = output.View(app_args=args, use_paginator=True)
if args.unique_job_id is not None:
try:
int(args.unique_job_id, 16)
if len(args.unique_job_id) != 40:
raise Exception
except:
print >> sys.stderr, \
'Error: Unique Job ID needs to be a 40 digit hex number'
return -1
raise ValueError
except ValueError:
view.notify(event='error', msg='Unique Job ID needs to be a 40 digit hex number')
return sys.exit(error_codes.numeric_status['AVOCADO_CRASH'])
job_instance = job.Job(args)
rc = job_instance.run()
......@@ -182,30 +130,3 @@ class TestRunner(plugin.Plugin):
self.parser.print_help()
return rc
class SystemInformation(plugin.Plugin):
"""
Collect system information
"""
name = 'sysinfo'
enabled = True
def configure(self, parser):
"""
Add the subparser for the run action.
:param parser: Main test runner parser.
"""
self.parser = parser.subcommands.add_parser(
'sysinfo',
help='Collect system information')
self.parser.add_argument('sysinfodir', type=str,
help='Dir where to dump sysinfo',
nargs='?', default='')
super(SystemInformation, self).configure(self.parser)
def run(self, args):
sysinfo.collect_sysinfo(args)
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See LICENSE for more details.
#
# Copyright: Red Hat Inc. 2013-2014
# Author: Lucas Meneghel Rodrigues <lmr@redhat.com>
"""
System information plugin
"""
from avocado.plugins import plugin
from avocado import sysinfo
class SystemInformation(plugin.Plugin):
"""
Collect system information
"""
name = 'sysinfo'
enabled = True
def configure(self, parser):
"""
Add the subparser for the run action.
:param parser: Main test runner parser.
"""
self.parser = parser.subcommands.add_parser(
'sysinfo',
help='Collect system information')
self.parser.add_argument('sysinfodir', type=str,
help='Dir where to dump sysinfo',
nargs='?', default='')
super(SystemInformation, self).configure(self.parser)
def run(self, args):
sysinfo.collect_sysinfo(args)
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See LICENSE for more details.
#
# Copyright: Red Hat Inc. 2013-2014
# Author: Lucas Meneghel Rodrigues <lmr@redhat.com>
import os
from avocado.core import data_dir
from avocado.core import output
from avocado.settings import settings
from avocado.utils import path
from avocado.plugins import plugin
class TestLister(plugin.Plugin):
"""
Implements the avocado 'list' subcommand
"""
name = 'test_lister'
enabled = True
def configure(self, parser):
"""
Add the subparser for the list action.
:param parser: Main test runner parser.
"""
self.parser = parser.subcommands.add_parser(
'list',
help='List available test modules')
super(TestLister, self).configure(self.parser)
def run(self, args):
"""
List available test modules.
:param args: Command line args received from the list subparser.
"""
view = output.View(app_args=args, use_paginator=True)
base_test_dir = data_dir.get_test_dir()
test_files = os.listdir(base_test_dir)
test_dirs = []
blength = 0
for t in test_files:
inspector = path.PathInspector(path=t)
if inspector.is_python():
clength = len((t.split('.')[0]))
if clength > blength:
blength = clength
test_dirs.append((t.split('.')[0], os.path.join(base_test_dir, t)))
format_string = " %-" + str(blength) + "s %s"
view.notify(event="message", msg='Config file path: %s' % settings.config_path)
view.notify(event="minor", msg='')
view.notify(event="message", msg='Tests dir: %s' % base_test_dir)
if len(test_dirs) > 0:
view.notify(event="minor", msg=format_string % ('Alias', 'Path'))
for test_dir in test_dirs:
view.notify(event="minor", msg=format_string % test_dir)
else:
view.notify(event="error", msg='No tests were found on current tests dir')
......@@ -180,8 +180,7 @@ class RunnerOperationTest(unittest.TestCase):
cmd_line = './scripts/avocado run --force-job-id foobar skiptest'
result = process.run(cmd_line, ignore_status=True)
self.assertNotEqual(0, result.exit_status)
self.assertIn('Error', result.stderr)
self.assertIn('needs to be a 40 digit hex', result.stderr)
self.assertIn('needs to be a 40 digit hex', result.stdout)
def test_valid_unique_id(self):
cmd_line = './scripts/avocado run --force-job-id 975de258ac05ce5e490648dec4753657b7ccc7d1 skiptest'
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册