summaryrefslogtreecommitdiffstats
path: root/csit/tests/filesprocessingconfigpmmapper/filesprocessingconfigpmmapper.robot
blob: 5f026d13064bfe393ab01c91adda1c2f47e15360 (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
*** Settings ***
Documentation     Testing PM Mapper functionality
Library           Collections
Library           OperatingSystem
Library           RequestsLibrary
Library           Process
Library           String
Library           libraries/DockerContainerManager.py
Library           libraries/LogReader.py

*** Variables ***

${ASSETS_PATH}                           %{WORKSPACE}/tests/filesprocessingconfigpmmapper/assets
${NR_VALID_METADATA_PATH}                ${ASSETS_PATH}/valid_metadata.json
${CLI_EXEC_CLI_PM_LOG_CLEAR}             docker exec pmmapper /bin/sh -c "echo -n "" > /var/log/ONAP/dcaegen2/services/pm-mapper/pm-mapper_output.log"
${PUBLISH_NODE_URL}                      https://${DR_NODE_IP}:8443/publish/1
${CLI_EXEC_LOGS_LIST}                    docker exec datarouter-node /bin/sh -c "ls /opt/app/datartr/logs"
${DOCKER_CLIENT_IMAGE}                   onap/org.onap.dcaegen2.services.pm-mapper:latest
${CLIENT_CONTAINER_NAME}                 pmmapper
${FILE_PATH}                             ${ASSETS_PATH}/ABigFile.xml
${CONFIG_ENVS_1_1}                       ${ASSETS_PATH}/config_1_1.env
${CONFIG_ENVS_4_1}                       ${ASSETS_PATH}/config_4_1.env
${CONFIG_ENVS_10_1}                      ${ASSETS_PATH}/config_10_1.env
${CONFIG_ENVS_1_10}                      ${ASSETS_PATH}/config_1_10.env

*** Test Cases ***

Verify that PM Mapper rejects 6-9 messages when limitRate is 1 and threads count is 1
    [Tags]                          FILES_PROCESSING_CONFIG_PM_MAPPER_1
    [Documentation]                 Verify that PM Mapper rejects 6-9/10 messages. Configuration: limitRate=1, threadsCount=1
    [Timeout]                       15 minute

    RestartPmmapper                 ${CONFIG_ENVS_1_1}

    ${testname}=                    Set Variable                    Afirst-

    SendFilesToDatarouter           ${testname}
    ${alllogs}=                     GetLogsOutput
    ${filtered_logs}=               GetFilteredLogs                 ${alllogs}                                    ${testname}
    ${dropped_nr}=                  GetDroppedNumber                ${filtered_logs}

    Sleep                           40s
    ${isCorrectDroppedCount}=       Evaluate  ${5} < ${dropped_nr} < ${10}
    SavePmMapperLogsAndDroppedCount  config_1_1  ${dropped_nr}
    Should Be True                  ${isCorrectDroppedCount}  Pm-mapper drop: ${dropped_nr} messages. Expected drop count: 6-9
    ClearLogs

Verify that PM Mapper rejects 0 messages when limitRate is 10 and threads count is 1
    [Tags]                          FILES_PROCESSING_CONFIG_PM_MAPPER_2
    [Documentation]                 Verify that PM Mapper rejects 0/10 messages. Configuration: limitRate=10, threadsCount=1
    [Timeout]                       25 minute

    RestartPmmapper                 ${CONFIG_ENVS_10_1}

    ${testname}=                    Set Variable                    Athird-

    SendFilesToDatarouter           ${testname}
    ${alllogs}=                     GetLogsOutput
    ${filtered_logs}=               GetFilteredLogs                 ${alllogs}                                    ${testname}
    ${dropped_nr}=                  GetDroppedNumber                ${filtered_logs}

    Sleep                           15s
    SavePmMapperLogsAndDroppedCount  config_10_1  ${dropped_nr}
    Should Be Equal As Numbers      ${dropped_nr}   0   Pm-mapper drop: ${dropped_nr} messages. Expected drop count: 0
    ClearLogs

Verify that PM Mapper rejects 0 messages when limitRate is 1 and threads count is 10
    [Tags]                          FILES_PROCESSING_CONFIG_PM_MAPPER_3
    [Documentation]                 Verify that PM Mapper rejects 0/10 messages. Configuration: limitRate=1, threadsCount=10
    [Timeout]                       25 minute

    RestartPmmapper                 ${CONFIG_ENVS_1_10}

    ${testname}=                    Set Variable                    Afourth-

    SendFilesToDatarouter           ${testname}
    ${alllogs}=                     GetLogsOutput
    ${filtered_logs}=               GetFilteredLogs                 ${alllogs}                                    ${testname}
    ${dropped_nr}=                  GetDroppedNumber                ${filtered_logs}

    Sleep                           15s
    SavePmMapperLogsAndDroppedCount  config_1_10  ${dropped_nr}
    Should Be Equal As Numbers      ${dropped_nr}   0   Pm-mapper drop: ${dropped_nr} messages. Expected drop count: 0
    ClearLogs

*** Keywords ***

SendFilesToDatarouter
    [Arguments]                     ${testnr}
    FOR                             ${i}                             IN RANGE                     10
                                    SendToDatarouter                 ${FILE_PATH}                 ${NR_VALID_METADATA_PATH}                 X-ONAP-RequestID=${i}        ${testnr}         ${i}
    END
    Sleep                           20s

SendToDatarouter
    [Arguments]                     ${filepath}                      ${metadatapath}            ${request_id}            ${testnr}      ${i}
    ${pmdata}=                      Get File                         ${filepath}
    ${metatdata}                    Get File                         ${metadatapath}
    ${newFilename}                  Catenate                         SEPARATOR=                 ${testnr}               ${i}               .xml
    ${resp}=                        PutCall                          ${PUBLISH_NODE_URL}/${newFilename}        ${request_id}    ${pmdata}    ${metatdata.replace("\n","")}    pmmapper
    VerifyResponse                  ${resp.status_code}              204

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}

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

ClearLogs
    Run Process                     ${CLI_EXEC_CLI_PM_LOG_CLEAR}                     shell=yes

GetLogsOutput
    ${filesString}=                   Run Process                      ${CLI_EXEC_LOGS_LIST}                     shell=yes
    ${filesList}=                     Get Log Files List               ${filesString.stdout}
    ${output}=                        Set Variable                     ${EMPTY}
    FOR                               ${file}                          IN                                        @{filesList}
                                      ${file_path}=                    Catenate                                  SEPARATOR=    "cat /opt/app/datartr/logs/      ${file}       "
                                      ${exec}=                         Catenate                                  docker exec datarouter-node /bin/sh -c      ${file_path}
                                      ${single_file}=                  Run Process                               ${exec}         shell=yes
                                      ${output}=                       Catenate                                  SEPARATOR=\n         ${output}                  ${single_file.stdout}
                                      Log                              ${output}
    END
    [Return]                          ${output}

GetFilteredLogs
    [Arguments]                       ${all_logs}                      ${testname}
    ${filtered_logs}=                 Filter Unique                    ${all_logs}                               ${testname}
    [Return]                          ${filtered_logs}

GetDroppedNumber
    [Arguments]                       ${logs_output}
    ${number}=                        Get Number Of Dropped Messages  ${logs_output}
    [Return]                          ${number}

RestartPmmapper
    [Arguments]                       ${envs}
    Remove Container                  ${CLIENT_CONTAINER_NAME}
    Sleep                             5s
    Run Pmmapper Container            ${DOCKER_CLIENT_IMAGE}      ${CLIENT_CONTAINER_NAME}        ${envs}        ${DR_NODE_IP}          ${NODE_IP}
    Sleep                             15s

SavePmMapperLogsAndDroppedCount
    [Arguments]                       ${test_name}                ${dropped_count}
    Run Process                      echo "Dropped: ${dropped_count}" > %{WORKSPACE}/archives/${test_name}_dropped_count.log  shell=yes
    Run Process                      docker logs ${CLIENT_CONTAINER_NAME} > %{WORKSPACE}/archives/${test_name}_pm_mapper_container_logs.log  shell=yes