Bug 2327 fix to verify ipaddress in sol003_02 testsuite
[osm/tests.git] / robot-systest / testsuite / basic_18-ns_ip_profile.robot
1 *** Comments ***
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
5 #
6 #       http://www.apache.org/licenses/LICENSE-2.0
7 #
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.
13
14
15 *** Settings ***
16 Documentation   [BASIC-18] NS with a VLD with a virtual link profile.
17
18 Library   OperatingSystem
19 Library   String
20 Library   Collections
21 Library   SSHLibrary
22
23 Resource   ../lib/vnfd_lib.resource
24 Resource   ../lib/nsd_lib.resource
25 Resource   ../lib/ns_lib.resource
26 Resource   ../lib/ssh_lib.resource
27
28 Test Tags   basic_18   cluster_main   daily   regression
29
30 Suite Teardown   Run Keyword And Ignore Error   Suite Cleanup
31
32
33 *** Variables ***
34 # NS and VNF descriptor package folder and ids
35 ${VNFD_PKG}   ubuntu_4ifaces_vnf
36 ${VNFD_NAME}   ubuntu_4ifaces-vnf
37 ${NSD_PKG}   ubuntu_4ifaces_ns
38 ${NSD_NAME}   ubuntu_4ifaces-ns
39
40 # NS instance name and configuration
41 ${NS_NAME}   basic_18
42 ${NS_CONFIG}   {vld: [ {name: mgmtnet, vim-network-name: %{VIM_MGMT_NET}} ] }
43
44 # SSH keys and username to be used
45 ${PUBLICKEY}   %{HOME}/.ssh/id_rsa.pub
46 ${PRIVATEKEY}   %{HOME}/.ssh/id_rsa
47 ${USERNAME}   ubuntu
48
49 # VNFs data
50 ${VNF_MEMBER_INDEX_1}   vnf1
51 ${VNF_MEMBER_INDEX_2}   vnf2
52 ${IFACE1_NAME}   eth1
53 ${IFACE2_NAME}   eth2
54 ${IFACE3_NAME}   eth3
55 ${DATANET1_PREFIX}   ^192.168.10.*
56 ${DATANET2_PREFIX}   ^192.168.20.*
57 ${DATANET3_PREFIX}   ^192.168.30.*
58
59 ${SUCCESS_RETURN_CODE}   0
60
61
62 *** Test Cases ***
63 Create VNF Descriptor
64     [Documentation]   Upload VNF package for the testsuite.
65     Create VNFD   '%{PACKAGES_FOLDER}/${VNFD_PKG}'
66
67 Create NS Descriptor
68     [Documentation]   Upload NS package for the testsuite.
69     Create NSD   '%{PACKAGES_FOLDER}/${NSD_PKG}'
70
71 Instantiate Network Service
72     [Documentation]   Instantiate NS for the testsuite.
73     ${id}=   Create Network Service   ${NSD_NAME}   %{VIM_TARGET}   ${NS_NAME}   ${NS_CONFIG}   ${PUBLICKEY}
74     Set Suite Variable   ${NS_ID}   ${id}
75
76 Get Vnfs Info
77     [Documentation]   Get information from the two VNF of the Ns, specifically the VNF instance id and the mgmt IP address.
78     Variable Should Exist   ${NS_ID}   msg=Network service instance is not available
79     @{vnfr_list}=   Get Ns Vnfr Ids   ${NS_ID}
80     Log List   ${vnfr_list}
81     Set Suite Variable   ${VNF_ID1}   ${vnfr_list}[0]
82     Set Suite Variable   ${VNF_ID2}   ${vnfr_list}[1]
83     ${ip}=   Get Vnf Management Ip Address   ${NS_ID}   ${VNF_MEMBER_INDEX_1}
84     Set Suite Variable   ${VNF1_IPMGMT}   ${ip}
85     Log   ${VNF1_IPMGMT}
86     ${ip}=   Get Vnf Management Ip Address   ${NS_ID}   ${VNF_MEMBER_INDEX_2}
87     Set Suite Variable   ${VNF2_IPMGMT}   ${ip}
88     Log   ${VNF2_IPMGMT}
89
90 Check Vnf1 IPs
91     [Documentation]   Check whether IP addresses of the first VNF in the VNF record meet the expected CIDR.
92     Variable Should Exist   ${VNF_ID1}   msg=VNF1 is not available
93     ${rc}   ${stdout}=   Run And Return RC And Output   osm vnf-show ${VNF_ID1} --literal | yq '.vdur[0].interfaces[] | select(.name == "${IFACE1_NAME}")' | yq -r '."ip-address"'
94     Should Be Equal As Integers   ${rc}   ${SUCCESS_RETURN_CODE}   msg=${stdout}   values=False
95     Should Match Regexp   ${stdout}   ${DATANET1_PREFIX}   msg=${stdout} doesn't match subnet's regexp ${DATANET1_PREFIX}
96     Set Suite Variable   ${VNF1_IP1}   ${stdout}
97     ${rc}   ${stdout}=   Run And Return RC And Output   osm vnf-show ${VNF_ID1} --literal | yq '.vdur[0].interfaces[] | select(.name == "${IFACE2_NAME}")' | yq -r '."ip-address"'
98     Should Be Equal As Integers   ${rc}   ${SUCCESS_RETURN_CODE}   msg=${stdout}   values=False
99     Should Match Regexp   ${stdout}   ${DATANET2_PREFIX}   msg=${stdout} doesn't match subnet's regexp ${DATANET2_PREFIX}
100     Set Suite Variable   ${VNF1_IP2}   ${stdout}
101     ${rc}   ${stdout}=   Run And Return RC And Output   osm vnf-show ${VNF_ID1} --literal | yq '.vdur[0].interfaces[] | select(.name == "${IFACE3_NAME}")' | yq -r '."ip-address"'
102     Should Be Equal As Integers   ${rc}   ${SUCCESS_RETURN_CODE}   msg=${stdout}   values=False
103     Should Match Regexp   ${stdout}   ${DATANET3_PREFIX}   msg=${stdout} doesn't match subnet's regexp ${DATANET3_PREFIX}
104     Set Suite Variable   ${VNF1_IP3}   ${stdout}
105
106 Check Vnf2 IPs
107     [Documentation]   Check whether IP addresses of the second VNF in the VNF record meet the expected CIDR.
108     Variable Should Exist   ${VNF_ID1}   msg=VNF2 is not available
109     ${rc}   ${stdout}=   Run And Return RC And Output   osm vnf-show ${VNF_ID2} --literal | yq '.vdur[0].interfaces[] | select(.name == "${IFACE1_NAME}")' | yq -r '."ip-address"'
110     Should Be Equal As Integers   ${rc}   ${SUCCESS_RETURN_CODE}   msg=${stdout}   values=False
111     Should Match Regexp   ${stdout}   ${DATANET1_PREFIX}   msg=${stdout} doesn't match subnet's regexp ${DATANET1_PREFIX}
112     Set Suite Variable   ${VNF2_IP1}   ${stdout}
113     ${rc}   ${stdout}=   Run And Return RC And Output   osm vnf-show ${VNF_ID2} --literal | yq '.vdur[0].interfaces[] | select(.name == "${IFACE2_NAME}")' | yq -r '."ip-address"'
114     Should Be Equal As Integers   ${rc}   ${SUCCESS_RETURN_CODE}   msg=${stdout}   values=False
115     Should Match Regexp   ${stdout}   ${DATANET2_PREFIX}   msg=${stdout} doesn't match subnet's regexp ${DATANET2_PREFIX}
116     Set Suite Variable   ${VNF2_IP2}   ${stdout}
117     ${rc}   ${stdout}=   Run And Return RC And Output   osm vnf-show ${VNF_ID2} --literal | yq '.vdur[0].interfaces[] | select(.name == "${IFACE3_NAME}")' | yq -r '."ip-address"'
118     Should Be Equal As Integers   ${rc}   ${SUCCESS_RETURN_CODE}   msg=${stdout}   values=False
119     Should Match Regexp   ${stdout}   ${DATANET3_PREFIX}   msg=${stdout} doesn't match subnet's regexp ${DATANET3_PREFIX}
120     Set Suite Variable   ${VNF2_IP3}   ${stdout}
121
122 Verify Vnf1 Interfaces
123     [Documentation]   Check whether IP addresses of the first VNF configured inside the VM meet the expected CIDR.
124     Variable Should Exist   ${VNF1_IPMGMT}   msg=IP address of the data VNF '${VNF_MEMBER_INDEX_1}' is not available
125     Variable Should Exist   ${PRIVATEKEY}   msg=SSH private key not available
126     Sleep   10 seconds   Wait for SSH daemon to be up
127     ${stdout}=   Execute Remote Command Check Rc Return Output   ${VNF1_IPMGMT}   ${USERNAME}   ${EMPTY}   ${PRIVATEKEY}   ip --brief addr show up | grep -v "^lo" | awk '{print $3}'
128     Log   ${stdout}
129     @{ip}=   Split String   ${stdout}
130     Should Match Regexp   ${ip}[1]   ${DATANET1_PREFIX}   msg=${ip}[1] doesn't match subnet's regexp ${DATANET1_PREFIX}
131     Should Match Regexp   ${ip}[2]   ${DATANET2_PREFIX}   msg=${ip}[2] doesn't match subnet's regexp ${DATANET2_PREFIX}
132     Should Match Regexp   ${ip}[3]   ${DATANET3_PREFIX}   msg=${ip}[3] doesn't match subnet's regexp ${DATANET3_PREFIX}
133
134 Verify Vnf2 Interfaces
135     [Documentation]   Check whether IP addresses of the second VNF configured inside the VM meet the expected CIDR.
136     Variable Should Exist   ${VNF2_IPMGMT}   msg=IP address of the data VNF '${VNF_MEMBER_INDEX_2}' is not available
137     Variable Should Exist   ${PRIVATEKEY}   msg=SSH private key not available
138     ${stdout}=   Execute Remote Command Check Rc Return Output   ${VNF2_IPMGMT}   ${USERNAME}   ${EMPTY}   ${PRIVATEKEY}   ip --brief addr show up | grep -v "^lo" | awk '{print $3}'
139     Log   ${stdout}
140     @{ip}=   Split String   ${stdout}
141     Should Match Regexp   ${ip}[1]   ${DATANET1_PREFIX}   msg=${ip}[1] doesn't match subnet's regexp ${DATANET1_PREFIX}
142     Should Match Regexp   ${ip}[2]   ${DATANET2_PREFIX}   msg=${ip}[2] doesn't match subnet's regexp ${DATANET2_PREFIX}
143     Should Match Regexp   ${ip}[3]   ${DATANET3_PREFIX}   msg=${ip}[3] doesn't match subnet's regexp ${DATANET3_PREFIX}
144
145 Ping from Vnf1 to Vnf2
146     [Documentation]   Check connectivity from the first VNF to the second VNF using ping.
147     Variable Should Exist   ${VNF1_IPMGMT}   msg=IP address of the data VNF '${VNF_MEMBER_INDEX_1}' is not available
148     Variable Should Exist   ${PRIVATEKEY}   msg=SSH private key not available
149     ${stdout}=   Execute Remote Command Check Rc Return Output   ${VNF1_IPMGMT}   ${USERNAME}   ${EMPTY}   ${PRIVATEKEY}   ip addr ; ping -c 5 ${VNF2_IPMGMT}
150     Log   ${stdout}
151     ${stdout}=   Execute Remote Command Check Rc Return Output   ${VNF1_IPMGMT}   ${USERNAME}   ${EMPTY}   ${PRIVATEKEY}   ping -c 5 ${VNF2_IP1}
152     Log   ${stdout}
153     ${stdout}=   Execute Remote Command Check Rc Return Output   ${VNF1_IPMGMT}   ${USERNAME}   ${EMPTY}   ${PRIVATEKEY}   ping -c 5 ${VNF2_IP2}
154     Log   ${stdout}
155     ${stdout}=   Execute Remote Command Check Rc Return Output   ${VNF1_IPMGMT}   ${USERNAME}   ${EMPTY}   ${PRIVATEKEY}   ping -c 5 ${VNF2_IP3}
156     Log   ${stdout}
157
158 Ping from Vnf2 to Vnf1
159     [Documentation]   Check connectivity from the second VNF to the first VNF using ping.
160     Variable Should Exist   ${VNF1_IPMGMT}   msg=IP address of the data VNF '${VNF_MEMBER_INDEX_2}' is not available
161     Variable Should Exist   ${PRIVATEKEY}   msg=SSH private key not available
162     ${stdout}=   Execute Remote Command Check Rc Return Output   ${VNF2_IPMGMT}   ${USERNAME}   ${EMPTY}   ${PRIVATEKEY}   ip addr ; ping -c 5 ${VNF1_IPMGMT}
163     Log   ${stdout}
164     ${stdout}=   Execute Remote Command Check Rc Return Output   ${VNF2_IPMGMT}   ${USERNAME}   ${EMPTY}   ${PRIVATEKEY}   ip addr ; ping -c 5 ${VNF1_IP1}
165     Log   ${stdout}
166     ${stdout}=   Execute Remote Command Check Rc Return Output   ${VNF2_IPMGMT}   ${USERNAME}   ${EMPTY}   ${PRIVATEKEY}   ip addr ; ping -c 5 ${VNF1_IP2}
167     Log   ${stdout}
168     ${stdout}=   Execute Remote Command Check Rc Return Output   ${VNF2_IPMGMT}   ${USERNAME}   ${EMPTY}   ${PRIVATEKEY}   ip addr ; ping -c 5 ${VNF1_IP3}
169     Log   ${stdout}
170
171 Delete NS Instance
172     [Documentation]   Delete NS instance.
173     [Tags]   cleanup
174     Delete NS   ${NS_NAME}
175
176 Delete NS Descriptor
177     [Documentation]   Delete NS package from OSM.
178     [Tags]   cleanup
179     Delete NSD   ${NSD_NAME}
180
181 Delete VNF Descriptor
182     [Documentation]   Delete VNF package from OSM.
183     [Tags]   cleanup
184     Delete VNFD   ${VNFD_NAME}
185
186
187 *** Keywords ***
188 Suite Cleanup
189     [Documentation]   Test Suite Cleanup: Deleting descriptors and NS instance
190     Run Keyword If Any Tests Failed   Delete NS   ${NS_NAME}
191     Run Keyword If Any Tests Failed   Delete NSD   ${NSD_NAME}
192     Run Keyword If Any Tests Failed   Delete VNFD   ${VNFD_NAME}