Exemple #1
0
def test_post_normal_addition_dimensions_metadata():
    met_buffer = Helper.get_buffer(10)
    met_config = Helper.default_config()

    configs = {
        'dimension_tags': ('dim_key1', 'dim_val1', 'dim_key2', 'dim_val2'),
        'meta_tags': ('meta_key1', 'meta_val1', 'meta_key2', 'meta_val2')
    }
    for (key, value) in configs.items():
        node = ConfigNode(getattr(ConfigOptions, key), value)
        config = CollectdConfig([Helper.url_node(), Helper.types_db_node(), node])
        met_config.parse_config(config)

    for i in range(10):
        met_buffer.put_pending_batch(['batch_%s' % i])

    met_sender = Helper.get_sender(met_config.conf, met_buffer)

    sleep_helper(10, 0.100, 100)

    assert requests.mock_server.url == met_config.conf[ConfigOptions.url]
    assert requests.mock_server.headers == {
        HeaderKeys.content_type: met_config.conf[ConfigOptions.content_type],
        HeaderKeys.content_encoding: met_config.conf[ConfigOptions.content_encoding],
        HeaderKeys.x_sumo_dimensions: 'dim_key1=dim_val1,dim_key2=dim_val2',
        HeaderKeys.x_sumo_metadata: 'meta_key1=meta_val1,meta_key2=meta_val2',
    }

    for i in range(10):
        assert_utf8_equal(met_config.conf, requests.mock_server.data[i], 'batch_%s' % i)

    met_sender.cancel_timer()
Exemple #2
0
def test_invalid_ds_in_types_db():
    met_config = Helper.default_config()
    types_db_node = ConfigNode(ConfigOptions.types_db,
                               [cwd + '/test/types_invalid_ds.db'])
    config = CollectdConfig([Helper.url_node(), types_db_node])
    met_config.parse_config(config)

    assert 'bytes' not in met_config.conf.keys()
Exemple #3
0
def test_parse_string_exception():
    with pytest.raises(Exception) as e:
        met_config = Helper.default_config()
        url_node = ConfigNode(ConfigOptions.url, [''])
        config = CollectdConfig([url_node])
        met_config.parse_config(config)

    assert 'Value for key URL cannot be empty' in str(e)
Exemple #4
0
def test_types_db_no_exist_exception():
    with pytest.raises(Exception) as e:
        met_config = Helper.default_config()
        types_db_node = ConfigNode(ConfigOptions.types_db,
                                   [cwd + '/test/types_not_exist.db'])
        config = CollectdConfig([Helper.url_node(), types_db_node])
        met_config.parse_config(config)

    assert 'No such file or directory' in str(e)
Exemple #5
0
def test_parse_int_exception():
    with pytest.raises(ValueError):
        met_config = Helper.default_config()
        max_batch_size = ''
        max_batch_size_node = ConfigNode(ConfigOptions.max_batch_size,
                                         [max_batch_size])
        config = CollectdConfig(
            [Helper.url_node(),
             Helper.types_db_node(), max_batch_size_node])
        met_config.parse_config(config)
Exemple #6
0
def test_parse_unknown_config_option():
    met_config = Helper.default_config()
    unknown_config = 'unknown_config'
    unknown_config_node = ConfigNode('unknown_config', unknown_config)
    config = CollectdConfig(
        [Helper.url_node(),
         Helper.types_db_node(), unknown_config_node])
    met_config.parse_config(config)

    assert hasattr(met_config, 'unknown_config') is False
Exemple #7
0
def test_parse_http_post_interval():
    met_config = Helper.default_config()
    http_post_interval = '0.5'
    http_post_interval_node = ConfigNode(ConfigOptions.http_post_interval,
                                         [http_post_interval])
    config = CollectdConfig(
        [Helper.url_node(),
         Helper.types_db_node(), http_post_interval_node])
    met_config.parse_config(config)

    assert met_config.conf[ConfigOptions.http_post_interval] == float(
        http_post_interval)
Exemple #8
0
def test_invalid_http_post_interval_exception():
    with pytest.raises(Exception) as e:
        met_config = Helper.default_config()
        http_post_interval = '100.0'
        http_post_interval_node = ConfigNode(ConfigOptions.http_post_interval,
                                             [http_post_interval])
        config = CollectdConfig([
            Helper.url_node(),
            Helper.types_db_node(), http_post_interval_node
        ])
        met_config.parse_config(config)

    assert 'Specify HttpPostInterval' in str(e)
Exemple #9
0
def test_parse_http_post_interval_exception():
    with pytest.raises(Exception) as e:
        met_config = Helper.default_config()
        http_post_interval = '0'
        http_post_interval_node = ConfigNode(ConfigOptions.http_post_interval,
                                             [http_post_interval])
        config = CollectdConfig([
            Helper.url_node(),
            Helper.types_db_node(), http_post_interval_node
        ])
        met_config.parse_config(config)

    assert 'Value 0.0 for key HttpPostInterval is not a positive number' in str(
        e)
 def parse_configs(met_config, configs):
     for (key, value) in configs.items():
         node = ConfigNode(getattr(ConfigOptions, key), [value])
         config = CollectdConfig([Helper.url_node(), Helper.types_db_node(), node])
         met_config.parse_config(config)
 def url_node():
     return ConfigNode(ConfigOptions.url, [Helper.url])
 def types_db_node():
     return ConfigNode(ConfigOptions.types_db, [Helper.types_db])
Exemple #13
0
def tags_node(key, values):
    return ConfigNode(key, values)