Fix bugs in test [epa-03], ignored environment variable OVERRIDES in test [epa-02...
[osm/tests.git] / robot-systest / lib / nsi_lib.robot
1 #   Copyright 2020 Atos
2 #
3 #   Licensed under the Apache License, Version 2.0 (the "License");
4 #   you may not use this file except in compliance with the License.
5 #   You may obtain a copy of the License at
6 #
7 #       http://www.apache.org/licenses/LICENSE-2.0
8 #
9 #   Unless required by applicable law or agreed to in writing, software
10 #   distributed under the License is distributed on an "AS IS" BASIS,
11 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 #   See the License for the specific language governing permissions and
13 #   limitations under the License.
14
15 *** Settings ***
16 Library           Collections
17
18
19 *** Variables ***
20 ${success_return_code}   0
21 ${slice_launch_max_wait_time}   5min
22 ${slice_launch_pol_time}   30sec
23 ${slice_delete_max_wait_time}   4min
24 ${slice_delete_pol_time}   15sec
25
26 *** Keywords ***
27
28 Create Network Slice
29     [Documentation]   Instantiates a NST and returns an instantiation id (nsi), verifying the slice is successfully instantiated
30     ...               Parameters:
31     ...                  nst: Name of the slice template
32     ...                  vim_name: Name of the VIM entry already in OSM
33     ...                  slice_name: Name of the slice instance
34     ...                  slice_config: Extra parameters that might require the slice instantiation i.e. configuration attributes
35     ...                  publickey: SSH public key of the local machine
36     ...               Execution example:
37     ...                  \${nsi}=   Create Network Slice   \${nst}   \${vim_name}   \${slice_name}   \${slice_config}   \${publickey}
38
39     [Arguments]   ${nst}   ${vim_name}   ${slice_name}   ${slice_config}   ${publickey}
40
41     ${config_attr}   Set Variable If   '${slice_config}'!='${EMPTY}'   --config '${slice_config}'   \
42     ${sshkeys_attr}   Set Variable If   '${publickey}'!='${EMPTY}'   --ssh_keys ${publickey}   \
43
44     ${nsi_id}=   Instantiate Network Slice   ${slice_name}   ${nst}   ${vim_name}   ${config_attr}   ${sshkeys_attr}
45     log   ${nsi_id}
46
47     WAIT UNTIL KEYWORD SUCCEEDS   ${slice_launch_max_wait_time}   ${slice_launch_pol_time}   Check For Network Slice Instance To Configured   ${slice_name}
48     Check For Network Slice Instance For Failure   ${slice_name}
49     [Return]  ${nsi_id}
50
51
52 Instantiate Network Slice
53     [Documentation]   Instantiates a NST and returns an instantiation id (nsi)
54     ...               Parameters:
55     ...                  slice_name: Name of the slice instance
56     ...                  nst: Name of the slice template
57     ...                  vim_name: Name of the VIM entry already in OSM
58     ...                  slice_extra_args: Extra parameters that might require the slice instantiation i.e. configuration attributes
59     ...               Execution example:
60     ...                  \${nsi}=   Instantiate Network Slice   \${slice_name}   \${nst}   \${vim_name}   \${config_attr}
61
62     [Arguments]   ${slice_name}   ${nst}   ${vim_name}   ${slice_extra_args}    ${sshkeys_attr}
63
64     ${rc}   ${stdout}=   Run and Return RC and Output   osm nsi-create --nsi_name ${slice_name} --nst_name ${nst} --vim_account ${vim_name} ${sshkeys_attr} ${slice_extra_args}
65     log   ${stdout}
66     Should Be Equal As Integers   ${rc}   ${success_return_code}
67     [Return]  ${stdout}
68
69
70 Get Slice Ns List
71     [Documentation]   Retrieves the list of NS in a slice
72     ...               Parameters:
73     ...                  slice_name: Name of the slice instance
74     ...               Execution example:
75     ...                  \@{slice_ns_list}=   Get Slice Ns List   \${slice_name}
76
77     [Arguments]   ${slice_name}
78
79     Should Not Be Empty   ${slice_name}
80     @{ns_list_string}=   Run and Return RC and Output   osm ns-list | grep ${slice_name} | awk '{print $4}' 2>&1
81     # Returns a String of ns_id and needs to be converted into a list
82     @{ns_list} =  Split String    ${ns_list_string}[1]
83     Log List    ${ns_list}
84     [Return]  @{ns_list}
85
86
87 Get Slice Ns List Except One
88     [Documentation]   Retrieves the list of NS in a slice removing one from the list. This is done to save time in the tests, avoiding one VNF to ping itself.
89     ...               Parameters:
90     ...                  slice_name: Name of the slice instance
91     ...                  exception_ns: Name of the ns that will not appear in the final list
92     ...               Execution example:
93     ...                  \@{slice_ns_list}=   Get Slice Ns List Except One   \${slice_name}   \${exception_ns}
94
95     [Arguments]   ${slice_name}   ${exception_ns}
96
97     Should Not Be Empty   ${slice_name}
98     Should Not Be Empty   ${exception_ns}
99
100     @{ns_list_string}=   Run and Return RC and Output   osm ns-list | grep ${slice_name} | awk '!/${exception_ns}/' | awk '{print $4}' 2>&1
101     # Returns a String of ns_id and needs to be converted into a list
102     @{ns_list} =  Split String    ${ns_list_string}[1]
103     Log List    ${ns_list}
104     [Return]  @{ns_list}
105
106
107 Get Slice Ns Count
108     [Documentation]   Returns the count of all the NS in a slice
109     ...               Parameters:
110     ...                  slice_name: Name of the slice instance
111     ...               Execution example:
112     ...                  \${slice_ns_count}=   Get Slice Ns Count   \${slice_name}
113
114     [Arguments]   ${slice_name}
115
116     Should Not Be Empty   ${slice_name}
117     ${rc}   ${stdout}=   Run and Return RC and Output   osm ns-list | grep ${slice_name} | wc -l 2>&1
118     log   ${stdout}
119     Should Be Equal As Integers   ${rc}   ${success_return_code}
120     [Return]  ${stdout}
121
122
123 Get Slice Vnf Ip Addresses
124     [Documentation]   Retrieves the list of IP addresses that belong to each of the VNFs in the slice
125     ...               Parameters:
126     ...                  slice_name: Name of the slice instance
127     ...               Execution example:
128     ...                  \@{slice_ip_address_list}=   Get Slice Vnf Ip Addresses   \${slice_name}
129
130     [Arguments]   ${slice_name}
131
132     # Get all the ns_id in the slice
133     @{slice_ns_list}  Get Slice Ns List   ${slice_name}
134     log many   @{slice_ns_list}
135     @{temp_list}=    Create List
136     # For each ns_id in the list, get all the vnf_id and their IP addresses
137     FOR   ${ns_id}   IN   @{slice_ns_list}
138         log   ${ns_id}
139         @{vnf_id_list}   Get Ns Vnf List   ${ns_id}
140         # For each vnf_id in the list, get all its IP addresses
141         @{ns_ip_list}   Get Ns Ip List   @{vnf_id_list}
142         @{temp_list}=   Combine Lists   ${temp_list}    ${ns_ip_list}
143     END
144     Log List   ${temp_list}
145     [Return]   @{temp_list}
146
147
148 Check For Network Slice Instance To Configured
149     [Documentation]   Verify the slice has been instantiated
150     ...               Parameters:
151     ...                  slice_name: Name of the slice instance
152     ...               Execution example:
153     ...                  Check For Network Slice Instance To Configured   \${slice_name}
154
155     [Arguments]  ${slice_name}
156
157     ${rc}   ${stdout}=   Run and Return RC and Output   osm nsi-list --filter name="${slice_name}"
158     log   ${stdout}
159     Should Be Equal As Integers   ${rc}   ${success_return_code}
160     Should Contain Any   ${stdout}   READY   BROKEN     configured
161
162
163 Check For Network Slice Instance For Failure
164     [Documentation]   Verify the slice instance is not in failure
165     ...               Parameters:
166     ...                  slice_name: Name of the slice instance
167     ...               Execution example:
168     ...                  Check For Network Slice Instance For Failure   \${slice_name}
169
170     [Arguments]  ${slice_name}
171
172     ${rc}   ${stdout}=   Run and Return RC and Output   osm nsi-list --filter name="${slice_name}"
173     log   ${stdout}
174     Should Be Equal As Integers   ${rc}   ${success_return_code}
175     Should Not Contain   ${stdout}   BROKEN
176
177
178 Delete NSI
179     [Documentation]   Delete Network Slice Instance (NSI)
180     ...               Parameters:
181     ...                  slice_name: Name of the slice instance
182     ...               Execution example:
183     ...                  Delete NST   \${slice_name}
184
185     [Arguments]  ${slice_name}
186
187     ${rc}   ${stdout}=   Run and Return RC and Output   osm nsi-delete ${slice_name}
188     log   ${stdout}
189     Should Be Equal As Integers   ${rc}   ${success_return_code}
190
191     WAIT UNTIL KEYWORD SUCCEEDS  ${slice_delete_max_wait_time}   ${slice_delete_pol_time}   Check For Network Slice Instance To Be Deleted   ${slice_name}
192
193
194 Check For Network Slice Instance To Be Deleted
195     [Documentation]   Verify the slice instance is not present
196     ...               Parameters:
197     ...                  slice_name: Name of the slice instance
198     ...               Execution example:
199     ...                  Check For Network Slice Instance   \${slice_name}
200
201     [Arguments]  ${slice_name}
202
203     ${rc}   ${stdout}=   Run and Return RC and Output   osm nsi-list | awk '{print $2}' | grep ${slice_name}
204     Should Not Be Equal As Strings   ${stdout}   ${slice_name}
205
206