Add CSIT tests for VES event-listener endpoint
[integration/csit.git] / tests / dcaegen2 / testcases / resources / dcae_keywords.robot
1 *** Settings ***
2 Documentation     The main interface for interacting with DCAE. It handles low level stuff like managing the http request library and DCAE required fields
3 Library               RequestsLibrary
4 Library           DcaeLibrary
5 Library           OperatingSystem
6 Library           Collections
7 Variables         ../resources/DcaeVariables.py
8 Resource          ../../../common.robot
9 Resource          ../resources/dcae_properties.robot
10
11 *** Keywords ***
12 Create sessions
13     [Documentation]  Create all required sessions
14     ${auth}=  Create List  ${VESC_HTTPS_USER}   ${VESC_HTTPS_PD}
15     ${wrong_auth}=  Create List  ${VESC_HTTPS_WRONG_USER}  ${VESC_HTTPS_WRONG_PD}
16     ${certs}=  Create List  ${VESC_ROOTCA_CERT}  ${VESC_ROOTCA_KEY}
17     ${wrong_certs}=  Create List  ${VESC_WRONG_CERT}  ${VESC_WRONG_KEY}
18     ${outdated_certs}=  Create List  ${VESC_OUTDATED_CERT}  ${VESC_OUTDATED_KEY}
19     Create Session    dcae_vesc_url    ${VESC_URL}
20     Set Suite Variable    ${http_session}    dcae_vesc_url
21     Create Session    dcae_vesc_url_https    ${VESC_URL_HTTPS}  auth=${auth}  disable_warnings=1
22     Set Suite Variable    ${https_basic_auth_session}    dcae_vesc_url_https
23     Create Session  dcae_vesc_url_https_wrong_auth  ${VESC_URL_HTTPS}  auth=${wrong_auth}  disable_warnings=1
24     Set Suite Variable  ${https_wrong_auth_session}  dcae_vesc_url_https_wrong_auth
25     Create Client Cert Session  dcae_vesc_url_https_cert  ${VESC_URL_HTTPS}  client_certs=${certs}  disable_warnings=1
26     Set Suite Variable  ${https_valid_cert_session}  dcae_vesc_url_https_cert
27     Create Client Cert Session  dcae_vesc_url_https_wrong_cert  ${VESC_URL_HTTPS}  client_certs=${wrong_certs}  disable_warnings=1  verify=${False}
28     Set Suite Variable  ${https_invalid_cert_session}  dcae_vesc_url_https_wrong_cert
29     Create Client Cert Session  dcae_vesc_url_https_outdated_cert  ${VESC_URL_HTTPS}  client_certs=${outdated_certs}  disable_warnings=1  verify=${False}
30     Set Suite Variable  ${https_outdated_cert_session}  dcae_vesc_url_https_outdated_cert
31     Create Session  dcae_vesc_url_https_wo_auth  ${VESC_URL_HTTPS}  disable_warnings=1
32     Set Suite Variable  ${https_no_cert_no_auth_session}  dcae_vesc_url_https_wo_auth
33
34 Create header
35     ${headers}=    Create Dictionary    Content-Type=application/json
36     Set Suite Variable    ${suite_headers}    ${headers}
37
38 Get DCAE Nodes
39     [Documentation]    Get DCAE Nodes from Consul Catalog
40     ${session}=    Create Session       dcae    ${GLOBAL_DCAE_CONSUL_URL}
41     ${uuid}=    Generate UUID
42     ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json  X-Consul-Token=abcd1234  X-TransactionId=${GLOBAL_APPLICATION_ID}-${uuid}    X-FromAppId=${GLOBAL_APPLICATION_ID}
43     ${resp}=    Get Request     dcae    /v1/catalog/nodes        headers=${headers}
44     Log    Received response from dcae consul: ${resp.json()}
45     Should Be Equal As Strings  ${resp.status_code}     200
46     ${NodeList}=   Get Json Value List   ${resp.text}   Node
47     ${NodeListLength}=  Get Length  ${NodeList}
48     ${len}=  Get Length   ${NodeList}
49     Should Not Be Equal As Integers   ${len}   0
50     [Return]    ${NodeList}
51
52 DCAE Node Health Check
53     [Documentation]    Perform DCAE Node Health Check
54     [Arguments]    ${NodeName}
55     ${session}=    Create Session       dcae-${NodeName}        ${GLOBAL_DCAE_CONSUL_URL}
56     ${uuid}=    Generate UUID
57     ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json  X-Consul-Token=abcd1234  X-TransactionId=${GLOBAL_APPLICATION_ID}-${uuid}    X-FromAppId=${GLOBAL_APPLICATION_ID}
58     ${hcpath}=   Catenate  SEPARATOR=    /v1/health/node/    ${NodeName}
59     ${resp}=    Get Request     dcae-${NodeName}        ${hcpath}        headers=${headers}
60     Log    Received response from dcae consul: ${resp.json()}
61     Should Be Equal As Strings  ${resp.status_code}     200
62     ${StatusList}=  Get Json Value List   ${resp.text}    Status
63     ${len}=  Get Length  ${StatusList}
64     Should Not Be Equal As Integers   ${len}   0
65     DCAE Check Health Status    ${NodeName}   ${StatusList[0]}    Serf Health Status
66
67 DCAE Check Health Status
68     [Arguments]    ${NodeName}    ${ItemStatus}   ${CheckType}
69     Should Be Equal As Strings    ${ItemStatus}    passing
70     Log   Node: ${NodeName} ${CheckType} check pass ok
71
72 VES Collector Suite Setup DMaaP
73     [Documentation]   Start DMaaP Mockup Server
74     ${ret}=  Setup DMaaP Server
75     Should Be Equal As Strings     ${ret}    true
76
77 VES Collector Suite Shutdown DMaaP
78     [Documentation]   Shutdown DMaaP Mockup Server
79     ${ret}=  Shutdown DMaap
80     Should Be Equal As Strings     ${ret}    true
81
82 Check DCAE Results
83     [Documentation]    Parse DCAE JSON response and make sure all rows have healthTestStatus=GREEN
84     [Arguments]    ${json}
85     @{rows}=    Get From Dictionary    ${json['returns']}    rows
86     @{headers}=    Get From Dictionary    ${json['returns']}    columns
87     # Retrieve column names from headers
88     ${columns}=    Create List
89     :for    ${header}    IN    @{headers}
90     \    ${colName}=    Get From Dictionary    ${header}    colName
91     \    Append To List    ${columns}    ${colName}
92     # Process each row making sure status=GREEN
93     :for    ${row}    IN    @{rows}
94     \    ${cells}=    Get From Dictionary    ${row}    cells
95     \    ${dict}=    Make A Dictionary    ${cells}    ${columns}
96     \    Dictionary Should Contain Item    ${dict}    healthTestStatus    GREEN
97
98 Make A Dictionary
99     [Documentation]    Given a list of column names and a list of dictionaries, map columname=value
100     [Arguments]     ${columns}    ${names}    ${valuename}=value
101     ${dict}=    Create Dictionary
102     ${collength}=    Get Length    ${columns}
103     ${namelength}=    Get Length    ${names}
104     :for    ${index}    IN RANGE    0   ${collength}
105     \    ${name}=    Evaluate     ${names}[${index}]
106     \    ${valued}=    Evaluate     ${columns}[${index}]
107     \    ${value}=    Get From Dictionary    ${valued}    ${valueName}
108     \    Set To Dictionary    ${dict}   ${name}    ${value}
109     [Return]     ${dict}
110
111 Json String To Dictionary
112     [Arguments]  ${json_string}
113     ${json_dict}=  evaluate    json.loads('''${json_string}''')    json
114     [Return]   ${json_dict}
115
116 Dictionary To Json String
117     [Arguments]  ${json_dict}
118     ${json_string}=    evaluate    json.dumps(${json_dict})    json
119     [Return]    ${json_string}
120
121 Get DCAE Service Component Status
122     [Documentation]   Get the status of a DCAE Service Component
123     [Arguments]    ${url}    ${urlpath}     ${usr}    ${passwd}
124     ${auth}=  Create List  ${usr}  ${passwd}
125     ${session}=    Create Session       dcae-service-component  ${url}    auth=${auth}
126     ${resp}=    Get Request     dcae-service-component  ${urlpath}
127     [Return]    ${resp}
128
129 Publish Event To VES Collector
130     [Documentation]    Send an event to VES Collector
131     [Arguments]     ${session}  ${evtpath}   ${evtdata}
132     ${resp}=    Post Request    ${session}      ${evtpath}     data=${evtdata}   headers=${suite_headers}
133     [Return]    ${resp}
134
135 Publish Event To VES Collector With Put Method
136     [Documentation]    Send an event to VES Collector
137     [Arguments]     ${session}  ${evtpath}   ${evtdata}
138     ${resp}=    Put Request     ${session}      ${evtpath}     data=${evtdata}   headers=${suite_headers}
139     [Return]    ${resp}
140
141 Send Request And Validate Response
142     [Documentation]  Post singel event to passed url with passed data and validate received response
143     [Arguments]  ${keyword}  ${session}  ${evtpath}  ${evtjson}  ${resp_code}  ${msg_code}=None
144     ${evtdata}=  Get Data From File  ${evtjson}
145     ${resp}=  Run Keyword  ${keyword}  ${session}  ${evtpath}  ${evtdata}
146     Log    Receive HTTPS Status code ${resp.status_code}
147     Should Be Equal As Strings  ${resp.status_code}     ${resp_code}
148     ${isEmpty}=   Is Json Empty    ${resp}
149     Run Keyword If   '${isEmpty}' == False   Log  ${resp.json()}
150     Run Keyword If  '${msg_code}' != 'None'  Check Whether Message Received  ${msg_code}
151
152 Check Whether Message Received
153     [Documentation]  Validare if message has been received
154     [Arguments]  ${msg_code}
155     ${ret}=  DMaaP Message Receive  ${msg_code}
156     Should Be Equal As Strings    ${ret}    true
157
158 Send Request And Expect Error
159     [Documentation]  Post singel event to passed url with passed data and expect error
160     [Arguments]  ${keyword}  ${session}  ${evtpath}  ${evtjson}  ${error_type}  @{error_content}
161     ${evtdata}=  Get Data From File  ${evtjson}
162     ${err_msg}=  Run Keyword And Expect Error  ${error_type}  ${keyword}  ${session}  ${evtpath}  ${evtdata}
163     :FOR    ${content}    IN    @{error_content}
164     \    Should Contain   ${err_msg}  ${content}
165     Log  Recieved error message ${err_msg}
166
167 Run Healthcheck
168     [Documentation]  Run Healthcheck
169     ${uuid}=    Generate UUID
170     ${headers}=  Create Dictionary     Accept=*/*     X-TransactionId=${GLOBAL_APPLICATION_ID}-${uuid}    X-FromAppId=${GLOBAL_APPLICATION_ID}
171     ${resp}=    Get Request     ${http_session}         /healthcheck        headers=${headers}
172     Should Be Equal As Strings  ${resp.status_code}     200