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