Adjust relative paths for CSIT files
[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          ../resources/dcae_properties.robot
9
10 *** Variables ***
11 ${DCAE_HEALTH_CHECK_BODY}    %{WORKSPACE}/tests/dcae/testcases/assets/json_events/dcae_healthcheck.json
12
13 *** Keywords ***
14 Create sessions
15     [Documentation]  Create all required sessions
16     Create Session    dcae_vesc_url    ${VESC_URL}
17     Set Suite Variable    ${suite_dcae_vesc_url_session}    dcae_vesc_url
18     ${auth}=  Create List  ${VESC_HTTPS_USER}   ${VESC_HTTPS_PD}
19     Create Session    dcae_vesc_url_https    ${VESC_URL_HTTPS}  auth=${auth}  disable_warnings=1
20     Set Suite Variable    ${suite_dcae_vesc_url_https_session}    dcae_vesc_url_https
21
22 Create header
23     ${headers}=    Create Dictionary    Content-Type=application/json
24     Set Suite Variable    ${suite_headers}    ${headers}
25
26 Get DCAE Nodes
27     [Documentation]    Get DCAE Nodes from Consul Catalog
28     #Log    Creating session   ${GLOBAL_DCAE_CONSUL_URL}
29     ${session}=    Create Session       dcae    ${GLOBAL_DCAE_CONSUL_URL}
30     ${uuid}=    Generate UUID
31     ${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}
32     ${resp}=    Get Request     dcae    /v1/catalog/nodes        headers=${headers}
33     Log    Received response from dcae consul: ${resp.json()}
34     Should Be Equal As Strings  ${resp.status_code}     200
35     ${NodeList}=   Get Json Value List   ${resp.text}   Node
36     ${NodeListLength}=  Get Length  ${NodeList}  
37     ${len}=  Get Length   ${NodeList}   
38     Should Not Be Equal As Integers   ${len}   0
39     [Return]    ${NodeList}
40
41 DCAE Node Health Check
42     [Documentation]    Perform DCAE Node Health Check
43     [Arguments]    ${NodeName}
44     ${session}=    Create Session       dcae-${NodeName}        ${GLOBAL_DCAE_CONSUL_URL}
45     ${uuid}=    Generate UUID
46     ${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}
47     ${hcpath}=   Catenate  SEPARATOR=    /v1/health/node/    ${NodeName}
48     ${resp}=    Get Request     dcae-${NodeName}        ${hcpath}        headers=${headers}
49     Log    Received response from dcae consul: ${resp.json()}
50     Should Be Equal As Strings  ${resp.status_code}     200
51     ${StatusList}=  Get Json Value List   ${resp.text}    Status
52     ${len}=  Get Length  ${StatusList}
53     Should Not Be Equal As Integers   ${len}   0
54     DCAE Check Health Status    ${NodeName}   ${StatusList[0]}    Serf Health Status
55     #Run Keyword if  ${len} > 1  DCAE Check Health Status  ${NodeName}  ${StatusList[1]}  Serf Health Status
56
57 DCAE Check Health Status
58     [Arguments]    ${NodeName}    ${ItemStatus}   ${CheckType}
59     Should Be Equal As Strings    ${ItemStatus}    passing   
60     Log   Node: ${NodeName} ${CheckType} check pass ok
61
62 VES Collector Suite Setup DMaaP
63     [Documentation]   Start DMaaP Mockup Server
64     ${ret}=  Setup DMaaP Server
65     Should Be Equal As Strings     ${ret}    true
66
67 VES Collector Suite Shutdown DMaaP
68     [Documentation]   Shutdown DMaaP Mockup Server
69     ${ret}=  Shutdown DMaap
70     Should Be Equal As Strings     ${ret}    true
71
72 Check DCAE Results
73     [Documentation]    Parse DCAE JSON response and make sure all rows have healthTestStatus=GREEN
74     [Arguments]    ${json}
75     @{rows}=    Get From Dictionary    ${json['returns']}    rows
76     @{headers}=    Get From Dictionary    ${json['returns']}    columns
77     # Retrieve column names from headers
78     ${columns}=    Create List
79     :for    ${header}    in    @{headers}
80     \    ${colName}=    Get From Dictionary    ${header}    colName
81     \    Append To List    ${columns}    ${colName}
82     # Process each row making sure status=GREEN
83     :for    ${row}    in    @{rows}
84     \    ${cells}=    Get From Dictionary    ${row}    cells
85     \    ${dict}=    Make A Dictionary    ${cells}    ${columns}
86     \    Dictionary Should Contain Item    ${dict}    healthTestStatus    GREEN
87
88 Make A Dictionary
89     [Documentation]    Given a list of column names and a list of dictionaries, map columname=value
90     [Arguments]     ${columns}    ${names}    ${valuename}=value
91     ${dict}=    Create Dictionary
92     ${collength}=    Get Length    ${columns}
93     ${namelength}=    Get Length    ${names}
94     :for    ${index}    in range    0   ${collength}
95     \    ${name}=    Evaluate     ${names}[${index}]
96     \    ${valued}=    Evaluate     ${columns}[${index}]
97     \    ${value}=    Get From Dictionary    ${valued}    ${valueName}
98     \    Set To Dictionary    ${dict}   ${name}    ${value}     
99     [Return]     ${dict}
100
101 Json String To Dictionary
102     [Arguments]  ${json_string}   
103     ${json_dict}=  evaluate    json.loads('''${json_string}''')    json
104     [Return]   ${json_dict}
105
106 Dictionary To Json String
107     [Arguments]  ${json_dict}
108     ${json_string}=    evaluate    json.dumps(${json_dict})    json
109     [Return]    ${json_string}
110
111 Get DCAE Service Component Status
112     [Documentation]   Get the status of a DCAE Service Component
113     [Arguments]    ${url}    ${urlpath}     ${usr}    ${passwd}    
114     ${auth}=  Create List  ${usr}  ${passwd}
115     ${session}=    Create Session       dcae-service-component  ${url}    auth=${auth}
116     ${resp}=    Get Request     dcae-service-component  ${urlpath}
117     [Return]    ${resp}
118
119 Publish Event To VES Collector No Auth
120     [Documentation]    Send an event to VES Collector
121     [Arguments]     ${evtpath}   ${evtdata}
122     ${resp}=    Post Request    ${suite_dcae_vesc_url_session}  ${evtpath}     data=${evtdata}   headers=${suite_headers}
123     #Log    Received response from dcae ${resp.json()}
124     [Return]    ${resp}
125
126 Publish Event To VES Collector
127     [Documentation]    Send an event to VES Collector
128     [Arguments]     ${evtpath}   ${evtdata}
129     ${resp}=    Post Request    ${suite_dcae_vesc_url_https_session}    ${evtpath}     data=${evtdata}   headers=${suite_headers}
130     #Log    Received response from dcae ${resp.json()}
131     [Return]    ${resp}
132
133 Publish Event To VES Collector With Put Method
134     [Documentation]    Send an event to VES Collector
135     [Arguments]     ${evtpath}   ${evtdata}
136     ${resp}=    Put Request     ${suite_dcae_vesc_url_https_session}    ${evtpath}     data=${evtdata}   headers=${suite_headers}
137     #Log    Received response from dcae ${resp.json()}
138     [Return]    ${resp}
139
140 Publish Event To VES Collector With Put Method No Auth
141     [Documentation]    Send an event to VES Collector
142     [Arguments]     ${evtpath}   ${evtdata}
143     ${resp}=    Put Request     ${suite_dcae_vesc_url_session}  ${evtpath}     data=${evtdata}   headers=${suite_headers}
144     #Log    Received response from dcae ${resp.json()}
145     [Return]    ${resp}