Add new testcase for network slicing capacity in slice-analysis-ms
[integration/csit.git] / tests / dcaegen2-services-slice-analysis-ms / testcases / slice-analysis-ms-test-cps-aai.robot
1 *** Settings ***
2 Library           Collections
3 Library           Process
4 Library           RequestsLibrary
5 Library           String
6 Library           OperatingSystem
7
8 Suite Teardown  Delete All Sessions
9
10 *** Variables ***
11 ${SLICE_ANALYSIS_MS_BASE_URL}             http://${SLICE_ANALYSIS_MS_IP}:8080
12 ${SLICE_CONFIG_ENDPOINT}                  ${SLICE_ANALYSIS_MS_BASE_URL}/api/v1/slices-config
13 ${HEALTHCHECK_ENDPOINT}                   /healthcheck
14 ${DMAAP_URL}                              http://${DMAAP_IP}:3904/events
15 ${unauthenticated.DCAE_CL_OUTPUT}         /unauthenticated.DCAE_CL_OUTPUT/23/23
16 ${POST_DMAAP_EVENT_FOR_ML_NOTIF_URL}      http://${DMAAP_IP}:3904/events/unauthenticated.ML_RESPONSE_TOPIC
17 ${POST_DMAAP_EVENT_FOR_PM_NOTIF_URL}      http://${DMAAP_IP}:3904/events/unauthenticated.PERFORMANCE_MEASUREMENTS
18 &{headers}                                Content-Type=application/json
19
20
21 *** Test Cases ***
22
23 HealthCheck
24
25         Create Session  sliceanalysisms  ${SLICE_ANALYSIS_MS_BASE_URL}
26         ${resp}=  Get On Session  sliceanalysisms   ${HEALTHCHECK_ENDPOINT}
27         Should Be Equal As Strings  ${resp.status_code}  200
28
29
30 Post ml notification to dmaap
31         Create Session  dmaap  ${DMAAP_URL}
32         ${headers}=    Create Dictionary    Content-Type    application/json
33         ${data}=   Get File      ${TEST_ROBOT_DIR}/data/ml_response0.json
34         ${response}=    Evaluate    requests.post('${POST_DMAAP_EVENT_FOR_ML_NOTIF_URL}', data=$data)
35         Should Be Equal As Strings  ${response.status_code}  200
36
37
38 Verify ml notification trigger
39         Create Session  dmaap  ${DMAAP_URL}
40         FOR    ${i}    IN RANGE   30
41                 ${result}=  Get On Session  dmaap   ${unauthenticated.DCAE_CL_OUTPUT}
42                 Exit For Loop If    ${result.json()} != @{EMPTY}
43                 Log     Waiting for slice-analysis-ms to handle trigger...         console=${True}
44                 Sleep   5s
45         END
46
47         ${expected_string}=   Get File            ${TEST_ROBOT_DIR}/data/expected_ml_payload0.json
48         ${expected_payload}=    Evaluate     json.loads("""${expected_string}""")     json
49         ${result}=  Convert To String  ${result.content}
50         ${result_string}=    Get Substring    ${result}  2    -2
51         ${actual_data}=      Evaluate     json.loads("""${result_string}""")     json
52         ${actual_payload_str}=    Set Variable     ${actual_data['payload']}
53         ${actual_payload}=       Evaluate     json.loads("""${actual_payload_str}""")     json
54
55 Post pm notification-1 to dmaap
56         ${data}=   Get File      ${TEST_ROBOT_DIR}/data/performance_notification0.json
57         FOR    ${j}    IN RANGE   6
58                 ${response}=    Evaluate    requests.post('${POST_DMAAP_EVENT_FOR_PM_NOTIF_URL}', data=$data)
59                 Sleep   10s
60         END
61         Should Be Equal As Strings  ${response.status_code}  200
62
63
64 Verify pm notification-1 trigger
65         Create Session  dmaap  ${DMAAP_URL}
66         FOR    ${i}    IN RANGE   20
67                 ${result}=  Get On Session  dmaap   ${unauthenticated.DCAE_CL_OUTPUT}
68                 Exit For Loop If    ${result.json()} != @{EMPTY}
69                 Log     Waiting for sliceanalysisms to handle trigger...         console=${True}
70                 Sleep   30s
71         END
72         ${expected_string}=   Get File            ${TEST_ROBOT_DIR}/data/expected_payload_pm0.json
73         ${expected_payload}=    Evaluate     json.loads("""${expected_string}""")     json
74         ${result}=  Convert To String  ${result.content}
75         ${result_string}=    Get Substring    ${result}  2    -2
76         ${actual_data}=      Evaluate     json.loads("""${result_string}""")     json
77         ${actual_payload_str}=    Set Variable     ${actual_data['payload']}
78         ${actual_payload}=       Evaluate     json.loads("""${actual_payload_str}""")     json
79         set to dictionary    ${expected_payload['additionalProperties']['nsiInfo']}   nsiId=${actual_payload['additionalProperties']['nsiInfo']['nsiId']}
80         Should Be True   """${actual_payload}""".strip() == """${expected_payload}""".strip()
81
82
83 Verify slice utilization respose
84         ${data}=      Get File       ${TEST_ROBOT_DIR}/data/slice_config_request.json
85         ${result}=    Evaluate       requests.get('${SLICE_CONFIG_ENDPOINT}', data=$data, headers=${headers})
86         ${expected_slice_config}=    Get File            ${TEST_ROBOT_DIR}/data/slice_config_response.json
87         ${actual_slice_config}=  Convert To String  ${result.content}
88         Should Be True   """${actual_slice_config}""".strip() == """${expected_slice_config}""".strip()