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