Server list info when waiting NS
[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_max_wait_time}   2min
26 ${vnf_scale_pol_time}   15sec
27 ${vim_timeout_multiplier}   %{OSM_VIM_MULTIPLIER_TIMEOUT=1.0}
28
29
30 *** Keywords ***
31 Create Network Service
32     [Arguments]   ${nsd}   ${vim_name}   ${ns_name}   ${ns_config}   ${publickey}   ${ns_launch_max_wait_time}=5min   ${config_file}=${EMPTY}
33
34     ${ns_launch_max_wait_time}=   Convert Time   ${ns_launch_max_wait_time}   result_format=number
35     ${ns_launch_max_wait_time}=   Evaluate   ${ns_launch_max_wait_time} * ${vim_timeout_multiplier}
36     Log   ${ns_launch_max_wait_time}
37     ${config_attr}   Set Variable If   '${ns_config}'!='${EMPTY}'   --config '${ns_config}'   \
38     ${sshkeys_attr}   Set Variable If   '${publickey}'!='${EMPTY}'   --ssh_keys ${publickey}   \
39     ${config_file_attr}   Set Variable If   '${config_file}'!='${EMPTY}'   --config_file '${config_file}'   \
40
41     ${ns_id}=   Instantiate Network Service   ${ns_name}   ${nsd}   ${vim_name}   ${config_attr} ${sshkeys_attr} ${config_file_attr}
42     log   ${ns_id}
43
44     WAIT UNTIL KEYWORD SUCCEEDS   ${ns_launch_max_wait_time}   ${ns_launch_pol_time}   Check For NS Instance To Configured   ${ns_name}
45     Check For NS Instance For Failure   ${ns_name}
46     [Return]  ${ns_id}
47
48
49 Instantiate Network Service
50     [Arguments]   ${ns_name}   ${nsd}   ${vim_name}   ${ns_extra_args}
51
52     ${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}
53     log   ${stdout}
54     Should Be Equal As Integers   ${rc}   ${success_return_code}
55     [Return]  ${stdout}
56
57
58 Get Vnf Management Ip Address
59     [Arguments]   ${ns_id}   ${vnf_member_index}
60
61     Should Not Be Empty   ${ns_id}
62     Should Not Be Empty   ${vnf_member_index}
63     ${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
64     log   ${stdout}
65     Should Be Equal As Integers   ${rc}   ${success_return_code}
66     [Return]  ${stdout}
67
68
69 Get Vnf Id
70     [Arguments]   ${ns_id}   ${vnf_member_index}
71
72     Should Not Be Empty   ${ns_id}
73     Should Not Be Empty   ${vnf_member_index}
74     ${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
75     log   ${stdout}
76     Should Be Equal As Integers   ${rc}   ${success_return_code}
77     [Return]  ${stdout}
78
79
80 Get Ns Vnf List
81     [Arguments]   ${ns_id}
82
83     Should Not Be Empty   ${ns_id}
84     @{vnf_list_string}=   Run and Return RC and Output   osm vnf-list | grep ${ns_id} | awk '{print $2}' 2>&1
85     # Returns a String of vnf_id and needs to be converted into a list
86     @{vnf_list} =  Split String    ${vnf_list_string}[1]
87     Log List    ${vnf_list}
88     [Return]  @{vnf_list}
89
90
91 Get Ns Ip List
92     [Arguments]   @{vnf_list}
93
94     should not be empty   @{vnf_list}
95     @{temp_list}=    Create List
96     FOR   ${vnf_id}   IN   @{vnf_list}
97         log   ${vnf_id}
98         @{vnf_ip_list}   Get Vnf Ip List   ${vnf_id}
99         @{temp_list}=   Combine Lists   ${temp_list}    ${vnf_ip_list}
100     END
101     should not be empty   ${temp_list}
102     [return]  @{temp_list}
103
104
105 Get Vnf Ip List
106     [arguments]   ${vnf_id}
107
108     should not be empty   ${vnf_id}
109     @{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
110     # returns a string of ip addresses and needs to be converted into a list
111     should not be empty   ${vnf_ip_list_string}[1]
112     @{vnf_ip_list} =  split string    ${vnf_ip_list_string}[1]
113     log list    ${vnf_ip_list}
114     should not be empty   ${vnf_ip_list}
115     [return]  @{vnf_ip_list}
116
117
118 Check For Ns Instance To Configured
119     [arguments]  ${ns_name}
120
121     ${rc}   ${stdout}=   Run and Return RC and Output   openstack server list
122     log   ${stdout}
123     ${rc}   ${stdout}=   run and return rc and output   osm ns-list --filter name="${ns_name}"
124     log   ${stdout}
125     Should Be Equal As Integers   ${rc}   ${success_return_code}
126     Should Contain Any   ${stdout}   READY   BROKEN
127
128 Check For NS Instance For Failure
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 Not Contain   ${stdout}   BROKEN
137
138 Check For NS Instance To Be Deleted
139     [Arguments]  ${ns}
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 | awk '{print $2}' | grep ${ns}
144     Should Not Be Equal As Strings   ${stdout}   ${ns}
145
146 Delete NS
147     [Documentation]   Delete ns
148     [Arguments]   ${ns}   ${ns_delete_max_wait_time}=4min
149
150     ${ns_delete_max_wait_time}=   Convert Time   ${ns_delete_max_wait_time}   result_format=number
151     ${ns_delete_max_wait_time}=   Evaluate   ${ns_delete_max_wait_time} * ${vim_timeout_multiplier}
152     Log   ${ns_delete_max_wait_time}
153     ${rc}   ${stdout}=   Run and Return RC and Output   osm ns-delete ${ns}
154     Log   ${stdout}
155     Should Be Equal As Integers   ${rc}   ${success_return_code}
156
157     WAIT UNTIL KEYWORD SUCCEEDS  ${ns_delete_max_wait_time}   ${ns_delete_pol_time}   Check For NS Instance To Be Deleted   ${ns}
158
159 Execute NS Action
160     [Documentation]     Execute an action over the desired NS.
161     ...                 Parameters are given to this function in key=value format (one argument per key/value pair).
162     ...                 Return the ID of the operation associated to the executed action.
163     ...                 Examples of execution:
164     ...                     \${ns_op_id}=  Execute NS Action  \${ns_name}  \${ns_action}  \${vnf_member_index}
165     ...                     \${ns_op_id}=  Execute NS Action  \${ns_name}  \${ns_action}  \${vnf_member_index}  \${param1}=\${value1}  \${param2}=\${value2}
166
167     [Arguments]  ${ns_name}  ${ns_action}  ${vnf_member_index}  @{action_params}
168
169     ${params}=  Set Variable  ${EMPTY}
170     FOR  ${param}  IN  @{action_params}
171         ${match}  ${param_name}  ${param_value} =  Should Match Regexp  ${param}  (.+)=(.+)  msg=Syntax error in parameters
172         ${params}=  Catenate  SEPARATOR=  ${params}  "${param_name}":"${param_value}",
173     END
174     ${osm_ns_action_command}=  Set Variable  osm ns-action --action_name ${ns_action} --vnf_name ${vnf_member_index}
175     ${osm_ns_action_command}=  Run Keyword If  '${params}'!='${EMPTY}'  Catenate  ${osm_ns_action_command}  --params '{${params}}'
176     ...  ELSE  Set Variable  ${osm_ns_action_command}
177     ${osm_ns_action_command}=  Catenate  ${osm_ns_action_command}  ${ns_name}
178     ${rc}  ${stdout}=  Run and Return RC and Output  ${osm_ns_action_command}
179     Should Be Equal As Integers  ${rc}  ${success_return_code}  msg=${stdout}  values=False
180     Wait Until Keyword Succeeds  ${ns_action_max_wait_time}  ${ns_action_pol_time}  Check For NS Operation Completed  ${stdout}
181     [Return]  ${stdout}
182
183
184 Execute NS K8s Action
185     [Documentation]     Execute an action over the desired K8s NS.
186     ...                 Parameters are given to this function in key=value format (one argument per key/value pair).
187     ...                 Return the ID of the operation associated to the executed action.
188     ...                 Examples of execution:
189     ...                     \${ns_op_id}=  Execute NS Action  \${ns_name}  \${ns_action}  \${vnf_member_index}
190     ...                     \${ns_op_id}=  Execute NS Action  \${ns_name}  \${ns_action}  \${vnf_member_index}  \${param1}=\${value1}  \${param2}=\${value2}
191
192     [Arguments]  ${ns_name}  ${ns_action}  ${vnf_member_index}  ${kdu_name}  @{action_params}
193
194     ${params}=  Set Variable  ${EMPTY}
195     FOR  ${param}  IN  @{action_params}
196         ${match}  ${param_name}  ${param_value} =  Should Match Regexp  ${param}  (.+)=(.+)  msg=Syntax error in parameters
197         ${params}=  Catenate  SEPARATOR=  ${params}  "${param_name}":"${param_value}",
198     END
199     ${osm_ns_action_command}=  Set Variable  osm ns-action --action_name ${ns_action} --vnf_name ${vnf_member_index} --kdu_name ${kdu_name}
200     ${osm_ns_action_command}=  Run Keyword If  '${params}'!='${EMPTY}'  Catenate  ${osm_ns_action_command}  --params '{${params}}'
201     ...  ELSE  Set Variable  ${osm_ns_action_command}
202     ${osm_ns_action_command}=  Catenate  ${osm_ns_action_command}  ${ns_name}
203     ${rc}  ${stdout}=  Run and Return RC and Output  ${osm_ns_action_command}
204     Should Be Equal As Integers  ${rc}  ${success_return_code}  msg=${stdout}  values=False
205     Wait Until Keyword Succeeds  ${ns_action_max_wait_time}  ${ns_action_pol_time}  Check For NS Operation Completed  ${stdout}
206     [Return]  ${stdout}
207
208
209 Execute Manual VNF Scale
210     [Documentation]     Execute a manual VNF Scale action.
211     ...                 The parameter 'scale_type' must be SCALE_IN or SCALE_OUT.
212     ...                 Return the ID of the operation associated to the executed scale action.
213
214     [Arguments]  ${ns_name}  ${vnf_member_index}  ${scaling_group}  ${scale_type}
215
216     Should Contain Any  ${scale_type}  SCALE_IN  SCALE_OUT  msg=Unknown scale type: ${scale_type}  values=False
217     ${osm_vnf_scale_command}=  Set Variable  osm vnf-scale --scaling-group ${scaling_group}
218     ${osm_vnf_scale_command}=  Run Keyword If  '${scale_type}'=='SCALE_IN'  Catenate  ${osm_vnf_scale_command}  --scale-in
219     ...  ELSE  Catenate  ${osm_vnf_scale_command}  --scale-out
220     ${osm_vnf_scale_command}=  Catenate  ${osm_vnf_scale_command}  ${ns_name}  ${vnf_member_index}
221     ${rc}  ${stdout}=  Run and Return RC and Output  ${osm_vnf_scale_command}
222     Should Be Equal As Integers  ${rc}  ${success_return_code}  msg=${stdout}  values=False
223     Wait Until Keyword Succeeds  ${vnf_scale_max_wait_time}  ${vnf_scale_pol_time}  Check For NS Operation Completed  ${stdout}
224     [Return]  ${stdout}
225
226
227 Get Operations List
228     [Arguments]  ${ns_name}
229
230     ${rc}  ${stdout}=  Run and Return RC and Output  osm ns-op-list ${ns_name}
231     log  ${stdout}
232     log  ${rc}
233     Should Be Equal As Integers  ${rc}  ${success_return_code}
234
235
236 Check For NS Operation Completed
237     [Documentation]     Check wheter the status of the desired operation is "COMPLETED" or not.
238
239     [Arguments]  ${ns_operation_id}
240
241     ${rc}  ${stdout}=  Run and Return RC and Output  osm ns-op-show ${ns_operation_id} --literal | yq .operationState | tr -d \\"
242     log  ${stdout}
243     Should Be Equal As Integers  ${rc}  ${success_return_code}
244     Should Contain  ${stdout}  COMPLETED  msg=Timeout waiting for ns-action with id ${ns_operation_id}  values=False
245
246
247 Get Ns Vnfr Ids
248     [Documentation]     Return a list with the IDs of the VNF records of a NS instance.
249
250     [Arguments]  ${ns_id}
251
252     ${rc}  ${stdout}=  Run and Return RC and Output  osm vnf-list | grep ${ns_id} | awk '{print $2}' 2>&1
253     Should Be Equal As Integers  ${rc}  ${success_return_code}  msg=${stdout}  values=False
254     @{vdur} =  Split String  ${stdout}
255     [Return]  @{vdur}
256
257
258 Get Vnf Vdur Names
259     [Documentation]     Return a list with the names of the VDU records of a VNF instance.
260
261     [Arguments]  ${vnf_id}
262
263     ${rc}  ${stdout}=  Run and Return RC and Output  osm vnf-show ${vnf_id} --literal | yq .vdur[].name | tr -d \\"
264     Should Be Equal As Integers  ${rc}  ${success_return_code}  msg=${stdout}  values=False
265     @{vdur} =  Split String  ${stdout}
266     [Return]  @{vdur}
267
268
269 Get Vnf Kdu Replica Count
270     [Documentation]     Return the number of KDU replicas (empty if none) of a VNF instance.
271
272     [Arguments]   ${vnf_id}   ${kdu_name}
273
274     ${rc}  ${stdout}=  Run and Return RC and Output  osm vnf-show ${vnf_id} --kdu ${kdu_name} | yq .config.replicaCount | tr -d \\"
275     Should Be Equal As Integers  ${rc}  ${success_return_code}  msg=${stdout}  values=False
276     ${return} =   Set Variable If   '${stdout}' == 'null'   ${EMPTY}    ${stdout}
277     [Return]  ${return}
278