Add SLA Validations for Apex-PDP
[policy/docker.git] / csit / resources / tests / apex-slas.robot
1 *** Settings ***
2 Library    Collections
3 Library    RequestsLibrary
4 Library    OperatingSystem
5 Library    DateTime
6 Library    Process
7 Library    json
8 Resource    ${CURDIR}/common-library.robot
9 Resource    ${CURDIR}/apex-pdp-common.robot
10
11 *** Test Cases ***
12 Healthcheck
13      [Documentation]    Runs Apex PDP Health check
14      ${hcauth}=  PolicyAdminAuth
15      ${resp}=  PerformGetRequest  ${APEX_IP}  /policy/apex-pdp/v1/healthcheck  200  null  ${hcauth}
16      Should Be Equal As Strings    ${resp.json()['code']}    200
17      Set Suite Variable    ${pdpName}    ${resp.json()['name']}
18
19 ValidatePolicyExecutionAndEventRateLowComplexity
20     [Documentation]  Validate that a moderate complexity policity can be executed in less than 100ms and minimum 10 events triggered per second
21     Set Test Variable    ${policyName}    onap.policies.apex.pnf.Test
22     ${postjson}=  Get File  ${CURDIR}/data/${policyName}.json
23     CreatePolicy  /policy/api/v1/policytypes/onap.policies.native.Apex/versions/1.0.0/policies  200  ${postjson}  ${policyName}  1.0.0
24     DeployPolicy
25     Wait Until Keyword Succeeds    2 min    5 sec    QueryPolicyStatus  ${policyName}  defaultGroup  apex  ${pdpName}  onap.policies.native.Apex
26     GetTopic     APEX-CL-MGT
27     Create Session   apexSession  http://${DMAAP_IP}   max_retries=1
28     ${data}=    Get Binary File     ${CURDIR}/data/VesEventForPnfPolicy.json
29     &{headers}=  Create Dictionary    Content-Type=application/json    Accept=application/json
30     ${eventStartTime}=  Get Current Date
31     ${resp}=    POST On Session    apexSession    /events/unauthenticated.DCAE_CL_OUTPUT    data=${data}   headers=${headers}
32     Should Be Equal As Strings    ${resp.status_code}   200
33     ${eventEndTime}=  Get Current Date
34     ValidateEventExecution    ${eventStartTime}  ${eventEndTime}  10
35
36 ValidatePolicyExecutionAndEventRateModerateComplexity
37     [Documentation]  Validate that a low complexity policity can be executed in less than 1000ms and minimum 1 events triggered per second
38     Set Test Variable    ${policyName}    onap.policies.native.apex.Sampledomain
39     ${postjson}=  Get File  ${CURDIR}/data/${policyName}.json
40     CreatePolicy  /policy/api/v1/policytypes/onap.policies.native.Apex/versions/1.0.0/policies  200  ${postjson}  ${policyName}  1.0.0
41     DeployPolicy
42     ${eventStartTime}=  Get Current Date
43     Wait Until Keyword Succeeds    4 min    5 sec    RunEventOnApexEngine
44     ${eventEndTime}=  Get Current Date
45     ValidateEventExecution    ${eventStartTime}  ${eventEndTime}  1
46
47 ValidatePolicyExecutionAndEventRateHighComplexity
48     [Documentation]  Validate that a high complexity policity can be executed in less than 5000ms and minimum 0.2 events triggered per second
49     Set Test Variable    ${policyName}    onap.policies.apex.pnf.metadataSet.Test
50     ${postjson}=  Get File  ${CURDIR}/data/${policyName}.json
51     CreatePolicy  /policy/api/v1/policytypes/onap.policies.native.Apex/versions/1.0.0/policies  200  ${postjson}  ${policyName}  1.0.0
52     ${postjson}=  Get File  ${CURDIR}/data/onap.pnf.metadataSet.Test.json
53     CreateNodeTemplate  /policy/api/v1/nodetemplates  200  ${postjson}  1
54     DeployPolicy
55     Wait Until Keyword Succeeds    2 min    5 sec    QueryPolicyStatus  ${policyName}  defaultGroup  apex  ${pdpName}  onap.policies.native.Apex
56     GetTopic     APEX-CL-MGT2
57     Create Session   apexSession  http://${DMAAP_IP}   max_retries=1
58     ${data}=    Get Binary File     ${CURDIR}/data/VesEventForVnfPolicy.json
59     &{headers}=  Create Dictionary    Content-Type=application/json    Accept=application/json
60     ${eventStartTime}=  Get Current Date
61     ${resp}=    POST On Session    apexSession    /events/unauthenticated.DCAE_POLICY_EXAMPLE_OUTPUT    data=${data}   headers=${headers}
62     Should Be Equal As Strings    ${resp.status_code}   200
63     ${eventEndTime}=  Get Current Date
64     ValidateEventExecution    ${eventStartTime}  ${eventEndTime}  0.2
65
66 WaitForPrometheusServer
67     [Documentation]  Sleep time to wait for Prometheus server to gather all metrics
68     Sleep    1 minute
69
70 ValidatePolicyExecutionTimes
71     [Documentation]    Validate policy execution times using prometheus metrics
72     ValidatePolicyExecution   pdpa_engine_average_execution_time_seconds{engine_instance_id="NSOApexEngine-0:0.0.1", instance="policy-apex-pdp:6969", job="apex-pdp-metrics"}  5000
73     ValidatePolicyExecution   pdpa_engine_average_execution_time_seconds{engine_instance_id="MyApexEngine-0:0.0.1"}  1000
74     ValidatePolicyExecution   pdpa_engine_average_execution_time_seconds{engine_instance_id="NSOApexEngine-1:0.0.1", instance="policy-apex-pdp:6969", job="apex-pdp-metrics"}  100