aboutsummaryrefslogtreecommitdiffstats
path: root/tests/dcaegen2/testcases/resources/dcae_keywords.robot
blob: c4cdbb9c41f293966c020545c202c300ea222554 (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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
*** Settings ***
Documentation     The main interface for interacting with DCAE. It handles low level stuff like managing the http request library and DCAE required fields
Library         RequestsLibrary
Library           DcaeLibrary
Library           OperatingSystem
Library           Collections
Variables         ../resources/DcaeVariables.py
Resource          ../resources/dcae_properties.robot

*** Variables ***
${DCAE_HEALTH_CHECK_BODY}    %{WORKSPACE}/tests/dcae/testcases/assets/json_events/dcae_healthcheck.json


*** Keywords ***
Create sessions
    [Documentation]  Create all required sessions
    Create Session    dcae_vesc_url    ${VESC_URL}
    Set Suite Variable    ${suite_dcae_vesc_url_session}    dcae_vesc_url
    ${auth}=  Create List  ${VESC_HTTPS_USER}   ${VESC_HTTPS_PD}
    Create Session    dcae_vesc_url_https    ${VESC_URL_HTTPS}  auth=${auth}  disable_warnings=1
    Set Suite Variable    ${suite_dcae_vesc_url_https_session}    dcae_vesc_url_https
    ${wrong_auth}=  Create List  ${VESC_HTTPS_WRONG_USER}  ${VESC_HTTPS_WRONG_PD}
    Create Session  dcae_vesc_url_https_wrong_auth  ${VESC_URL_HTTPS}  auth=${wrong_auth}  disable_warnings=1
    Set Suite Variable  ${suite_dcae_vesc_url_https_wrong_auth_session}  dcae_vesc_url_https_wrong_auth
    ${certs}=  Create List  ${VESC_ROOTCA_CERT}  ${VESC_ROOTCA_KEY}
    Create Client Cert Session  dcae_vesc_url_https_cert  ${VESC_URL_HTTPS}  client_certs=${certs}  disable_warnings=1
    Set Suite Variable  ${suite_dcae_vesc_url_https_cert_session}  dcae_vesc_url_https_cert
    ${wrong_certs}=  Create List  ${VESC_WRONG_CERT}  ${VESC_WRONG_KEY}
    Create Client Cert Session  dcae_vesc_url_https_wrong_cert  ${VESC_URL_HTTPS}  client_certs=${wrong_certs}  disable_warnings=1  verify=${False}
    Set Suite Variable  ${suite_dcae_vesc_url_https_wrong_cert_session}  dcae_vesc_url_https_wrong_cert
    Create Session  dcae_vesc_url_https_wo_auth  ${VESC_URL_HTTPS}  disable_warnings=1
    Set Suite Variable  ${suite_dcae_vesc_url_https_wo_auth_session}  dcae_vesc_url_https_wo_auth

Create header
    ${headers}=    Create Dictionary    Content-Type=application/json
    Set Suite Variable    ${suite_headers}    ${headers}

Get DCAE Nodes
    [Documentation]    Get DCAE Nodes from Consul Catalog
    #Log    Creating session   ${GLOBAL_DCAE_CONSUL_URL}
    ${session}=    Create Session   dcae  ${GLOBAL_DCAE_CONSUL_URL}
    ${uuid}=    Generate UUID
    ${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}
    ${resp}=  Get Request   dcae  /v1/catalog/nodes        headers=${headers}
    Log    Received response from dcae consul: ${resp.json()}
    Should Be Equal As Strings  ${resp.status_code}   200
    ${NodeList}=   Get Json Value List   ${resp.text}   Node
    ${NodeListLength}=  Get Length  ${NodeList}
    ${len}=  Get Length   ${NodeList}
    Should Not Be Equal As Integers   ${len}   0
    [Return]    ${NodeList}

DCAE Node Health Check
    [Documentation]    Perform DCAE Node Health Check
    [Arguments]    ${NodeName}
    ${session}=    Create Session   dcae-${NodeName}  ${GLOBAL_DCAE_CONSUL_URL}
    ${uuid}=    Generate UUID
    ${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}
    ${hcpath}=   Catenate  SEPARATOR=    /v1/health/node/    ${NodeName}
    ${resp}=  Get Request   dcae-${NodeName}  ${hcpath}        headers=${headers}
    Log    Received response from dcae consul: ${resp.json()}
    Should Be Equal As Strings  ${resp.status_code}   200
    ${StatusList}=  Get Json Value List   ${resp.text}    Status
    ${len}=  Get Length  ${StatusList}
    Should Not Be Equal As Integers   ${len}   0
    DCAE Check Health Status    ${NodeName}   ${StatusList[0]}    Serf Health Status
    #Run Keyword if  ${len} > 1  DCAE Check Health Status  ${NodeName}  ${StatusList[1]}  Serf Health Status

DCAE Check Health Status
    [Arguments]    ${NodeName}    ${ItemStatus}   ${CheckType}
    Should Be Equal As Strings    ${ItemStatus}    passing
    Log   Node: ${NodeName} ${CheckType} check pass ok

VES Collector Suite Setup DMaaP
    [Documentation]   Start DMaaP Mockup Server
    ${ret}=  Setup DMaaP Server
    Should Be Equal As Strings     ${ret}    true

VES Collector Suite Shutdown DMaaP
    [Documentation]   Shutdown DMaaP Mockup Server
    ${ret}=  Shutdown DMaap
    Should Be Equal As Strings     ${ret}    true

Check DCAE Results
    [Documentation]    Parse DCAE JSON response and make sure all rows have healthTestStatus=GREEN
    [Arguments]    ${json}
    @{rows}=    Get From Dictionary    ${json['returns']}    rows
    @{headers}=    Get From Dictionary    ${json['returns']}    columns
    # Retrieve column names from headers
    ${columns}=    Create List
    :for    ${header}    IN    @{headers}
    \    ${colName}=    Get From Dictionary    ${header}    colName
    \    Append To List    ${columns}    ${colName}
    # Process each row making sure status=GREEN
    :for    ${row}    IN    @{rows}
    \    ${cells}=    Get From Dictionary    ${row}    cells
    \    ${dict}=    Make A Dictionary    ${cells}    ${columns}
    \    Dictionary Should Contain Item    ${dict}    healthTestStatus    GREEN

Make A Dictionary
    [Documentation]    Given a list of column names and a list of dictionaries, map columname=value
    [Arguments]     ${columns}    ${names}    ${valuename}=value
    ${dict}=    Create Dictionary
    ${collength}=    Get Length    ${columns}
    ${namelength}=    Get Length    ${names}
    :for    ${index}    IN RANGE    0   ${collength}
    \    ${name}=    Evaluate     ${names}[${index}]
    \    ${valued}=    Evaluate     ${columns}[${index}]
    \    ${value}=    Get From Dictionary    ${valued}    ${valueName}
    \    Set To Dictionary    ${dict}   ${name}    ${value}
    [Return]     ${dict}

Json String To Dictionary
    [Arguments]  ${json_string}
    ${json_dict}=  evaluate    json.loads('''${json_string}''')    json
    [Return]   ${json_dict}

Dictionary To Json String
    [Arguments]  ${json_dict}
    ${json_string}=    evaluate    json.dumps(${json_dict})    json
    [Return]    ${json_string}

Get DCAE Service Component Status
    [Documentation]   Get the status of a DCAE Service Component
    [Arguments]    ${url}    ${urlpath}     ${usr}    ${passwd}
    ${auth}=  Create List  ${usr}  ${passwd}
    ${session}=    Create Session   dcae-service-component  ${url}    auth=${auth}
    ${resp}=  Get Request   dcae-service-component  ${urlpath}
    [Return]    ${resp}

Publish Event To VES Collector No Auth
    [Documentation]    Send an event to VES Collector
    [Arguments]     ${evtpath}   ${evtdata}
    ${resp}=  Post Request  ${suite_dcae_vesc_url_session}  ${evtpath}     data=${evtdata}   headers=${suite_headers}
    [Return]  ${resp}

Publish Event To VES Collector
    [Documentation]    Send an event to VES Collector
    [Arguments]     ${evtpath}   ${evtdata}
    ${resp}=  Post Request  ${suite_dcae_vesc_url_https_session}    ${evtpath}     data=${evtdata}   headers=${suite_headers}
    [Return]  ${resp}

Publish Event To VES Collector With Put Method
    [Documentation]    Send an event to VES Collector
    [Arguments]     ${evtpath}   ${evtdata}
    ${resp}=  Put Request   ${suite_dcae_vesc_url_https_session}    ${evtpath}     data=${evtdata}   headers=${suite_headers}
    [Return]  ${resp}

Publish Event To VES Collector With Put Method No Auth
    [Documentation]    Send an event to VES Collector
    [Arguments]     ${evtpath}   ${evtdata}
    ${resp}=  Put Request   ${suite_dcae_vesc_url_session}  ${evtpath}     data=${evtdata}   headers=${suite_headers}
    [Return]  ${resp}

Publish Event To VES Collector With Wrong Auth
    [Documentation]   Send an event to VES Collector by session with wrong auth
    [Arguments]   ${evtpath}  ${evtdata}
    ${resp}=  Post Request  ${suite_dcae_vesc_url_https_wrong_auth_session}  ${evtpath}  data=${evtdata}  headers=${suite_headers}
    [Return]   ${resp}

Publish Event To VES Collector With Cert
    [Documentation]   Send an event to VES Collector by session with certs
    [Arguments]   ${evtpath}  ${evtdata}
    ${resp}=  Post Request  ${suite_dcae_vesc_url_https_cert_session}  ${evtpath}  data=${evtdata}  headers=${suite_headers}
    [Return]   ${resp}

Publish Event To VES Collector With Wrong Cert
    [Documentation]   Send an event to VES Collector by session with wrong certs
    [Arguments]   ${evtpath}  ${evtdata}
    ${resp}=  Post Request  ${suite_dcae_vesc_url_https_wrong_cert_session}  ${evtpath}  data=${evtdata}  headers=${suite_headers}
    [Return]   ${resp}

Publish Event To VES Collector Without Auth And Cert
    [Documentation]   Send an event to VES Collector by session without Auth and Cert
    [Arguments]   ${evtpath}  ${evtdata}
    ${resp}=  Post Request  ${suite_dcae_vesc_url_https_wo_auth_session}  ${evtpath}  data=${evtdata}  headers=${suite_headers}
    [Return]   ${resp}