Feature 11001: Robot framework linting for E2E tests
[osm/tests.git] / robot-systest / testsuite / slice_02-shared_network_slicing.robot
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   [SLICE-02] Shared Network Slicing.
19
20 Library   OperatingSystem
21 Library   String
22 Library   Collections
23 Library   Process
24 Library   SSHLibrary
25
26 Resource   ../lib/vnfd_lib.resource
27 Resource   ../lib/nsd_lib.resource
28 Resource   ../lib/nst_lib.resource
29 Resource   ../lib/nsi_lib.resource
30 Resource   ../lib/ns_lib.resource
31 Resource   ../lib/connectivity_lib.resource
32 Resource   ../lib/ssh_lib.resource
33
34 Test Tags   slice_02   cluster_slices   daily   regression
35
36 Suite Teardown   Run Keyword And Ignore Error   Suite Cleanup
37
38
39 *** Variables ***
40 # NS and VNF descriptor package files
41 ${VNFD1_PKG}   slice_basic_vnf
42 ${VNFD2_PKG}   slice_basic_middle_vnf
43 ${NSD1_PKG}   slice_basic_ns
44 ${NSD2_PKG}   slice_basic_middle_ns
45 ${NST}   slice_basic_nst/slice_basic_nst.yaml
46 ${NST2}   slice_basic_nst/slice_basic_2nd_nst.yaml
47
48 # Instance names
49 ${SLICE_NAME}   slicebasic
50 ${SLICE2_NAME}   sliceshared
51 ${MIDDLE_NS_NAME}   slicebasic.slice_basic_nsd_2
52
53 # Descriptor names
54 ${NST_NAME}   slice_basic_nst
55 ${NST2_NAME}   slice_basic_nst2
56 ${VNFD1_NAME}   slice_basic_vnf
57 ${VNFD2_NAME}   slice_basic_middle_vnf
58 ${NSD1_NAME}   slice_basic_ns
59 ${NSD2_NAME}   slice_basic_middle_ns
60
61 # SSH keys and username to be used
62 ${PUBLICKEY}   %{HOME}/.ssh/id_rsa.pub
63 ${PRIVATEKEY}   %{HOME}/.ssh/id_rsa
64 ${USERNAME}   ubuntu
65 ${PASSWORD}   ${EMPTY}
66
67 ${VNF_MEMBER_INDEX}   middle
68 ${VNF_IP_ADDR}   ${EMPTY}
69 ${NST_CONFIG}   {netslice-vld: [ {name: slice_vld_mgmt, vim-network-name: %{VIM_MGMT_NET}} ] }
70
71
72 *** Test Cases ***
73 Create Slice VNF Descriptors
74     [Documentation]   Onboards all the VNFDs required for the test: vnfd1_pkg and vnfd2_pkg (in the variables file)
75     Create VNFD   '%{PACKAGES_FOLDER}/${VNFD1_PKG}'
76     Create VNFD   '%{PACKAGES_FOLDER}/${VNFD2_PKG}'
77
78 Create Slice NS Descriptors
79     [Documentation]   Onboards all the NSDs required for the test: nsd1_pkg and nsd2_pkg (in the variables file)
80     Create NSD   '%{PACKAGES_FOLDER}/${NSD1_PKG}'
81     Create NSD   '%{PACKAGES_FOLDER}/${NSD2_PKG}'
82
83 Create Slice Templates
84     [Documentation]   Onboards the Network Slice Templates: nst, nst2 (in the variables file)
85     Create NST   '%{PACKAGES_FOLDER}/${NST}'
86     Create NST   '%{PACKAGES_FOLDER}/${NST2}'
87
88 Network Slice First Instance
89     [Documentation]   Instantiates the First NST recently onboarded (nst_name) and sets the instantiation id as a suite variable (nsi_id)
90     ...               The slice contains 3 NS (1 shared)
91     ${id}=   Create Network Slice   ${NST_NAME}   %{VIM_TARGET}   ${SLICE_NAME}   ${NST_CONFIG}   ${PUBLICKEY}
92     Set Suite Variable   ${NSI_ID}   ${id}
93
94 Network Slice Second Instance
95     [Documentation]   Instantiates the Second NST recently onboarded (nst2_name) and sets the instantiation id as a suite variable (nsi2_id)
96     ...               The slice contains 2 NS (1 shared)
97     ${id}=   Create Network Slice   ${NST2_NAME}   %{VIM_TARGET}   ${SLICE2_NAME}   ${NST_CONFIG}   ${PUBLICKEY}
98     Set Suite Variable   ${NSI2_ID}   ${id}
99
100 First Network Slice Ns Count
101     [Documentation]   Counts the NS in both slice instances and shoul be equal to 4
102     ${slice1_count}=   Get Slice Ns Count   ${SLICE_NAME}
103     ${slice2_count}=   Get Slice Ns Count   ${SLICE2_NAME}
104     ${together}=   Evaluate   ${slice1_count} + ${slice2_count}
105     Should Be Equal As Integers   ${together}   4
106
107 Get Middle Vnf Management Ip
108     [Documentation]   Obtains the management IP of the shared NS main (only) VNF and sets it as a suite variable (mgmt_vnf_ip)
109     ${middle_ns_id}=   Run And Return RC And Output   osm ns-list | grep ${MIDDLE_NS_NAME} | awk '{print $4}' 2>&1
110     ${vnf_ip}=   Get Vnf Management Ip Address   ${middle_ns_id}[1]   ${VNF_MEMBER_INDEX}
111     IF   '${vnf_ip}' == '${EMPTY}'   Fatal Error   Variable \$\{ vnf_ip\} Empty
112     Set Suite Variable   ${MGMT_VNF_IP}   ${vnf_ip}
113
114 Get First Slice Vnf IPs
115     [Documentation]   Obtains the list of IPs addresses in the first slice and sets the list as a suite variable (slice1_vnfs_ips)
116     # Get all the ns_id in the slice except the middle one
117     @{ip_list}=   Get Slice Vnf Ip Addresses   ${SLICE_NAME}
118     Should Be True   ${ip_list} is not None
119     Set Suite Variable   ${SLICE1_VNFS_IPS}   ${ip_list}
120
121 Test Middle Ns Ping
122     [Documentation]   Pings the slice middle vnf (mgmt_vnf_ip)
123     Sleep   60s   Waiting for the network to be up
124     # Ping to the middle VNF
125     Test Connectivity   ${MGMT_VNF_IP}
126
127 Test Middle Vnf SSH Access
128     [Documentation]   SSH access to the slice middle vnf (mgmt_vnf_ip) with the credentials provided in the variables file
129     Sleep   30s   Waiting ssh daemon to be up
130     Test SSH Connection   ${MGMT_VNF_IP}   ${USERNAME}   ${PASSWORD}   ${PRIVATEKEY}
131
132 Test First Slice Connectivity
133     [Documentation]   SSH access to the slice middle vnf (mgmt_vnf_ip) with the credentials provided in the variables file
134     ...               and pings all the IP addresses in the list (slice1_vnfs_ips)
135     Ping Many   ${MGMT_VNF_IP}   ${USERNAME}   ${PASSWORD}   ${PRIVATEKEY}   @{SLICE1_VNFS_IPS}
136
137 Delete Slice One Instance
138     [Documentation]   Stops the slice instance (slice_name)
139     [Tags]   cleanup
140     Delete NSI   ${SLICE_NAME}
141
142 Second Network Slice Ns Count
143     [Documentation]   Counts the NS in both slice instances and should be equal to 2
144     ${slice1_count}=   Get Slice Ns Count   ${SLICE_NAME}
145     ${slice2_count}=   Get Slice Ns Count   ${SLICE2_NAME}
146     ${together}=   Evaluate   ${slice1_count} + ${slice2_count}
147     Should Be Equal As Integers   ${together}   2
148
149 Get Second Slice Vnf IPs
150     [Documentation]   Obtains the list of IPs addresses in the second slice and sets the list as a suite variable (slice2_vnfs_ips)
151     # Get all the ns_id in the slice
152     @{ip_list}=   Get Slice Vnf Ip Addresses   ${SLICE2_NAME}
153     Should Be True   ${ip_list} is not None
154     Set Suite Variable   ${SLICE2_VNFS_IPS}   ${ip_list}
155
156 Test Second Slice Connectivity
157     [Documentation]   SSH access to the slice middle vnf (mgmt_vnf_ip) with the credentials provided in the variables file
158     ...               and pings all the IP addresses in the list (slice2_vnfs_ips)
159     Ping Many   ${MGMT_VNF_IP}   ${USERNAME}   ${PASSWORD}   ${PRIVATEKEY}   @{SLICE2_VNFS_IPS}
160
161 Delete Slice Two Instance
162     [Documentation]   Stops the slice instance (slice2_name)
163     [Tags]   cleanup
164     Delete NSI   ${SLICE2_NAME}
165
166 Delete Slice One Template
167     [Documentation]   Deletes the NST (nst_name) from OSM
168     [Tags]   cleanup
169     Delete NST   ${NST_NAME}
170
171 Delete Slice Two Template
172     [Documentation]   Deletes the NST (nst2_name) from OSM
173     [Tags]   cleanup
174     Delete NST   ${NST2_NAME}
175
176 Delete NS Descriptors
177     [Documentation]   Deletes all the NSDs created for the test: nsd1_name, nsd2_name
178     [Tags]   cleanup
179     Delete NSD   ${NSD1_NAME}
180     Delete NSD   ${NSD2_NAME}
181
182 Delete VNF Descriptors
183     [Documentation]   Deletes all the VNFDs created for the test: vnfd1_name, vnfd2_name
184     [Tags]   cleanup
185     Delete VNFD   ${VNFD1_NAME}
186     Delete VNFD   ${VNFD2_NAME}
187
188
189 *** Keywords ***
190 Suite Cleanup
191     [Documentation]   Test Suit Cleanup: Deleting Descriptors, instance and templates
192     Run Keyword If Any Tests Failed   Delete NSI   ${SLICE_NAME}
193     Run Keyword If Any Tests Failed   Delete NSI   ${SLICE2_NAME}
194
195     Run Keyword If Any Tests Failed   Delete NST   ${NST_NAME}
196     Run Keyword If Any Tests Failed   Delete NST   ${NST2_NAME}
197
198     Run Keyword If Any Tests Failed   Delete NSD   ${NSD1_NAME}
199     Run Keyword If Any Tests Failed   Delete NSD   ${NSD2_NAME}
200
201     Run Keyword If Any Tests Failed   Delete VNFD   ${VNFD1_NAME}
202     Run Keyword If Any Tests Failed   Delete VNFD   ${VNFD2_NAME}