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 Library to deploy and delete NS, and run operations on them.
20 Library OperatingSystem
25 ${SUCCESS_RETURN_CODE} 0
26 ${NS_LAUNCH_POL_TIME} 30sec
27 ${NS_DELETE_POL_TIME} 15sec
28 ${VIM_TIMEOUT_MULTIPLIER} %{OSM_VIM_MULTIPLIER_TIMEOUT=1.0}
32 Create Network Service
33 [Documentation] Launch the instantation of a NS and verify in a loop that the NS instance is successfully created in a given time, and return the NS instance id.
34 [Arguments] ${nsd} ${vim_name} ${ns_name} ${ns_config} ${publickey} ${ns_launch_max_wait_time}=5min ${config_file}=${EMPTY}
35 ${ns_launch_max_wait_time}= Convert Time ${ns_launch_max_wait_time} result_format=number
36 ${ns_launch_max_wait_time}= Evaluate ${ns_launch_max_wait_time} * ${VIM_TIMEOUT_MULTIPLIER}
37 Log ${ns_launch_max_wait_time}
38 ${config_attr}= Set Variable If '${ns_config}'!='${EMPTY}' --config '${ns_config}' ${EMPTY}
39 ${sshkeys_attr}= Set Variable If '${publickey}'!='${EMPTY}' --ssh_keys ${publickey} ${EMPTY}
40 ${config_file_attr}= Set Variable If '${config_file}'!='${EMPTY}' --config_file '${config_file}' ${EMPTY}
41 ${ns_id}= Instantiate Network Service ${ns_name} ${nsd} ${vim_name} ${config_attr} ${sshkeys_attr} ${config_file_attr}
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}
47 Instantiate Network Service
48 [Documentation] Launch the instantation of a NS, and return the NS instance id.
49 [Arguments] ${ns_name} ${nsd} ${vim_name} ${ns_extra_args}
50 ${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 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
55 Get Vnf Management Ip Address
56 [Documentation] Get the mgmt IP address of a member VNF in a NS instance, and return it.
57 [Arguments] ${ns_id} ${vnf_member_index}
58 Should Not Be Empty ${ns_id}
59 Should Not Be Empty ${vnf_member_index}
60 ${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
62 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
66 [Documentation] Get the VNF instance ID of a member VNF in a NS instance, and return it.
67 [Arguments] ${ns_id} ${vnf_member_index}
68 Should Not Be Empty ${ns_id}
69 Should Not Be Empty ${vnf_member_index}
70 ${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
72 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
76 [Documentation] Get the NS instance ID from a NS instance name passed as argument, and return it.
77 [Arguments] ${ns_name}
78 Should Not Be Empty ${ns_name}
79 ${rc} ${stdout}= Run And Return Rc And Output osm ns-list | grep ${ns_name} | awk '{print $4}' 2>&1
81 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
82 Should Not Be Empty ${stdout}
86 [Documentation] Get the list of NS instances and return it.
87 ${rc} ${stdout}= Run And Return Rc And Output osm ns-list 2>&1
89 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
93 [Documentation] Get the list of VNF instances of a given NS instance id, and return it.
95 Should Not Be Empty ${ns_id}
96 @{vnf_list_string}= Run And Return Rc And Output osm vnf-list --ns ${ns_id} | grep ${ns_id} | awk '{print $2}' 2>&1
97 # Returns a String of vnf_id and needs to be converted into a list
98 @{vnf_list}= Split String ${vnf_list_string}[1]
103 [Documentation] Obtain the list of IP addresses of all VM in a NS, and return it.
104 [Arguments] @{vnf_list}
105 Should Not Be Empty @{vnf_list}
106 @{temp_list}= Create List
107 FOR ${vnf_id} IN @{vnf_list}
109 @{vnf_ip_list}= Get Vnf Ip List ${vnf_id}
110 @{temp_list}= Combine Lists ${temp_list} ${vnf_ip_list}
112 Should Not Be Empty ${temp_list}
116 [Documentation] Obtain the list of IP addresses of all VM in a VNF, and return it.
117 [Arguments] ${vnf_id}
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 Many ${vnf_ip_list}
124 Should Not Be Empty ${vnf_ip_list}
125 RETURN @{vnf_ip_list}
127 Check For Ns Instance To Configured
128 [Documentation] Check if a given NS instance has completed the instantiation, no matter if it succeeded (the status should be READY or BROKEN).
129 [Arguments] ${ns_name}
130 ${rc} ${stdout}= Run And Return Rc And Output openstack server list
132 ${rc} ${stdout}= Run And Return Rc And Output osm ns-list --filter name="${ns_name}"
134 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
135 Should Contain Any ${stdout} READY BROKEN
137 Check For NS Instance For Failure
138 [Documentation] Check if a given NS instance has not failed in the instantiation (the status should not be BROKEN).
139 [Arguments] ${ns_name}
140 ${rc} ${stdout}= Run And Return Rc And Output openstack server list
142 ${rc} ${stdout}= Run And Return Rc And Output osm ns-list --filter name="${ns_name}"
144 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
145 Should Not Contain ${stdout} BROKEN
147 Check For NS Instance To Be Deleted
148 [Documentation] Check if a given NS instance is not present in OSM.
150 ${rc} ${stdout}= Run And Return Rc And Output openstack server list
152 ${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}
157 [Documentation] Delete a NS instance.
158 [Arguments] ${ns} ${ns_delete_max_wait_time}=4min
159 ${ns_delete_max_wait_time}= Convert Time ${ns_delete_max_wait_time} result_format=number
160 ${ns_delete_max_wait_time}= Evaluate ${ns_delete_max_wait_time} * ${VIM_TIMEOUT_MULTIPLIER}
161 Log ${ns_delete_max_wait_time}
162 ${rc} ${stdout}= Run And Return Rc And Output osm ns-delete ${ns}
164 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
165 Wait Until Keyword Succeeds ${ns_delete_max_wait_time} ${NS_DELETE_POL_TIME} Check For NS Instance To Be Deleted ${ns}
168 [Documentation] Return a list with the IDs of the VNF records of a NS instance.
170 Should Not Be Empty ${ns_id}
171 ${rc} ${stdout}= Run And Return Rc And Output osm vnf-list --ns ${ns_id} | grep ${ns_id} | awk '{print $2}' 2>&1
172 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} msg=${stdout} values=False
173 @{vdur}= Split String ${stdout}
177 [Documentation] Return a list with the names of the VDU records of a VNF instance.
178 [Arguments] ${vnf_id}
179 Should Not Be Empty ${vnf_id}
180 ${rc} ${stdout}= Run And Return Rc And Output osm vnf-show ${vnf_id} --literal | yq -r .vdur[].name
181 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} msg=${stdout} values=False
182 @{vdur}= Split String ${stdout}
185 Get Vnf Kdu Replica Count
186 [Documentation] Return the number of KDU replicas (empty if none) of a VNF instance.
187 [Arguments] ${vnf_id} ${kdu_name}
188 Should Not Be Empty ${vnf_id}
189 Should Not Be Empty ${kdu_name}
190 ${rc} ${stdout}= Run And Return Rc And Output osm vnf-show ${vnf_id} --kdu ${kdu_name} | yq -r .config.replicaCount
191 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} msg=${stdout} values=False
192 ${return}= Set Variable If '${stdout}' == 'null' ${EMPTY} ${stdout}
195 Get Application Names
196 [Documentation] Return the list of the application of a VNF instance.
197 [Arguments] ${ns_name}
198 Should Not Be Empty ${ns_name}
199 ${rc} ${stdout}= Run And Return Rc And Output osm ns-show ${ns_name} --literal | yq -r ._admin.deployed.VCA[].application
200 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} msg=${stdout} values=False
201 @{app_names}= Split String ${stdout}
204 Get VDU Affinity Group Name
205 [Documentation] Return the affinity group name for a NF
206 [Arguments] ${ns_name} ${vnf_id} ${vdur_id}
207 ${rc} ${affinity_group_id}= Run And Return Rc And Output osm vnf-show ${vnf_id} --literal | yq '.vdur[] | select(.id == "'${vdur_id}'")' | yq -r '."affinity-or-anti-affinity-group-id"[0]' 2>&1
208 Log ${affinity_group_id}
209 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} msg=${affinity_group_id} values=False
210 ${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 -r '.name' 2>&1
211 Log ${affinity_group_name}
212 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} msg=${affinity_group_name} values=False
213 RETURN ${affinity_group_name}
216 [Documentation] Get dual ip from the ns list
218 Should Not Be Empty ${ns_id}
219 ${rc} ${stdout}= Run And Return RC And Output osm ns-show ${ns_id} --literal | grep -A2 ip-address | grep -v "ip-address:" | awk '{print $2}' | tr -d ',-'
223 Get NSD Id From The NS
224 [Documentation] Get the nsd id from the ns
226 Should Not Be Empty ${ns_id}
227 ${stdout}= Run osm ns-show ${ns_id} --literal | grep nsd-id | awk '{print $2}'