Fix monitoring config

Allow monitoring config to contain XML body as well as file name.

Added test.
This commit is contained in:
Andrew Grigorev 2015-02-17 02:10:18 +03:00
parent 2c6cb8a0f5
commit 5947b910ad
2 changed files with 15 additions and 2 deletions

View File

@ -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()

View File

@ -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)