Bug 2327 fix to verify ipaddress in sol003_02 testsuite
[osm/tests.git] / robot-systest / testsuite / slice_01-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-01] Network Slicing.
19
20 Library   OperatingSystem
21 Library   String
22 Library   Collections
23 Library   Process
24 Library   SSHLibrary
25 Library   yaml
26
27 Resource   ../lib/vnfd_lib.resource
28 Resource   ../lib/nsd_lib.resource
29 Resource   ../lib/nst_lib.resource
30 Resource   ../lib/nsi_lib.resource
31 Resource   ../lib/ns_lib.resource
32 Resource   ../lib/connectivity_lib.resource
33 Resource   ../lib/ssh_lib.resource
34
35 Test Tags   slice_01   cluster_slices   daily   regression
36
37 Suite Teardown   Run Keyword And Ignore Error   Suite Cleanup
38
39
40 *** Variables ***
41 # NS and VNF descriptor package files
42 ${VNFD1_PKG}   slice_basic_vnf
43 ${VNFD2_PKG}   slice_basic_middle_vnf
44 ${NSD1_PKG}   slice_basic_ns
45 ${NSD2_PKG}   slice_basic_middle_ns
46 ${NST}   slice_basic_nst/slice_basic_nst.yaml
47
48 # Descriptor names
49 ${NST_NAME}   slice_basic_nst
50 ${VNFD1_NAME}   slice_basic_vnf
51 ${VNFD2_NAME}   slice_basic_middle_vnf
52 ${NSD1_NAME}   slice_basic_ns
53 ${NSD2_NAME}   slice_basic_middle_ns
54
55 # Instance names
56 ${SLICE_NAME}   slicebasic
57 ${MIDDLE_NS_NAME}   slicebasic.slice_basic_nsd_2
58
59 # SSH keys and username to be used
60 ${PUBLICKEY}   %{HOME}/.ssh/id_rsa.pub
61 ${PRIVATEKEY}   %{HOME}/.ssh/id_rsa
62 ${USERNAME}   ubuntu
63 ${PASSWORD}   ${EMPTY}
64
65 ${VNF_MEMBER_INDEX}   middle
66 ${VNF_IP_ADDR}   ${EMPTY}
67 ${MGMT_VNF_IP}   ${EMPTY}
68 ${NST_CONFIG}   {netslice-vld: [ {name: slice_vld_mgmt, vim-network-name: %{VIM_MGMT_NET}} ] }
69
70
71 *** Test Cases ***
72 Create Slice VNF Descriptors
73     [Documentation]   Onboards all the VNFDs required for the test: vnfd1_pkg and vnfd2_pkg (in the variables file)
74     Create VNFD   '%{PACKAGES_FOLDER}/${VNFD1_PKG}'
75     Create VNFD   '%{PACKAGES_FOLDER}/${VNFD2_PKG}'
76
77 Create Slice NS Descriptors
78     [Documentation]   Onboards all the NSDs required for the test: nsd1_pkg and nsd2_pkg (in the variables file)
79     Create NSD   '%{PACKAGES_FOLDER}/${NSD1_PKG}'
80     Create NSD   '%{PACKAGES_FOLDER}/${NSD2_PKG}'
81
82 Create Slice Template
83     [Documentation]   Onboards the Network Slice Template: nst (in the variables file)
84     Create NST   '%{PACKAGES_FOLDER}/${NST}'
85
86 Network Slice Instance Test
87     [Documentation]   Instantiates the NST recently onboarded and sets the instantiation id as a suite variable (nsi_id)
88     ${id}=   Create Network Slice   ${NST_NAME}   %{VIM_TARGET}   ${SLICE_NAME}   ${NST_CONFIG}   ${PUBLICKEY}
89     Set Suite Variable   ${NSI_ID}   ${id}
90
91 Get Middle Vnf Management Ip
92     [Documentation]   Obtains the management IP of the slice middle VNF (name in the reources file) and sets the ip as a suite variable (mgmt_vnf_ip)
93     ${middle_ns_id}=   Run And Return RC And Output   osm ns-list | grep ${MIDDLE_NS_NAME} | awk '{print $4}' 2>&1
94     ${vnf_ip}=   Get Vnf Management Ip Address   ${middle_ns_id}[1]   ${VNF_MEMBER_INDEX}
95     IF   '${vnf_ip}' == '${EMPTY}'   Fatal Error   Variable \$\{ vnf_ip\} Empty
96     Set Suite Variable   ${MGMT_VNF_IP}   ${vnf_ip}
97
98 Get Slice Vnf Ip Addresses
99     [Documentation]   Obtains the list of IPs addresses in the slice and sets the list as a suite variable (slice_vnfs_ips)
100     # Get all the ns_id in the slice except the middle one to avoid self ping
101     @{slice_ns_list}=   Get Slice Ns List Except One   ${SLICE_NAME}   ${MIDDLE_NS_NAME}
102     Log Many   @{slice_ns_list}
103     @{temp_list}=   Create List
104     # For each ns_id in the list, get all the vnf_id and their IP addresses
105     FOR   ${ns_id}   IN   @{slice_ns_list}
106         Log   ${ns_id}
107         @{vnf_id_list}=   Get Ns Vnf List   ${ns_id}
108         # For each vnf_id in the list, get all its IP addresses
109         @{ns_ip_list}=   Get Ns Ip List   @{vnf_id_list}
110         @{temp_list}=   Combine Lists   ${temp_list}   ${ns_ip_list}
111     END
112     Log List   ${temp_list}
113     Set Suite Variable   ${SLICE_VNFS_IPS}   ${temp_list}
114
115 Test Middle Ns Ping
116     [Documentation]   Pings the slice middle vnf (mgmt_vnf_ip)
117     Sleep   60s   Waiting for the network to be up
118     # Ping to the middle VNF
119     Log   ${MGMT_VNF_IP}
120     Test Connectivity   ${MGMT_VNF_IP}
121
122 Test Middle Vnf SSH Access
123     [Documentation]   SSH access to the slice middle vnf (mgmt_vnf_ip) with the credentials provided in the variables file
124     Sleep   30s   Waiting ssh daemon to be up
125     Test SSH Connection   ${MGMT_VNF_IP}   ${USERNAME}   ${PASSWORD}   ${PRIVATEKEY}
126
127 Test Slice Connectivity
128     [Documentation]   SSH access to the slice middle vnf (mgmt_vnf_ip) with the credentials provided in the variables file
129     ...               and pings all the IP addresses in the list (slice_vnfs_ips)
130     Ping Many   ${MGMT_VNF_IP}   ${USERNAME}   ${PASSWORD}   ${PRIVATEKEY}   @{SLICE_VNFS_IPS}
131
132 Delete Slice Instance
133     [Documentation]   Stops the slice instance (slice_name)
134     [Tags]   cleanup
135     Delete NSI   ${SLICE_NAME}
136
137 Delete Slice Template
138     [Documentation]   Deletes the NST (nst_name) from OSM
139     [Tags]   cleanup
140     Delete NST   ${NST_NAME}
141
142 Delete NS Descriptors
143     [Documentation]   Deletes all the NSDs created for the test: nsd1_name, nsd2_name
144     [Tags]   cleanup
145     Delete NSD   ${NSD1_NAME}
146     Delete NSD   ${NSD2_NAME}
147
148 Delete VNF Descriptors
149     [Documentation]   Deletes all the VNFDs created for the test: vnfd1_name, vnfd2_name
150     [Tags]   cleanup
151     Delete VNFD   ${VNFD1_NAME}
152     Delete VNFD   ${VNFD2_NAME}
153
154
155 *** Keywords ***
156 Suite Cleanup
157     [Documentation]   Test Suit Cleanup: Deleting Descriptors, instance and template
158     Run Keyword If Any Tests Failed   Delete NSI   ${SLICE_NAME}
159     Run Keyword If Any Tests Failed   Delete NST   ${NST_NAME}
160     Run Keyword If Any Tests Failed   Delete NSD   ${NSD1_NAME}
161     Run Keyword If Any Tests Failed   Delete NSD   ${NSD2_NAME}
162     Run Keyword If Any Tests Failed   Delete VNFD   ${VNFD1_NAME}
163     Run Keyword If Any Tests Failed   Delete VNFD   ${VNFD2_NAME}