Bug 2327 fix to verify ipaddress in sol003_02 testsuite
[osm/tests.git] / robot-systest / lib / nsi_lib.resource
1 *** Comments ***
2 #   Copyright 2020 Atos
3 #
4 #   Licensed under the Apache License, Version 2.0 (the "License");
5 #   you may not use this file except in compliance with the License.
6 #   You may obtain a copy of the License at
7 #
8 #       http://www.apache.org/licenses/LICENSE-2.0
9 #
10 #   Unless required by applicable law or agreed to in writing, software
11 #   distributed under the License is distributed on an "AS IS" BASIS,
12 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 #   See the License for the specific language governing permissions and
14 #   limitations under the License.
15
16
17 *** Settings ***
18 Documentation   Library providing keywords for CRUD operations over Network Slice Instances with OSM client.
19
20 Library   Collections
21 Library   OperatingSystem
22 Library   DateTime
23 Library   String
24
25 Resource   ns_lib.resource
26
27
28 *** Variables ***
29 ${SUCCESS_RETURN_CODE}   0
30 ${SLICE_LAUNCH_POL_TIME}   30sec
31 ${SLICE_DELETE_POL_TIME}   15sec
32 ${VIM_TIMEOUT_MULTIPLIER}   %{OSM_VIM_MULTIPLIER_TIMEOUT=1.0}
33
34
35 *** Keywords ***
36 Create Network Slice
37     [Documentation]   Instantiates a NST and returns an instantiation id (nsi), verifying the slice is successfully instantiated
38     ...               Parameters:
39     ...                  nst: Name of the slice template
40     ...                  vim_name: Name of the VIM entry already in OSM
41     ...                  slice_name: Name of the slice instance
42     ...                  slice_config: Extra parameters that might require the slice instantiation i.e. configuration attributes
43     ...                  publickey: SSH public key of the local machine
44     ...               Execution example:
45     ...                  \${nsi}=   Create Network Slice   \${nst}   \${vim_name}   \${slice_name}   \${slice_config}   \${publickey}
46     [Arguments]   ${nst}   ${vim_name}   ${slice_name}   ${slice_config}   ${publickey}   ${slice_launch_max_wait_time}=6min   ${config_file}=${EMPTY}
47     ${slice_launch_max_wait_time}=   Convert Time   ${slice_launch_max_wait_time}   result_format=number
48     ${slice_launch_max_wait_time}=   Evaluate   ${slice_launch_max_wait_time} * ${VIM_TIMEOUT_MULTIPLIER}
49     ${config_attr}=   Set Variable If   "${slice_config}" != "${EMPTY}"   --config '${slice_config}'   ${EMPTY}
50     ${sshkeys_attr}=   Set Variable If   "${publickey}" != "${EMPTY}"   --ssh_keys ${publickey}   ${EMPTY}
51     ${config_file_attr}=   Set Variable If   "${config_file}" != "${EMPTY}"   --config_file '${config_file}'   ${EMPTY}
52     ${nsi_id}=   Instantiate Network Slice   ${slice_name}   ${nst}   ${vim_name}   ${config_attr} ${config_file_attr}   ${sshkeys_attr}
53     Log   ${nsi_id}
54     Wait Until Keyword Succeeds   ${slice_launch_max_wait_time}   ${SLICE_LAUNCH_POL_TIME}   Check For Network Slice Instance To Configured   ${slice_name}
55     Check For Network Slice Instance For Failure   ${slice_name}
56     RETURN   ${nsi_id}
57
58 Instantiate Network Slice
59     [Documentation]   Instantiates a NST and returns an instantiation id (nsi)
60     ...               Parameters:
61     ...                  slice_name: Name of the slice instance
62     ...                  nst: Name of the slice template
63     ...                  vim_name: Name of the VIM entry already in OSM
64     ...                  slice_extra_args: Extra parameters that might require the slice instantiation i.e. configuration attributes
65     ...               Execution example:
66     ...                  \${nsi}=   Instantiate Network Slice   \${slice_name}   \${nst}   \${vim_name}   \${config_attr}
67     [Arguments]   ${slice_name}   ${nst}   ${vim_name}   ${slice_extra_args}   ${sshkeys_attr}
68     ${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}
69     Log   ${rc},${stdout}
70     Should Be Equal As Integers   ${rc}   ${SUCCESS_RETURN_CODE}
71     RETURN   ${stdout}
72
73 Get Slice Ns List
74     [Documentation]   Retrieves the list of NS in a slice
75     ...               Parameters:
76     ...                  slice_name: Name of the slice instance
77     ...               Execution example:
78     ...                  \@{slice_ns_list}=   Get Slice Ns List   \${slice_name}
79     [Arguments]   ${slice_name}
80     Should Not Be Empty   ${slice_name}
81     @{ns_list_string}=   Run And Return Rc And Output   osm ns-list | grep ${slice_name} | awk '{print $4}' 2>&1
82     # Returns a String of ns_id and needs to be converted into a list
83     @{ns_list}=   Split String   ${ns_list_string}[1]
84     Log List   ${ns_list}
85     RETURN   @{ns_list}
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     [Arguments]   ${slice_name}   ${exception_ns}
95     Should Not Be Empty   ${slice_name}
96     Should Not Be Empty   ${exception_ns}
97     @{ns_list_string}=   Run And Return Rc And Output   osm ns-list | grep ${slice_name} | awk '!/${exception_ns}/' | awk '{print $4}' 2>&1
98     # Returns a String of ns_id and needs to be converted into a list
99     @{ns_list}=   Split String   ${ns_list_string}[1]
100     Log List   ${ns_list}
101     RETURN   @{ns_list}
102
103 Get Slice Ns Count
104     [Documentation]   Returns the count of all the NS in a slice
105     ...               Parameters:
106     ...                  slice_name: Name of the slice instance
107     ...               Execution example:
108     ...                  \${slice_ns_count}=   Get Slice Ns Count   \${slice_name}
109     [Arguments]   ${slice_name}
110     Should Not Be Empty   ${slice_name}
111     ${rc}   ${stdout}=   Run And Return Rc And Output   osm ns-list | grep ${slice_name} | wc -l 2>&1
112     Log   ${stdout}
113     Should Be Equal As Integers   ${rc}   ${SUCCESS_RETURN_CODE}
114     RETURN   ${stdout}
115
116 Get Slice Vnf Ip Addresses
117     [Documentation]   Retrieves the list of IP addresses that belong to each of the VNFs in the slice
118     ...               Parameters:
119     ...                  slice_name: Name of the slice instance
120     ...               Execution example:
121     ...                  \@{slice_ip_address_list}=   Get Slice Vnf Ip Addresses   \${slice_name}
122     [Arguments]   ${slice_name}
123     # Get all the ns_id in the slice
124     @{slice_ns_list}=   Get Slice Ns List   ${slice_name}
125     Log Many   @{slice_ns_list}
126     @{temp_list}=   Create List
127     # For each ns_id in the list, get all the vnf_id and their IP addresses
128     FOR   ${ns_id}   IN   @{slice_ns_list}
129         Log   ${ns_id}
130         @{vnf_id_list}=   Get Ns Vnf List   ${ns_id}
131         # For each vnf_id in the list, get all its IP addresses
132         @{ns_ip_list}=   Get Ns Ip List   @{vnf_id_list}
133         @{temp_list}=   Combine Lists   ${temp_list}   ${ns_ip_list}
134     END
135     Log List   ${temp_list}
136     RETURN   @{temp_list}
137
138 Check For Network Slice Instance To Configured
139     [Documentation]   Verify the slice has been instantiated
140     ...               Parameters:
141     ...                  slice_name: Name of the slice instance
142     ...               Execution example:
143     ...                  Check For Network Slice Instance To Configured   \${slice_name}
144     [Arguments]   ${slice_name}
145     ${rc}   ${stdout}=   Run And Return Rc And Output   osm nsi-list --filter name="${slice_name}"
146     Log   ${stdout}
147     Should Be Equal As Integers   ${rc}   ${SUCCESS_RETURN_CODE}
148     Should Contain Any   ${stdout}   READY   BROKEN   configured
149
150 Check For Network Slice Instance For Failure
151     [Documentation]   Verify the slice instance is not in failure
152     ...               Parameters:
153     ...                  slice_name: Name of the slice instance
154     ...               Execution example:
155     ...                  Check For Network Slice Instance For Failure   \${slice_name}
156     [Arguments]   ${slice_name}
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 Not Contain   ${stdout}   failed
161
162 Delete NSI
163     [Documentation]   Delete Network Slice Instance (NSI)
164     ...               Parameters:
165     ...                  slice_name: Name of the slice instance
166     ...                  slice_delete_max_wait_time: Delete operation timeout
167     ...               Execution example:
168     ...                  Delete NST   \${slice_name}
169     [Arguments]   ${slice_name}   ${slice_delete_max_wait_time}=4min
170     ${rc}   ${stdout}=   Run And Return Rc And Output   osm nsi-delete ${slice_name}
171     Log   ${stdout}
172     Should Be Equal As Integers   ${rc}   ${SUCCESS_RETURN_CODE}
173     ${slice_delete_max_wait_time}=   Convert Time   ${slice_delete_max_wait_time}   result_format=number
174     ${slice_delete_max_wait_time}=   Evaluate   ${slice_delete_max_wait_time} * ${VIM_TIMEOUT_MULTIPLIER}
175     Wait Until Keyword Succeeds   ${slice_delete_max_wait_time}   ${SLICE_DELETE_POL_TIME}   Check For Network Slice Instance To Be Deleted   ${slice_name}
176
177 Check For Network Slice Instance To Be Deleted
178     [Documentation]   Verify the slice instance is not present
179     ...               Parameters:
180     ...                  slice_name: Name of the slice instance
181     ...               Execution example:
182     ...                  Check For Network Slice Instance   \${slice_name}
183     [Arguments]   ${slice_name}
184     ${rc}   ${stdout}=   Run And Return Rc And Output   osm nsi-list | awk '{print $2}' | grep ${slice_name}
185     Log   ${rc},${stdout}
186     Should Not Be Equal As Strings   ${stdout}   ${slice_name}