diff --git a/src/service/clmcservice/alertsapi/views.py b/src/service/clmcservice/alertsapi/views.py index 09cf3132247ed421b7c23fc8da962f5260168cd7..d5d41b2a560397f493cad9349b3b5c0c2d58564c 100644 --- a/src/service/clmcservice/alertsapi/views.py +++ b/src/service/clmcservice/alertsapi/views.py @@ -124,9 +124,11 @@ class AlertsConfigurationAPI(object): if len(alert_tasks_errors) > 0: return_msg["triggers_specification_errors"] = alert_tasks_errors + self.request.response.status = 400 if len(alert_handlers_errors) > 0: return_msg["triggers_action_errors"] = alert_handlers_errors + self.request.response.status = 400 return return_msg diff --git a/src/test/clmctest/alerts/alerts_test_config.yaml b/src/test/clmctest/alerts/alerts_test_config.yaml index 8100fda2ab8bdb1c6d14cf48bd35c1798a585c3c..3fd6b04b8c05523e3b411ad8bb41baee4e3f11be 100644 --- a/src/test/clmctest/alerts/alerts_test_config.yaml +++ b/src/test/clmctest/alerts/alerts_test_config.yaml @@ -60,7 +60,7 @@ topology_template: action: implementation: - http://172.40.231.200:9999/ - - deadman_policies: + - deadman_policy: type: eu.ict-flame.policies.StateChange triggers: no_measurements: diff --git a/src/test/clmctest/alerts/conftest.py b/src/test/clmctest/alerts/conftest.py index 3d40a90fcc14f9f21edd9dcd2f4408f24f5ea1c7..73a65b726d0f6af32e18f71d21b90d30e4189b77 100644 --- a/src/test/clmctest/alerts/conftest.py +++ b/src/test/clmctest/alerts/conftest.py @@ -91,19 +91,17 @@ def set_up_tear_down_fixture(rspec_config): 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)] + kapacitor_task_links = [task["link"]["href"] for task in kapacitor_tasks] 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"])) + 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"])) + delete("{0}{1}".format(kapacitor_url, topic["link"]["href"])) diff --git a/src/test/clmctest/alerts/resources_test_config.yaml b/src/test/clmctest/alerts/resources_test_config.yaml new file mode 100644 index 0000000000000000000000000000000000000000..ee1bc956c09b4b009fc8a5efb5ea47ce55f1c54c --- /dev/null +++ b/src/test/clmctest/alerts/resources_test_config.yaml @@ -0,0 +1,141 @@ +tosca_definitions_version: tosca_simple_profile_for_nfv_1_0_0 + +metadata: + template_name: Flame CLMC Alerts Integration Test + sfc: CLMCMetrics + sfci: MS_I1 + + +# Import own definitions of nodes, capabilities and policy syntax. +imports: + - flame_definitions-0.1.7.yaml + +# Starting the template + +## Topology +topology_template: + node_templates: + database: + type: eu.ict-flame.nodes.ServiceFunction + capabilities: + host: + properties: + num_cpus: 2 + mem_size: 4096 MB + disk_size: 10 GB + properties: + hypervisor: kvm + image_url: http://cdimage.debian.org/cdimage/openstack/current-9/debian-9-openstack-amd64.qcow2 + fqdn: + - db.app.ict-flame.eu + + + frontend: + type: eu.ict-flame.nodes.ServiceFunction + capabilities: + host: + properties: + num_cpus: 2 + disk_size: 10 GB + mem_size: 4096 MB + properties: + hypervisor: kvm + image_url: http://cdimage.debian.org/cdimage/openstack/current-9/debian-9-openstack-amd64.qcow2 + fqdn: + - frontend.app.ict-flame.eu + - www.app.ict-flame.eu + + policies: + - init: + type: eu.ict-flame.policies.InitialPolicy + description: Start the nodes initially + properties: + parent: service_paid + triggers: + inital_trigger: + condition: + constraint: initialise + action: + frontend: + - + fqdn: frontend.app.ict-flame.eu + lifecycle_actions: + London: eu.ict-flame.sfe.state.lifecycle.connected + Bristol: eu.ict-flame.sfe.state.lifecycle.booted + Manchester: eu.ict-flame.sfe.state.lifecycle.connected + database: + - + fqdn: db.app.ict-flame.eu + lifecycle_actions: + London: eu.ict-flame.sfe.state.lifecycle.connected + + - scale_nginx_policy: + type: eu.ict-flame.policies.StateChange + properties: + parent: service_paid + triggers: + tigger_a: + condition: + constraint: clmc::high_requests + action: + frontend: + - + fqdn: frontend.app.ict-flame.eu + lifecycle_actions: + Bristol: eu.ict-flame.sfe.state.lifecycle.connected + tigger_b: + condition: + constraint: clmc::high_cpu_usage + period: 600 # integer required, unit: seconds + action: + frontend: + - fqdn: frontend.app.ict-flame.eu + lifecycle_actions: + Bristol: eu.ict-flame.sfe.state.lifecycle.connected + tigger_c: + condition: + constraint: clmc::increase_in_active_requests + period: 600 # integer required, unit: seconds + action: + frontend: + - fqdn: frontend.app.ict-flame.eu + lifecycle_actions: + Bristol: eu.ict-flame.sfe.state.lifecycle.connected + + - deadman_policy: + type: eu.ict-flame.policies.StateChange + properties: + parent: service_paid + triggers: + tigger_a: + condition: + constraint: clmc::no_measurements + action: + frontend: + - + fqdn: frontend.app.ict-flame.eu + lifecycle_actions: + Bristol: eu.ict-flame.sfe.state.lifecycle.connected + + - service_paid: + type: eu.ict-flame.policies.StateChange + description: Check outstanding payments. If there are outstanding payments, we shutdown the deployed service. + triggers: + not_paid_trigger: + description: Check if the payment is late + condition: + constraint: clmc-user-db::serviceIsNotPaid # this will be ignored, source must be clmc + period: 3600 # integer required, unit: seconds + action: + frontend: + - + fqdn: frontend.app.ict-flame.eu + lifecycle_actions: + London: eu.ict-flame.sfe.state.lifecycle.shutdown + Bristol: eu.ict-flame.sfe.state.lifecycle.shutdown + Manchester: eu.ict-flame.sfe.state.lifecycle.shutdown + database: + - + fqdn: db.app.ict-flame.eu + lifecycle_action: + London: eu.ict-flame.sfe.state.lifecycle.shutdown diff --git a/src/test/clmctest/alerts/test_alerts.py b/src/test/clmctest/alerts/test_alerts.py index 645bff025441abdf1c317dcd1bf7e8512a05bcb4..2f338b5c335d34a75e49ac4ba1d1325c02e9d50a 100644 --- a/src/test/clmctest/alerts/test_alerts.py +++ b/src/test/clmctest/alerts/test_alerts.py @@ -61,11 +61,16 @@ class TestAlerts(object): print("Sending alerts specification to clmc service...") alerts_spec = join(dirname(__file__), "alerts_test_config.yaml") - - with open(alerts_spec, 'rb') as fh: - files = {'alert-spec': fh} - response = post("http://{0}:{1}/alerts".format(clmc_service_host, CLMC_SERVICE_PORT), files=files) - assert response.status_code == 200 + resources_spec = join(dirname(__file__), "resources_test_config.yaml") + + with open(alerts_spec, 'rb') as alerts: + with open(resources_spec, 'rb') as resources: + files = {'alert-spec': alerts, 'resource-spec': resources} + response = post("http://{0}:{1}/alerts".format(clmc_service_host, CLMC_SERVICE_PORT), files=files) + assert response.status_code == 200 + clmc_service_response = response.json() + assert "triggers_specification_errors" not in clmc_service_response, "Unexpected error was returned for triggers specification" + assert "triggers_action_errors" not in clmc_service_response, "Unexpected error was returned for handlers specification" print("Alert spec sent successfully") print("Wait 10 seconds for Kapacitor stream/batch tasks to start working...")