taf.testlib.linux.collectd¶
collectd.py
Class to abstract collectd operations
Note
collectd.conf path is retrieved from testcases/config/setup/setup.json in format:
{
"env": [
{
"id": "213207",
"collectd_conf_path": "/opt/collectd/etc/collectd.conf"
}
],
"cross": {}
}
If “collectd_conf_path” is not specified in setup.json then default value is set: /etc/collectd.conf
Examples of collectd usage in tests:
# If required, stop running collectd service:
env.lhost[1].ui.collectd.stop()
# Start collectd service:
env.lhost[1].ui.collectd.start()
Consistent and valid collectd.conf content is built from OrderedDict object, e.g.:
python_plugin_config = collections.OrderedDict(
(('ModulePath', '"/tmp/"'),
('Interactive', 'false'),
('Import', '"python_module_name"'),
('Module "python_module_name"', {'Test': 'arg1'})))
env.lhost[1].ui.collectd.plugins_config = collections.OrderedDict(
(('Interval', 3),
('AutoLoadPlugins', 'false'),
('LoadPlugin cpu', {}),
('LoadPlugin "csv"', {}),
('LoadPlugin "python"', {'Interval': 5, 'Globals': 'true'}),
('Plugin "csv"', {'DataDir': '"/tmp/csv_data/"'}),
('Plugin "python"', python_plugin_config)))
As shown above, config parts that depend on parameters order should be presented as OrderedDict objects. Otherwise, dict() object can be used.
Transform data structure into multiline text block:
env.lhost[1].ui.collectd.update_config_file()
If required, in other test the default plugins configuration may be changed, e.g.:
env.lhost[1].ui.collectd.plugins_config['LoadPlugin "csv"'].update({'Interval': 9})
env.lhost[1].ui.collectd.update_config_file()
Some plugins support multiple entries of parameter with same name. Such case should be presented as:
{param_name: [param1_value, ...]}
Example of resulting collectd.conf file:
Interval 3
AutoLoadPlugins false
<LoadPlugin cpu>
</LoadPlugin>
<LoadPlugin "csv">
Interval 9
</LoadPlugin>
<LoadPlugin "python">
Interval 5
Globals true
</LoadPlugin>
<Plugin "csv">
DataDir "/tmp/csv_data/"
</Plugin>
<Plugin "python">
ModulePath "/tmp/"
Interactive false
Import "python_module_name"
<Module "python_module_name">
Test arg1
</Module>
</Plugin>
Restart collectd service:
env.lhost[1].ui.collectd.restart()