diff --git a/src/service/clmcservice/alertsapi/tests.py b/src/service/clmcservice/alertsapi/tests.py index 5b294acbfd6c06f741404a566edf0dfe8f04d537..2c2066f153ab0e36d6c93bb2f8f4734dc77de6a3 100644 --- a/src/service/clmcservice/alertsapi/tests.py +++ b/src/service/clmcservice/alertsapi/tests.py @@ -34,7 +34,8 @@ from pyramid import testing from toscaparser.tosca_template import ToscaTemplate # CLMC-service imports -from clmcservice.alertsapi.utilities import adjust_tosca_definitions_import, validate_clmc_alerts_specification +from clmcservice.alertsapi.utilities import adjust_tosca_definitions_import +from clmcservice.alertsapi.alerts_specification_schema import validate_clmc_alerts_specification from clmcservice.alertsapi.views import AlertsConfigurationAPI from clmcservice import ROOT_DIR @@ -127,6 +128,11 @@ class TestAlertsConfigurationAPI(object): """ Tests the POST API endpoint of the alerts configuration API responsible for receiving alerts specifications. + Unit test consists of: + * Traverse all valid TOSCA Alerts Specifications in the src/service/clmcservice/resources/tosca/test-data/clmc-validator/valid + * Sending a valid TOSCA Alert Specification to the view responsible for configuring Kapacitor + * Check that Kapacitor alerts, topics and handlers are created with the correct identifier and arguments + :param app_config: fixture for setUp/tearDown of the web service registry """ diff --git a/src/service/clmcservice/resources/tosca/test-data/clmc-validator/valid/alerts_test_config-1.yaml b/src/service/clmcservice/resources/tosca/test-data/clmc-validator/valid/alerts_test_config-1.yaml index 46c11dff859188f9d025fe98ccebddedd8bf2946..74391ed7c37c967f1fbdc685db2e90acb47fc6be 100644 --- a/src/service/clmcservice/resources/tosca/test-data/clmc-validator/valid/alerts_test_config-1.yaml +++ b/src/service/clmcservice/resources/tosca/test-data/clmc-validator/valid/alerts_test_config-1.yaml @@ -30,6 +30,7 @@ topology_template: implementation: - http://sfemc.flame.eu/notify - http://companyA.alert-handler.flame.eu/high-latency + - low_requests_policy: type: eu.ict-flame.policies.StateChange triggers: @@ -52,3 +53,59 @@ topology_template: implementation: - http://sfemc.flame.eu/notify - http://companyA.alert-handler.flame.eu/low-requests + + - requests_diff_policy: + type: eu.ict-flame.policies.StateChange + triggers: + increase_in_requests: + description: | + This event triggers when the number of requests has increased relative to the number of requests received + 120 seconds ago. + event_type: relative + metric: storage.requests + condition: + threshold: 100 # requests have increased by at least 100 + granularity: 120 + resource_type: + sf_package: storage + sf: storage-users + location: watershed + comparison_operator: gte + action: + implementation: + - http://sfemc.flame.eu/notify + decrease_in_requests: + description: | + This event triggers when the number of requests has decreased relative to the number of requests received + 120 seconds ago. + event_type: relative + metric: storage.requests + condition: + threshold: -100 # requests have decreased by at least 100 + granularity: 120 + resource_type: + sf_package: storage + sf: storage-users + location: watershed + comparison_operator: lte + action: + implementation: + - http://sfemc.flame.eu/notify + + - missing_measurement_policy: + type: eu.ict-flame.policies.StateChange + triggers: + missing_storage_measurements: + description: This event triggers when the number of storage measurements reported falls below the threshold value. + event_type: deadman + # deadman trigger instances monitor the whole measurement (storage in this case), so simply put a star for field value + # to be compliant with the <measurement>.<field> format + metric: storage.* + condition: + threshold: 0 # if requests are less than or equal to 0 (in other words, no measurements are reported) + granularity: 60 # check for for missing data for the last 60 seconds + resource_type: + sf_package: storage + action: + implementation: + - http://sfemc.flame.eu/notify \ No newline at end of file diff --git a/src/service/clmcservice/resources/tosca/test-data/tosca-parser/invalid/alerts_test_config-2.yaml b/src/service/clmcservice/resources/tosca/test-data/tosca-parser/invalid/alerts_test_config-2.yaml index b7e5b8b39d7a3f215cab076a64d22029bcc5229e..4eb465211573b183fc123b02381e6b5c0ed56a24 100644 --- a/src/service/clmcservice/resources/tosca/test-data/tosca-parser/invalid/alerts_test_config-2.yaml +++ b/src/service/clmcservice/resources/tosca/test-data/tosca-parser/invalid/alerts_test_config-2.yaml @@ -1,4 +1,4 @@ -# Fails because it's missing tosca version. +tosca_definitions_version: tosca_simple_profile_for_nfv_1_0_0 description: TOSCA Alerts Configuration document imports: @@ -22,32 +22,30 @@ topology_template: threshold: 45 granularity: 120 aggregation_method: mean - resource_type: + global_tags: # correct field is called resource_type, not global_tags location: watershed comparison_operator: gt action: implementation: - http://sfemc.flame.eu/notify - http://companyA.alert-handler.flame.eu/high-latency - - low_requests_policy: + - requests_diff_policy: type: eu.ict-flame.policies.StateChange triggers: - low_requests: + increase_in_requests: description: | - This event triggers when the last reported number of requests for a given service function - falls behind a given threshold. - event_type: threshold + This event triggers when the number of requests has increased relative to the number of requests received + 120 seconds ago. + event_type: relative metric: storage.requests condition: - threshold: 5 - granularity: 60 - aggregation_method: last + threshold: 100 + granularity: 120 resource_type: sf_package: storage sf: storage-users location: watershed - comparison_operator: lt + comparison_operator: gte action: implementation: - - http://sfemc.flame.eu/notify - - http://companyA.alert-handler.flame.eu/low-requests \ No newline at end of file + - http://sfemc.flame.eu/notify \ No newline at end of file diff --git a/src/service/clmcservice/resources/tosca/test-data/tosca-parser/valid/alerts_test_config-1.yaml b/src/service/clmcservice/resources/tosca/test-data/tosca-parser/valid/alerts_test_config-1.yaml index dba2e226ee53d92f3de572303b3ba10ead334aed..3c7019a2ba4bdd0e6d3f0f119a31f5dbbbe4fe7e 100644 --- a/src/service/clmcservice/resources/tosca/test-data/tosca-parser/valid/alerts_test_config-1.yaml +++ b/src/service/clmcservice/resources/tosca/test-data/tosca-parser/valid/alerts_test_config-1.yaml @@ -51,4 +51,56 @@ topology_template: action: implementation: - http://sfemc.flame.eu/notify - - http://companyA.alert-handler.flame.eu/low-requests \ No newline at end of file + - http://companyA.alert-handler.flame.eu/low-requests + - requests_diff_policy: + type: eu.ict-flame.policies.StateChange + triggers: + increase_in_requests: + description: | + This event triggers when the number of requests has increased relative to the number of requests received + 120 seconds ago. + event_type: relative + metric: storage.requests + condition: + threshold: 100 + granularity: 120 + resource_type: + sf_package: storage + sf: storage-users + location: watershed + comparison_operator: gte + action: + implementation: + - http://sfemc.flame.eu/notify + decrease_in_requests: + description: | + This event triggers when the number of requests has decreased relative to the number of requests received + 120 seconds ago. + event_type: relative + metric: storage.requests + condition: + threshold: -100 + granularity: 120 + resource_type: + sf_package: storage + sf: storage-users + location: watershed + comparison_operator: lte + action: + implementation: + - http://sfemc.flame.eu/notify + - missing_measurement_policy: + type: eu.ict-flame.policies.StateChange + triggers: + missing_storage_measurements: + description: This event triggers when the number of storage measurements reported falls below the threshold value. + event_type: deadman + metric: storage.* + condition: + threshold: 0 + granularity: 60 + resource_type: + sf_package: storage + action: + implementation: + - http://sfemc.flame.eu/notify diff --git a/src/service/clmcservice/resources/tosca/test-data/tosca-parser/valid/alerts_test_config-2.yaml b/src/service/clmcservice/resources/tosca/test-data/tosca-parser/valid/alerts_test_config-2.yaml index 4196cf6b64bf3f6e31a80b3b8115fd21510c7a94..4df849dc46b75eceef0f3bf51fdb2f93bfc4d23e 100644 --- a/src/service/clmcservice/resources/tosca/test-data/tosca-parser/valid/alerts_test_config-2.yaml +++ b/src/service/clmcservice/resources/tosca/test-data/tosca-parser/valid/alerts_test_config-2.yaml @@ -45,4 +45,18 @@ topology_template: action: implementation: - http://sfemc.flame.eu/notify - - http://companyA.alert-handler.flame.eu/low-requests \ No newline at end of file + - http://companyA.alert-handler.flame.eu/low-requests + - missing_measurement_policy: + type: eu.ict-flame.policies.StateChange + triggers: + missing_storage_measurements: + event_type: deadman + metric: storage.field + condition: + threshold: 0 + granularity: 60 + resource_type: + sf_package: storage + action: + implementation: + - http://sfemc.flame.eu/notify \ No newline at end of file diff --git a/src/service/clmcservice/resources/tosca/test-data/tosca-parser/valid/alerts_test_config-4.yaml b/src/service/clmcservice/resources/tosca/test-data/tosca-parser/valid/alerts_test_config-4.yaml index 8e7f188988282a34a85d1382c718dbad32a3dd5e..7ad8e0e57c8c1ea0d02d6078916f772b20daf2ce 100644 --- a/src/service/clmcservice/resources/tosca/test-data/tosca-parser/valid/alerts_test_config-4.yaml +++ b/src/service/clmcservice/resources/tosca/test-data/tosca-parser/valid/alerts_test_config-4.yaml @@ -32,4 +32,21 @@ topology_template: comparison_operator: lt action: implementation: - - http://companyA.alert-handler.flame.eu/low-requests \ No newline at end of file + - http://companyA.alert-handler.flame.eu/low-requests + - requests_diff_policy: + type: eu.ict-flame.policies.StateChange + triggers: + increase_in_requests: + event_type: relative + metric: storage.requests + condition: + threshold: 100 + granularity: 120 + resource_type: + sf_package: storage + sf: storage-users + location: watershed + comparison_operator: gte + action: + implementation: + - http://sfemc.flame.eu/notify \ No newline at end of file