mirror of
https://github.com/valitydev/yandex-tank.git
synced 2024-11-06 18:35:18 +00:00
Fix monitoring config
Allow monitoring config to contain XML body as well as file name. Added test.
This commit is contained in:
parent
2c6cb8a0f5
commit
5947b910ad
@ -18,6 +18,11 @@ class MonitoringCollectorTestCase(TankTestCase):
|
||||
# XXX: write a better test
|
||||
assert conf
|
||||
|
||||
def test_inline_config(self):
|
||||
mon = MonitoringCollector()
|
||||
conf = mon.getconfig("<Monitoring>\n<Host address='[target]'/>\n</Monitoring>", 'localhost')
|
||||
assert conf
|
||||
|
||||
def test_collector(self):
|
||||
mon = MonitoringCollector()
|
||||
mon.config = "config/mon1.conf"
|
||||
@ -111,6 +116,7 @@ class MonitoringCollectorTestCase(TankTestCase):
|
||||
core.plugins_prepare_test()
|
||||
mon = MonitoringPlugin(core)
|
||||
mon.monitoring.ssh_wrapper_class = SSHEmulator
|
||||
# XXX: not working!
|
||||
core.set_option(mon.SECTION, 'config', "<Monitoring>\n<Host address='[target]'/>\n</Monitoring>")
|
||||
mon.configure()
|
||||
mon.prepare_test()
|
||||
|
@ -23,11 +23,18 @@ import yandextank.core as tankcore
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def parse_xml(config):
|
||||
if os.path.exists(config):
|
||||
return etree.parse(config)
|
||||
else:
|
||||
return etree.fromstring(config)
|
||||
|
||||
|
||||
class Config(object):
|
||||
"""Config reader helper"""
|
||||
|
||||
def __init__(self, config):
|
||||
self.tree = etree.parse(config)
|
||||
self.tree = parse_xml(config)
|
||||
|
||||
def loglevel(self):
|
||||
"""Get log level from config file. Possible values: info, debug"""
|
||||
@ -476,7 +483,7 @@ class MonitoringCollector:
|
||||
"""Prepare config data"""
|
||||
|
||||
try:
|
||||
tree = etree.parse(filename)
|
||||
tree = parse_xml(filename)
|
||||
except IOError as exc:
|
||||
logging.error("Error loading config: %s", exc)
|
||||
raise RuntimeError("Can't read monitoring config %s" % filename)
|
||||
|
Loading…
Reference in New Issue
Block a user