Fix bug 1931: adds missing parameter
[osm/tests.git] / robot-systest / lib / ns_lib.robot
1 #   Licensed under the Apache License, Version 2.0 (the "License");
2 #   you may not use this file except in compliance with the License.
3 #   You may obtain a copy of the License at
4 #
5 #       http://www.apache.org/licenses/LICENSE-2.0
6 #
7 #   Unless required by applicable law or agreed to in writing, software
8 #   distributed under the License is distributed on an "AS IS" BASIS,
9 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 #   See the License for the specific language governing permissions and
11 #   limitations under the License.
12
13 *** Settings ***
14 Documentation     Library to deploy and delete NS, and run operations on them.
15
16 Library   DateTime
17
18
19 *** Variables ***
20 ${success_return_code}   0
21 ${ns_launch_pol_time}   30sec
22 ${ns_delete_pol_time}   15sec
23 ${ns_action_max_wait_time}   1min
24 ${ns_action_pol_time}   15sec
25 ${vnf_scale_pol_time}   15sec
26 ${vim_timeout_multiplier}   %{OSM_VIM_MULTIPLIER_TIMEOUT=1.0}
27
28
29 *** Keywords ***
30 Create Network Service
31     [Arguments]   ${nsd}   ${vim_name}   ${ns_name}   ${ns_config}   ${publickey}   ${ns_launch_max_wait_time}=5min   ${config_file}=${EMPTY}
32
33     ${ns_launch_max_wait_time}=   Convert Time   ${ns_launch_max_wait_time}   result_format=number
34     ${ns_launch_max_wait_time}=   Evaluate   ${ns_launch_max_wait_time} * ${vim_timeout_multiplier}
35     Log   ${ns_launch_max_wait_time}
36     ${config_attr}   Set Variable If   '${ns_config}'!='${EMPTY}'   --config '${ns_config}'   \
37     ${sshkeys_attr}   Set Variable If   '${publickey}'!='${EMPTY}'   --ssh_keys ${publickey}   \
38     ${config_file_attr}   Set Variable If   '${config_file}'!='${EMPTY}'   --config_file '${config_file}'   \
39
40     ${ns_id}=   Instantiate Network Service   ${ns_name}   ${nsd}   ${vim_name}   ${config_attr} ${sshkeys_attr} ${config_file_attr}
41     log   ${ns_id}
42
43     WAIT UNTIL KEYWORD SUCCEEDS   ${ns_launch_max_wait_time}   ${ns_launch_pol_time}   Check For NS Instance To Configured   ${ns_name}
44     Check For NS Instance For Failure   ${ns_name}
45     [Return]  ${ns_id}
46
47
48 Instantiate Network Service
49     [Arguments]   ${ns_name}   ${nsd}   ${vim_name}   ${ns_extra_args}
50
51     ${rc}   ${stdout}=   Run and Return RC and Output   osm ns-create --ns_name ${ns_name} --nsd_name ${nsd} --vim_account ${vim_name} ${ns_extra_args}
52     log   ${stdout}
53     Should Be Equal As Integers   ${rc}   ${success_return_code}
54     [Return]  ${stdout}
55
56
57 Get Vnf Management Ip Address
58     [Arguments]   ${ns_id}   ${vnf_member_index}
59
60     Should Not Be Empty   ${ns_id}
61     Should Not Be Empty   ${vnf_member_index}
62     ${rc}   ${stdout}=   Run and Return RC and Output   osm vnf-list --filter member-vnf-index-ref=${vnf_member_index} | grep ${ns_id} | awk '{print $14}' 2>&1
63     log   ${stdout}
64     Should Be Equal As Integers   ${rc}   ${success_return_code}
65     [Return]  ${stdout}
66
67
68 Get Vnf Id
69     [Arguments]   ${ns_id}   ${vnf_member_index}
70
71     Should Not Be Empty   ${ns_id}
72     Should Not Be Empty   ${vnf_member_index}
73     ${rc}   ${stdout}=   Run and Return RC and Output   osm vnf-list --filter member-vnf-index-ref=${vnf_member_index} | grep ${ns_id} | awk '{print $2}' 2>&1
74     log   ${stdout}
75     Should Be Equal As Integers   ${rc}   ${success_return_code}
76     [Return]  ${stdout}
77
78
79 Get Ns Id
80     [Arguments]   ${ns_name}
81
82     Should Not Be Empty   ${ns_name}
83     ${rc}   ${stdout}=   Run and Return RC and Output   osm ns-list | grep ${ns_name} | awk '{print $4}' 2>&1
84     log   ${stdout}
85     Should Be Equal As Integers   ${rc}   ${success_return_code}
86     Should Not Be Empty   ${stdout}
87     [Return]   ${stdout}
88
89
90 Get Ns Vnf List
91     [Arguments]   ${ns_id}
92
93     Should Not Be Empty   ${ns_id}
94     @{vnf_list_string}=   Run and Return RC and Output   osm vnf-list | grep ${ns_id} | awk '{print $2}' 2>&1
95     # Returns a String of vnf_id and needs to be converted into a list
96     @{vnf_list} =  Split String    ${vnf_list_string}[1]
97     Log List    ${vnf_list}
98     [Return]  @{vnf_list}
99
100
101 Get Ns Ip List
102     [Arguments]   @{vnf_list}
103
104     should not be empty   @{vnf_list}
105     @{temp_list}=    Create List
106     FOR   ${vnf_id}   IN   @{vnf_list}
107         log   ${vnf_id}
108         @{vnf_ip_list}   Get Vnf Ip List   ${vnf_id}
109         @{temp_list}=   Combine Lists   ${temp_list}    ${vnf_ip_list}
110     END
111     should not be empty   ${temp_list}
112     [return]  @{temp_list}
113
114
115 Get Vnf Ip List
116     [arguments]   ${vnf_id}
117
118     should not be empty   ${vnf_id}
119     @{vnf_ip_list_string}=   run and return rc and output   osm vnf-list --filter id=${vnf_id} | grep -o '[0-9]\\{1,3\\}\\.[0-9]\\{1,3\\}\\.[0-9]\\{1,3\\}\\.[0-9]\\{1,3\\}' | sort -t: -u -k1,1 2>&1
120     # returns a string of ip addresses and needs to be converted into a list
121     should not be empty   ${vnf_ip_list_string}[1]
122     @{vnf_ip_list} =  split string    ${vnf_ip_list_string}[1]
123     log list    ${vnf_ip_list}
124     should not be empty   ${vnf_ip_list}
125     [return]  @{vnf_ip_list}
126
127
128 Check For Ns Instance To Configured
129     [arguments]  ${ns_name}
130
131     ${rc}   ${stdout}=   Run and Return RC and Output   openstack server list
132     log   ${stdout}
133     ${rc}   ${stdout}=   run and return rc and output   osm ns-list --filter name="${ns_name}"
134     log   ${stdout}
135     Should Be Equal As Integers   ${rc}   ${success_return_code}
136     Should Contain Any   ${stdout}   READY   BROKEN
137
138 Check For NS Instance For Failure
139     [Arguments]  ${ns_name}
140
141     ${rc}   ${stdout}=   Run and Return RC and Output   openstack server list
142     log   ${stdout}
143     ${rc}   ${stdout}=   Run and Return RC and Output   osm ns-list --filter name="${ns_name}"
144     log   ${stdout}
145     Should Be Equal As Integers   ${rc}   ${success_return_code}
146     Should Not Contain   ${stdout}   BROKEN
147
148 Check For NS Instance To Be Deleted
149     [Arguments]  ${ns}
150
151     ${rc}   ${stdout}=   Run and Return RC and Output   openstack server list
152     log   ${stdout}
153     ${rc}   ${stdout}=   Run and Return RC and Output   osm ns-list | awk '{print $2}' | grep ${ns}
154     Should Not Be Equal As Strings   ${stdout}   ${ns}
155
156 Delete NS
157     [Documentation]   Delete ns
158     [Arguments]   ${ns}   ${ns_delete_max_wait_time}=4min
159
160     ${ns_delete_max_wait_time}=   Convert Time   ${ns_delete_max_wait_time}   result_format=number
161     ${ns_delete_max_wait_time}=   Evaluate   ${ns_delete_max_wait_time} * ${vim_timeout_multiplier}
162     Log   ${ns_delete_max_wait_time}
163     ${rc}   ${stdout}=   Run and Return RC and Output   osm ns-delete ${ns}
164     Log   ${stdout}
165     Should Be Equal As Integers   ${rc}   ${success_return_code}
166
167     WAIT UNTIL KEYWORD SUCCEEDS  ${ns_delete_max_wait_time}   ${ns_delete_pol_time}   Check For NS Instance To Be Deleted   ${ns}
168
169 Execute NS Action
170     [Documentation]     Execute an action over the desired NS.
171     ...                 Parameters are given to this function in key=value format (one argument per key/value pair).
172     ...                 Return the ID of the operation associated to the executed action.
173     ...                 Examples of execution:
174     ...                     \${ns_op_id}=  Execute NS Action  \${ns_name}  \${ns_action}  \${vnf_member_index}
175     ...                     \${ns_op_id}=  Execute NS Action  \${ns_name}  \${ns_action}  \${vnf_member_index}  \${param1}=\${value1}  \${param2}=\${value2}
176
177     [Arguments]  ${ns_name}  ${ns_action}  ${vnf_member_index}  @{action_params}
178
179     ${params}=  Set Variable  ${EMPTY}
180     FOR  ${param}  IN  @{action_params}
181         ${match}  ${param_name}  ${param_value} =  Should Match Regexp  ${param}  (.+)=(.+)  msg=Syntax error in parameters
182         ${params}=  Catenate  SEPARATOR=  ${params}  "${param_name}":"${param_value}",
183     END
184     ${osm_ns_action_command}=  Set Variable  osm ns-action --action_name ${ns_action} --vnf_name ${vnf_member_index}
185     ${osm_ns_action_command}=  Run Keyword If  '${params}'!='${EMPTY}'  Catenate  ${osm_ns_action_command}  --params '{${params}}'
186     ...  ELSE  Set Variable  ${osm_ns_action_command}
187     ${osm_ns_action_command}=  Catenate  ${osm_ns_action_command}  ${ns_name}
188     ${rc}  ${stdout}=  Run and Return RC and Output  ${osm_ns_action_command}
189     Should Be Equal As Integers  ${rc}  ${success_return_code}  msg=${stdout}  values=False
190     Wait Until Keyword Succeeds  ${ns_action_max_wait_time}  ${ns_action_pol_time}  Check For NS Operation Completed  ${stdout}
191     [Return]  ${stdout}
192
193
194 Execute NS K8s Action
195     [Documentation]     Execute an action over the desired K8s NS.
196     ...                 Parameters are given to this function in key=value format (one argument per key/value pair).
197     ...                 Return the ID of the operation associated to the executed action.
198     ...                 Examples of execution:
199     ...                     \${ns_op_id}=  Execute NS Action  \${ns_name}  \${ns_action}  \${vnf_member_index}
200     ...                     \${ns_op_id}=  Execute NS Action  \${ns_name}  \${ns_action}  \${vnf_member_index}  \${param1}=\${value1}  \${param2}=\${value2}
201
202     [Arguments]  ${ns_name}  ${ns_action}  ${vnf_member_index}  ${kdu_name}  @{action_params}
203
204     ${params}=  Set Variable  ${EMPTY}
205     FOR  ${param}  IN  @{action_params}
206         ${match}  ${param_name}  ${param_value} =  Should Match Regexp  ${param}  (.+)=(.+)  msg=Syntax error in parameters
207         ${params}=  Catenate  SEPARATOR=  ${params}  "${param_name}":"${param_value}",
208     END
209     ${osm_ns_action_command}=  Set Variable  osm ns-action --action_name ${ns_action} --vnf_name ${vnf_member_index} --kdu_name ${kdu_name}
210     ${osm_ns_action_command}=  Run Keyword If  '${params}'!='${EMPTY}'  Catenate  ${osm_ns_action_command}  --params '{${params}}'
211     ...  ELSE  Set Variable  ${osm_ns_action_command}
212     ${osm_ns_action_command}=  Catenate  ${osm_ns_action_command}  ${ns_name}
213     ${rc}  ${stdout}=  Run and Return RC and Output  ${osm_ns_action_command}
214     Should Be Equal As Integers  ${rc}  ${success_return_code}  msg=${stdout}  values=False
215     Wait Until Keyword Succeeds  ${ns_action_max_wait_time}  ${ns_action_pol_time}  Check For NS Operation Completed  ${stdout}
216     [Return]  ${stdout}
217
218
219 Execute Manual VNF Scale
220     [Documentation]     Execute a manual VNF Scale action.
221     ...                 The parameter 'scale_type' must be SCALE_IN or SCALE_OUT.
222     ...                 Return the ID of the operation associated to the executed scale action.
223
224     [Arguments]   ${ns_name}   ${vnf_member_index}   ${scaling_group}   ${scale_type}   ${vnf_scale_max_wait_time}=2min
225
226     ${vnf_scale_max_wait_time}=   Convert Time   ${vnf_scale_max_wait_time}   result_format=number
227     ${vnf_scale_max_wait_time}=   Evaluate   ${vnf_scale_max_wait_time} * ${vim_timeout_multiplier}
228     Should Contain Any  ${scale_type}  SCALE_IN  SCALE_OUT  msg=Unknown scale type: ${scale_type}  values=False
229     ${osm_vnf_scale_command}=  Set Variable  osm vnf-scale --scaling-group ${scaling_group}
230     ${osm_vnf_scale_command}=  Run Keyword If  '${scale_type}'=='SCALE_IN'  Catenate  ${osm_vnf_scale_command}  --scale-in
231     ...  ELSE  Catenate  ${osm_vnf_scale_command}  --scale-out
232     ${osm_vnf_scale_command}=  Catenate  ${osm_vnf_scale_command}  ${ns_name}  ${vnf_member_index}
233     ${rc}  ${stdout}=  Run and Return RC and Output  ${osm_vnf_scale_command}
234     Should Be Equal As Integers  ${rc}  ${success_return_code}  msg=${stdout}  values=False
235     Wait Until Keyword Succeeds  ${vnf_scale_max_wait_time}  ${vnf_scale_pol_time}  Check For NS Operation Completed  ${stdout}
236     [Return]  ${stdout}
237
238
239 Get Operations List
240     [Arguments]  ${ns_name}
241
242     ${rc}  ${stdout}=  Run and Return RC and Output  osm ns-op-list ${ns_name}
243     log  ${stdout}
244     log  ${rc}
245     Should Be Equal As Integers  ${rc}  ${success_return_code}
246
247
248 Check For NS Operation Completed
249     [Documentation]     Check wheter the status of the desired operation is "COMPLETED" or not.
250
251     [Arguments]  ${ns_operation_id}
252
253     ${rc}  ${stdout}=  Run and Return RC and Output  osm ns-op-show ${ns_operation_id} --literal | yq .operationState | tr -d \\"
254     log  ${stdout}
255     Should Be Equal As Integers  ${rc}  ${success_return_code}
256     Should Contain  ${stdout}  COMPLETED  msg=Timeout waiting for ns-action with id ${ns_operation_id}  values=False
257
258
259 Get Ns Vnfr Ids
260     [Documentation]     Return a list with the IDs of the VNF records of a NS instance.
261
262     [Arguments]  ${ns_id}
263
264     ${rc}  ${stdout}=  Run and Return RC and Output  osm vnf-list | grep ${ns_id} | awk '{print $2}' 2>&1
265     Should Be Equal As Integers  ${rc}  ${success_return_code}  msg=${stdout}  values=False
266     @{vdur} =  Split String  ${stdout}
267     [Return]  @{vdur}
268
269
270 Get Vnf Vdur Names
271     [Documentation]     Return a list with the names of the VDU records of a VNF instance.
272
273     [Arguments]  ${vnf_id}
274
275     ${rc}  ${stdout}=  Run and Return RC and Output  osm vnf-show ${vnf_id} --literal | yq .vdur[].name | tr -d \\"
276     Should Be Equal As Integers  ${rc}  ${success_return_code}  msg=${stdout}  values=False
277     @{vdur} =  Split String  ${stdout}
278     [Return]  @{vdur}
279
280
281 Get Vnf Kdu Replica Count
282     [Documentation]     Return the number of KDU replicas (empty if none) of a VNF instance.
283
284     [Arguments]   ${vnf_id}   ${kdu_name}
285
286     ${rc}  ${stdout}=  Run and Return RC and Output  osm vnf-show ${vnf_id} --kdu ${kdu_name} | yq .config.replicaCount | tr -d \\"
287     Should Be Equal As Integers  ${rc}  ${success_return_code}  msg=${stdout}  values=False
288     ${return} =   Set Variable If   '${stdout}' == 'null'   ${EMPTY}    ${stdout}
289     [Return]  ${return}
290
291
292 Get Application Names
293     [Documentation]    Return the list of the application of a VNF instance.
294
295     [Arguments]   ${ns_name}
296
297     ${rc}  ${stdout}=  Run and Return RC and Output  osm ns-show ${ns_name} --literal | yq ._admin.deployed.VCA[].application | tr -d \\"
298     Should Be Equal As Integers  ${rc}  ${success_return_code}  msg=${stdout}  values=False
299     @{app_names} =  Split String  ${stdout}
300     [Return]  ${app_names}
301
302
303 Get VDU Affinity Group Name
304     [Documentation]   Return the affinity group name for a NF
305
306     [Arguments]   ${ns_name}   ${vnf_id}   ${vdur_id}
307
308     ${rc}   ${affinity_group_id}=   Run and Return RC and Output   osm vnf-show ${vnf_id} --literal | yq '.vdur[] | select(.id == "'${vdur_id}'")' | yq '."affinity-or-anti-affinity-group-id"[0]' | tr -d \\" 2>&1
309     log   ${affinity_group_id}
310     Should Be Equal As Integers   ${rc}   ${success_return_code}   msg=${affinity_group_id}   values=False
311     ${rc}   ${affinity_group_name}=   Run and Return RC and Output   osm ns-show ${ns_name} --literal | yq '."affinity-or-anti-affinity-group"[] | select(.id == "'${affinity_group_id}'")' | yq '.name' | tr -d \\" 2>&1
312     log   ${affinity_group_name}
313     Should Be Equal As Integers   ${rc}   ${success_return_code}   msg=${affinity_group_name}   values=False
314     [Return]   ${affinity_group_name}
315
316
317 Get Vnf Namespace
318     [Documentation]    Return the KDU's namespace
319
320     [Arguments]   ${vnf_id}
321
322     ${rc}  ${stdout}=  Run and Return RC and Output  osm vnf-show ${vnf_id} --literal | yq '.kdur[]."k8s-namespace"' | tr -d \\"
323     Should Be Equal As Integers  ${rc}  ${success_return_code}  msg=${stdout}  values=False
324     Should Not Be Empty   ${stdout}
325     log  namespace: ${stdout}
326     [Return]  ${stdout}