Bug 2327 fix to verify ipaddress in sol003_02 testsuite
[osm/tests.git] / robot-systest / testsuite / sol003_01-vnf-lifecycle-management.robot
1 *** Comments ***
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
5 #
6 #       http://www.apache.org/licenses/LICENSE-2.0
7 #
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
13
14
15 *** Settings ***
16 Documentation   [SOL003-01] Sol003 Api testing
17
18 Library   OperatingSystem
19 Library   String
20 Library   Collections
21 Library   RequestsLibrary
22 Library   yaml
23 Library   JsonValidator
24 Library   JSONLibrary
25
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
31
32 Test Tags   sol003_01   cluster_osm_rest   daily   regression
33
34 Suite Teardown   Run Keyword And Ignore Error   Suite Cleanup
35
36
37 *** Variables ***
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
41
42 # NS and VNF descriptor package folder and ids
43 ${VNFD_PKG}   hackfest_basic_metrics_vnf
44 ${VNFD_NAME}   hackfest_basic_metrics-vnf
45
46
47 *** Test Cases ***
48 Create VNF Package From JSON File
49     [Documentation]   Create a VNF package and update it via SOL003 interface using a JSON file
50     Get VNFDs List
51     ${id}=   Create VNFD   '%{PACKAGES_FOLDER}/${VNFD_PKG}'
52     Log   ${id}
53     ${CREATED_VIM_ACCOUNT_ID}=   Get VIM Target ID   %{VIM_TARGET}
54     Set Suite Variable   ${CREATED_VIM_ACCOUNT_ID}
55     Get Auth Token
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]}
70     Get VNFDs List
71
72 Instantiate VNF
73     [Documentation]   Test case to Instantiate a VNF
74     Get Ns List
75     Get Vnf List
76     Get Auth Token
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]}
87     Sleep   12s
88     Get Ns List
89     Get Vnf List
90
91 Query VNF Instances
92     [Documentation]   Test case to query VNF Instance
93     Get Auth Token
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]}
100
101 Query VNF Instance ID
102     [Documentation]   Test case to query Vnf instance ID
103     Get Auth Token
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]}
110
111 Query VNF LCM Ops
112     [Documentation]   Test case to Query VNF LCM operation
113     Get Auth Token
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
118         Log   ${index}
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
122         IF   ${status}
123             BREAK
124         ELSE
125             Sleep   10s
126         END
127     END
128
129 Query VNF LCM Ops ID
130     [Documentation]   Check if the operation has completed.
131     Get Auth Token
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
136         Log   ${index}
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
140         IF   ${status}
141             BREAK
142         ELSE
143             Sleep   10s
144         END
145     END
146
147 Scale VNF
148     [Documentation]   Scale out VNF
149     Get Auth Token
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}
155     ${value}=   Get ID   id
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
162         Log   ${index}
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
166         IF   ${status}
167             BREAK
168         ELSE
169             Sleep   10s
170         END
171     END
172     Pass Execution If   ${request_response.status_code} in ${SUCCESS_STATUS_CODE_LIST}   Scale VNF instance completed
173
174 Terminate VNF
175     [Documentation]   Test case to terminate the VNF
176     Get Auth Token
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
188         Log   ${index}
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
192         IF   ${status}
193             BREAK
194         ELSE
195             Sleep   10s
196         END
197     END
198     Pass Execution If   ${request_response.status_code} in ${SUCCESS_STATUS_CODE_LIST}   Terminate VNF instance completed
199
200 Delete VNF
201     [Documentation]   Delete VNF instance.
202     Get Auth Token
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
207
208 Delete VNF Descriptor Test
209     [Documentation]   Delete VNF package from OSM.
210     [Tags]   cleanup
211     Delete VNFD   ${VNFD_NAME}
212
213
214 *** Keywords ***
215 Suite Cleanup
216     [Documentation]   Test Suit Cleanup: Deleting Descriptor
217     Run Keyword If Any Tests Failed   Delete VNFD   ${VNFD_NAME}