Skip to content

Commit

Permalink
Merge pull request #570 from fomars/develop
Browse files Browse the repository at this point in the history
config_contents is back
  • Loading branch information
fomars committed Apr 25, 2018
2 parents 3964c07 + 83a795a commit 1d9a27a
Show file tree
Hide file tree
Showing 23 changed files with 47 additions and 86 deletions.
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

setup(
name='yandextank',
version='1.9.12',

version='1.9.13',
description='a performance measurement tool',
longer_description='''
Yandex.Tank is a performance measurement and load testing automatization tool.
Expand Down
8 changes: 4 additions & 4 deletions yandextank/common/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def get_key():
raise TypeError("Abstract method needs to be overridden")

# TODO: do we realy need cfg_updater here?
def __init__(self, core, cfg, cfg_updater=None):
def __init__(self, core, cfg):
"""
@type core: TankCore
Expand All @@ -25,7 +25,7 @@ def __init__(self, core, cfg, cfg_updater=None):
self.cfg = cfg

def set_option(self, option, value):
self.cfg.setdefault('meta', {})[option] = value
self.cfg[option] = value

def configure(self):
""" A stage to read config values and instantiate objects """
Expand Down Expand Up @@ -190,8 +190,8 @@ class GeneratorPlugin(AbstractPlugin):
'loop_count': 0
}

def __init__(self, core, cfg, cfg_updater):
super(GeneratorPlugin, self).__init__(core, cfg, cfg_updater)
def __init__(self, core, cfg):
super(GeneratorPlugin, self).__init__(core, cfg)
self.stats_reader = None
self.reader = None
self.process = None
Expand Down
4 changes: 2 additions & 2 deletions yandextank/core/tankcore.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def load_plugins(self):
Tells core to take plugin options and instantiate plugin classes
"""
logger.info("Loading plugins...")
for (plugin_name, plugin_path, plugin_cfg, cfg_updater) in self.config.plugins:
for (plugin_name, plugin_path, plugin_cfg) in self.config.plugins:
logger.debug("Loading plugin %s from %s", plugin_name, plugin_path)
if plugin_path is "yandextank.plugins.Overload":
logger.warning(
Expand All @@ -187,7 +187,7 @@ def load_plugins(self):
logger.debug('Plugin name %s path %s import error', plugin_name, plugin_path, exc_info=True)
raise
try:
instance = getattr(plugin, 'Plugin')(self, cfg=plugin_cfg, cfg_updater=cfg_updater)
instance = getattr(plugin, 'Plugin')(self, cfg=plugin_cfg)
except AttributeError:
logger.warning('Plugin %s classname should be `Plugin`', plugin_name)
raise
Expand Down
4 changes: 2 additions & 2 deletions yandextank/plugins/Android/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ class Plugin(AbstractPlugin):
SECTION = "android"
SECTION_META = "meta"

def __init__(self, core, cfg, cfg_updater):
def __init__(self, core, cfg):
self.stats_reader = None
self.reader = None
super(Plugin, self).__init__(core, cfg, cfg_updater)
super(Plugin, self).__init__(core, cfg)
self.device = None
try:
self.cfg = cfg['volta_options']
Expand Down
4 changes: 2 additions & 2 deletions yandextank/plugins/Autostop/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class Plugin(AbstractPlugin, AggregateResultListener):
""" Plugin that accepts criterion classes and triggers autostop """
SECTION = 'autostop'

def __init__(self, core, cfg, cfg_updater):
AbstractPlugin.__init__(self, core, cfg, cfg_updater)
def __init__(self, core, cfg):
AbstractPlugin.__init__(self, core, cfg)
AggregateResultListener.__init__(self)

self.cause_criterion = None
Expand Down
2 changes: 1 addition & 1 deletion yandextank/plugins/Bfg/guns.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class GunConfigError(Exception):

class AbstractGun(AbstractPlugin):
def __init__(self, core, cfg):
super(AbstractGun, self).__init__(core, cfg, None)
super(AbstractGun, self).__init__(core, cfg)
self.results = None

@contextmanager
Expand Down
4 changes: 2 additions & 2 deletions yandextank/plugins/Bfg/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class Plugin(GeneratorPlugin):
""" Big Fucking Gun plugin """
SECTION = 'bfg'

def __init__(self, core, cfg, cfg_updater):
super(Plugin, self).__init__(core, cfg, cfg_updater)
def __init__(self, core, cfg):
super(Plugin, self).__init__(core, cfg)
self._bfg = None
self.log = logging.getLogger(__name__)
self.gun_type = None
Expand Down
4 changes: 2 additions & 2 deletions yandextank/plugins/Console/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class Plugin(AbstractPlugin, AggregateResultListener):
''' Console plugin '''
SECTION = 'console'

def __init__(self, core, cfg, cfg_updater):
AbstractPlugin.__init__(self, core, cfg, cfg_updater)
def __init__(self, core, cfg):
AbstractPlugin.__init__(self, core, cfg)
self.log = logging.getLogger(__name__)
self.screen = None
self.render_exception = None
Expand Down
7 changes: 5 additions & 2 deletions yandextank/plugins/DataUploader/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ class Plugin(AbstractPlugin, AggregateResultListener,
VERSION = '3.0'
SECTION = 'uploader'

def __init__(self, core, cfg, cfg_updater):
AbstractPlugin.__init__(self, core, cfg, cfg_updater)
def __init__(self, core, cfg):
AbstractPlugin.__init__(self, core, cfg)
self.data_queue = Queue()
self.monitoring_queue = Queue()
if self.core.error_log:
Expand Down Expand Up @@ -106,6 +106,9 @@ def __init__(self, core, cfg, cfg_updater):

self.finished = False

def set_option(self, option, value):
self.cfg.setdefault('meta', {})[option] = value

@staticmethod
def get_key():
return __file__
Expand Down
4 changes: 2 additions & 2 deletions yandextank/plugins/Influx/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class Plugin(AbstractPlugin, AggregateResultListener,

SECTION = 'influx'

def __init__(self, core, cfg, cfg_updater):
AbstractPlugin.__init__(self, core, cfg, cfg_updater)
def __init__(self, core, cfg):
AbstractPlugin.__init__(self, core, cfg)
self.tank_tag = self.get_option("tank_tag")
address = self.get_option("address")
port = self.get_option("port")
Expand Down
4 changes: 2 additions & 2 deletions yandextank/plugins/JMeter/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class Plugin(GeneratorPlugin):
STOP_TEST_NOW = 'Stop Test'
DISCOVER_PORT_PATTERN = 'Waiting for possible shutdown message on port (?P<port>\d+)'

def __init__(self, core, cfg, cfg_updater):
super(Plugin, self).__init__(core, cfg, cfg_updater)
def __init__(self, core, cfg):
super(Plugin, self).__init__(core, cfg)
self.args = None
self.original_jmx = None
self.jtl_file = None
Expand Down
4 changes: 2 additions & 2 deletions yandextank/plugins/JsonReport/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class Plugin(AbstractPlugin, AggregateResultListener, MonitoringDataListener):
# pylint:disable=R0902
SECTION = 'json_report'

def __init__(self, core, cfg, cfg_updater):
super(Plugin, self).__init__(core, cfg, cfg_updater)
def __init__(self, core, cfg):
super(Plugin, self).__init__(core, cfg)
self.monitoring_stream = io.open(os.path.join(self.core.artifacts_dir,
self.get_option('monitoring_log')),
mode='wb')
Expand Down
4 changes: 2 additions & 2 deletions yandextank/plugins/Pandora/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class Plugin(GeneratorPlugin):
OPTION_CONFIG = "config"
SECTION = "pandora"

def __init__(self, core, cfg, cfg_updater):
super(Plugin, self).__init__(core, cfg, cfg_updater)
def __init__(self, core, cfg):
super(Plugin, self).__init__(core, cfg)
self.enum_ammo = False
self.process_start_time = None
self.pandora_cmd = None
Expand Down
4 changes: 2 additions & 2 deletions yandextank/plugins/Phantom/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class Plugin(GeneratorPlugin):

OPTION_CONFIG = "config"

def __init__(self, core, cfg, cfg_updater):
super(Plugin, self).__init__(core, cfg, cfg_updater)
def __init__(self, core, cfg):
super(Plugin, self).__init__(core, cfg)
self.predefined_phout = None
self.did_phout_import_try = False
self.eta_file = None
Expand Down
4 changes: 2 additions & 2 deletions yandextank/plugins/Platform/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class Plugin(AbstractPlugin):
def get_key():
return __file__

def __init__(self, core, cfg, cfg_updater):
AbstractPlugin.__init__(self, core, cfg, cfg_updater)
def __init__(self, core, cfg):
AbstractPlugin.__init__(self, core, cfg)
self.hosts = []
self.port = None
self.logfile = None
Expand Down
4 changes: 2 additions & 2 deletions yandextank/plugins/RCAssert/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
class Plugin(AbstractPlugin):
SECTION = 'rcassert'

def __init__(self, core, cfg, cfg_updater):
AbstractPlugin.__init__(self, core, cfg, cfg_updater)
def __init__(self, core, cfg):
AbstractPlugin.__init__(self, core, cfg)
self.ok_codes = []
self.fail_code = 10

Expand Down
4 changes: 2 additions & 2 deletions yandextank/plugins/ResourceCheck/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ class Plugin(AbstractPlugin):
def get_key():
return __file__

def __init__(self, core, cfg, cfg_updater):
def __init__(self, core, cfg):
''' Constructor '''
AbstractPlugin.__init__(self, core, cfg, cfg_updater)
AbstractPlugin.__init__(self, core, cfg)
self.interval = "10s"
self.disk_limit = 2048 # 2 GB
self.mem_limit = 512 # 0.5 GB
Expand Down
4 changes: 2 additions & 2 deletions yandextank/plugins/ShellExec/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class Plugin(AbstractPlugin):
"""
SECTION = 'shellexec'

def __init__(self, core, cfg, cfg_updater):
AbstractPlugin.__init__(self, core, cfg, cfg_updater)
def __init__(self, core, cfg):
AbstractPlugin.__init__(self, core, cfg)
self.catch_out = False
self.end = None
self.poll = None
Expand Down
4 changes: 2 additions & 2 deletions yandextank/plugins/ShellExec/tests/test_shellexec_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@


def test_plugin_execute():
plugin = Plugin(None, {}, None)
plugin = Plugin(None, {})
assert plugin.execute('echo foo') == 0


def test_plugin_execute_raises():
plugin = Plugin(None, {}, None)
plugin = Plugin(None, {})
with pytest.raises(RuntimeError) as error:
plugin.execute('echo "foo')
assert 'Subprocess returned 2' in error.message
4 changes: 2 additions & 2 deletions yandextank/plugins/ShootExec/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class Plugin(AbstractPlugin, GeneratorPlugin):

SECTION = 'shootexec'

def __init__(self, core, cfg, cfg_updater):
AbstractPlugin.__init__(self, core, cfg, cfg_updater)
def __init__(self, core, cfg):
AbstractPlugin.__init__(self, core, cfg)
self.stats_reader = None
self.reader = None
self.__process = None
Expand Down
4 changes: 2 additions & 2 deletions yandextank/plugins/Telegraf/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class Plugin(AbstractPlugin):

SECTION = 'telegraf' # may be redefined to 'monitoring' sometimes.

def __init__(self, core, cfg, cfg_updater):
super(Plugin, self).__init__(core, cfg, cfg_updater)
def __init__(self, core, cfg):
super(Plugin, self).__init__(core, cfg)
self.jobno = None
self.default_target = None
self.default_config = "{path}/config/monitoring_default_config.xml".format(
Expand Down
34 changes: 1 addition & 33 deletions yandextank/validator/tests/test_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,39 +557,7 @@ def test_validate_all_error(config, expected):
)
])
def test_get_plugins(config, expected):
assert {(name, pack) for name, pack, cfg, updater in TankConfig(config).plugins} == expected


@pytest.mark.parametrize('config, plugin, key, value', [
({
"version": "1.9.3",
"core": {
'operator': 'fomars',
'artifacts_base_dir': './',
},
'telegraf': {
'package': 'yandextank.plugins.Telegraf',
'enabled': True,
'config': 'monitoring.xml',
'disguise_hostnames': True
},
}, 'telegraf', 'config', 'foobar.xml')
])
def test_setter(config, plugin, key, value):
tankconfig = TankConfig(config)
tankconfig._TankConfig__get_cfg_updater(plugin)(key, value)
assert tankconfig.get_option(plugin, key) == value

# configparser = ConfigParser.ConfigParser()
# configparser.read(config_file)
# plugins_conf = {section: dict(configparser.items(section)) for section in configparser.sections()}
# config = {
# "version": "1.9.3",
# "core": {
# 'operator': 'fomars'
# },
# "plugins": plugins_conf
# }
assert {(name, pack) for name, pack, cfg in TankConfig(config).plugins} == expected


@pytest.mark.parametrize('value', [
Expand Down
11 changes: 1 addition & 10 deletions yandextank/validator/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,14 @@ def _validate_description(self, description, field, value):
""" {'type': 'string'} """
pass

# monkey-patch cerberus validator to allow values descriptions field
def _validate_values_description(self, values_description, field, value):
""" {'type': 'dict'} """
pass

# monkey-patch cerberus validator to allow tutorial_link field
def _validate_tutorial_link(self, tutorial_link, field, value):
""" {'type': 'string'} """
pass

# monkey-patch cerberus validator to allow examples field
def _validate_examples(self, examples, field, value):
""" {'type': 'dict'} """
pass
Expand Down Expand Up @@ -199,8 +196,7 @@ def plugins(self):
self._plugins = [
(plugin_name,
plugin_cfg['package'],
plugin_cfg,
self.__get_cfg_updater(plugin_name)) for plugin_name,
plugin_cfg) for plugin_name,
plugin_cfg in self.validated.items() if (
plugin_name not in self.BASE_SCHEMA.keys()) and plugin_cfg['enabled']]
return self._plugins
Expand Down Expand Up @@ -304,11 +300,6 @@ def __set_core_dynamic_options(self, config):
config[self.CORE_SECTION] = {option: setter()}
return config

def __get_cfg_updater(self, plugin_name):
def cfg_updater(key, value):
self.validated[plugin_name][key] = value
return cfg_updater

def __str__(self):
return yaml.dump(self.validated)

Expand Down

0 comments on commit 1d9a27a

Please sign in to comment.