Merge "Refactor PM Mapper tests"
[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
8 Test Setup        Create Session  mapper_session  ${PMMAPPER_BASE_URL}
9 Test Teardown     Delete All Sessions
10
11
12 *** Variables ***
13 ${CLI_EXEC_CLI_CONFIG}                   { head -n 5 | tail -1;} < /tmp/pmmapper.log
14 ${CLI_EXEC_CLI_SUBS}                     curl -k https://${DR_PROV_IP}:8443/internal/prov
15 ${PMMAPPER_BASE_URL}                     http://${PMMAPPER_IP}:8081
16 ${DELIVERY_ENDPOINT}                     /delivery
17 ${HEALTHCHECK_ENDPOINT}                  /healthcheck
18 ${NO_MANAGED_ELEMENT_PATH}               %{WORKSPACE}/tests/dcaegen2-pmmapper/pmmapper/assets/no_managed_element.xml
19 ${NO_MEASDATA_PATH}                      %{WORKSPACE}/tests/dcaegen2-pmmapper/pmmapper/assets/no_measdata.xml
20 ${MEASD_RESULT_PATH}                     %{WORKSPACE}/tests/dcaegen2-pmmapper/pmmapper/assets/meas_result.xml
21 ${VALID_METADATA_PATH}                   %{WORKSPACE}/tests/dcaegen2-pmmapper/pmmapper/assets/valid_metadata.json
22 ${CLI_EXEC_CLI_PM_LOG}                   docker exec pmmapper /bin/sh -c "tail -5 /var/log/ONAP/dcaegen2/services/pm-mapper/pm-mapper_output.log"
23 ${PUBLISH_NODE_URL}                      https://${DR_NODE_IP}:8443/publish/1/pm.xml
24 ${PM_DATA_FILE_PATH}                     %{WORKSPACE}/tests/dcaegen2-pmmapper/pmmapper/assets/A20181002.0000-1000-0015-1000_5G.xml
25 ${PUBLISH_CONTENT_TYPE}                  application/octet-stream
26
27
28 *** Test Cases ***
29
30 Verify PM Mapper Receive Configuraton From Config Binding Service
31     [Tags]                          PM_MAPPER_01
32     [Documentation]                 Verify 3gpp pm mapper successfully receive config data from CBS
33     CheckLog                        ${CLI_EXEC_CLI_CONFIG}           Received pm-mapper configuration
34
35 Verify 3GPP PM Mapper Subscribes to Data Router
36     [Tags]                          PM_MAPPER_02
37     [Documentation]                 Verify 3gpp pm mapper subscribes to data router
38     CheckLog                        ${CLI_EXEC_CLI_SUBS}             3gpppmmapper
39
40 Verify Health Check returns 200 when a REST GET request to healthcheck url
41     [Tags]                          PM_MAPPER_03
42     [Documentation]                 Verify Health Check returns 200 when a REST GET request to healthcheck url
43     [Timeout]                       1 minute
44     ${resp}=                        Get Request                      mapper_session  ${HEALTHCHECK_ENDPOINT}
45     VerifyResponse                  ${resp.status_code}              200
46
47 Verify 3GPP PM Mapper responds appropriately when no metadata is provided
48     [Tags]                          PM_MAPPER_04
49     [Documentation]                 Verify 3GPP PM Mapper responds 400 with the message "Missing Metadata." when no metadata is provided
50     [Timeout]                       1 minute
51     ${headers}=                     Create Dictionary               X-ONAP-RequestID=1  Content-Type=application/xml
52     ${resp}=                        Put Request                     mapper_session  ${DELIVERY_ENDPOINT}/filename    data='${EMPTY}'    headers=${headers}
53     VerifyResponse                  ${resp.status_code}             400
54     VerifyResponse                  ${resp.content}                 Missing Metadata.
55     CheckLog                        ${CLI_EXEC_CLI_PM_LOG}          RequestID=1
56
57 Verify 3GPP PM Mapper responds appropriately when invalid metadata is provided
58     [Tags]                          PM_MAPPER_05
59     [Documentation]                 Verify 3GPP PM Mapper responds 400 with the message "Malformed Metadata." when invalid metadata is provided
60     [Timeout]                       1 minute
61     ${headers}=                     Create Dictionary               X-ONAP-RequestID=2  X-DMAAP-DR-META='not metadata'  Content-Type=application/xml
62     ${resp}=                        Put Request                     mapper_session  ${DELIVERY_ENDPOINT}/filename  data='${EMPTY}'  headers=${headers}
63     VerifyResponse                  ${resp.status_code}             400
64     VerifyResponse                  ${resp.content}                 Malformed Metadata.
65     CheckLog                        ${CLI_EXEC_CLI_PM_LOG}          RequestID=2
66
67 Verify 3GPP PM Mapper received pushed PM data from Data Router
68     [Tags]                          PM_MAPPER_06
69     [Documentation]                 Verify 3GPP PM Mapper received pushed PM data from Data Router
70     [Timeout]                       1 minute
71     ${PM_DATA}=                     Get File                         ${PM_DATA_FILE_PATH}
72     ${valid_metatdata}              Get File                         ${VALID_METADATA_PATH}
73     ${resp}=                        PutCall                          ${PUBLISH_NODE_URL}     3    ${PM_DATA}    ${PUBLISH_CONTENT_TYPE}    ${valid_metatdata.replace("\n","")}    pmmapper
74     VerifyResponse                  ${resp.status_code}              204
75     Sleep     10s
76     CheckLog                        ${CLI_EXEC_CLI_PM_LOG}           XML validation successful
77     CheckLog                        ${CLI_EXEC_CLI_PM_LOG}           RequestID=3
78
79 Verify that PM Mapper logs successful when a file that contains measdata is provided
80     [Tags]                          PM_MAPPER_07
81     [Documentation]                 Verify that PM Mapper logs successful when a file that contains measdata is provided
82     [Timeout]                       1 minute
83     ${valid_meas_result_content}=   Get File                         ${MEASD_RESULT_PATH}
84     ${valid_metatdata}              Get File                         ${VALID_METADATA_PATH}
85     ${headers}=                     Create Dictionary                X-ONAP-RequestID=4  Content-Type=application/xml  X-DMAAP-DR-PUBLISH-ID=4  X-DMAAP-DR-META=${valid_metatdata.replace("\n","")}
86     ${resp}=                        Put Request                      mapper_session  ${DELIVERY_ENDPOINT}/filename    data=${valid_meas_result_content}    headers=${headers}
87     VerifyResponse                  ${resp.status_code}              200
88     CheckLog                        ${CLI_EXEC_CLI_PM_LOG}           XML validation successful
89     CheckLog                        ${CLI_EXEC_CLI_PM_LOG}           RequestID=4
90
91 Verify that PM Mapper logs successful when a file that contains no measdata is provided
92     [Tags]                          PM_MAPPER_08
93     [Documentation]                 Verify that PM Mapper logs successful when a file that contains no measdata is provided
94     [Timeout]                       1 minute
95     ${valid_no_measdata_content}=   Get File                         ${NO_MEASDATA_PATH}
96     ${valid_metatdata}              Get File                         ${VALID_METADATA_PATH}
97     ${headers}=                     Create Dictionary                X-ONAP-RequestID=5  Content-Type=application/xml  X-DMAAP-DR-PUBLISH-ID=3  X-DMAAP-DR-META=${valid_metatdata.replace("\n","")}
98     ${resp}=                        Put Request                      mapper_session  ${DELIVERY_ENDPOINT}/filename    data=${valid_no_measdata_content}    headers=${headers}
99     VerifyResponse                  ${resp.status_code}              200
100     CheckLog                        ${CLI_EXEC_CLI_PM_LOG}           XML validation successful
101     CheckLog                        ${CLI_EXEC_CLI_PM_LOG}           RequestID=5
102
103 Verify that PM Mapper throws Event failed validation against schema error when no managed element content is provided
104     [Tags]                          PM_MAPPER_09
105     [Documentation]                 Verify 3gpp pm mapper responds with an error when no managed element content is provided
106     [Timeout]                       1 minute
107     ${no_managed_element_content}=  Get File                         ${NO_MANAGED_ELEMENT_PATH}
108     ${valid_metatdata}              Get File                         ${VALID_METADATA_PATH}
109     ${headers}=                     Create Dictionary                X-ONAP-RequestID=6  Content-Type=application/xml  X-DMAAP-DR-PUBLISH-ID=2  X-DMAAP-DR-META=${valid_metatdata.replace("\n","")}
110     ${resp}=                        Put Request                      mapper_session  ${DELIVERY_ENDPOINT}/filename    data=${no_managed_element_content}    headers=${headers}
111     VerifyResponse                  ${resp.status_code}              200
112     CheckLog                        ${CLI_EXEC_CLI_PM_LOG}           XML validation failed
113     CheckLog                        ${CLI_EXEC_CLI_PM_LOG}           RequestID=6
114
115
116 *** Keywords ***
117
118 PostCall
119     [Arguments]    ${url}           ${data}
120     ${headers}=    Create Dictionary    Accept=application/json    Content-Type=application/json
121     ${resp}=       Evaluate    requests.post('${url}',data='${data}', headers=${headers},verify=False)    requests
122     [Return]       ${resp}
123
124 PutCall
125     [Arguments]      ${url}       ${request_id}       ${data}            ${content_type}           ${meta}          ${user}
126     ${headers}=      Create Dictionary   X-ONAP-RequestID=${request_id}    X-DMAAP-DR-META=${meta}    Content-Type=${content_type}   X-DMAAP-DR-ON-BEHALF-OF=${user}    Authorization=Basic cG1tYXBwZXI6cG1tYXBwZXI=
127     ${resp}=         Evaluate            requests.put('${url}', data="""${data}""", headers=${headers}, verify=False, allow_redirects=False)    requests
128     [Return]         ${resp}
129
130
131 CheckLog
132     [Arguments]                     ${cli_exec_log_Path}    ${string_to_check_in_log}
133     ${cli_cmd_output}=              Run Process                      ${cli_exec_log_Path}                     shell=yes
134     Log                             ${cli_cmd_output.stdout}
135     Should Be Equal As Strings      ${cli_cmd_output.rc}             0
136     Should Contain                  ${cli_cmd_output.stdout}         ${string_to_check_in_log}
137
138 VerifyResponse
139     [Arguments]                     ${actual_response_value}         ${expected_response_value}
140     Should Be Equal As Strings      ${actual_response_value}         ${expected_response_value}