255ba40097a98500ca68d3212b80643b4303730a
[testsuite.git] / robot / resources / oof_interface.robot
1 *** Settings ***
2 Documentation     The main interface for interacting with OOF: SNIRO and Homing Service
3 Library           RequestsLibrary
4 Library           ONAPLibrary.Utilities
5 Library           OperatingSystem
6 Library           String
7 Library           DateTime
8 Library           Collections
9 Library           ONAPLibrary.JSON
10 Library           ONAPLibrary.OOF    WITH NAME    OOF
11 Library           ONAPLibrary.Templating    WITH NAME    Templating
12 Resource          global_properties.robot
13
14 *** Variables ***
15 ${OOF_HOMING_HEALTH_CHECK_PATH}       /v1/plans/healthcheck
16 ${OOF_SNIRO_HEALTH_CHECK_PATH}        /api/oof/v1/healthcheck
17 ${OOF_CMSO_HEALTH_CHECK_PATH}        /cmso/v1/health?checkInterfaces=true
18
19 ${OOF_CMSO_TEMPLATE_FOLDER}   cmso
20 ${OOF_CMSO_UTC}   %Y-%m-%dT%H:%M:%SZ
21 ${OOF_HOMING_PLAN_FOLDER}    robot/assets/oof/optf-has
22 ${OOF_OSDF_TEMPLATE_FOLDER}   robot/assets/oof/optf-osdf
23
24 ${OOF_HOMING_ENDPOINT}    ${GLOBAL_OOF_SERVER_PROTOCOL}://${GLOBAL_INJECTED_OOF_HOMING_IP_ADDR}:${GLOBAL_OOF_HOMING_SERVER_PORT}
25 ${OOF_SNIRO_ENDPOINT}     ${GLOBAL_OOF_SERVER_PROTOCOL}://${GLOBAL_INJECTED_OOF_SNIRO_IP_ADDR}:${GLOBAL_OOF_SNIRO_SERVER_PORT}
26 ${OOF_CMSO_ENDPOINT}      ${GLOBAL_OOF_CMSO_PROTOCOL}://${GLOBAL_INJECTED_OOF_CMSO_IP_ADDR}:${GLOBAL_OOF_CMSO_SERVER_PORT}
27 ${OOF_OSDF_ENDPOINT}      ${GLOBAL_OOF_SERVER_PROTOCOL}://${GLOBAL_INJECTED_OOF_HOMING_IP_ADDR}:${GLOBAL_OOF_HOMING_SERVER_PORT}
28
29
30 *** Keywords ***
31 Run OOF-Homing Health Check
32         [Documentation]    Runs OOF-Homing Health check
33         ${resp}=    Run OOF-Homing Get Request    ${OOF_HOMING_HEALTH_CHECK_PATH}
34         Should Be Equal As Integers   ${resp.status_code}   200
35
36 Run OOF-Homing Get Request
37         [Documentation]    Runs OOF-Homing Get request
38         [Arguments]    ${data_path}
39         ${session}=    Create Session   session   ${OOF_HOMING_ENDPOINT}
40         ${resp}=   Get Request   session   ${data_path}
41         Should Be Equal As Integers   ${resp.status_code}   200
42         Log    Received response from OOF-Homing ${resp.text}
43         [Return]    ${resp}
44
45 RUN OOF-Homing SendPlanWithWrongVersion
46         [Documentation]    It sends a POST request to conductor
47     ${session}=    Create Session   optf-cond      ${OOF_HOMING_ENDPOINT}
48     ${data}=         Get Binary File     ${OOF_HOMING_PLAN_FOLDER}${/}plan_with_wrong_version.json
49     ${auth}=  Create List  ${GLOBAL_OOF_HOMING_USERNAME}    ${GLOBAL_OOF_HOMING_PASSWORD}
50     ${session}=    Create Session   session   ${OOF_CMSO_ENDPOINT}   auth=${auth}
51     &{headers}=      Create Dictionary    Content-Type=application/json  Accept=application/json
52     ${resp}=         Post Request        optf-cond   /v1/plans     data=${data}     headers=${headers}
53     Log               *********************
54     Log               response = ${resp}
55     Log               body = ${resp.text}
56     ${generatedPlanId}=    Convert To String      ${resp.json()['id']}
57     Set Global Variable     ${generatedPlanId}
58     Log              generatedPlanId = ${generatedPlanId}
59     Should Be Equal As Integers    ${resp.status_code}    201
60     Sleep    10s    Wait Plan Resolution
61
62 Run OOF-SNIRO Health Check
63      [Documentation]    Runs OOF-SNIRO Health check
64      ${resp}=    OOF.Run SNIRO Get Request    ${OOF_SNIRO_ENDPOINT}    ${OOF_SNIRO_HEALTH_CHECK_PATH}
65
66 Run OOF-CMSO Health Check
67      [Documentation]    Runs OOF-CMSO Health check
68      ${resp}=    Run OOF-CMSO Get Request    ${OOF_CMSO_HEALTH_CHECK_PATH}
69      Should Be Equal As Integers   ${resp.status_code}   200
70
71 Run OOF-CMSO Get Request
72      [Documentation]    Runs OOF-CMSO Get request
73      [Arguments]    ${data_path}
74      ${auth}=  Create List  ${GLOBAL_OOF_CMSO_USERNAME}    ${GLOBAL_OOF_CMSO_PASSWORD}
75      ${session}=    Create Session   session   ${OOF_CMSO_ENDPOINT}   auth=${auth}
76      ${resp}=   Get Request   session   ${data_path}
77      Should Be Equal As Integers   ${resp.status_code}   200
78      Log    Received response from OOF-CMSO ${resp.text}
79      [Return]    ${resp}
80
81 Run OOF-CMSO Post Scheduler
82     [Documentation]    Runs a scheduler POST request
83     [Arguments]   ${data_path}   ${data}={}
84     ${auth}=  Create List  ${GLOBAL_OOF_CMSO_USERNAME}    ${GLOBAL_OOF_CMSO_PASSWORD}
85     ${session}=    Create Session   session   ${OOF_CMSO_ENDPOINT}   auth=${auth}
86     ${headers}=  Create Dictionary   Accept=application/json    Content-Type=application/json
87     ${resp}=    Post Request    session         ${data_path}     headers=${headers}   data=${data}
88     Log    Received response from scheduler ${resp.text}
89     [Return]    ${resp}
90
91 Run OOF-CMSO Future Schedule
92    [Documentation]   Runs CMSO Future Schedule ETE test. One VNF, One Change Window
93    [Arguments]    ${request_file}=OneVnfOneChangeWindow.jinja   ${workflow}=Replace   ${minutesFromNow}=3
94    ${uuid}=   Generate UUID4
95    ${resp}=   OOF-CMSO Create Schedule   ${uuid}   ${request_file}   workflow=${workflow}   minutesFromNow=${minutesFromNow}
96    Should Be Equal as Strings    ${resp.status_code}    202
97    Wait Until Keyword Succeeds    600s    30s    OOF-CMSO Wait For Pending Approval   ${uuid}
98    OOF-CMSO Send Tier2 Approval   ${uuid}   jf9860    Accepted
99    Wait Until Keyword Succeeds    600s    30s    OOF-CMSO Wait for Schedule to Complete   Completed   ${uuid}
100
101
102 OOF-CMSO Create Schedule
103     [Documentation]   Creates a CMSO future schedule request for the passed template.
104     [Arguments]   ${uuid}   ${request_file}    ${workflow}    ${minutesFromNow}=5
105     ${testid}=   Catenate   ${uuid}
106     ${testid}=   Get Substring   ${testid}   -4
107     ${dict}=   Create Dictionary   serviceInstanceId=${uuid}   parent_service_model_name=${uuid}
108         ${map}=   Create Dictionary   uuid=${uuid}   callbackUrl=http://localhost:8080    testid=${testid}   workflow=${workflow}      userId=oof@oof.onap.org
109         ${nodelist}=   Create List   node1   node2   node3   node4
110         ${nn}=    Catenate    1
111     # Support up to 4 ChangeWindows
112     :FOR   ${i}   IN RANGE   1    4
113     \  ${today}=    Evaluate   ((${i}-1)*1440)+${minutesFromNow}
114     \  ${tomorrow}   Evaluate   ${today}+1440
115     \  ${last_time}   Evaluate  ${today}+30
116     \  ${start_time}=    Get Current Date   UTC  + ${today} minutes   result_format=${OOF_CMSO_UTC}
117     \  ${end_time}=    Get Current Date   UTC   + ${tomorrow} minutes   result_format=${OOF_CMSO_UTC}
118     \  Set To Dictionary    ${map}   start_time${i}=${start_time}   end_time${i}=${end_time}
119     ${requestList}=   Create List
120     Templating.Create Environment    oof    ${GLOBAL_TEMPLATE_FOLDER}
121         :FOR   ${vnf}   IN    @{nodelist}
122         \   Set To Dictionary    ${map}   node${nn}   ${vnf}
123         \   ${nn}=   Evaluate    ${nn}+1
124         \   Set To DIctionary   ${dict}   vnfName=${vnf} 
125     \   ${requestInfo}=   Templating.Apply Template    oof    ${OOF_CMSO_TEMPLATE_FOLDER}/VidCallbackData.jinja   ${dict}
126     \   Append To List   ${requestList}   ${requestInfo}
127     ${callBackDataMap}=  Create Dictionary   requestType=Update   requestDetails=${requestList}
128     ${callbackDataString}=   OOF-CMSO Json Escape    ${callbackDataMap}
129     Set To Dictionary   ${map}   callbackData=${callbackDataString}
130     ${data}=   Templating.Apply Template    oof    ${OOF_CMSO_TEMPLATE_FOLDER}/${request_file}   ${map}
131     ${resp}=   Run OOF-CMSO Post Scheduler   cmso/v1/schedules/${uuid}   data=${data}
132     [Return]   ${resp}
133
134 OOF-CMSO Wait For Pending Approval
135      [Documentation]    Gets the schedule identified by the uuid and checks if it is in the Pending Approval state
136      [Arguments]   ${uuid}     ${status}=Pending Approval
137      ${resp}=   Run OOF-CMSO Get Request   cmso/v1/schedules/${uuid}
138      ${json}=   Catenate   ${resp.json()}
139      Dictionary Should Contain Item    ${resp.json()}    status    ${status}
140
141 OOF-CMSO Send Tier2 Approval
142     [Documentation]    Sends an approval post request for the given schedule using the UUID and User given and checks that request worked
143     [Arguments]   ${uuid}   ${user}   ${status}
144     ${approval}=   Create Dictionary   approvalUserId=${user}   approvalType=Tier 2   approvalStatus=${status}
145     ${resp}=   Run OOF-CMSO Post Scheduler   cmso/v1/schedules/${uuid}/approvals   data=${approval}
146     Should Be Equal As Strings    ${resp.status_code}   204
147
148 OOF-CMSO Wait for Schedule to Complete
149     [Arguments]   ${status}   ${uuid}
150     ${resp}=   Run OOF-CMSO Get Request   cmso/v1/schedules/${uuid}
151     Dictionary Should Contain Item   ${resp.json()}   status   Completed
152
153 OOF-CMSO Json Escape
154     [Arguments]    ${json}
155     ${json_string}=    Evaluate    json.dumps(${json})    json
156     ${escaped}=   Replace String    ${json_string}   "   \\"
157     [Return]   ${escaped}
158
159 Run OOF-OSDF Post Request
160     [Documentation]    Runs a scheduler POST request
161     [Arguments]   ${data_path}   ${auth}    ${data}={}     
162
163     ${session}=    Create Session   session   ${OOF_OSDF_ENDPOINT}   auth=${auth}
164     ${headers}=  Create Dictionary   Accept=application/json    Content-Type=application/json
165     ${resp}=    Post Request    session         ${data_path}     headers=${headers}   data=${data}
166     Log    Received response from osdf ${resp.text}
167     [Return]    ${resp}
168
169 Run OOF-OSDF Post Homing
170    [Documentation]    Runs a osdf homing request
171     ${auth}=  Create List  ${GLOBAL_OOF_OSDF_USERNAME}    ${GLOBAL_OOF_OSDF_PASSWORD}
172     ${data}=         Get Binary File     ${OOF_OSDF_TEMPLATE_FOLDER}${/}placement_request.json
173     ${resp}=   Run OOF-OSDF Post Request  /api/oof/placement/v1       auth=${auth}    data=${data}
174     Should Be Equal As Strings    ${resp.status_code}   204
175
176 Run OOF-OSDF Post PCI-OPT
177     [Documentation]    Runs a osdf PCI-OPT request
178     ${auth}=  Create List  ${GLOBAL_OOF_PCI_USERNAME}    ${GLOBAL_OOF_PCI_PASSWORD}
179     ${data}=         Get Binary File     ${OOF_OSDF_TEMPLATE_FOLDER}${/}pci-opt-request.json
180     ${resp}=   Run OOF-OSDF Post Request  /api/oof/pci/v1   auth=${auth}    data=${data}    
181     Should Be Equal As Strings    ${resp.status_code}   204