First Pass Automated vFW control setup
[testsuite.git] / 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 ${MSO_ENDPOINT}     ${GLOBAL_MSO_SERVER_PROTOCOL}://${GLOBAL_INJECTED_SO_IP_ADDR}:${GLOBAL_MSO_SERVER_PORT}
12
13 *** Keywords ***
14 Run MSO Health Check
15     [Documentation]    Runs an MSO global health check
16     ${auth}=  Create List  ${GLOBAL_MSO_USERNAME}    ${GLOBAL_MSO_PASSWORD}
17     ${session}=    Create Session       mso     ${MSO_ENDPOINT}
18     ${uuid}=    Generate UUID
19     ${headers}=  Create Dictionary     Accept=text/html    Content-Type=text/html    X-TransactionId=${GLOBAL_APPLICATION_ID}-${uuid}    X-FromAppId=${GLOBAL_APPLICATION_ID}
20     ${resp}=    Get Request     mso     ${MSO_HEALTH_CHECK_PATH}     headers=${headers}
21     Should Be Equal As Strings  ${resp.status_code}     200
22
23 Run MSO Get ModelInvariantId
24     [Documentation]    Runs an MSO Get ModelInvariantID for ClosedLoop Polieis 
25     [Arguments]    ${service_model_name}    
26     ${param_dict}=    Create Dictionary    serviceModelName    ${service_model_name}
27     ${param}=   Evaluate   urllib.urlencode(${param_dict})    urllib
28     ${data_path}=   Catenate   SEPARATOR=     /ecomp/mso/catalog/v2/serviceVnfs?  ${param}
29     ${resp}=    Run MSO Get Request    ${data_path}
30     Log    ${resp.json()}
31     [Return]   ${resp.json()['serviceVnfs'][0]['modelInfo']['modelInvariantUuid']}
32     
33 Run MSO Get Request
34     [Documentation]    Runs an MSO get request
35     [Arguments]    ${data_path}    ${accept}=application/json
36     ${auth}=  Create List  ${GLOBAL_MSO_USERNAME}    ${GLOBAL_MSO_PASSWORD}
37     Log    Creating session ${MSO_ENDPOINT}
38     ${session}=    Create Session       mso     ${MSO_ENDPOINT}    auth=${auth}
39     ${uuid}=    Generate UUID
40     ${headers}=  Create Dictionary     Accept=${accept}    Content-Type=application/json    X-TransactionId=${GLOBAL_APPLICATION_ID}-${uuid}    X-FromAppId=${GLOBAL_APPLICATION_ID}
41     ${resp}=    Get Request     mso     ${data_path}     headers=${headers}
42     Log    Received response from mso ${resp.text}
43     [Return]    ${resp}
44
45 Poll MSO Get Request
46     [Documentation]    Runs an MSO get request until a certain status is received. valid values are COMPLETE
47     [Arguments]    ${data_path}     ${status}
48     ${auth}=  Create List  ${GLOBAL_MSO_USERNAME}    ${GLOBAL_MSO_PASSWORD}
49     Log    Creating session ${MSO_ENDPOINT}
50     ${session}=    Create Session       mso     ${MSO_ENDPOINT}    auth=${auth}
51     ${uuid}=    Generate UUID
52     ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json    X-TransactionId=${GLOBAL_APPLICATION_ID}-${uuid}    X-FromAppId=${GLOBAL_APPLICATION_ID}
53     #do this until it is done
54     :FOR    ${i}    IN RANGE    20
55     \    ${resp}=       Get Request     mso     ${data_path}     headers=${headers}
56     \    Should Not Contain    ${resp.text}    FAILED
57     \    Log    ${resp.json()['request']['requestStatus']['requestState']}
58     \    ${exit_loop}=    Evaluate    "${resp.json()['request']['requestStatus']['requestState']}" == "${status}"
59     \    Exit For Loop If  ${exit_loop}
60     \    Sleep    15s
61     Log    Received response from mso ${resp.text}
62     [Return]    ${resp}
63
64 Run MSO Post request
65     [Documentation]    Runs an MSO post request
66     [Arguments]  ${data_path}  ${data}
67     ${auth}=  Create List  ${GLOBAL_MSO_USERNAME}    ${GLOBAL_MSO_PASSWORD}
68     Log    Creating session ${MSO_ENDPOINT}
69     ${session}=    Create Session       mso     ${MSO_ENDPOINT}    auth=${auth}
70     ${uuid}=    Generate UUID
71     ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json    X-TransactionId=${GLOBAL_APPLICATION_ID}-${uuid}    X-FromAppId=${GLOBAL_APPLICATION_ID}
72         ${resp}=        Post Request    mso     ${data_path}     data=${data}   headers=${headers}
73         Log    Received response from mso ${resp.text}
74         [Return]  ${resp}
75
76 Run MSO Delete request
77     [Documentation]    Runs an MSO Delete request
78     [Arguments]  ${data_path}  ${data}
79     ${auth}=    Create List    ${GLOBAL_MSO_USERNAME}    ${GLOBAL_MSO_PASSWORD}
80     Log    Creating session ${MSO_ENDPOINT}
81     ${session}=    Create Session    mso    ${MSO_ENDPOINT}    auth=${auth}
82     ${uuid}=    Generate UUID
83     ${headers}=    Create Dictionary    Accept=application/json    Content-Type=application/json    X-TransactionId=${GLOBAL_APPLICATION_ID}-${uuid}    X-FromAppId=${GLOBAL_APPLICATION_ID}
84     ${resp}=    Delete Request    mso    ${data_path}    ${data}    headers=${headers}
85     Log    Received response from mso ${resp.text}
86     [Return]    ${resp}