onap on kubernetes source files
[oom.git] / kubernetes / config / docker / init / src / config / robot / robot / resources / mso_interface.robot
1 *** Settings ***
2 Documentation     The main interface for interacting with MSO. It handles low level stuff like managing the http request library and MSO required fields
3 Library               RequestsLibrary
4 Library           UUID      
5 Library           OperatingSystem
6 Library           Collections
7 Resource          global_properties.robot
8 Resource          ../resources/json_templater.robot
9 *** Variables ***
10 ${MSO_HEALTH_CHECK_PATH}    /ecomp/mso/infra/globalhealthcheck
11
12 *** Keywords ***
13 Run MSO Health Check
14     [Documentation]    Runs an MSO global health check
15     ${auth}=  Create List  ${GLOBAL_MSO_USERNAME}    ${GLOBAL_MSO_PASSWORD}
16     ${session}=    Create Session       mso     ${GLOBAL_MSO_SERVER}
17     ${uuid}=    Generate UUID
18     ${headers}=  Create Dictionary     Accept=text/html    Content-Type=text/html    X-TransactionId=${GLOBAL_APPLICATION_ID}-${uuid}    X-FromAppId=${GLOBAL_APPLICATION_ID}
19     ${resp}=    Get Request     mso     ${MSO_HEALTH_CHECK_PATH}     headers=${headers}
20     Should Be Equal As Strings  ${resp.status_code}     200
21
22 Run MSO Get Request
23     [Documentation]    Runs an MSO get request
24     [Arguments]    ${data_path}    ${accept}=application/json
25     ${auth}=  Create List  ${GLOBAL_MSO_USERNAME}    ${GLOBAL_MSO_PASSWORD}
26     Log    Creating session ${GLOBAL_MSO_SERVER}
27     ${session}=    Create Session       mso     ${GLOBAL_MSO_SERVER}    auth=${auth}
28     ${uuid}=    Generate UUID
29     ${headers}=  Create Dictionary     Accept=${accept}    Content-Type=application/json    X-TransactionId=${GLOBAL_APPLICATION_ID}-${uuid}    X-FromAppId=${GLOBAL_APPLICATION_ID}
30     ${resp}=    Get Request     mso     ${data_path}     headers=${headers}
31     Log    Received response from mso ${resp.text}
32     [Return]    ${resp}
33     
34 Poll MSO Get Request
35     [Documentation]    Runs an MSO get request until a certain status is received. valid values are COMPLETE
36     [Arguments]    ${data_path}     ${status}
37     ${auth}=  Create List  ${GLOBAL_MSO_USERNAME}    ${GLOBAL_MSO_PASSWORD}
38     Log    Creating session ${GLOBAL_MSO_SERVER}
39     ${session}=    Create Session       mso     ${GLOBAL_MSO_SERVER}    auth=${auth}
40     ${uuid}=    Generate UUID
41     ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json    X-TransactionId=${GLOBAL_APPLICATION_ID}-${uuid}    X-FromAppId=${GLOBAL_APPLICATION_ID}
42     #do this until it is done
43     :FOR    ${i}    IN RANGE    20
44     \    ${resp}=       Get Request     mso     ${data_path}     headers=${headers}
45     \    Should Not Contain    ${resp.text}    FAILED
46     \    Log    ${resp.json()['request']['requestStatus']['requestState']}   
47     \    ${exit_loop}=    Evaluate    "${resp.json()['request']['requestStatus']['requestState']}" == "${status}"
48     \    Exit For Loop If  ${exit_loop}
49     \    Sleep    15s
50     Log    Received response from mso ${resp.text}
51     [Return]    ${resp}
52
53
54