Skip to content
Snippets Groups Projects
Commit e63f4198 authored by Nikolay Stanchev's avatar Nikolay Stanchev
Browse files

[ Issue #57 and #47 ] - moved the kapacitor conf setup POST in a pytest fixture

parent ef4cd061
No related branches found
No related tags found
No related merge requests found
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
import pytest import pytest
import yaml import yaml
import requests
@pytest.fixture(scope="module", params=[{'config': {'rspec': '/vagrant/test/streaming/rspec.yml'}}]) @pytest.fixture(scope="module", params=[{'config': {'rspec': '/vagrant/test/streaming/rspec.yml'}}])
...@@ -16,3 +17,15 @@ def streaming_config(request): ...@@ -16,3 +17,15 @@ def streaming_config(request):
with open(request.param['config']['rspec'], 'r') as stream: with open(request.param['config']['rspec'], 'r') as stream:
data_loaded = yaml.load(stream) data_loaded = yaml.load(stream)
return data_loaded return data_loaded
@pytest.fixture(scope="module", autouse=True,
params=[{'config': {'kapacitor_url': 'http://localhost:8888/chronograf/v1/sources/1/kapacitors', 'kapacitor_file': '/vagrant/test/streaming/kapacitor.json'}}])
def kapacitor_config(request):
kapacitor_configuration = request.param['config']['kapacitor_file']
with open(kapacitor_configuration, "r") as rule_file:
data = "".join(line.strip() for line in rule_file.readlines())
kapacitor_url = request.param['config']['kapacitor_url']
requests.post(url=kapacitor_url, data=data, headers={"Content-Type": "application/json"})
...@@ -33,18 +33,8 @@ echo $TEST_DIR"/kapacitor.conf" ...@@ -33,18 +33,8 @@ echo $TEST_DIR"/kapacitor.conf"
cp $TEST_DIR/kapacitor.conf /etc/kapacitor/kapacitor.conf cp $TEST_DIR/kapacitor.conf /etc/kapacitor/kapacitor.conf
systemctl start kapacitor systemctl start kapacitor
# wait for kapacitor to restart
# TODO: do this better
sleep 5
# Set up Influx data source # Set up Influx data source
curl -i -X POST -H "Content-Type: application/json" http://localhost:8888/chronograf/v1/sources -d @$TEST_DIR/influx.json curl -i -X POST -H "Content-Type: application/json" http://localhost:8888/chronograf/v1/sources -d @$TEST_DIR/influx.json
# Set up Kapacitor
curl -i -X POST -H "Content-Type: application/json" http://localhost:8888/chronograf/v1/sources/1/kapacitors -d @$TEST_DIR/kapacitor.json
# Set up rules
curl -i -X POST -H "Content-Type: application/json" http://localhost:9092/kapacitor/v1/tasks -d @$TEST_DIR/rules.json
# Set up dashboard # Set up dashboard
curl -i -X POST -H "Content-Type: application/json" http://localhost:8888/chronograf/v1/dashboards -d @$TEST_DIR/dashboard.json curl -i -X POST -H "Content-Type: application/json" http://localhost:8888/chronograf/v1/dashboards -d @$TEST_DIR/dashboard.json
...@@ -69,6 +69,8 @@ class TestStreamingAlerts(object): ...@@ -69,6 +69,8 @@ class TestStreamingAlerts(object):
counter += time_delay # the counter tracks the time taken, for the rules under test usually a 20 seconds time frame is enough counter += time_delay # the counter tracks the time taken, for the rules under test usually a 20 seconds time frame is enough
if counter >= 8*time_delay: if counter >= 8*time_delay:
for t in threads: # kill all running threads in case of test failure
t.stop()
break break
assert alert_created, "Alerts test failed: no log file is created indicating a triggered alert for rule {0}.".format(rule) assert alert_created, "Alerts test failed: no log file is created indicating a triggered alert for rule {0}.".format(rule)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment