Use configMap instead of Consul to configure hv-ves
[testsuite.git] / robot / resources / dcae / hvves.robot
1 *** Settings ***
2 Documentation    Template contains stuff for HV-VES use case.
3 Library    OperatingSystem
4 Library    RequestsLibrary
5 Library    BuiltIn
6 Library    Collections
7 Library    ONAPLibrary.Utilities
8 Library    String
9 Library    ONAPLibrary.Kafka
10 Resource    ../mr_interface.robot
11
12 *** Variables ***
13 ${HVVES_MESSAGE}    \xaa\x01\x00\x00\x00\x00\x00\x01\x00\x00\x01'\n\x94\x02\n\x0esample-version\x12\x08perf3gpp\x18\x01 \x01*\nperf3GPP222\x11sample-event-name:\x11sample-event-type@\xf1\x9a\xfd\xdd\x05H\xf1\x9a\xfd\xdd\x05R\x15sample-nf-naming-codeZ\x16sample-nfc-naming-codeb\x15sample-nf-vendor-namej\x1asample-reporting-entity-idr\x1csample-reporting-entity-namez\x10sample-source-id\x82\x01\x0fsample-xnf-name\x8a\x01\tUTC+02:00\x92\x01\x057.0.2\x12\x0etest test test
14 ${CA_CERT}    /tmp/ca.pem
15 ${CLIENT_CERT}    /tmp/client.pem
16 ${CLIENT_KEY}    /tmp/client.key
17
18 ${PREV_CM_FILE}                   /tmp/prevCm.json
19 ${CURRENT_CONFIG_FILE}            /tmp/currentConfig.yaml
20 ${CM_NAME}                        dev-dcae-hv-ves-collector-application-config-configmap
21 ${GET_PREV_CM}                    kubectl -n onap get cm ${CM_NAME} -o json
22
23 ${TEST_TRUSTSTORE_PASS_PATH}      security.keys.trustStorePasswordFile: /dev/null
24
25 ${COPY_CURRENT_CONFIG}            kubectl -n onap cp $(kubectl get pods -n onap | grep hv-ves | awk '{print $1}' | grep -v NAME):/app-config-input/..data/application_config.yaml ${CURRENT_CONFIG_FILE}
26 ${GET_TRUSTSTORE_PASS_PATH}       cat ${CURRENT_CONFIG_FILE} | grep security.keys.trustStorePasswordFile
27
28 ${GET_CONFIG_FROM_CM}             kubectl -n onap get cm ${CM_NAME} -o jsonpath="{.data.application_config\\.yaml}"
29 ${TEST_CONFIG_YAML_PATH}          ${EXECDIR}/robot/assets/dcae/hvves_test_config.yaml
30
31
32 *** Keywords ***
33 Check Message Router Api
34     [Documentation]    Checks message via message router API.
35     [Arguments]    ${message_router}    ${message_router_port}    ${topic}
36     ${session}=    Create Session   session   http://${message_router}:${message_router_port}/events
37     ${resp}=   Get Request   session   /${topic}/1/1
38     Run Keyword If    400 <= ${resp.status_code} < 500    Log    Topic ${topic} does not exist.
39     Run Keyword If    200 <= ${resp.status_code} < 300    Log    Topic ${topic} exists.
40
41 Check If Topic Exists
42     [Documentation]      Checks if specific topic exists on kafka.
43     [Arguments]      ${message_router}      ${message_router_port}      ${topic}
44     ${session}=    Create Session   session   http://${message_router}:${message_router_port}/topics
45     ${resp}=   Get Request   session   /
46     ${value}=    Catenate    ${resp.json()['topics']}
47     Should Contain    ${value}    ${topic}
48
49 Send Message
50     [Documentation]     Sends message to HV-VES over TCP.
51     [Arguments]     ${hvves_server_ip}     ${hvves_server_port}
52     ${msg}=    Convert To Bytes     ${HVVES_MESSAGE}
53     Send Binary Data    ${hvves_server_ip}    ${hvves_server_port}    ${msg}
54
55 Send Message Over Ssl
56     [Documentation]     Sends message to HV-VES over TCP wih SSL enabled.
57     [Arguments]     ${hvves_server_ip}     ${hvves_server_port}
58     ${msg}=    Convert To Bytes     ${HVVES_MESSAGE}
59     Send Binary Data    ${hvves_server_ip}    ${hvves_server_port}    ${msg}    ${TRUE}    ${TRUE}    ${CA_CERT}    ${CLIENT_CERT}    ${CLIENT_KEY}
60
61 Decode Last Message From Topic
62     [Documentation]     Decode last message from Kafka topic.
63     [Arguments]     ${kafka_server}     ${kafka_port}     ${kafka_topic}    ${username}    ${password}
64     Connect    kafka    ${kafka_server}:${kafka_port}    ${username}    ${password}
65     ${msg}=     Consume    kafka    ${kafka_topic}
66     [Return]    ${msg}
67
68 Set Test Config
69     [Documentation]     Changes HV-VES config.
70
71     ${TEST_CONFIG}=                            Get File                                       ${TEST_CONFIG_YAML_PATH}    encoding=UTF-8
72
73     ${rc}    ${prev_conf} =                    Run and Return RC and Output                   ${GET_PREV_CM}
74     Should Be Equal As Integers                ${rc}                                          0
75     Create File                                ${PREV_CM_FILE}                                ${prev_conf}
76
77     ${rc}    ${prev_conf_yaml} =               Run and Return RC and Output                   ${GET_CONFIG_FROM_CM}
78     Should Be Equal As Integers                ${rc}                                          0
79     Set Environment Variable                   OLD_CONFIG_YAML                                ${prev_conf_yaml}
80
81     Set Environment Variable                   TEST_CONFIG                                    ${TEST_CONFIG}
82
83     ${rc} =                                    Run and Return RC                              kubectl -n onap patch cm ${CM_NAME} --type strategic -p "%{TEST_CONFIG}"
84     Should Be Equal As Integers                ${rc}                                          0
85
86     Wait Until Keyword Succeeds                2 min                5 sec                    Check If Config Is Applied    ${TEST_TRUSTSTORE_PASS_PATH}
87     Sleep                                      5s
88
89
90 Check If Config Is Applied
91     [Documentation]    Checks if the config is applied.
92     [Arguments]        ${truststore_pass_path}
93
94     ${rc} =                                    Run and Return RC                              ${COPY_CURRENT_CONFIG}
95     Should Be Equal As Integers                ${rc}                                          0
96
97     ${rc}      ${current_trust_pass_path} =    Run and Return RC and Output                   ${GET_TRUSTSTORE_PASS_PATH}
98     Should Be Equal As Integers                ${rc}                                          0
99
100     Should Be Equal As Strings                 ${truststore_pass_path}                        ${current_trust_pass_path}
101
102 Set Old Config
103     [Documentation]     Changes HV-VES config back to normal mode.
104
105     ${rc} =                                    Run and Return RC                              kubectl -n onap replace --force -f ${PREV_CM_FILE}
106     Should Be Equal As Integers                ${rc}                                          0
107
108     ${rc}    ${old_trust_pass_path} =          Run and Return RC and Output                   echo "%{OLD_CONFIG_YAML}" | grep security.keys.trustStorePasswordFile
109     Should Be Equal As Integers                ${rc}                                          0
110
111     Remove File                                ${PREV_CM_FILE}
112     Remove File                                ${CURRENT_CONFIG_FILE}
113
114     Wait Until Keyword Succeeds                2 min                5 sec                    Check If Config Is Applied    ${old_trust_pass_path}
115
116     Sleep                                      10s