aboutsummaryrefslogtreecommitdiffstats
path: root/tests/dcaegen2-pmmapper/pmmapper/pmmapper.robot
blob: 9bba481758e24fbd67c940c4ab1364a3fc304e44 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
*** Settings ***
Documentation     Testing PM Mapper functionality
Library           Collections
Library           OperatingSystem
Library           RequestsLibrary
Library           Process
Library           String

Test Setup        Create Session  mapper_session  ${PMMAPPER_BASE_URL}
Test Teardown     Delete All Sessions


*** Variables ***
${CLI_EXEC_CLI_CONFIG}                   { head -n 6 | tail -2;} < /tmp/pmmapper.log
${CLI_EXEC_CLI_SUBS}                     curl -k https://${DR_PROV_IP}:8443/internal/prov
${PMMAPPER_BASE_URL}                     http://${PMMAPPER_IP}:8081
${DELIVERY_ENDPOINT}                     /delivery
${HEALTHCHECK_ENDPOINT}                  /healthcheck
${RECONFIGURE_ENDPOINT}                  /reconfigure
${NO_MANAGED_ELEMENT_PATH}               %{WORKSPACE}/tests/dcaegen2-pmmapper/pmmapper/assets/A_no_managed_element.xml
${NO_MEASDATA_PATH}                      %{WORKSPACE}/tests/dcaegen2-pmmapper/pmmapper/assets/A_no_measdata.xml
${VALID_METADATA_PATH}                   %{WORKSPACE}/tests/dcaegen2-pmmapper/pmmapper/assets/valid_metadata.json
${DIFF_VENDOR_METADATA}                  %{WORKSPACE}/tests/dcaegen2-pmmapper/pmmapper/assets/diff_vendor_metadata.json
${NON_XML_FILE}                          %{WORKSPACE}/tests/dcaegen2-pmmapper/pmmapper/assets/diff_vendor_metadata.json
${CLI_EXEC_CLI_PM_LOG}                   docker exec pmmapper /bin/sh -c "tail -15 /var/log/ONAP/dcaegen2/services/pm-mapper/pm-mapper_output.log"
${PUBLISH_NODE_URL}                      https://${DR_NODE_IP}:8443/publish/1
${TYPE-A_PM_DATA_FILE_PATH}              %{WORKSPACE}/tests/dcaegen2-pmmapper/pmmapper/assets/A20181002.0000-1000-0015-1000_5G.xml
${TYPE-C_PM_DATA_FILE_PATH}              %{WORKSPACE}/tests/dcaegen2-pmmapper/pmmapper/assets/C20190328.0000-0015.xml
${PUBLISH_CONTENT_TYPE}                  application/octet-stream
${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
${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
${CLI_RESTART_PMMAPPER}                  docker restart pmmapper
${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
${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
${CLI_MESSAGE_ROUTER_TOPIC}              curl http://${DMAAP_MR_IP}:3904/events/PM_MAPPER/CG1/C1?timeout=1000
${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
${CLI_MR_LOG}                            cat /tmp/mr.log

*** Test Cases ***
Verify PM Mapper Receive Configuraton From Config Binding Service
    [Tags]                          PM_MAPPER_01
    [Documentation]                 Verify 3gpp pm mapper successfully receive config data from CBS
    CheckLog                        ${CLI_EXEC_CLI_CONFIG}           Received pm-mapper configuration

Verify Health Check returns 200 when a REST GET request to healthcheck url
    [Tags]                          PM_MAPPER_02
    [Documentation]                 Verify Health Check returns 200 when a REST GET request to healthcheck url
    [Timeout]                       1 minute
    ${resp}=                        Get Request                      mapper_session  ${HEALTHCHECK_ENDPOINT}
    VerifyResponse                  ${resp.status_code}              200

Verify 3GPP PM Mapper responds appropriately when no metadata is provided
    [Tags]                          PM_MAPPER_03
    [Documentation]                 Verify 3GPP PM Mapper responds 400 with the message "Missing Metadata." when no metadata is provided
    [Timeout]                       1 minute
    ${headers}=                     Create Dictionary               X-ONAP-RequestID=1  Content-Type=application/xml
    ${resp}=                        Put Request                     mapper_session  ${DELIVERY_ENDPOINT}/filename    data='${EMPTY}'    headers=${headers}
    VerifyResponse                  ${resp.status_code}             400
    VerifyResponse                  ${resp.content}                 Missing Metadata.
    CheckLog                        ${CLI_EXEC_CLI_PM_LOG}          RequestID=1

Verify 3GPP PM Mapper responds appropriately when invalid metadata is provided
    [Tags]                          PM_MAPPER_04
    [Documentation]                 Verify 3GPP PM Mapper responds 400 with the message "Malformed Metadata." when invalid metadata is provided
    [Timeout]                       1 minute
    ${headers}=                     Create Dictionary               X-ONAP-RequestID=2  X-DMAAP-DR-META='not metadata'  Content-Type=application/xml
    ${resp}=                        Put Request                     mapper_session  ${DELIVERY_ENDPOINT}/filename  data='${EMPTY}'  headers=${headers}
    VerifyResponse                  ${resp.status_code}             400
    VerifyResponse                  ${resp.content}                 Malformed Metadata.
    CheckLog                        ${CLI_EXEC_CLI_PM_LOG}          RequestID=2

Verify 3GPP PM Mapper maps Type-A file and publish 3gpp perf VES evnets to message router
    [Tags]                          PM_MAPPER_05
    [Documentation]                 Verify 3GPP PM Mapper maps Type-A file and publish 3gpp perf VES evnets to message router.
    [Timeout]                       1 minute
    SendToDatarouter                ${TYPE-A_PM_DATA_FILE_PATH}      ${VALID_METADATA_PATH}            X-ONAP-RequestID=3
    CheckLog                        ${CLI_EXEC_CLI_PM_LOG}           Successfully published VES events to messagerouter
    CheckLog                        ${CLI_EXEC_CLI_PM_LOG}           RequestID=3
    Sleep                           10s
    CheckLog                        ${CLI_MESSAGE_ROUTER_TOPIC}      perf3gpp_gnb-Ericsson_pmMeasResult

Verify that PM Mapper maps Type-C xml file and publish 3gpp perf VES evnets to message router.
    [Tags]                          PM_MAPPER_06
    [Documentation]                 Verify that PM Mapper maps Type-C xml file and publish 3gpp perf VES evnets to message router.
    [Timeout]                       1 minute
    SendToDatarouter                ${TYPE-C_PM_DATA_FILE_PATH}      ${VALID_METADATA_PATH}           X-ONAP-RequestID=4
    CheckLog                        ${CLI_EXEC_CLI_PM_LOG}           Successfully published VES events to messagerouter
    CheckLog                        ${CLI_EXEC_CLI_PM_LOG}           RequestID=4
    Run Process                     ${CLI_MR_EVENT_COUNT}            shell=yes
    CheckLog                        ${CLI_MR_LOG}                    measInfoId1
    CheckLog                        ${CLI_MR_LOG}                    measInfoId2
    CheckLog                        ${CLI_MR_LOG}                    measInfoId3

Verify that PM Mapper logs successful when a file that contains no measdata is provided
    [Tags]                          PM_MAPPER_07
    [Documentation]                 Verify that PM Mapper logs successful when a file that contains no measdata is provided
    [Timeout]                       1 minute
    SendToDatarouter                ${NO_MEASDATA_PATH}              ${VALID_METADATA_PATH}            X-ONAP-RequestID=5
    CheckLog                        ${CLI_EXEC_CLI_PM_LOG}           MeasData is empty
    CheckLog                        ${CLI_EXEC_CLI_PM_LOG}           RequestID=5

Verify that PM Mapper throws Event failed validation against schema error when no managed element content is provided
    [Tags]                          PM_MAPPER_08
    [Documentation]                 Verify 3gpp pm mapper responds with an error when no managed element content is provided
    [Timeout]                       1 minute
    SendToDatarouter                ${NO_MANAGED_ELEMENT_PATH}       ${VALID_METADATA_PATH}             X-ONAP-RequestID=6
    CheckLog                        ${CLI_EXEC_CLI_PM_LOG}           XML validation failed
    CheckLog                        ${CLI_EXEC_CLI_PM_LOG}           RequestID=6

Verify that PM Mapper correctly identifies a file that should not be mapped based on metadata filtering.
    [Tags]                          PM_MAPPER_09
    [Documentation]                 Verify that PM Mapper correctly identifies a file that should not be mapped based on metadata filtering.
    [Timeout]                       1 minute
    ${cli_cmd_output}=              Run Process                      ${CLI_EXEC_VENDOR_FILTER}         shell=yes
    Should Be Equal As Strings      ${cli_cmd_output.rc}             0
    ${resp}=                        Get Request                      mapper_session                    ${RECONFIGURE_ENDPOINT}
    Sleep                           5s
    SendToDatarouter                ${TYPE-A_PM_DATA_FILE_PATH}      ${DIFF_VENDOR_METADATA}           X-ONAP-RequestID=7
    CheckLog                        ${CLI_EXEC_CLI_PM_LOG}           Metadata does not match any filters
    CheckLog                        ${CLI_EXEC_CLI_PM_LOG}           RequestID=7

Verify that PM Mapper correctly identifies a non-xml file.
    [Tags]                          PM_MAPPER_10
    [Documentation]                 Verify that PM Mapper correctly identifies a non-xml file.
    [Timeout]                       1 minute
    SendToDatarouter                ${NON_XML_FILE}                  ${VALID_METADATA_PATH}             X-ONAP-RequestID=8
    CheckLog                        ${CLI_EXEC_CLI_PM_LOG}           PM measurement file type not supported
    CheckLog                        ${CLI_EXEC_CLI_PM_LOG}           RequestID=8


*** Keywords ***

SendToDatarouter
    [Arguments]                     ${filepath}                      ${metadatapath}            ${request_id}
    ${pmdata}=                      Get File                         ${filepath}
    ${metatdata}                    Get File                         ${metadatapath}
    ${filename}                     Fetch From Right                 ${filepath}                /
    ${resp}=                        PutCall                          ${PUBLISH_NODE_URL}/${filename}        ${request_id}    ${pmdata}    ${metatdata.replace("\n","")}    pmmapper
    VerifyResponse                  ${resp.status_code}              204
    Sleep                           10s

PutCall
    [Arguments]                     ${url}                           ${request_id}              ${data}            ${meta}          ${user}
    ${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=
    ${resp}=                        Evaluate                         requests.put('${url}', data="""${data}""", headers=${headers}, verify=False, allow_redirects=False)    requests
    [Return]                        ${resp}

CheckLog
    [Arguments]                     ${cli_exec_log_Path}             ${string_to_check_in_log}
    ${cli_cmd_output}=              Run Process                      ${cli_exec_log_Path}                     shell=yes
    Log                             ${cli_cmd_output.stdout}
    Should Be Equal As Strings      ${cli_cmd_output.rc}             0
    Should Contain                  ${cli_cmd_output.stdout}         ${string_to_check_in_log}

VerifyResponse
    [Arguments]                     ${actual_response_value}         ${expected_response_value}
    Should Be Equal As Strings      ${actual_response_value}         ${expected_response_value}