diff options
author | Yujun Zhang <zhang.yujunz@zte.com.cn> | 2017-02-09 10:12:39 +0800 |
---|---|---|
committer | Yujun Zhang <zhang.yujunz@zte.com.cn> | 2017-02-15 06:54:40 +0800 |
commit | 0f3ad6f2db26fb91190e47c89f77fb59b7601b84 (patch) | |
tree | 8b855519dfb53d0abdd96a6eb93f3463df35817b /qtip/loader | |
parent | 6add7fcac82f9b807e71fe84d16c673682d82327 (diff) |
Refactoring collector initialization in plan loader
- move ClassProps to module
- collectors should be array in plan definition
Change-Id: I37d85dbc977c91aa1bb81de45b5e1c41660e6d1f
Signed-off-by: Yujun Zhang <zhang.yujunz@zte.com.cn>
Diffstat (limited to 'qtip/loader')
-rw-r--r-- | qtip/loader/module.py | 19 | ||||
-rw-r--r-- | qtip/loader/plan.py | 28 |
2 files changed, 42 insertions, 5 deletions
diff --git a/qtip/loader/module.py b/qtip/loader/module.py new file mode 100644 index 00000000..05cb1b76 --- /dev/null +++ b/qtip/loader/module.py @@ -0,0 +1,19 @@ +############################################################################## +# Copyright (c) 2017 ZTE Corp and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + + +from qtip.collector.logfile import LogfileCollector + + +# TODO(yujunz) more elegant way to load module dynamically +def load_collector(type_name): + if type_name == LogfileCollector.TYPE: + return LogfileCollector + else: + raise Exception("Invalid collector type: {}".format(type_name)) diff --git a/qtip/loader/plan.py b/qtip/loader/plan.py index 9b5546e0..0fd9ff52 100644 --- a/qtip/loader/plan.py +++ b/qtip/loader/plan.py @@ -8,8 +8,9 @@ ############################################################################## -from qtip.base.constant import PlanProp -from qtip.collector.logfile import LogfileCollector +from qtip.base.constant import BaseProp +from qtip.collector.base import CollectorProp as CProp +from qtip.loader.module import load_collector from qtip.loader.yaml_file import YamlFileLoader from qtip.loader.qpi import QPISpec @@ -24,9 +25,26 @@ class Plan(YamlFileLoader): def __init__(self, name, paths=None): super(Plan, self).__init__(name, paths) + _config = self.content[PlanProp.CONFIG] + + self.collectors = [load_collector(c[CProp.TYPE])(c, self) + for c in _config[PlanProp.COLLECTORS]] + self.qpis = [QPISpec(qpi, paths=paths) for qpi in self.content[PlanProp.QPIS]] - _config = self.content[PlanProp.CONFIG] - # TODO(yujunz) create collector by name - self.collector = LogfileCollector(_config[PlanProp.COLLECTOR], paths) + +class PlanProp(BaseProp): + # plan + INFO = 'info' + + FACILITY = 'facility' + ENGINEER = 'engineer' + + CONFIG = 'config' + + DRIVER = 'driver' + COLLECTORS = 'collectors' + REPORTER = 'reporter' + + QPIS = 'QPIs' |