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

Updates conftest file of alerts integration test

parent e74c157c
No related branches found
No related tags found
No related merge requests found
......@@ -31,9 +31,13 @@ from shutil import rmtree
from signal import SIGKILL
from json import load
from pkg_resources import resource_filename
from requests import delete, get
from clmctest.alerts.alert_handler_server import LOG_TEST_FOLDER_PATH
KAPACITOR_PORT = 9092
@fixture(scope="module")
def rspec_config():
"""
......@@ -51,11 +55,23 @@ def rspec_config():
@fixture(autouse=True, scope="module")
def set_up_tear_down_fixture():
def set_up_tear_down_fixture(rspec_config):
"""
Set up/tear down fixture for the alerts integration test.
"""
global KAPACITOR_PORT
kapacitor_host = None
for host in rspec_config:
if host["name"] == "clmc-service":
kapacitor_host = host["ip_address"]
break
assert kapacitor_host is not None
kapacitor_url = "http://{0}:{1}".format(kapacitor_host, KAPACITOR_PORT)
if exists(LOG_TEST_FOLDER_PATH):
rmtree(LOG_TEST_FOLDER_PATH) # clean out the log directory
makedirs(LOG_TEST_FOLDER_PATH) # create the log directory
......@@ -73,3 +89,21 @@ def set_up_tear_down_fixture():
kill(process_id, SIGKILL)
if exists(LOG_TEST_FOLDER_PATH):
rmtree(LOG_TEST_FOLDER_PATH)
print("Deleting Kapacitor tasks, topics and handlers that were created for this test...")
test_sfc_instance_scope = "CLMCMetrics.MS_I1"
# get all tasks from kapacitor (that were created in this test) and delete them
kapacitor_tasks = get("{0}/kapacitor/v1/tasks".format(kapacitor_url)).json()["tasks"]
kapacitor_task_links = [task["link"]["href"] for task in kapacitor_tasks if task["id"].startswith(test_sfc_instance_scope)]
for task_link in kapacitor_task_links:
delete("{0}{1}".format(kapacitor_url, task_link))
# get all topics and handlers from kapacitor (that were created in this test) and delete them
kapacitor_topics = get("{0}/kapacitor/v1/alerts/topics".format(kapacitor_url)).json()["topics"]
for topic in kapacitor_topics:
if topic["id"].startswith(test_sfc_instance_scope):
topic_handlers = get("{0}{1}".format(kapacitor_url, topic["handlers-link"]["href"])).json()["handlers"]
for handler in topic_handlers:
delete("{0}{1}".format(kapacitor_url, handler["link"]["href"]))
delete("{0}{1}".format(kapacitor_url, topic["link"]["href"]))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment