Fix and update on version for dublin branch - 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 10 | tail -5;} < /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 ${NON_XML_FILE}                          %{WORKSPACE}/tests/dcaegen2-pmmapper/pmmapper/assets/diff_vendor_metadata.json
25 ${CLI_EXEC_CLI_PM_LOG}                   docker exec pmmapper /bin/sh -c "tail -15 /var/log/ONAP/dcaegen2/services/pm-mapper/pm-mapper_output.log"
26 ${PUBLISH_NODE_URL}                      https://${DR_NODE_IP}:8443/publish/1
27 ${TYPE-A_PM_DATA_FILE_PATH}              %{WORKSPACE}/tests/dcaegen2-pmmapper/pmmapper/assets/A20181002.0000-1000-0015-1000_5G.xml
28 ${TYPE-C_PM_DATA_FILE_PATH}              %{WORKSPACE}/tests/dcaegen2-pmmapper/pmmapper/assets/C20190328.0000-0015.xml
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_MESSAGE_ROUTER_TOPIC}              curl http://${DMAAP_MR_IP}:3904/events/PM_MAPPER/CG1/C1?timeout=1000 > /tmp/mr.log
32 ${CLI_MR_LOG}                            cat /tmp/mr.log
33
34
35 *** Test Cases ***
36 Verify PM Mapper Receive Configuraton From Config Binding Service
37     [Tags]                          PM_MAPPER_01
38     [Documentation]                 Verify 3gpp pm mapper successfully receive config data from CBS
39     CheckLog                        ${CLI_EXEC_CLI_CONFIG}           Received pm-mapper configuration
40
41 Verify Health Check returns 200 when a REST GET request to healthcheck url
42     [Tags]                          PM_MAPPER_02
43     [Documentation]                 Verify Health Check returns 200 when a REST GET request to healthcheck url
44     [Timeout]                       1 minute
45     ${resp}=                        Get Request                      mapper_session  ${HEALTHCHECK_ENDPOINT}
46     VerifyResponse                  ${resp.status_code}              200
47
48 Verify 3GPP PM Mapper responds appropriately when no metadata is provided
49     [Tags]                          PM_MAPPER_03
50     [Documentation]                 Verify 3GPP PM Mapper responds 400 with the message "Missing Metadata." when no metadata is provided
51     [Timeout]                       1 minute
52     ${headers}=                     Create Dictionary               X-ONAP-RequestID=1  Content-Type=application/xml
53     ${resp}=                        Put Request                     mapper_session  ${DELIVERY_ENDPOINT}/filename    data='${EMPTY}'    headers=${headers}
54     VerifyResponse                  ${resp.status_code}             400
55     VerifyResponse                  ${resp.content}                 Missing Metadata.
56     CheckLog                        ${CLI_EXEC_CLI_PM_LOG}          RequestID=1
57
58 Verify 3GPP PM Mapper responds appropriately when invalid metadata is provided
59     [Tags]                          PM_MAPPER_04
60     [Documentation]                 Verify 3GPP PM Mapper responds 400 with the message "Malformed Metadata." when invalid metadata is provided
61     [Timeout]                       1 minute
62     ${headers}=                     Create Dictionary               X-ONAP-RequestID=2  X-DMAAP-DR-META='not metadata'  Content-Type=application/xml
63     ${resp}=                        Put Request                     mapper_session  ${DELIVERY_ENDPOINT}/filename  data='${EMPTY}'  headers=${headers}
64     VerifyResponse                  ${resp.status_code}             400
65     VerifyResponse                  ${resp.content}                 Malformed Metadata.
66     CheckLog                        ${CLI_EXEC_CLI_PM_LOG}          RequestID=2
67
68 Verify that PM Mapper logs successful when a file that contains no measdata is provided
69     [Tags]                          PM_MAPPER_05
70     [Documentation]                 Verify that PM Mapper logs successful when a file that contains no measdata is provided
71     [Timeout]                       1 minute
72     SendToDatarouter                ${NO_MEASDATA_PATH}              ${VALID_METADATA_PATH}            X-ONAP-RequestID=3
73     CheckLog                        ${CLI_EXEC_CLI_PM_LOG}           MeasData is empty
74     CheckLog                        ${CLI_EXEC_CLI_PM_LOG}           RequestID=3
75
76 Verify that PM Mapper throws Event failed validation against schema error when no managed element content is provided
77     [Tags]                          PM_MAPPER_06
78     [Documentation]                 Verify 3gpp pm mapper responds with an error when no managed element content is provided
79     [Timeout]                       1 minute
80     SendToDatarouter                ${NO_MANAGED_ELEMENT_PATH}       ${VALID_METADATA_PATH}             X-ONAP-RequestID=4
81     CheckLog                        ${CLI_EXEC_CLI_PM_LOG}           XML validation failed
82     CheckLog                        ${CLI_EXEC_CLI_PM_LOG}           RequestID=4
83
84 Verify that PM Mapper maps Type-C xml file and publish 3gpp perf VES evnets to message router
85     [Tags]                          PM_MAPPER_07
86     [Documentation]                 Verify that PM Mapper maps Type-C xml file and publish 3gpp perf VES evnets to message router.
87     [Timeout]                       1 minute
88     SendToDatarouter                ${TYPE-C_PM_DATA_FILE_PATH}      ${VALID_METADATA_PATH}           X-ONAP-RequestID=5
89     CheckLog                        ${CLI_EXEC_CLI_PM_LOG}           Successfully published VES events to messagerouter
90     CheckLog                        ${CLI_EXEC_CLI_PM_LOG}           RequestID=5
91     Run Process                     ${CLI_MESSAGE_ROUTER_TOPIC}      shell=yes
92     CheckLog                        ${CLI_MR_LOG}                    measInfoId1
93     CheckLog                        ${CLI_MR_LOG}                    measInfoId2
94     CheckLog                        ${CLI_MR_LOG}                    measInfoId3
95
96 Verify 3GPP PM Mapper maps Type-A file based on counter filtering and publish 3gpp perf VES evnets to message router
97     [Tags]                          PM_MAPPER_08
98     [Documentation]                 Verify 3GPP PM Mapper maps Type-A file and publish 3gpp perf VES evnets to message router.
99     [Timeout]                       1 minute
100     ${cli_cmd_output}=              Run Process                      ${CLI_EXEC_PM_FILTER}             shell=yes
101     ${resp}=                        Get Request                      mapper_session                    ${RECONFIGURE_ENDPOINT}
102     Sleep                           5s
103     SendToDatarouter                ${TYPE-A_PM_DATA_FILE_PATH}      ${VALID_METADATA_PATH}            X-ONAP-RequestID=6
104     CheckLog                        ${CLI_EXEC_CLI_PM_LOG}           Successfully published VES events to messagerouter
105     CheckLog                        ${CLI_EXEC_CLI_PM_LOG}           RequestID=6
106     Run Process                     ${CLI_MESSAGE_ROUTER_TOPIC}      shell=yes
107     CheckLog                        ${CLI_MR_LOG}                    attTCHSeizures
108     CheckLog                        ${CLI_MR_LOG}                    234
109     CheckLog                        ${CLI_MR_LOG}                    890
110     CheckLog                        ${CLI_MR_LOG}                    456
111     CheckLog                        ${CLI_MR_LOG}                    succTCHSeizures2
112     CheckLog                        ${CLI_MR_LOG}                    86,87,2,6,77,96,75,33,24
113     CheckLog                        ${CLI_MR_LOG}                    succImmediateAssignProcs8
114     CheckLog                        ${CLI_MR_LOG}                    787
115     CheckLog                        ${CLI_MR_LOG}                    238
116     CheckLog                        ${CLI_MR_LOG}                    785
117
118 Verify that PM Mapper correctly identifies a file that should not be mapped based on metadata filtering.
119     [Tags]                          PM_MAPPER_09
120     [Documentation]                 Verify that PM Mapper correctly identifies a file that should not be mapped based on metadata filtering.
121     [Timeout]                       1 minute
122     ${cli_cmd_output}=              Run Process                      ${CLI_EXEC_VENDOR_FILTER}         shell=yes
123     Should Be Equal As Strings      ${cli_cmd_output.rc}             0
124     ${resp}=                        Get Request                      mapper_session                    ${RECONFIGURE_ENDPOINT}
125     Sleep                           5s
126     SendToDatarouter                ${TYPE-A_PM_DATA_FILE_PATH}      ${DIFF_VENDOR_METADATA}           X-ONAP-RequestID=7
127     CheckLog                        ${CLI_EXEC_CLI_PM_LOG}           Metadata does not match any filters
128     CheckLog                        ${CLI_EXEC_CLI_PM_LOG}           RequestID=7
129
130 Verify that PM Mapper correctly identifies a non-xml file.
131     [Tags]                          PM_MAPPER_10
132     [Documentation]                 Verify that PM Mapper correctly identifies a non-xml file.
133     [Timeout]                       1 minute
134     SendToDatarouter                ${NON_XML_FILE}                  ${VALID_METADATA_PATH}             X-ONAP-RequestID=8
135     CheckLog                        ${CLI_EXEC_CLI_PM_LOG}           PM measurement file type not supported
136     CheckLog                        ${CLI_EXEC_CLI_PM_LOG}           RequestID=8
137
138
139 *** Keywords ***
140
141 SendToDatarouter
142     [Arguments]                     ${filepath}                      ${metadatapath}            ${request_id}
143     ${pmdata}=                      Get File                         ${filepath}
144     ${metatdata}                    Get File                         ${metadatapath}
145     ${filename}                     Fetch From Right                 ${filepath}                /
146     ${resp}=                        PutCall                          ${PUBLISH_NODE_URL}/${filename}        ${request_id}    ${pmdata}    ${metatdata.replace("\n","")}    pmmapper
147     VerifyResponse                  ${resp.status_code}              204
148     Sleep                           10s
149
150 PutCall
151     [Arguments]                     ${url}                           ${request_id}              ${data}            ${meta}          ${user}
152     ${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=
153     ${resp}=                        Evaluate                         requests.put('${url}', data="""${data}""", headers=${headers}, verify=False, allow_redirects=False)    requests
154     [Return]                        ${resp}
155
156 CheckLog
157     [Arguments]                     ${cli_exec_log_Path}             ${string_to_check_in_log}
158     ${cli_cmd_output}=              Run Process                      ${cli_exec_log_Path}                     shell=yes
159     Log                             ${cli_cmd_output.stdout}
160     Should Be Equal As Strings      ${cli_cmd_output.rc}             0
161     Should Contain                  ${cli_cmd_output.stdout}         ${string_to_check_in_log}
162
163 VerifyResponse
164     [Arguments]                     ${actual_response_value}         ${expected_response_value}
165     Should Be Equal As Strings      ${actual_response_value}         ${expected_response_value}