onap on kubernetes source files
[oom.git] / kubernetes / config / docker / init / src / config / robot / robot / resources / dcae_interface.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           UUID      
5 Library           OperatingSystem
6 Library           Collections
7 Resource          global_properties.robot
8
9 *** Variables ***
10 ${DCAE_HEALTH_CHECK_BODY}    robot/assets/dcae/dcae_healthcheck.json
11 ${DCAE_HEALTH_CHECK_PATH}    /gui
12
13 *** Keywords ***
14 Run DCAE Health Check
15     [Documentation]    Runs a DCAE health check
16     ${auth}=  Create List  ${GLOBAL_DCAE_USERNAME}    ${GLOBAL_DCAE_PASSWORD}
17     Log    Creating session ${GLOBAL_DCAE_SERVER}
18     ${session}=    Create Session       dcae    ${GLOBAL_DCAE_SERVER}    auth=${auth}
19     ${uuid}=    Generate UUID
20     ${data}=    OperatingSystem.Get File    ${DCAE_HEALTH_CHECK_BODY}
21     ${headers}=  Create Dictionary     action=getTable    Accept=application/json    Content-Type=application/json    X-TransactionId=${GLOBAL_APPLICATION_ID}-${uuid}    X-FromAppId=${GLOBAL_APPLICATION_ID}
22     ${resp}=    Put Request     dcae    ${DCAE_HEALTH_CHECK_PATH}     data=${data}    headers=${headers}
23     Log    Received response from dcae ${resp.json()}
24     Should Be Equal As Strings  ${resp.status_code}     200
25     Check DCAE Results    ${resp.json()}
26     
27 Check DCAE Results
28     [Documentation]    Parse DCAE JSON response and make sure all rows have healthTestStatus=GREEN
29     [Arguments]    ${json}
30     @{rows}=    Get From Dictionary    ${json['returns']}    rows
31     @{headers}=    Get From Dictionary    ${json['returns']}    columns
32     
33     # Retrieve column names from headers
34     ${columns}=    Create List
35     :for    ${header}    in    @{headers}
36     \    ${colName}=    Get From Dictionary    ${header}    colName 
37     \    Append To List    ${columns}    ${colName}
38     
39     # Process each row making sure status=GREEN          
40     :for    ${row}    in    @{rows}
41     \    ${cells}=    Get From Dictionary    ${row}    cells
42     \    ${dict}=    Make A Dictionary    ${cells}    ${columns} 
43     \    Dictionary Should Contain Item    ${dict}    healthTestStatus    GREEN
44
45         
46 Make A Dictionary
47     [Documentation]    Given a list of column names and a list of dictionaries, map columname=value
48     [Arguments]     ${columns}    ${names}    ${valuename}=value
49     ${dict}=    Create Dictionary
50     ${collength}=    Get Length    ${columns} 
51     ${namelength}=    Get Length    ${names} 
52     :for    ${index}    in range    0   ${collength}
53     \    ${name}=    Evaluate     ${names}[${index}]
54     \    ${valued}=    Evaluate     ${columns}[${index}]
55     \    ${value}=    Get From Dictionary    ${valued}    ${valueName}
56     \    Set To Dictionary    ${dict}   ${name}    ${value}     
57     [Return]     ${dict}