62a13af5fcc1178041e0ad9a379f68a6eba7be27
[testsuite.git] / 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     X-ECOMP-Client-Version=ONAP-R2   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 (except for the exceptions ;-)
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     \    Is DCAE Status Valid    ${dict}
44
45 Is DCAE Status Valid
46     [Arguments]   ${dict}
47     # If it is GREEN we are done.
48     ${status}   ${value}=   Run Keyword And Ignore Error       Dictionary Should Contain Item    ${dict}    healthTestStatus    GREEN
49     Return From Keyword If   '${status}' == 'PASS'
50
51     # Check for Exceptions
52     # Only 1 so far
53     ${status}   ${value}=   Run Keyword And Ignore Error       Check For Exception    ${dict}    vm-controller    UNDEPLOYED   YELLOW
54     Return From Keyword If   '${status}' == 'PASS'
55
56     # Status not GREEN or is not an exception
57     Fail    Health check failed ${dict}
58
59 Check for Exception
60     [Arguments]   ${dict}   ${service}    ${status}   ${healthTestStatus}
61     # Test the significant attributes to see if this is a legit exception
62     ${exception}=   Copy Dictionary   ${dict}
63     Set To Dictionary   ${exception}   service=${service}   status=${status}    healthTestStatus=${healthTestStatus}
64     Dictionaries Should Be Equal    ${dict}    ${exception}
65
66
67
68 Make A Dictionary
69     [Documentation]    Given a list of column names and a list of dictionaries, map columname=value
70     [Arguments]     ${columns}    ${names}    ${valuename}=value
71     ${dict}=    Create Dictionary
72     ${collength}=    Get Length    ${columns}
73     ${namelength}=    Get Length    ${names}
74     :for    ${index}    in range    0   ${collength}
75     \    ${name}=    Evaluate     ${names}[${index}]
76     \    ${valued}=    Evaluate     ${columns}[${index}]
77     \    ${value}=    Get From Dictionary    ${valued}    ${valueName}
78     \    Set To Dictionary    ${dict}   ${name}    ${value}
79     [Return]     ${dict}