ec67a26703236b99a41ed27eacbf9460850de0bf
[testsuite.git] / robot / resources / oof_interface.robot
1 *** Settings ***
2 Documentation     The main interface for interacting with OOF: OSDF 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_OSDF_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_OSDF_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-OSDF Health Check
63     [Documentation]    Runs OOF-OSDF Health check
64     ${resp}=    Run OOF-OSDF Get Request    ${OOF_OSDF_HEALTH_CHECK_PATH}
65     Should Be Equal As Integers   ${resp.status_code}   200
66
67 Run OOF-OSDF Get Request
68     [Documentation]    Runs OOF-OSDF Get request
69     [Arguments]    ${data_path}
70     ${session}=    Create Session   session   ${OOF_OSDF_ENDPOINT}
71     ${resp}=   Get Request   session   ${data_path}
72     Should Be Equal As Integers   ${resp.status_code}   200
73     Log    Received response from OOF-OSDF ${resp.text}
74     [Return]    ${resp}
75
76 Run OOF-CMSO Health Check
77      [Documentation]    Runs OOF-CMSO Health check
78      ${resp}=    Run OOF-CMSO Get Request    ${OOF_CMSO_HEALTH_CHECK_PATH}
79      Should Be Equal As Integers   ${resp.status_code}   200
80
81 Run OOF-CMSO Get Request
82      [Documentation]    Runs OOF-CMSO Get request
83      [Arguments]    ${data_path}
84      ${auth}=  Create List  ${GLOBAL_OOF_CMSO_USERNAME}    ${GLOBAL_OOF_CMSO_PASSWORD}
85      ${session}=    Create Session   session   ${OOF_CMSO_ENDPOINT}   auth=${auth}
86      ${resp}=   Get Request   session   ${data_path}
87      Should Be Equal As Integers   ${resp.status_code}   200
88      Log    Received response from OOF-CMSO ${resp.text}
89      [Return]    ${resp}
90
91 Run OOF-CMSO Post Scheduler
92     [Documentation]    Runs a scheduler POST request
93     [Arguments]   ${data_path}   ${data}={}
94     ${auth}=  Create List  ${GLOBAL_OOF_CMSO_USERNAME}    ${GLOBAL_OOF_CMSO_PASSWORD}
95     ${session}=    Create Session   session   ${OOF_CMSO_ENDPOINT}   auth=${auth}
96     ${headers}=  Create Dictionary   Accept=application/json    Content-Type=application/json
97     ${resp}=    Post Request    session         ${data_path}     headers=${headers}   data=${data}
98     Log    Received response from scheduler ${resp.text}
99     [Return]    ${resp}
100
101 Run OOF-CMSO Future Schedule
102    [Documentation]   Runs CMSO Future Schedule ETE test. One VNF, One Change Window
103    [Arguments]    ${request_file}=OneVnfOneChangeWindow.jinja   ${workflow}=Replace   ${minutesFromNow}=3
104    ${uuid}=   Generate UUID4
105    ${resp}=   OOF-CMSO Create Schedule   ${uuid}   ${request_file}   workflow=${workflow}   minutesFromNow=${minutesFromNow}
106    Should Be Equal as Strings    ${resp.status_code}    202
107    Wait Until Keyword Succeeds    600s    30s    OOF-CMSO Wait For Pending Approval   ${uuid}
108    OOF-CMSO Send Tier2 Approval   ${uuid}   jf9860    Accepted
109    Wait Until Keyword Succeeds    600s    30s    OOF-CMSO Wait for Schedule to Complete   Completed   ${uuid}
110
111
112 OOF-CMSO Create Schedule
113     [Documentation]   Creates a CMSO future schedule request for the passed template.
114     [Arguments]   ${uuid}   ${request_file}    ${workflow}    ${minutesFromNow}=5
115     ${testid}=   Catenate   ${uuid}
116     ${testid}=   Get Substring   ${testid}   -4
117     ${dict}=   Create Dictionary   serviceInstanceId=${uuid}   parent_service_model_name=${uuid}
118         ${map}=   Create Dictionary   uuid=${uuid}   callbackUrl=http://localhost:8080    testid=${testid}   workflow=${workflow}      userId=oof@oof.onap.org
119         ${nodelist}=   Create List   node1   node2   node3   node4
120         ${nn}=    Catenate    1
121     # Support up to 4 ChangeWindows
122     :FOR   ${i}   IN RANGE   1    4
123     \  ${today}=    Evaluate   ((${i}-1)*1440)+${minutesFromNow}
124     \  ${tomorrow}   Evaluate   ${today}+1440
125     \  ${last_time}   Evaluate  ${today}+30
126     \  ${start_time}=    Get Current Date   UTC  + ${today} minutes   result_format=${OOF_CMSO_UTC}
127     \  ${end_time}=    Get Current Date   UTC   + ${tomorrow} minutes   result_format=${OOF_CMSO_UTC}
128     \  Set To Dictionary    ${map}   start_time${i}=${start_time}   end_time${i}=${end_time}
129     ${requestList}=   Create List
130     Templating.Create Environment    oof    ${GLOBAL_TEMPLATE_FOLDER}
131         :FOR   ${vnf}   IN    @{nodelist}
132         \   Set To Dictionary    ${map}   node${nn}   ${vnf}
133         \   ${nn}=   Evaluate    ${nn}+1
134         \   Set To DIctionary   ${dict}   vnfName=${vnf}
135     \   ${requestInfo}=   Templating.Apply Template    oof    ${OOF_CMSO_TEMPLATE_FOLDER}/VidCallbackData.jinja   ${dict}
136     \   Append To List   ${requestList}   ${requestInfo}
137     ${callBackDataMap}=  Create Dictionary   requestType=Update   requestDetails=${requestList}
138     ${callbackDataString}=   OOF-CMSO Json Escape    ${callbackDataMap}
139     Set To Dictionary   ${map}   callbackData=${callbackDataString}
140     ${data}=   Templating.Apply Template    oof    ${OOF_CMSO_TEMPLATE_FOLDER}/${request_file}   ${map}
141     ${resp}=   Run OOF-CMSO Post Scheduler   cmso/v1/schedules/${uuid}   data=${data}
142     [Return]   ${resp}
143
144 OOF-CMSO Wait For Pending Approval
145      [Documentation]    Gets the schedule identified by the uuid and checks if it is in the Pending Approval state
146      [Arguments]   ${uuid}     ${status}=Pending Approval
147      ${resp}=   Run OOF-CMSO Get Request   cmso/v1/schedules/${uuid}
148      ${json}=   Catenate   ${resp.json()}
149      Dictionary Should Contain Item    ${resp.json()}    status    ${status}
150
151 OOF-CMSO Send Tier2 Approval
152     [Documentation]    Sends an approval post request for the given schedule using the UUID and User given and checks that request worked
153     [Arguments]   ${uuid}   ${user}   ${status}
154     ${approval}=   Create Dictionary   approvalUserId=${user}   approvalType=Tier 2   approvalStatus=${status}
155     ${resp}=   Run OOF-CMSO Post Scheduler   cmso/v1/schedules/${uuid}/approvals   data=${approval}
156     Should Be Equal As Strings    ${resp.status_code}   204
157
158 OOF-CMSO Wait for Schedule to Complete
159     [Arguments]   ${status}   ${uuid}
160     ${resp}=   Run OOF-CMSO Get Request   cmso/v1/schedules/${uuid}
161     Dictionary Should Contain Item   ${resp.json()}   status   Completed
162
163 OOF-CMSO Json Escape
164     [Arguments]    ${json}
165     ${json_string}=    Evaluate    json.dumps(${json})    json
166     ${escaped}=   Replace String    ${json_string}   "   \\"
167     [Return]   ${escaped}
168
169 Run OOF-OSDF Post Request
170     [Documentation]    Runs a scheduler POST request
171     [Arguments]   ${data_path}   ${auth}    ${data}={}
172
173     ${session}=    Create Session   session   ${OOF_OSDF_ENDPOINT}   auth=${auth}
174     ${headers}=  Create Dictionary   Accept=application/json    Content-Type=application/json
175     ${resp}=    Post Request    session         ${data_path}     headers=${headers}   data=${data}
176     Log    Received response from osdf ${resp.text}
177     [Return]    ${resp}
178
179 Run OOF-OSDF Post Homing
180    [Documentation]    Runs a osdf homing request
181     ${auth}=  Create List  ${GLOBAL_OOF_OSDF_USERNAME}    ${GLOBAL_OOF_OSDF_PASSWORD}
182     ${data}=         Get Binary File     ${OOF_OSDF_TEMPLATE_FOLDER}${/}placement_request.json
183     ${resp}=   Run OOF-OSDF Post Request  /api/oof/placement/v1       auth=${auth}    data=${data}
184     Should Be Equal As Strings    ${resp.status_code}   204
185
186 Run OOF-OSDF Post PCI-OPT
187     [Documentation]    Runs a osdf PCI-OPT request
188     ${auth}=  Create List  ${GLOBAL_OOF_PCI_USERNAME}    ${GLOBAL_OOF_PCI_PASSWORD}
189     ${data}=         Get Binary File     ${OOF_OSDF_TEMPLATE_FOLDER}${/}pci-opt-request.json
190     ${resp}=   Run OOF-OSDF Post Request  /api/oof/pci/v1   auth=${auth}    data=${data}
191     Should Be Equal As Strings    ${resp.status_code}   204