提交 0a6dc703 编写于 作者: C Cleber Rosa

sysinfo: replace hard coded commands and files for configurable files

This change adds flexibility to the current sysinfo implementation in
the sense that the commands to be executed and files to be collected
are no longer hard coded, but configurable.

The configuration file gains a section for that, and the files
themselves are plain text files that can be easily customized by users
to include extra commands/files.

Also, the the configuration for the profilers has been adjusted for a
uniform look, feel and experience.

Changes from v1:
 * Return the default `profiler` parameter value to None, so that it
   looks at the configuration value by default
Signed-off-by: NCleber Rosa <crosa@redhat.com>
上级 c2909732
Summary: Avocado Test Framework
Name: avocado
Version: 0.21.0
Release: 5%{?dist}
Release: 6%{?dist}
License: GPLv2
Group: Development/Tools
URL: http://avocado-framework.github.io/
......@@ -54,8 +54,12 @@ selftests/run selftests/all/unit
%doc README.rst LICENSE
%dir /etc/avocado
%dir /etc/avocado/conf.d
%dir /etc/avocado/sysinfo
%config(noreplace)/etc/avocado/avocado.conf
%config(noreplace)/etc/avocado/conf.d/README
%config(noreplace)/etc/avocado/sysinfo/commands
%config(noreplace)/etc/avocado/sysinfo/files
%config(noreplace)/etc/avocado/sysinfo/profilers
%{python_sitelib}/avocado*
%{_bindir}/avocado
%{_bindir}/avocado-rest-client
......@@ -99,6 +103,9 @@ examples of how to write tests on your own.
%{_datadir}/avocado/api
%changelog
* Mon Apr 13 2015 Cleber Rosa <cleber@redhat.com> - 0.21.0-6
- Added sysinfo configuration files
* Sat Mar 28 2015 Cleber Rosa <cleber@redhat.com> - 0.21.0-5
- Change the way man pages are built, now using Makefile targets
- Reorganized runtime and build requirements
......
......@@ -31,38 +31,6 @@ from avocado.settings import settings
log = logging.getLogger("avocado.sysinfo")
_DEFAULT_COMMANDS_JOB = ["df -mP",
"dmesg -c",
"uname -a",
"lspci -vvnn",
"gcc --version",
"ld --version",
"mount",
"hostname",
"uptime",
"dmidecode",
"ifconfig -a",
"brctl show",
"ip link",
"numactl --hardware show",
"lscpu",
"fdisk -l"]
_DEFAULT_FILES_JOB = ["/proc/cmdline",
"/proc/mounts",
"/proc/pci",
"/proc/meminfo",
"/proc/slabinfo",
"/proc/version",
"/proc/cpuinfo",
"/proc/modules",
"/proc/interrupts",
"/proc/partitions",
"/sys/kernel/debug/sched_features",
"/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor",
"/sys/devices/system/clocksource/clocksource0/current_clocksource"]
class Collectible(object):
"""
......@@ -336,7 +304,7 @@ class SysInfo(object):
* end_job
"""
def __init__(self, basedir=None, log_packages=None, profilers=None):
def __init__(self, basedir=None, log_packages=None, profiler=None):
"""
Set sysinfo collectibles.
......@@ -345,8 +313,8 @@ class SysInfo(object):
logging packages is a costly operation). If not
given explicitly, tries to look in the config
files, and if not found, defaults to False.
:param profilers: Wether to use the profiler. If not given explicitly,
tries to look in the config files.
:param profiler: Wether to use the profiler. If not given explicitly,
tries to look in the config files.
"""
if basedir is None:
basedir = utils.path.init_dir('sysinfo')
......@@ -361,26 +329,41 @@ class SysInfo(object):
else:
self.log_packages = log_packages
if profilers is None:
commands_file = settings.get_value('sysinfo.collectibles',
'commands',
key_type='str',
default='')
log.info('Commands configured by file: %s', commands_file)
self.commands = utils.genio.read_all_lines(commands_file)
files_file = settings.get_value('sysinfo.collectibles',
'files',
key_type='str',
default='')
log.info('Files configured by file: %s', files_file)
self.files = utils.genio.read_all_lines(files_file)
if profiler is None:
self.profiler = settings.get_value('sysinfo.collect',
'profiler',
key_type='bool',
default=False)
profiler_commands = settings.get_value('sysinfo.collect',
'profiler_commands',
key_type='str',
default='')
else:
self.profiler = True
profiler_commands = profilers
self.profiler = profiler
profiler_file = settings.get_value('sysinfo.collectibles',
'profilers',
key_type='str',
default='')
self.profilers = utils.genio.read_all_lines(profiler_file)
self.profiler_commands = [x for x in profiler_commands.split(':') if x.strip()]
log.info('Profilers declared: %s', self.profiler_commands)
if not self.profiler_commands:
log.info('Profilers configured by file: %s', profiler_file)
log.info('Profilers declared: %s', self.profilers)
if not self.profilers:
self.profiler = False
if self.profiler is False:
if not self.profiler_commands:
if not self.profilers:
log.info('Profiler disabled: no profiler commands configured')
else:
log.info('Profiler disabled')
......@@ -420,14 +403,14 @@ class SysInfo(object):
def _set_collectibles(self):
if self.profiler:
for cmd in self.profiler_commands:
for cmd in self.profilers:
self.start_job_collectibles.add(Daemon(cmd))
for cmd in _DEFAULT_COMMANDS_JOB:
for cmd in self.commands:
self.start_job_collectibles.add(Command(cmd))
self.end_job_collectibles.add(Command(cmd))
for filename in _DEFAULT_FILES_JOB:
for filename in self.files:
self.start_job_collectibles.add(Logfile(filename))
self.end_job_collectibles.add(Logfile(filename))
......
......@@ -15,8 +15,14 @@ enabled = True
installed_packages = False
# Whether to run certain commands in bg to give extra job debug information
profiler = False
# Commands to run in bg (colon separated)
profiler_commands = vmstat 1:journalctl -f
[sysinfo.collectibles]
# File with list of commands that will be executed and have their output collected
commands = /etc/avocado/sysinfo/commands
# File with list of files that will be collected verbatim
files = /etc/avocado/sysinfo/files
# File with list of commands that will run alongside the job/test
profilers = /etc/avocado/sysinfo/profilers
[runner.output]
# Whether to display colored output in terminals that support it
......
df -mP
dmesg -c
uname -a
lspci -vvnn
gcc --version
ld --version
mount
hostname
uptime
dmidecode
ifconfig -a
brctl show
ip link
numactl --hardware show
lscpu
fdisk -l
/proc/cmdline
/proc/mounts
/proc/pci
/proc/meminfo
/proc/slabinfo
/proc/version
/proc/cpuinfo
/proc/modules
/proc/interrupts
/proc/partitions
/sys/kernel/debug/sched_features
/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
/sys/devices/system/clocksource/clocksource0/current_clocksource
......@@ -61,6 +61,9 @@ def get_data_files():
data_files = [(get_dir(['etc', 'avocado']), ['etc/avocado/avocado.conf'])]
data_files += [(get_dir(['etc', 'avocado', 'conf.d']),
['etc/avocado/conf.d/README'])]
data_files += [(get_dir(['etc', 'avocado', 'sysinfo']),
['etc/avocado/sysinfo/commands', 'etc/avocado/sysinfo/files',
'etc/avocado/sysinfo/profilers'])]
data_files += [(get_tests_dir(), glob.glob('examples/tests/*.py'))]
for data_dir in glob.glob('examples/tests/*.data'):
fmt_str = '%s/*' % data_dir
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册