blob: a15227371cf6740fe6d8ec14ca70c74ce8b47383 [file] [log] [blame]
kelvin8ec71442015-01-15 16:57:00 -08001"""
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00002Copyright 2015 Open Networking Foundation (ONF)
Jeremy Songsterae01bba2016-07-11 15:39:17 -07003
4Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
5the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
6or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07007
8 TestON is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 2 of the License, or
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +000011 (at your option) any later version.
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -070012
13 TestON is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with TestON. If not, see <http://www.gnu.org/licenses/>.
20
21
22
23Driver for blank dataplane VMs. Created for SDNIP test.
24
kelvin8ec71442015-01-15 16:57:00 -080025"""
timlindbergef8d55d2013-09-27 12:50:13 -070026import pexpect
timlindbergef8d55d2013-09-27 12:50:13 -070027from drivers.common.clidriver import CLI
28
timlindbergef8d55d2013-09-27 12:50:13 -070029
kelvin8ec71442015-01-15 16:57:00 -080030class DPCliDriver( CLI ):
timlindbergef8d55d2013-09-27 12:50:13 -070031
kelvin8ec71442015-01-15 16:57:00 -080032 def __init__( self ):
Devin Limdc78e202017-06-09 18:30:07 -070033 super( DPCliDriver, self ).__init__()
kelvin8ec71442015-01-15 16:57:00 -080034
35 def connect( self, **connectargs ):
timlindbergef8d55d2013-09-27 12:50:13 -070036 for key in connectargs:
kelvin8ec71442015-01-15 16:57:00 -080037 vars( self )[ key ] = connectargs[ key ]
timlindbergef8d55d2013-09-27 12:50:13 -070038
kelvin8ec71442015-01-15 16:57:00 -080039 self.name = self.options[ 'name' ]
40 self.handle = super( DPCliDriver, self ).connect( user_name=self.user_name,
Jeremy Ronquillo82705492017-10-18 14:19:55 -070041 ip_address=self.ip_address,
42 port=self.port,
43 pwd=self.pwd )
timlindbergef8d55d2013-09-27 12:50:13 -070044
45 if self.handle:
46 return self.handle
kelvin8ec71442015-01-15 16:57:00 -080047 else:
48 main.log.info( "NO HANDLE" )
timlindbergef8d55d2013-09-27 12:50:13 -070049 return main.FALSE
50
kelvin8ec71442015-01-15 16:57:00 -080051 def create_interfaces( self, net, number, start ):
52 """
Jon Hallefbd9792015-03-05 16:11:36 -080053 Creates a number,specified by 'number,' of subinterfaces on eth0.
54 Ip addresses start at 'net'.'start'.1.1 with a 24 bit netmask.
55 Addresses increment sequentially in the third quad, therefore all
56 interfaces are in different subnets on the same machine. When the
57 third quad reaches 255, it is reset to 1 and the second quad is
58 incremented. Every single ip address is placed in a file in /tmp
59 titled 'ip_table{net}.txt'. The file is used by 'pingall_interfaces()'
60 as a fping argument
61
62 This method returns true if all interfaces are created without a hitch,
63 and false if a single interface has issues
kelvin8ec71442015-01-15 16:57:00 -080064 """
65 self.handle.sendline( "" )
Devin Limdc78e202017-06-09 18:30:07 -070066 self.handle.expect( self.prompt )
SeanCorcoranf580d102013-09-27 15:13:21 -070067
kelvin8ec71442015-01-15 16:57:00 -080068 self.handle.sendline( "rm /tmp/local_ip.txt" )
Devin Limdc78e202017-06-09 18:30:07 -070069 self.handle.expect( self.prompt )
kelvin8ec71442015-01-15 16:57:00 -080070 self.handle.sendline( "touch /tmp/local_ip.txt" )
Devin Limdc78e202017-06-09 18:30:07 -070071 self.handle.expect( self.prompt )
timlindbergef8d55d2013-09-27 12:50:13 -070072
kelvin8ec71442015-01-15 16:57:00 -080073 main.log.info( "Creating interfaces" )
timlindbergef8d55d2013-09-27 12:50:13 -070074 k = 0
75 intf = 0
76 while number != 0:
kelvin8ec71442015-01-15 16:57:00 -080077 k = k + 1
timlindbergef8d55d2013-09-27 12:50:13 -070078 if k == 256:
79 k = 1
80 start = start + 1
81 number = number - 1
82 intf = intf + 1
kelvin8ec71442015-01-15 16:57:00 -080083 ip = net + "." + str( start ) + "." + str( k ) + ".1"
84 self.handle.sendline(
85 "sudo ifconfig eth0:" + str(
86 intf ) + " " + ip + " netmask 255.255.255.0" )
timlindbergef8d55d2013-09-27 12:50:13 -070087
kelvin8ec71442015-01-15 16:57:00 -080088 i = self.handle.expect( [
Devin Limdc78e202017-06-09 18:30:07 -070089 self.prompt,
kelvin8ec71442015-01-15 16:57:00 -080090 "password",
91 pexpect.TIMEOUT,
92 pexpect.EOF ],
Jon Hallefbd9792015-03-05 16:11:36 -080093 timeout=120 )
SeanCorcoranf580d102013-09-27 15:13:21 -070094
kelvin8ec71442015-01-15 16:57:00 -080095 if i == 0:
96 self.handle.sendline(
97 "echo " + str( ip ) + " >> /tmp/local_ip.txt" )
Devin Limdc78e202017-06-09 18:30:07 -070098 self.handle.expect( self.prompt )
kelvin8ec71442015-01-15 16:57:00 -080099 elif i == 1:
100 main.log.info( "Sending sudo password" )
101 self.handle.sendline( self.pwd )
Devin Limdc78e202017-06-09 18:30:07 -0700102 self.handle.expect( self.prompt )
kelvin8ec71442015-01-15 16:57:00 -0800103 else:
104 main.log.error( "INTERFACES NOT CREATED" )
105 return main.FALSE
SeanCorcoranf580d102013-09-27 15:13:21 -0700106
kelvin8ec71442015-01-15 16:57:00 -0800107 def pingall_interfaces( self, netsrc, netstrt, netdst, destlogin, destip ):
108 """
Jon Hallefbd9792015-03-05 16:11:36 -0800109 Copies the /tmp/ip_table{ net }.txt file from the machine you wish to
110 ping, then runs fping with a source address of
111 { netsrc }.{ netstrt }.1.1 on the copied file.
112 Check every single response for reachable or unreachable. If all are
113 reachable, function returns true. If a SINGLE host is unreachable,
114 then the function stops and returns false. If fping is not installed,
115 this function will install fping then run the same command
kelvin8ec71442015-01-15 16:57:00 -0800116 """
117 self.handle.sendline( "" )
Devin Limdc78e202017-06-09 18:30:07 -0700118 self.handle.expect( self.prompt )
SeanCorcoranf580d102013-09-27 15:13:21 -0700119
Jon Hallfebb1c72015-03-05 13:30:09 -0800120 self.handle.sendline( "scp " + str( destlogin ) + "@" +
Jon Hallefbd9792015-03-05 16:11:36 -0800121 str( destip ) +
122 ":/tmp/local_ip.txt /tmp/ip_table" +
Jon Hallfebb1c72015-03-05 13:30:09 -0800123 str( netsrc ) + ".txt" )
124
125 i = self.handle.expect( [
126 "100%",
kelvin8ec71442015-01-15 16:57:00 -0800127 "password",
128 pexpect.TIMEOUT ],
Jon Hallfebb1c72015-03-05 13:30:09 -0800129 timeout=30 )
kelvin8ec71442015-01-15 16:57:00 -0800130
SeanCorcoranf580d102013-09-27 15:13:21 -0700131 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -0800132 main.log.info( "Copied ping file successfully" )
SeanCorcoranf580d102013-09-27 15:13:21 -0700133 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800134 self.handle.sendline( self.pwd )
135 self.handle.expect( "100%" )
136 main.log.info( "Copied ping file successfully" )
SeanCorcoranf580d102013-09-27 15:13:21 -0700137 elif i == 2:
kelvin8ec71442015-01-15 16:57:00 -0800138 main.log.error( "COULD NOT COPY PING FILE FROM " + str( destip ) )
SeanCorcoranf580d102013-09-27 15:13:21 -0700139 result = main.FALSE
140 return result
SeanCorcoranf580d102013-09-27 15:13:21 -0700141
kelvin8ec71442015-01-15 16:57:00 -0800142 self.handle.sendline( "" )
Devin Limdc78e202017-06-09 18:30:07 -0700143 self.handle.expect( self.prompt )
kelvin8ec71442015-01-15 16:57:00 -0800144
145 main.log.info( "Pinging interfaces on the " + str( netdst ) +
Jon Hallfebb1c72015-03-05 13:30:09 -0800146 " network from " + str( netsrc ) + "." +
147 str( netstrt ) + ".1.1" )
kelvin8ec71442015-01-15 16:57:00 -0800148 self.handle.sendline( "sudo fping -S " + str( netsrc ) + "." +
Jon Hallfebb1c72015-03-05 13:30:09 -0800149 str( netstrt ) + ".1.1 -f /tmp/ip_table" +
150 str( netdst ) + ".txt" )
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700151 while True:
kelvin8ec71442015-01-15 16:57:00 -0800152 i = self.handle.expect( [
Jon Hallfebb1c72015-03-05 13:30:09 -0800153 "reachable",
kelvin8ec71442015-01-15 16:57:00 -0800154 "unreachable",
Devin Limdc78e202017-06-09 18:30:07 -0700155 self.prompt,
kelvin8ec71442015-01-15 16:57:00 -0800156 "password",
157 pexpect.TIMEOUT,
158 "not installed" ],
Jon Hallfebb1c72015-03-05 13:30:09 -0800159 timeout=45 )
timlindbergef8d55d2013-09-27 12:50:13 -0700160 if i == 0:
161 result = main.TRUE
162 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800163 main.log.error( "An interface was unreachable" )
timlindbergef8d55d2013-09-27 12:50:13 -0700164 result = main.FALSE
165 return result
166 elif i == 2:
kelvin8ec71442015-01-15 16:57:00 -0800167 main.log.info( "All interfaces reachable" )
Jon Hallfebb1c72015-03-05 13:30:09 -0800168 result = main.FALSE
timlindbergef8d55d2013-09-27 12:50:13 -0700169 return result
170 elif i == 3:
kelvin8ec71442015-01-15 16:57:00 -0800171 self.handle.sendline( self.pwd )
timlindbergef8d55d2013-09-27 12:50:13 -0700172 elif i == 4:
kelvin8ec71442015-01-15 16:57:00 -0800173 main.log.error( "Unable to fping" )
timlindbergef8d55d2013-09-27 12:50:13 -0700174 result = main.FALSE
175 return result
176 elif i == 5:
kelvin8ec71442015-01-15 16:57:00 -0800177 main.log.info( "fping not installed, installing fping" )
178 self.handle.sendline( "sudo apt-get install fping" )
Jon Hallefbd9792015-03-05 16:11:36 -0800179 i = self.handle.expect( [ "password",
Devin Limdc78e202017-06-09 18:30:07 -0700180 self.prompt,
Jon Hallefbd9792015-03-05 16:11:36 -0800181 pexpect.TIMEOUT ],
182 timeout=60 )
timlindbergef8d55d2013-09-27 12:50:13 -0700183 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -0800184 self.handle.sendline( self.pwd )
Devin Limdc78e202017-06-09 18:30:07 -0700185 self.handle.expect( self.prompt, timeout=30 )
kelvin8ec71442015-01-15 16:57:00 -0800186 main.log.info( "fping installed, now pinging interfaces" )
187 self.handle.sendline(
188 "sudo fping -S " + str(
189 netsrc ) + "." + str(
190 netstrt ) + ".1.1 -f /tmp/ip_table" + str(
191 netdst ) + ".txt" )
timlindbergef8d55d2013-09-27 12:50:13 -0700192 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800193 main.log.info( "fping installed, now pinging interfaces" )
194 self.handle.sendline(
195 "sudo fping -S " + str(
196 netsrc ) + "." + str(
197 netstrt ) + ".1.1 -f /tmp/ip_table" + str(
198 netdst ) + ".txt" )
timlindbergef8d55d2013-09-27 12:50:13 -0700199 elif i == 2:
kelvin8ec71442015-01-15 16:57:00 -0800200 main.log.error( "Could not install fping" )
timlindbergef8d55d2013-09-27 12:50:13 -0700201 result = main.FALSE
202 return result
203
kelvin8ec71442015-01-15 16:57:00 -0800204 def disconnect( self ):
timlindbergef8d55d2013-09-27 12:50:13 -0700205 response = ''
206 try:
kelvin8ec71442015-01-15 16:57:00 -0800207 self.handle.sendline( "exit" )
208 self.handle.expect( "closed" )
Jon Hallefbd9792015-03-05 16:11:36 -0800209 except pexpect.ExceptionPexpect:
Jon Hallfebb1c72015-03-05 13:30:09 -0800210 main.log.exception( "Connection failed to the host" )
timlindbergef8d55d2013-09-27 12:50:13 -0700211 response = main.FALSE
212 return response