diff --git a/test/streaming/conftest.py b/test/streaming/conftest.py index 77e0f1d2d5f50a2a13d7918d24b155563a377436..16a6a0517be86d6063af888523adb73038730362 100644 --- a/test/streaming/conftest.py +++ b/test/streaming/conftest.py @@ -2,6 +2,7 @@ import pytest import yaml +import requests @pytest.fixture(scope="module", params=[{'config': {'rspec': '/vagrant/test/streaming/rspec.yml'}}]) @@ -16,3 +17,15 @@ def streaming_config(request): with open(request.param['config']['rspec'], 'r') as stream: data_loaded = yaml.load(stream) 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"}) diff --git a/test/streaming/setupCLMC.sh b/test/streaming/setupCLMC.sh index 6d2bd38390aca17ad2ad89a2debb6d5f89eab794..e7e2fc91b89cef38d690781cac3f1c92ba39a901 100644 --- a/test/streaming/setupCLMC.sh +++ b/test/streaming/setupCLMC.sh @@ -33,18 +33,8 @@ echo $TEST_DIR"/kapacitor.conf" cp $TEST_DIR/kapacitor.conf /etc/kapacitor/kapacitor.conf systemctl start kapacitor -# wait for kapacitor to restart -# TODO: do this better -sleep 5 - # 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 -# 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 curl -i -X POST -H "Content-Type: application/json" http://localhost:8888/chronograf/v1/dashboards -d @$TEST_DIR/dashboard.json diff --git a/test/streaming/test_streaming.py b/test/streaming/test_streaming.py index aa8a96916e386d273eb5c4b7f85d7ecbc9a6063d..0b0b695c5074b60ff76174cf61c71419c47c4f53 100644 --- a/test/streaming/test_streaming.py +++ b/test/streaming/test_streaming.py @@ -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 if counter >= 8*time_delay: + for t in threads: # kill all running threads in case of test failure + t.stop() break assert alert_created, "Alerts test failed: no log file is created indicating a triggered alert for rule {0}.".format(rule)