Updated Setup files for PM Mapper
[integration/csit.git] / tests / dcaegen2-pmmapper / pmmapper / pmmapper.robot
1 *** Settings ***
2 Documentation     Testing PM Mapper functionality
3 Library           Collections
4 Library           OperatingSystem
5 Library           RequestsLibrary
6 Library           Process
7 Library           String
8
9 Test Setup        Create Session  mapper_session  ${PMMAPPER_BASE_URL}
10 Test Teardown     Delete All Sessions
11
12
13 *** Variables ***
14 ${CLI_EXEC_CLI_CONFIG}                   { head -n 6 | tail -2;} < /tmp/pmmapper.log
15 ${CLI_EXEC_CLI_SUBS}                     curl -k https://${DR_PROV_IP}:8443/internal/prov
16 ${PMMAPPER_BASE_URL}                     http://${PMMAPPER_IP}:8081
17 ${DELIVERY_ENDPOINT}                     /delivery
18 ${HEALTHCHECK_ENDPOINT}                  /healthcheck
19 ${RECONFIGURE_ENDPOINT}                  /reconfigure
20 ${NO_MANAGED_ELEMENT_PATH}               %{WORKSPACE}/tests/dcaegen2-pmmapper/pmmapper/assets/A_no_managed_element.xml
21 ${NO_MEASDATA_PATH}                      %{WORKSPACE}/tests/dcaegen2-pmmapper/pmmapper/assets/A_no_measdata.xml
22 ${VALID_METADATA_PATH}                   %{WORKSPACE}/tests/dcaegen2-pmmapper/pmmapper/assets/valid_metadata.json
23 ${DIFF_VENDOR_METADATA}                  %{WORKSPACE}/tests/dcaegen2-pmmapper/pmmapper/assets/diff_vendor_metadata.json
24 ${CLI_EXEC_CLI_PM_LOG}                   docker exec pmmapper /bin/sh -c "tail -15 /var/log/ONAP/dcaegen2/services/pm-mapper/pm-mapper_output.log"
25 ${PUBLISH_NODE_URL}                      https://${DR_NODE_IP}:8443/publish/1
26 ${TYPE-A_PM_DATA_FILE_PATH}              %{WORKSPACE}/tests/dcaegen2-pmmapper/pmmapper/assets/A20181002.0000-1000-0015-1000_5G.xml
27 ${TYPE-C_PM_DATA_FILE_PATH}              %{WORKSPACE}/tests/dcaegen2-pmmapper/pmmapper/assets/C20190328.0000-0015.xml
28 ${PUBLISH_CONTENT_TYPE}                  application/octet-stream
29 ${CLI_EXEC_VENDOR_FILTER}                curl 'http://${CONSUL_IP}:8500/v1/kv/pmmapper?dc=dc1' -X PUT -H 'Accept: application/^Con' -H 'Content-Type: application/json' -H 'X-Requested-With: XMLHttpRequest' --data @$WORKSPACE/tests/dcaegen2-pmmapper/pmmapper/assets/vendor_filter_config.json
30 ${CLI_EXEC_PM_FILTER}                    curl 'http://${CONSUL_IP}:8500/v1/kv/pmmapper?dc=dc1' -X PUT -H 'Accept: application/^Con' -H 'Content-Type: application/json' -H 'X-Requested-With: XMLHttpRequest' --data @$WORKSPACE/tests/dcaegen2-pmmapper/pmmapper/assets/pm_filter_config.json
31 ${CLI_RESTART_PMMAPPER}                  docker restart pmmapper
32 ${CLI_DELETE_SUB1}                       curl -i -X DELETE -H "Content-Type:application/vnd.dmaap-dr.subscription" -H "X-DMAAP-DR-ON-BEHALF-OF:DGL" -k https://localhost:8443/subs/1
33 ${CLI_DELETE_SUB2}                       curl -i -X DELETE -H "Content-Type:application/vnd.dmaap-dr.subscription" -H "X-DMAAP-DR-ON-BEHALF-OF:DGL" -k https://localhost:8443/subs/2
34 ${CLI_MESSAGE_ROUTER_TOPIC}              curl http://${DMAAP_MR_IP}:3904/events/PM_MAPPER/CG1/C1?timeout=1000
35 ${CLI_MR_EVENT_COUNT}                    curl http://${DMAAP_MR_IP}:3904/events/PM_MAPPER/CG1/C1?timeout=1000 | egrep -o 'measInfoId1|measInfoId2|measInfoId3' > /tmp/mr.log
36 ${CLI_MR_LOG}                            cat /tmp/mr.log
37
38 *** Test Cases ***
39 Verify PM Mapper Receive Configuraton From Config Binding Service
40     [Tags]                          PM_MAPPER_01
41     [Documentation]                 Verify 3gpp pm mapper successfully receive config data from CBS
42     CheckLog                        ${CLI_EXEC_CLI_CONFIG}           Received pm-mapper configuration
43
44 Verify Health Check returns 200 when a REST GET request to healthcheck url
45     [Tags]                          PM_MAPPER_02
46     [Documentation]                 Verify Health Check returns 200 when a REST GET request to healthcheck url
47     [Timeout]                       1 minute
48     ${resp}=                        Get Request                      mapper_session  ${HEALTHCHECK_ENDPOINT}
49     VerifyResponse                  ${resp.status_code}              200
50
51 Verify 3GPP PM Mapper responds appropriately when no metadata is provided
52     [Tags]                          PM_MAPPER_03
53     [Documentation]                 Verify 3GPP PM Mapper responds 400 with the message "Missing Metadata." when no metadata is provided
54     [Timeout]                       1 minute
55     ${headers}=                     Create Dictionary               X-ONAP-RequestID=1  Content-Type=application/xml
56     ${resp}=                        Put Request                     mapper_session  ${DELIVERY_ENDPOINT}/filename    data='${EMPTY}'    headers=${headers}
57     VerifyResponse                  ${resp.status_code}             400
58     VerifyResponse                  ${resp.content}                 Missing Metadata.
59     CheckLog                        ${CLI_EXEC_CLI_PM_LOG}          RequestID=1
60
61 Verify 3GPP PM Mapper responds appropriately when invalid metadata is provided
62     [Tags]                          PM_MAPPER_04
63     [Documentation]                 Verify 3GPP PM Mapper responds 400 with the message "Malformed Metadata." when invalid metadata is provided
64     [Timeout]                       1 minute
65     ${headers}=                     Create Dictionary               X-ONAP-RequestID=2  X-DMAAP-DR-META='not metadata'  Content-Type=application/xml
66     ${resp}=                        Put Request                     mapper_session  ${DELIVERY_ENDPOINT}/filename  data='${EMPTY}'  headers=${headers}
67     VerifyResponse                  ${resp.status_code}             400
68     VerifyResponse                  ${resp.content}                 Malformed Metadata.
69     CheckLog                        ${CLI_EXEC_CLI_PM_LOG}          RequestID=2
70
71 Verify 3GPP PM Mapper maps Type-A file and publish 3gpp perf VES evnets to message router
72     [Tags]                          PM_MAPPER_05
73     [Documentation]                 Verify 3GPP PM Mapper maps Type-A file and publish 3gpp perf VES evnets to message router.
74     [Timeout]                       1 minute
75     SendToDatarouter                ${TYPE-A_PM_DATA_FILE_PATH}      ${VALID_METADATA_PATH}            X-ONAP-RequestID=3
76     CheckLog                        ${CLI_EXEC_CLI_PM_LOG}           Successfully published VES events to messagerouter
77     CheckLog                        ${CLI_EXEC_CLI_PM_LOG}           RequestID=3
78     Sleep                           10s
79     CheckLog                        ${CLI_MESSAGE_ROUTER_TOPIC}      perf3gpp_gnb-Ericsson_pmMeasResult
80
81 Verify that PM Mapper maps Type-C xml file and publish 3gpp perf VES evnets to message router.
82     [Tags]                          PM_MAPPER_06
83     [Documentation]                 Verify that PM Mapper maps Type-C xml file and publish 3gpp perf VES evnets to message router.
84     [Timeout]                       1 minute
85     SendToDatarouter                ${TYPE-C_PM_DATA_FILE_PATH}      ${VALID_METADATA_PATH}           X-ONAP-RequestID=4
86     CheckLog                        ${CLI_EXEC_CLI_PM_LOG}           Successfully published VES events to messagerouter
87     CheckLog                        ${CLI_EXEC_CLI_PM_LOG}           RequestID=4
88     Run Process                     ${CLI_MR_EVENT_COUNT}            shell=yes
89     CheckLog                        ${CLI_MR_LOG}                    measInfoId1
90     CheckLog                        ${CLI_MR_LOG}                    measInfoId2
91     CheckLog                        ${CLI_MR_LOG}                    measInfoId3
92
93 Verify that PM Mapper logs successful when a file that contains no measdata is provided
94     [Tags]                          PM_MAPPER_07
95     [Documentation]                 Verify that PM Mapper logs successful when a file that contains no measdata is provided
96     [Timeout]                       1 minute
97     SendToDatarouter                ${NO_MEASDATA_PATH}              ${VALID_METADATA_PATH}            X-ONAP-RequestID=5
98     CheckLog                        ${CLI_EXEC_CLI_PM_LOG}           MeasData is empty
99     CheckLog                        ${CLI_EXEC_CLI_PM_LOG}           RequestID=5
100
101 Verify that PM Mapper throws Event failed validation against schema error when no managed element content is provided
102     [Tags]                          PM_MAPPER_08
103     [Documentation]                 Verify 3gpp pm mapper responds with an error when no managed element content is provided
104     [Timeout]                       1 minute
105     SendToDatarouter                ${NO_MANAGED_ELEMENT_PATH}       ${VALID_METADATA_PATH}             X-ONAP-RequestID=6
106     CheckLog                        ${CLI_EXEC_CLI_PM_LOG}           XML validation failed
107     CheckLog                        ${CLI_EXEC_CLI_PM_LOG}           RequestID=6
108
109 Verify that PM Mapper correctly identifies a file that should not be mapped based on metadata filtering.
110     [Tags]                          PM_MAPPER_09
111     [Documentation]                 Verify that PM Mapper correctly identifies a file that should not be mapped based on metadata filtering.
112     [Timeout]                       1 minute
113     ${cli_cmd_output}=              Run Process                      ${CLI_EXEC_VENDOR_FILTER}         shell=yes
114     Should Be Equal As Strings      ${cli_cmd_output.rc}             0
115     ${resp}=                        Get Request                      mapper_session                    ${RECONFIGURE_ENDPOINT}
116     Sleep                           5s
117     SendToDatarouter                ${TYPE-A_PM_DATA_FILE_PATH}      ${DIFF_VENDOR_METADATA}           X-ONAP-RequestID=7
118     CheckLog                        ${CLI_EXEC_CLI_PM_LOG}           Metadata does not match any filters
119     CheckLog                        ${CLI_EXEC_CLI_PM_LOG}           RequestID=7
120
121 *** Keywords ***
122
123 SendToDatarouter
124     [Arguments]                     ${filepath}                      ${metadatapath}            ${request_id}
125     ${pmdata}=                      Get File                         ${filepath}
126     ${metatdata}                    Get File                         ${metadatapath}
127     ${filename}                     Fetch From Right                 ${filepath}                /
128     ${resp}=                        PutCall                          ${PUBLISH_NODE_URL}/${filename}        ${request_id}    ${pmdata}    ${metatdata.replace("\n","")}    pmmapper
129     VerifyResponse                  ${resp.status_code}              204
130     Sleep                           10s
131
132 PutCall
133     [Arguments]                     ${url}                           ${request_id}              ${data}            ${meta}          ${user}
134     ${headers}=                     Create Dictionary                X-ONAP-RequestID=${request_id}                X-DMAAP-DR-META=${meta}    Content-Type=application/octet-stream     X-DMAAP-DR-ON-BEHALF-OF=${user}    Authorization=Basic cG1tYXBwZXI6cG1tYXBwZXI=
135     ${resp}=                        Evaluate                         requests.put('${url}', data="""${data}""", headers=${headers}, verify=False, allow_redirects=False)    requests
136     [Return]                        ${resp}
137
138 CheckLog
139     [Arguments]                     ${cli_exec_log_Path}             ${string_to_check_in_log}
140     ${cli_cmd_output}=              Run Process                      ${cli_exec_log_Path}                     shell=yes
141     Log                             ${cli_cmd_output.stdout}
142     Should Be Equal As Strings      ${cli_cmd_output.rc}             0
143     Should Contain                  ${cli_cmd_output.stdout}         ${string_to_check_in_log}
144
145 VerifyResponse
146     [Arguments]                     ${actual_response_value}         ${expected_response_value}
147     Should Be Equal As Strings      ${actual_response_value}         ${expected_response_value}