Example #1
0
 def test_invalid_ammo(self, phout, expected_results):
     with open(os.path.join(get_test_path(), phout)) as fp:
         reader = [string_to_df(line) for line in fp.readlines()]
     pipeline = Aggregator(
         TimeChopper(DataPoller(source=reader, poll_period=0),
                     cache_size=3), AGGR_CONFIG, True)
     with open(os.path.join(get_test_path(), expected_results)) as fp:
         expected_results_parsed = json.load(fp)
     for item, expected_result in zip(pipeline, expected_results_parsed):
         for key, expected_value in expected_result.items():
             assert item[key] == expected_value
Example #2
0
 def test_reader_us(self):
     with open(
             os.path.join(
                 get_test_path(),
                 'yandextank/plugins/Phantom/tests/phout.dat')) as f:
         chunk = f.read()
     result = string_to_df_microsec(chunk)
     expected = pd.read_pickle(
         os.path.join(get_test_path(),
                      'yandextank/plugins/Phantom/tests/expected_df.dat'))
     result['ts'] -= result['ts'][0]
     assert result.equals(expected)
Example #3
0
 def test_target_hint(self):
     """ test target hint (special address=[target] option) """
     manager = ConfigManager()
     configs = manager.getconfig(
         os.path.join(get_test_path(),
                      'yandextank/plugins/Telegraf/tests/target_hint.xml'),
         'somehost.yandex.tld')
     assert (configs[0]['host'] == 'somehost.yandex.tld')
Example #4
0
 def test_xml_telegraf_parse(self):
     """ telegraf-style monitoring xml parse """
     manager = ConfigManager()
     configs = manager.getconfig(
         os.path.join(get_test_path(),
                      'yandextank/plugins/Telegraf/tests/telegraf_mon.xml'),
         'sometargethint')
     assert (configs[0]['host'] == 'somehost.yandex.tld'
             and configs[0]['host_config']['CPU']['name'] == '[inputs.cpu]')
Example #5
0
def test_agregator(phout, expected_rps):
    generator = PhantomMock(os.path.join(get_test_path(), phout))
    aggregator = TankAggregator(generator)
    listener = ListenerMock(expected_rps)
    aggregator.add_result_listener(listener)
    aggregator.start_test(poll_period=0)
    generator.finished.set()
    while not aggregator.is_aggr_finished():
        aggregator.is_test_finished()
    aggregator.end_test(1)
    assert abs(listener.avg - expected_rps) < 0.1 * expected_rps
Example #6
0
 def test_create_custom_exec_script(self):
     """ test agent config creates custom_exec config """
     manager = ConfigManager()
     telegraf_configs = manager.getconfig(
         os.path.join(get_test_path(),
                      'yandextank/plugins/Telegraf/tests/telegraf_mon.xml'),
         'sometargethint')
     agent_config = AgentConfig(telegraf_configs[0], False)
     custom_exec_config = agent_config.create_custom_exec_script()
     with open(custom_exec_config, 'r') as custom_fname:
         data = custom_fname.read()
     assert (data.find("-0) curl -s 'http://localhost:6100/stat'") != -1)
Example #7
0
 def test_create_startup_configs(self):
     """ test agent config creates startup config """
     manager = ConfigManager()
     telegraf_configs = manager.getconfig(
         os.path.join(get_test_path(),
                      'yandextank/plugins/Telegraf/tests/telegraf_mon.xml'),
         'sometargethint')
     agent_config = AgentConfig(telegraf_configs[0], False)
     startup = agent_config.create_startup_config()
     cfg_parser = RawConfigParser(strict=False)
     cfg_parser.read(startup)
     assert cfg_parser.has_section('startup')
Example #8
0
    def test_closed(self):
        STEPS = [[1.0, 1], [1.0, 1], [1.0, 1], [2.0, 1], [2.0, 1], [2.0, 1],
                 [2.0, 1], [2.0, 1], [3.0, 1], [3.0, 1], [3.0, 1], [3.0, 1],
                 [3.0, 1], [4.0, 1], [4.0, 1], [4.0, 1], [4.0, 1], [4.0, 1],
                 [5.0, 1], [5.0, 1], [5.0, 1]]
        reader = PhantomStatsReader(os.path.join(
            get_test_path(),
            'yandextank/plugins/Phantom/tests/phantom_stat.dat'),
                                    MockInfo(STEPS),
                                    cache_size=1024 * 10)
        reader.close()
        stats = reduce(lambda l1, l2: l1 + l2, [i for i in reader])

        assert len(stats) == 19
Example #9
0
 def test_create_collector_configs(self):
     """ test agent config creates collector config """
     manager = ConfigManager()
     telegraf_configs = manager.getconfig(
         os.path.join(get_test_path(),
                      'yandextank/plugins/Telegraf/tests/telegraf_mon.xml'),
         'sometargethint')
     agent_config = AgentConfig(telegraf_configs[0], False)
     remote_workdir = '/path/to/workdir/temp'
     collector_config = agent_config.create_collector_config(remote_workdir)
     cfg_parser = RawConfigParser(strict=False)
     cfg_parser.read(collector_config)
     assert (cfg_parser.has_section('agent')
             and cfg_parser.get('agent', 'interval') == "'1s'"
             and cfg_parser.has_section('[outputs.file')
             and cfg_parser.get('[outputs.file', 'files')
             == "['{rmt}/monitoring.rawdata']".format(rmt=remote_workdir))
Example #10
0
def test_ammo(stepper_kwargs, expected_stpd):
    stepper = Stepper(
        TankCore([{}], threading.Event(), TankInfo({})),
        rps_schedule=["const(10,10s)"],
        http_ver="1.1",
        instances_schedule=None,
        instances=10,
        loop_limit=1000,
        ammo_limit=1000,
        enum_ammo=False,
        **stepper_kwargs
    )
    stepper_output = io.BytesIO()
    stepper.write(stepper_output)
    stepper_output.seek(0)
    expected_lines = read_resource(os.path.join(get_test_path(), expected_stpd), 'rb').split(b'\n')
    for i, (result, expected) in enumerate(zip(stepper_output, expected_lines)):
        assert result.strip() == expected.strip(), 'Line {} mismatch'.format(i)
Example #11
0
 def test_legacy_plugin_configuration(self):
     """ testing legacy plugin configuration, old-style monitoring """
     cfg = {
         'core': {},
         'monitoring': {
             'package':
             'yandextank.plugins.Telegraf',
             'enabled':
             True,
             'config':
             os.path.join(get_test_path(),
                          'yandextank/plugins/Telegraf/tests/old_mon.xml')
         }
     }
     core = TankCore(cfg, threading.Event(), TankInfo({}))
     telegraf_plugin = core.get_plugin_of_type(TelegrafPlugin)
     telegraf_plugin.configure()
     assert telegraf_plugin.detected_conf == 'monitoring'
Example #12
0
        assert take(check_point, (create(rps_schedule))) == expected


# ([0-9.]+d)?([0-9.]+h)?([0-9.]+m)?([0-9.]+s)?
@pytest.mark.parametrize('step_config, expected_duration', [
    ('line(1,500,1m30s)', 90),
    ('const(50,1h30s)', 3630 * 1000),
    ('step(10,200,10,1h20m)', 4800 * 1000)
])
def test_step_factory(step_config, expected_duration):
    steps = StepFactory.produce(step_config)
    assert steps.duration == expected_duration


@pytest.mark.parametrize('stepper_kwargs, expected_stpd', [
    ({'ammo_file': os.path.join(get_test_path(), 'yandextank/stepper/tests/test-ammo.txt')},
     'yandextank/stepper/tests/expected.stpd'),
    ({'ammo_type': 'uripost',
      'ammo_file': os.path.join(get_test_path(), 'yandextank/stepper/tests/test-uripost.txt')},
     'yandextank/stepper/tests/uripost-expected.stpd'),
    ({'uris': ['/case1?sleep=1000', '/case2?sleep=100', '/case3?sleep=10'],
      'headers': ['[Connection: close]']},
     'yandextank/stepper/tests/uris-expected.stpd'),
    ({'ammo_file': os.path.join(get_test_path(), 'yandextank/stepper/tests/test-unicode.txt'),
      'headers': ['Connection: close', 'Host: web-load03f.yandex.ru']},
     'yandextank/stepper/tests/unicode-expected.stpd'),
    ({'ammo_type': 'caseline',
      'ammo_file': os.path.join(get_test_path(), 'yandextank/stepper/tests/test-caseline.txt')},
     'yandextank/stepper/tests/caseline-expected.stpd'),
    ({'ammo_file': os.path.join(get_test_path(), 'yandextank/stepper/tests/test-protobuf-autocases.txt'),
      'autocases': 2},
Example #13
0
def data():
    df = pd.read_csv(os.path.join(get_test_path(),
                                  'yandextank/aggregator/tests/data.csv'),
                     delimiter=',',
                     index_col=0)
    return df
Example #14
0

# ([0-9.]+d)?([0-9.]+h)?([0-9.]+m)?([0-9.]+s)?
@pytest.mark.parametrize('step_config, expected_duration',
                         [('line(1,500,1m30s)', 90),
                          ('const(50,1h30s)', 3630 * 1000),
                          ('step(10,200,10,1h20m)', 4800 * 1000)])
def test_step_factory(step_config, expected_duration):
    steps = StepFactory.produce(step_config)
    assert steps.duration == expected_duration


@pytest.mark.parametrize('stepper_kwargs, expected_stpd', [
    ({
        'ammo_file':
        os.path.join(get_test_path(), 'yandextank/stepper/tests/test-ammo.txt')
    }, 'yandextank/stepper/tests/expected.stpd'),
    ({
        'ammo_type':
        'uripost',
        'ammo_file':
        os.path.join(get_test_path(),
                     'yandextank/stepper/tests/test-uripost.txt')
    }, 'yandextank/stepper/tests/uripost-expected.stpd'),
    ({
        'uris': ['/case1?sleep=1000', '/case2?sleep=100', '/case3?sleep=10'],
        'headers': ['[Connection: close]']
    }, 'yandextank/stepper/tests/uris-expected.stpd'),
    ({
        'ammo_file':
        os.path.join(get_test_path(),
Example #15
0
 def setup_class(self):
     stop = Event()
     self.multireader = FileMultiReader(
         os.path.join(get_test_path(),
                      'yandextank/plugins/Phantom/tests/phout.dat'), stop)
     stop.set()
Example #16
0
import pytest
import os

from yandextank.common.util import get_test_path
from yandextank.plugins.DataUploader.cli import from_tank_config, get_logger


@pytest.mark.parametrize('test_dir, expected', [
    (os.path.join(
        get_test_path(),
        'yandextank/plugins/DataUploader/tests/test_postloader/test_empty'),
     (None, {})),
    (os.path.join(
        get_test_path(),
        'yandextank/plugins/DataUploader/tests/test_postloader/test_full'),
     ('uploader', {
         'api_address': 'https://lunapark.yandex-team.ru/',
         'api_attempts': 2,
         'api_timeout': 5,
         'enabled': True,
         'job_dsc': 'hell of a kitty',
         'job_name': 'Hello kitty',
         'jobno_file': 'jobno.txt',
         'lock_targets': 'foo.bar',
         'maintenance_timeout': 5,
         'network_attempts': 2,
         'operator': 'fomars',
         'package': 'yandextank.plugins.DataUploader',
         'task': 'LOAD-204'
     })),
    (os.path.join(