2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at
6 # http://www.apache.org/licenses/LICENSE-2.0
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License
16 Documentation [SOL003-01] Sol003 Api testing
18 Library OperatingSystem
21 Library RequestsLibrary
26 Resource ../lib/rest_lib.resource
27 Resource ../lib/vnfd_lib.resource
28 Resource ../lib/ns_lib.resource
29 Resource ../lib/vnf_lib.resource
30 Resource ../lib/vim_lib.resource
32 Test Tags sol003_01 cluster_osm_rest daily regression
34 Suite Teardown Run Keyword And Ignore Error Suite Cleanup
38 # SOL003 API URI paths
39 ${VNF_INSTANCE_URI} /osm/vnflcm/v1/vnf_instances
40 ${VNF_INSTANCE_LCM_OPS} /osm/vnflcm/v1/vnf_lcm_op_occs
42 # NS and VNF descriptor package folder and ids
43 ${VNFD_PKG} hackfest_basic_metrics_vnf
44 ${VNFD_NAME} hackfest_basic_metrics-vnf
48 Create VNF Package From JSON File
49 [Documentation] Create a VNF package and update it via SOL003 interface using a JSON file
51 ${id}= Create VNFD '%{PACKAGES_FOLDER}/${VNFD_PKG}'
53 ${CREATED_VIM_ACCOUNT_ID}= Get VIM Target ID %{VIM_TARGET}
54 Set Suite Variable ${CREATED_VIM_ACCOUNT_ID}
56 ${json_path}= Read Directory
57 ${json_obj}= Load JSON From File ${json_path}/sol003_01-vnf-lifecycle-management.json
58 ${json_obj}= Get Variable Value ${json_obj['data'][0]}
59 ${UPDATED_JSON_OBJ}= JSONLibrary.Update Value To Json ${json_obj} $..vimAccountId ${CREATED_VIM_ACCOUNT_ID}
60 Log ${UPDATED_JSON_OBJ}
61 ${UPDATED_JSON_OBJ}= JSONLibrary.Update Value To Json ${UPDATED_JSON_OBJ} $..additionalParams.virtual-link-desc[0][id] %{VIM_MGMT_NET}
62 Log ${UPDATED_JSON_OBJ}
63 ${UPDATED_JSON_OBJ}= JSONLibrary.Update Value To Json ${UPDATED_JSON_OBJ} $..additionalParams.virtual-link-profile-id %{VIM_MGMT_NET}
64 Log ${UPDATED_JSON_OBJ}
65 Set Test Variable ${UPDATED_JSON_OBJ}
66 Post Api Request ${VNF_INSTANCE_URI} ${UPDATED_JSON_OBJ}
67 Pass Execution If ${request_response.status_code} in ${SUCCESS_STATUS_CODE_LIST} Query VNF Instance completed
68 ${id}= Get Value From Json ${request_response.json()} $..id
69 Set Suite Variable ${CREATEID} ${id[0]}
73 [Documentation] Test case to Instantiate a VNF
77 ${json_path}= Read Directory
78 ${json_obj}= Load JSON From File ${json_path}/sol003_01-vnf-lifecycle-management.json
79 ${json_obj}= Get Variable Value ${json_obj['data'][1]}
80 ${UPDATED_JSON_OBJ}= JSONLibrary.Update Value To Json ${json_obj} $..vimAccountId ${CREATED_VIM_ACCOUNT_ID}
81 ${UPDATED_JSON_OBJ}= JSONLibrary.Update Value To Json ${UPDATED_JSON_OBJ} $..vnfId ${CREATEID}
82 Set Test Variable ${UPDATED_JSON_OBJ}
83 Post Api Request ${VNF_INSTANCE_URI}/${CREATEID}/instantiate ${UPDATED_JSON_OBJ}
84 Pass Execution If ${request_response.status_code} in ${SUCCESS_STATUS_CODE_LIST} Instantiate VNF Instance completed
85 ${id}= Get Value From Json ${request_response.json()} $..id
86 Set Suite Variable ${INSTANTIATEID} ${id[0]}
92 [Documentation] Test case to query VNF Instance
94 Get Api Request ${VNF_INSTANCE_URI}
95 ${value}= Get ID nsState
96 Should Be Equal ${value} INSTANTIATED
97 Pass Execution If ${request_response.status_code} in ${SUCCESS_STATUS_CODE_LIST} Query VNF Instance completed
98 ${id}= Get Value From Json ${request_response.json()} $.._id
99 Set Suite Variable ${QUERYID} ${id[0]}
101 Query VNF Instance ID
102 [Documentation] Test case to query Vnf instance ID
104 Get Api Request ${VNF_INSTANCE_URI}/${QUERYID}
105 ${value}= Get ID nsState
106 Should Be Equal ${value} INSTANTIATED
107 Should Be Equal As Strings ${RequestResponse.status_code} 200
108 ${id}= Get Value From Json ${request_response.json()} $.._id
109 Set Suite Variable ${INSTANCEID} ${id[0]}
112 [Documentation] Test case to Query VNF LCM operation
114 Get Api Request ${VNF_INSTANCE_LCM_OPS}
115 ${id1}= Get Value From Json ${request_response.json()} $.._id
116 Set Suite Variable ${LCMOPS} ${id1[0]}
117 FOR ${index} IN RANGE 0 15
119 Get Api Request ${VNF_INSTANCE_LCM_OPS}
120 ${value}= Get ID operationState
121 ${status}= Run Keyword And Return Status Should Be Equal ${value} COMPLETED
130 [Documentation] Check if the operation has completed.
132 Get Api Request ${VNF_INSTANCE_LCM_OPS}/${LCMOPS}
133 ${id1}= Get Value From Json ${request_response.json()} $.._id
134 Set Suite Variable ${LCMOPSID} ${id1[0]}
135 FOR ${index} IN RANGE 0 15
137 Get Api Request ${VNF_INSTANCE_LCM_OPS}/${LCMOPS}
138 ${value}= Get ID operationState
139 ${status}= Run Keyword And Return Status Should Be Equal ${value} COMPLETED
148 [Documentation] Scale out VNF
150 ${json_path}= Read Directory
151 ${updated_json_obj}= Load JSON From File ${json_path}/sol003_01-vnf-lifecycle-management.json
152 ${updated_json_obj}= Get Variable Value ${UPDATED_JSON_OBJ['data'][2]}
153 Set Test Variable ${UPDATED_JSON_OBJ}
154 Post Api Request ${VNF_INSTANCE_URI}/${CREATEID}/scale ${UPDATED_JSON_OBJ}
156 ${id1}= Get Value From Json ${request_response.json()} $..id
157 Set Suite Variable ${SCALEOUTID} ${id1[0]}
158 Get Api Request ${VNF_INSTANCE_LCM_OPS}/${SCALEOUTID}
159 ${LcmopsScale}= Get Value From Json ${request_response.json()} $.._id
160 Set Suite Variable ${LCMOPSSCALEID} ${LcmopsScale[0]}
161 FOR ${index} IN RANGE 0 15
163 Get Api Request ${VNF_INSTANCE_LCM_OPS}/${SCALEOUTID}
164 ${value}= Get ID operationState
165 ${status}= Run Keyword And Return Status Should Be Equal ${value} COMPLETED
172 Pass Execution If ${request_response.status_code} in ${SUCCESS_STATUS_CODE_LIST} Scale VNF instance completed
175 [Documentation] Test case to terminate the VNF
177 ${json_path}= Read Directory
178 ${updated_json_obj}= Load JSON From File ${json_path}/sol003_01-vnf-lifecycle-management.json
179 ${updated_json_obj}= Get Variable Value ${UPDATED_JSON_OBJ['data'][3]}
180 Set Suite Variable ${UPDATED_JSON_OBJ}
181 Post Api Request ${VNF_INSTANCE_URI}/${CREATEID}/terminate ${UPDATED_JSON_OBJ}
182 ${id}= Get Value From Json ${request_response.json()} $..id
183 Set Suite Variable ${TERMINATEID} ${id[0]}
184 Get Api Request ${VNF_INSTANCE_LCM_OPS}/${TERMINATEID}
185 ${LcmopsTerminate}= Get Value From Json ${request_response.json()} $.._id
186 Set Suite Variable ${LCMOPSSCALEID} ${LcmopsTerminate[0]}
187 FOR ${index} IN RANGE 0 15
189 Get Api Request ${VNF_INSTANCE_LCM_OPS}/${TERMINATEID}
190 ${value}= Get ID operationState
191 ${status}= Run Keyword And Return Status Should Be Equal ${value} COMPLETED
198 Pass Execution If ${request_response.status_code} in ${SUCCESS_STATUS_CODE_LIST} Terminate VNF instance completed
201 [Documentation] Delete VNF instance.
203 Create Session APISession ${REST_API_HOST}
204 &{Headers}= Create Dictionary Content-Type=application/json Accept=application/json Authorization=Bearer ${ACCESS_TOKEN}
205 ${resp}= DELETE On Session APISession ${VNF_INSTANCE_URI}/${CREATEID} headers=${Headers}
206 Pass Execution If ${resp.status_code} in ${SUCCESS_STATUS_CODE_LIST} Delete VNF Instance completed
208 Delete VNF Descriptor Test
209 [Documentation] Delete VNF package from OSM.
211 Delete VNFD ${VNFD_NAME}
216 [Documentation] Test Suit Cleanup: Deleting Descriptor
217 Run Keyword If Any Tests Failed Delete VNFD ${VNFD_NAME}