kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1 | """ |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2 | Copyright 2015 Open Networking Foundation (ONF) |
Jeremy Songster | ae01bba | 2016-07-11 15:39:17 -0700 | [diff] [blame] | 3 | |
| 4 | Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 5 | the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 6 | or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg> |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 7 | |
| 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 Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 11 | (at your option) any later version. |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 12 | |
| 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 | |
| 23 | Driver for blank dataplane VMs. Created for SDNIP test. |
| 24 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 25 | """ |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 26 | import pexpect |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 27 | from drivers.common.clidriver import CLI |
| 28 | |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 29 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 30 | class DPCliDriver( CLI ): |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 31 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 32 | def __init__( self ): |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 33 | super( DPCliDriver, self ).__init__() |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 34 | |
| 35 | def connect( self, **connectargs ): |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 36 | for key in connectargs: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 37 | vars( self )[ key ] = connectargs[ key ] |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 38 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 39 | self.name = self.options[ 'name' ] |
| 40 | self.handle = super( DPCliDriver, self ).connect( user_name=self.user_name, |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 41 | ip_address=self.ip_address, |
| 42 | port=self.port, |
| 43 | pwd=self.pwd ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 44 | |
| 45 | if self.handle: |
| 46 | return self.handle |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 47 | else: |
| 48 | main.log.info( "NO HANDLE" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 49 | return main.FALSE |
| 50 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 51 | def create_interfaces( self, net, number, start ): |
| 52 | """ |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 53 | 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 |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 64 | """ |
| 65 | self.handle.sendline( "" ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 66 | self.handle.expect( self.prompt ) |
SeanCorcoran | f580d10 | 2013-09-27 15:13:21 -0700 | [diff] [blame] | 67 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 68 | self.handle.sendline( "rm /tmp/local_ip.txt" ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 69 | self.handle.expect( self.prompt ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 70 | self.handle.sendline( "touch /tmp/local_ip.txt" ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 71 | self.handle.expect( self.prompt ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 72 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 73 | main.log.info( "Creating interfaces" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 74 | k = 0 |
| 75 | intf = 0 |
| 76 | while number != 0: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 77 | k = k + 1 |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 78 | if k == 256: |
| 79 | k = 1 |
| 80 | start = start + 1 |
| 81 | number = number - 1 |
| 82 | intf = intf + 1 |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 83 | ip = net + "." + str( start ) + "." + str( k ) + ".1" |
| 84 | self.handle.sendline( |
| 85 | "sudo ifconfig eth0:" + str( |
| 86 | intf ) + " " + ip + " netmask 255.255.255.0" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 87 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 88 | i = self.handle.expect( [ |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 89 | self.prompt, |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 90 | "password", |
| 91 | pexpect.TIMEOUT, |
| 92 | pexpect.EOF ], |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 93 | timeout=120 ) |
SeanCorcoran | f580d10 | 2013-09-27 15:13:21 -0700 | [diff] [blame] | 94 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 95 | if i == 0: |
| 96 | self.handle.sendline( |
| 97 | "echo " + str( ip ) + " >> /tmp/local_ip.txt" ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 98 | self.handle.expect( self.prompt ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 99 | elif i == 1: |
| 100 | main.log.info( "Sending sudo password" ) |
| 101 | self.handle.sendline( self.pwd ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 102 | self.handle.expect( self.prompt ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 103 | else: |
| 104 | main.log.error( "INTERFACES NOT CREATED" ) |
| 105 | return main.FALSE |
SeanCorcoran | f580d10 | 2013-09-27 15:13:21 -0700 | [diff] [blame] | 106 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 107 | def pingall_interfaces( self, netsrc, netstrt, netdst, destlogin, destip ): |
| 108 | """ |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 109 | 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 |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 116 | """ |
| 117 | self.handle.sendline( "" ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 118 | self.handle.expect( self.prompt ) |
SeanCorcoran | f580d10 | 2013-09-27 15:13:21 -0700 | [diff] [blame] | 119 | |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 120 | self.handle.sendline( "scp " + str( destlogin ) + "@" + |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 121 | str( destip ) + |
| 122 | ":/tmp/local_ip.txt /tmp/ip_table" + |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 123 | str( netsrc ) + ".txt" ) |
| 124 | |
| 125 | i = self.handle.expect( [ |
| 126 | "100%", |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 127 | "password", |
| 128 | pexpect.TIMEOUT ], |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 129 | timeout=30 ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 130 | |
SeanCorcoran | f580d10 | 2013-09-27 15:13:21 -0700 | [diff] [blame] | 131 | if i == 0: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 132 | main.log.info( "Copied ping file successfully" ) |
SeanCorcoran | f580d10 | 2013-09-27 15:13:21 -0700 | [diff] [blame] | 133 | elif i == 1: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 134 | self.handle.sendline( self.pwd ) |
| 135 | self.handle.expect( "100%" ) |
| 136 | main.log.info( "Copied ping file successfully" ) |
SeanCorcoran | f580d10 | 2013-09-27 15:13:21 -0700 | [diff] [blame] | 137 | elif i == 2: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 138 | main.log.error( "COULD NOT COPY PING FILE FROM " + str( destip ) ) |
SeanCorcoran | f580d10 | 2013-09-27 15:13:21 -0700 | [diff] [blame] | 139 | result = main.FALSE |
| 140 | return result |
SeanCorcoran | f580d10 | 2013-09-27 15:13:21 -0700 | [diff] [blame] | 141 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 142 | self.handle.sendline( "" ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 143 | self.handle.expect( self.prompt ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 144 | |
| 145 | main.log.info( "Pinging interfaces on the " + str( netdst ) + |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 146 | " network from " + str( netsrc ) + "." + |
| 147 | str( netstrt ) + ".1.1" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 148 | self.handle.sendline( "sudo fping -S " + str( netsrc ) + "." + |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 149 | str( netstrt ) + ".1.1 -f /tmp/ip_table" + |
| 150 | str( netdst ) + ".txt" ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 151 | while True: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 152 | i = self.handle.expect( [ |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 153 | "reachable", |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 154 | "unreachable", |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 155 | self.prompt, |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 156 | "password", |
| 157 | pexpect.TIMEOUT, |
| 158 | "not installed" ], |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 159 | timeout=45 ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 160 | if i == 0: |
| 161 | result = main.TRUE |
| 162 | elif i == 1: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 163 | main.log.error( "An interface was unreachable" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 164 | result = main.FALSE |
| 165 | return result |
| 166 | elif i == 2: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 167 | main.log.info( "All interfaces reachable" ) |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 168 | result = main.FALSE |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 169 | return result |
| 170 | elif i == 3: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 171 | self.handle.sendline( self.pwd ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 172 | elif i == 4: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 173 | main.log.error( "Unable to fping" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 174 | result = main.FALSE |
| 175 | return result |
| 176 | elif i == 5: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 177 | main.log.info( "fping not installed, installing fping" ) |
| 178 | self.handle.sendline( "sudo apt-get install fping" ) |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 179 | i = self.handle.expect( [ "password", |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 180 | self.prompt, |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 181 | pexpect.TIMEOUT ], |
| 182 | timeout=60 ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 183 | if i == 0: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 184 | self.handle.sendline( self.pwd ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 185 | self.handle.expect( self.prompt, timeout=30 ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 186 | 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" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 192 | elif i == 1: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 193 | 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" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 199 | elif i == 2: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 200 | main.log.error( "Could not install fping" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 201 | result = main.FALSE |
| 202 | return result |
| 203 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 204 | def disconnect( self ): |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 205 | response = '' |
| 206 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 207 | self.handle.sendline( "exit" ) |
| 208 | self.handle.expect( "closed" ) |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 209 | except pexpect.ExceptionPexpect: |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 210 | main.log.exception( "Connection failed to the host" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 211 | response = main.FALSE |
| 212 | return response |