示例#1
0
def test_emission_queuing():
    plugin.instantiate(config["plugin"], None)
    queue_tester = plugin.get_instance("queue_tester")
    emit_store1 = plugin.get_output("emit_store1", None)
    emit_store2 = plugin.get_output("emit_store2", None)

    # daemon handles this, do it manually here since
    # we are not starting the daemon
    queue_tester._emit = [emit_store1, emit_store2]

    message = queue_tester.probe()
    queue_tester.queue_emission(message)

    queue_tester.send_emission()
    assert emit_store1.store[0] == message
    assert emit_store2.store == []

    queue_tester.send_emission()
    assert emit_store1.store[0] == message
    assert len(emit_store1.store) == 1
    assert emit_store2.store[0] == message
    assert len(emit_store2.store) == 1
    assert queue_tester._emit_queue.qsize() == 0

    message = queue_tester.probe()
    queue_tester.queue_emission(message)
    queue_tester.emit_all()
    assert len(emit_store1.store) == 2
    assert len(emit_store2.store) == 2
    assert queue_tester._emit_queue.qsize() == 0
示例#2
0
def test_update_and_create():
    """
    test that update() and create() are called accordingly during
    emit()
    """
    inst = plugin.get_instance(config, None)
    t = time.time()
    inst.emit({
        "type":
        "test",
        "source":
        "test_update_and_create",
        "ts":
        t,
        "data": [
            {
                "test": 123,
                "a": "row",
                "b": "1"
            },
            {
                "test": 456,
                "a": "row",
                "b": "2"
            },
        ],
    })
    assert inst.created == True
    assert inst.updated["row-1-test"] == (t, 123)
    assert inst.updated["row-2-test"] == (t, 456)
示例#3
0
文件: test_plugin.py 项目: 20c/vaping
def test_emission_queuing():
    plugin.instantiate(config["plugin"], None)
    queue_tester = plugin.get_instance("queue_tester")
    emit_store1 = plugin.get_output("emit_store1", None)
    emit_store2 = plugin.get_output("emit_store2", None)

    # daemon handles this, do it manually here since
    # we are not starting the daemon
    queue_tester._emit = [emit_store1, emit_store2]

    message = queue_tester.probe()
    queue_tester.queue_emission(message)

    queue_tester.send_emission()
    assert emit_store1.store[0] == message
    assert emit_store2.store == []

    queue_tester.send_emission()
    assert emit_store1.store[0] == message
    assert len(emit_store1.store) == 1
    assert emit_store2.store[0] == message
    assert len(emit_store2.store) == 1
    assert queue_tester._emit_queue.qsize() == 0

    message = queue_tester.probe()
    queue_tester.queue_emission(message)
    queue_tester.emit_all()
    assert len(emit_store1.store) == 2
    assert len(emit_store2.store) == 2
    assert queue_tester._emit_queue.qsize() == 0
示例#4
0
def test_config_defaults():
    inst = plugin.get_instance(config_default, None)
    config = inst.config

    assert config["fields"] == {}
    assert config["exclude"] == []
    assert config["include"] == []
    assert config["aggregate"] == {}
示例#5
0
def test_parse_line(line,result,raises):
    inst = plugin.get_instance(config, None)
    if raises:
        with pytest.raises(ValueError) as exception_info:
            _result = inst.parse_line(line)
        assert str(exception_info).find(raises) > -1
    else:
        _result = inst.parse_line(line)
        assert _result == result
示例#6
0
def test_filename_format():
    """
    test filename formatting from data
    """
    inst = plugin.get_instance(config, None)
    assert (inst.format_filename({}, {
        "a": "first",
        "b": "second"
    }) == "first-second-test")
示例#7
0
def test_whisper(tmpdir):
    """
    test whisper-db creation and update from emit
    """

    config["filename"] = str(tmpdir.mkdir("whisper").join(FILENAME_TEMPLATE))
    inst = plugin.get_instance(config, None)
    inst.start()
    i = 0
    t = int(time.time()) - 10

    # emit and insert 10 data points for 2 graphs at 1 second intervals
    while i < 10:
        inst.emit({
            "type":
            "test",
            "source":
            "test_whisper",
            "ts":
            t + i,
            "data": [{
                "test": 123 + i,
                "id": 1
            }, {
                "test": 456 + i,
                "id": 2
            }]
        })
        i += 1

    # retrieve data from whisper db
    times_1, values_1 = inst.get(inst.format_filename({}, {"id": 1}), t - 1,
                                 t + 9)
    times_2, values_2 = inst.get(inst.format_filename({}, {"id": 2}), t - 1,
                                 t + 9)

    assert times_1[0] == t
    assert times_1[1] == t + 10
    assert times_1[2] == 1

    assert times_2[0] == t
    assert times_2[1] == t + 10
    assert times_2[2] == 1

    def value_assert(points, start):
        i = 0
        for k in points:
            assert k == start + i
            i += 1

    value_assert(values_1, 123)
    value_assert(values_2, 456)
示例#8
0
def test_time_parser(line,result,raises):
    inst = plugin.get_instance(config_time_parser, None)
    if raises:
        with pytest.raises(ValueError) as exception_info:
            _result = inst.process_line(line, {})
        assert str(exception_info).find(raises) > -1
    else:
        _result = inst.process_line(line, {})
        if not result:
            assert _result == result
        else:
            dt = datetime.datetime.fromtimestamp(_result["ts"])
            assert dt.strftime("%Y.%m.%d %H:%M:%S") == result
示例#9
0
def test_whisper_config():
    config["filename"] = "{id}-{field}.wsp"
    inst = plugin.get_instance(config, None)
    whisper_config = inst.config

    # Check that whisper config takes values from
    # provided config
    for k, v in config.items():
        assert whisper_config[k] == v

    # Check that certain attributes are
    # available on plugin instance
    inst.retention = config["retention"]
    inst.x_files_factor = config["x_files_factor"]
    inst.aggregation_method = config["aggregation_method"]
    inst.sparse = config["sparse"]
示例#10
0
def test_whisper(tmpdir):
    """
    test whisper-db creation and update from emit
    """

    config["filename"] = str(tmpdir.mkdir("whisper").join(FILENAME_TEMPLATE))
    inst = plugin.get_instance(config, None)
    inst.start()
    i = 0
    t = int(time.time())-10

    # emit and insert 10 data points for 2 graphs at 1 second intervals
    while i < 10:
        inst.emit({
            "type" : "test",
            "source" : "test_whisper",
            "ts" : t+i,
            "data" : [
                { "test" : 123+i, "id" : 1 },
                { "test" : 456+i, "id" : 2 }
            ]
        })
        i += 1

    # retrieve data from whisper db
    times_1, values_1 = inst.get(inst.format_filename({}, {"id":1}), t - 1, t + 9)
    times_2, values_2 = inst.get(inst.format_filename({}, {"id":2}), t - 1, t + 9)

    assert times_1[0] == t
    assert times_1[1] == t+10
    assert times_1[2] == 1

    assert times_2[0] == t
    assert times_2[1] == t+10
    assert times_2[2] == 1

    def value_assert(points, start):
        i = 0
        for k in points:
            assert k == start + i
            i += 1

    value_assert(values_1, 123)
    value_assert(values_2, 456)
示例#11
0
def test_update_and_create():
    """
    test that update() and create() are called accordingly during
    emit()
    """
    inst = plugin.get_instance(config, None)
    t = time.time()
    inst.emit({
        "type" : "test",
        "source" : "test_update_and_create",
        "ts" : t,
        "data" : [
            { "test" : 123, "a" : "row", "b" : "1" },
            { "test" : 456, "a" : "row", "b" : "2" }
        ]
    })
    assert inst.created == True
    assert inst.updated["row-1-test"] == (t, 123)
    assert inst.updated["row-2-test"] == (t, 456)
示例#12
0
文件: test_plugin.py 项目: 20c/vaping
def test_plugin_instance():
    with pytest.raises(ValueError):
        plugin.new_plugin({}, None)

    with pytest.raises(ValueError):
        plugin.get_instance('nonexistant', None)
    with pytest.raises(ValueError):
        plugin.get_instance(['unparsable'], None)

    plugin.instantiate(config['plugin'], None)
    for each in config['plugin']:
        if 'name' not in each:
            continue
        obj = plugin.get_instance(each['name'], None)
        for k,v in list(each.items()):
            assert v == obj.config[k]

    obj = plugin.get_instance(anon_config, None)
    assert obj.config == anon_config

    # copy ctor
    obj = plugin.get_instance('fancy_copy', None)
    assert 'reeb' == obj.config['str0']

    obj = plugin.get_instance({'fancy_copy': {'var0': 'luggage'}}, None)
    assert 'reeb' == obj.config['str0']

    with pytest.raises(TypeError):
        plugin.get_probe('emit0', None)
    assert None != plugin.get_probe('probe1', None)
    assert not hasattr(plugin.get_probe('probe1', None), 'emit')

    with pytest.raises(TypeError):
        plugin.get_output('emit_abc', None)
    with pytest.raises(TypeError):
        plugin.get_output('probe1', None)
    assert None != plugin.get_output('emit0', None)
示例#13
0
文件: test_plugin.py 项目: 20c/vaping
def test_plugin_instance():
    with pytest.raises(ValueError):
        plugin.new_plugin({}, None)

    with pytest.raises(ValueError):
        plugin.get_instance("nonexistant", None)
    with pytest.raises(ValueError):
        plugin.get_instance(["unparsable"], None)

    plugin.instantiate(config["plugin"], None)
    for each in config["plugin"]:
        if "name" not in each:
            continue
        obj = plugin.get_instance(each["name"], None)
        for k, v in list(each.items()):
            assert v == obj.config[k]

    obj = plugin.get_instance(anon_config, None)
    assert obj.config == anon_config

    # copy ctor
    obj = plugin.get_instance("fancy_copy", None)
    assert "reeb" == obj.config["str0"]

    obj = plugin.get_instance({"fancy_copy": {"var0": "luggage"}}, None)
    assert "reeb" == obj.config["str0"]

    with pytest.raises(TypeError):
        plugin.get_probe("emit0", None)
    assert plugin.get_probe("probe1", None) is not None
    assert not hasattr(plugin.get_probe("probe1", None), "emit")

    with pytest.raises(TypeError):
        plugin.get_output("emit_abc", None)
    with pytest.raises(TypeError):
        plugin.get_output("probe1", None)
    assert plugin.get_output("emit0", None) is not None
示例#14
0
def test_plugin_instance():
    with pytest.raises(ValueError):
        plugin.new_plugin({}, None)

    with pytest.raises(ValueError):
        plugin.get_instance('nonexistant', None)
    with pytest.raises(ValueError):
        plugin.get_instance(['unparsable'], None)

    plugin.instantiate(config['plugin'], None)
    for each in config['plugin']:
        if 'name' not in each:
            continue
        obj = plugin.get_instance(each['name'], None)
        for k, v in list(each.items()):
            assert v == obj.config[k]

    obj = plugin.get_instance(anon_config, None)
    assert obj.config == anon_config

    # copy ctor
    obj = plugin.get_instance('fancy_copy', None)
    assert 'reeb' == obj.config['str0']

    obj = plugin.get_instance({'fancy_copy': {'var0': 'luggage'}}, None)
    assert 'reeb' == obj.config['str0']

    with pytest.raises(TypeError):
        plugin.get_probe('emit0', None)
    assert None != plugin.get_probe('probe1', None)
    assert not hasattr(plugin.get_probe('probe1', None), 'emit')

    with pytest.raises(TypeError):
        plugin.get_output('emit_abc', None)
    with pytest.raises(TypeError):
        plugin.get_output('probe1', None)
    assert None != plugin.get_output('emit0', None)
示例#15
0
文件: test_plugin.py 项目: 20c/vaping
def test_emission_queuing():

    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)

    plugin.instantiate(config["plugin"], None)
    queue_tester = plugin.get_instance("queue_tester")
    emit_store1 = plugin.get_output("emit_store1", None)
    emit_store2 = plugin.get_output("emit_store2", None)

    # plugins = [queue_tester, emit_store1, emit_store2]

    # daemon handles this, do it manually here since
    # we are not starting the daemon
    queue_tester._emit = [emit_store1, emit_store2]

    message = queue_tester.probe()
    asyncio.run(queue_tester.queue_emission(message))

    asyncio.run(queue_tester.send_emission())
    assert emit_store1.store[0] == message
    assert emit_store2.store == []

    asyncio.run(queue_tester.send_emission())
    assert emit_store1.store[0] == message
    assert len(emit_store1.store) == 1
    assert emit_store2.store[0] == message
    assert len(emit_store2.store) == 1
    assert queue_tester._emit_queue.qsize() == 0

    message = queue_tester.probe()
    asyncio.run(queue_tester.queue_emission(message))
    asyncio.run(queue_tester.emit_all())
    assert len(emit_store1.store) == 2
    assert len(emit_store2.store) == 2
    assert queue_tester._emit_queue.qsize() == 0

    loop.close()
示例#16
0
def test_aggregate(line, iterations,result,raises):
    inst = plugin.get_instance(config_aggr, None)
    count = config_aggr.get("aggregate").get("count")
    if raises:
        pass
    else:
        messages = []
        for i in range(0, iterations):
            msg = inst.new_message()
            data = {}
            data = inst.process_line(line, data)
            data = inst.process_probe(data)
            msg["data"] = [data]
            messages.append(msg)
        messages = inst.process_messages(messages)

        for row in result:
            row["messages"] = count

        assert len(messages) == math.floor(iterations / count)
        i = 0
        for msg in messages:
            assert msg["data"] == [result[i]]
            i += 1
示例#17
0
文件: test_vodka.py 项目: 20c/vaping
def test_init(this_dir):
    config_dir = os.path.join(this_dir, 'data', 'config', 'vodka')
    vaping.daemon.Vaping(config_dir=config_dir)
    plugin.get_instance("vodka")
示例#18
0
def test_filename_format():
    """
    test filename formatting from data
    """
    inst = plugin.get_instance(config, None)
    assert inst.format_filename({}, {"a":"first", "b":"second"}) == "first-second-test"
示例#19
0
def test_init(this_dir):
    config_dir = os.path.join(this_dir, "data", "config", "vodka")
    vaping.daemon.Vaping(config_dir=config_dir)
    plugin.get_instance("vodka")
示例#20
0
def test_init(this_dir):
    config_dir = os.path.join(this_dir, 'data', 'config', 'vodka')
    vaping.daemon.Vaping(config_dir=config_dir)
    plugin.get_instance("vodka")