kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1 | """ |
| 2 | Driver for blank dataplane VMs. Created for SDNIP test. |
Jeremy Songster | ae01bba | 2016-07-11 15:39:17 -0700 | [diff] [blame] | 3 | Modified 2015 by ON.Lab |
| 4 | |
| 5 | Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 6 | the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 7 | or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg> |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 8 | """ |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 9 | import pexpect |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 10 | from drivers.common.clidriver import CLI |
| 11 | |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 12 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 13 | class DPCliDriver( CLI ): |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 14 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 15 | def __init__( self ): |
| 16 | super( CLI, self ).__init__() |
| 17 | |
| 18 | def connect( self, **connectargs ): |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 19 | for key in connectargs: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 20 | vars( self )[ key ] = connectargs[ key ] |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 21 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 22 | self.name = self.options[ 'name' ] |
| 23 | self.handle = super( DPCliDriver, self ).connect( user_name=self.user_name, |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 24 | ip_address=self.ip_address, |
| 25 | port=self.port, |
| 26 | pwd=self.pwd ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 27 | |
| 28 | if self.handle: |
| 29 | return self.handle |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 30 | else: |
| 31 | main.log.info( "NO HANDLE" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 32 | return main.FALSE |
| 33 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 34 | def create_interfaces( self, net, number, start ): |
| 35 | """ |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 36 | Creates a number,specified by 'number,' of subinterfaces on eth0. |
| 37 | Ip addresses start at 'net'.'start'.1.1 with a 24 bit netmask. |
| 38 | Addresses increment sequentially in the third quad, therefore all |
| 39 | interfaces are in different subnets on the same machine. When the |
| 40 | third quad reaches 255, it is reset to 1 and the second quad is |
| 41 | incremented. Every single ip address is placed in a file in /tmp |
| 42 | titled 'ip_table{net}.txt'. The file is used by 'pingall_interfaces()' |
| 43 | as a fping argument |
| 44 | |
| 45 | This method returns true if all interfaces are created without a hitch, |
| 46 | and false if a single interface has issues |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 47 | """ |
| 48 | self.handle.sendline( "" ) |
| 49 | self.handle.expect( "\$" ) |
SeanCorcoran | f580d10 | 2013-09-27 15:13:21 -0700 | [diff] [blame] | 50 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 51 | self.handle.sendline( "rm /tmp/local_ip.txt" ) |
| 52 | self.handle.expect( "\$" ) |
| 53 | self.handle.sendline( "touch /tmp/local_ip.txt" ) |
| 54 | self.handle.expect( "\$" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 55 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 56 | main.log.info( "Creating interfaces" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 57 | k = 0 |
| 58 | intf = 0 |
| 59 | while number != 0: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 60 | k = k + 1 |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 61 | if k == 256: |
| 62 | k = 1 |
| 63 | start = start + 1 |
| 64 | number = number - 1 |
| 65 | intf = intf + 1 |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 66 | ip = net + "." + str( start ) + "." + str( k ) + ".1" |
| 67 | self.handle.sendline( |
| 68 | "sudo ifconfig eth0:" + str( |
| 69 | intf ) + " " + ip + " netmask 255.255.255.0" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 70 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 71 | i = self.handle.expect( [ |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 72 | "\$", |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 73 | "password", |
| 74 | pexpect.TIMEOUT, |
| 75 | pexpect.EOF ], |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 76 | timeout=120 ) |
SeanCorcoran | f580d10 | 2013-09-27 15:13:21 -0700 | [diff] [blame] | 77 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 78 | if i == 0: |
| 79 | self.handle.sendline( |
| 80 | "echo " + str( ip ) + " >> /tmp/local_ip.txt" ) |
| 81 | self.handle.expect( "\$" ) |
| 82 | elif i == 1: |
| 83 | main.log.info( "Sending sudo password" ) |
| 84 | self.handle.sendline( self.pwd ) |
| 85 | self.handle.expect( "\$" ) |
| 86 | else: |
| 87 | main.log.error( "INTERFACES NOT CREATED" ) |
| 88 | return main.FALSE |
SeanCorcoran | f580d10 | 2013-09-27 15:13:21 -0700 | [diff] [blame] | 89 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 90 | def pingall_interfaces( self, netsrc, netstrt, netdst, destlogin, destip ): |
| 91 | """ |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 92 | Copies the /tmp/ip_table{ net }.txt file from the machine you wish to |
| 93 | ping, then runs fping with a source address of |
| 94 | { netsrc }.{ netstrt }.1.1 on the copied file. |
| 95 | Check every single response for reachable or unreachable. If all are |
| 96 | reachable, function returns true. If a SINGLE host is unreachable, |
| 97 | then the function stops and returns false. If fping is not installed, |
| 98 | this function will install fping then run the same command |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 99 | """ |
| 100 | self.handle.sendline( "" ) |
| 101 | self.handle.expect( "\$" ) |
SeanCorcoran | f580d10 | 2013-09-27 15:13:21 -0700 | [diff] [blame] | 102 | |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 103 | self.handle.sendline( "scp " + str( destlogin ) + "@" + |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 104 | str( destip ) + |
| 105 | ":/tmp/local_ip.txt /tmp/ip_table" + |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 106 | str( netsrc ) + ".txt" ) |
| 107 | |
| 108 | i = self.handle.expect( [ |
| 109 | "100%", |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 110 | "password", |
| 111 | pexpect.TIMEOUT ], |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 112 | timeout=30 ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 113 | |
SeanCorcoran | f580d10 | 2013-09-27 15:13:21 -0700 | [diff] [blame] | 114 | if i == 0: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 115 | main.log.info( "Copied ping file successfully" ) |
SeanCorcoran | f580d10 | 2013-09-27 15:13:21 -0700 | [diff] [blame] | 116 | elif i == 1: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 117 | self.handle.sendline( self.pwd ) |
| 118 | self.handle.expect( "100%" ) |
| 119 | main.log.info( "Copied ping file successfully" ) |
SeanCorcoran | f580d10 | 2013-09-27 15:13:21 -0700 | [diff] [blame] | 120 | elif i == 2: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 121 | main.log.error( "COULD NOT COPY PING FILE FROM " + str( destip ) ) |
SeanCorcoran | f580d10 | 2013-09-27 15:13:21 -0700 | [diff] [blame] | 122 | result = main.FALSE |
| 123 | return result |
SeanCorcoran | f580d10 | 2013-09-27 15:13:21 -0700 | [diff] [blame] | 124 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 125 | self.handle.sendline( "" ) |
| 126 | self.handle.expect( "\$" ) |
| 127 | |
| 128 | main.log.info( "Pinging interfaces on the " + str( netdst ) + |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 129 | " network from " + str( netsrc ) + "." + |
| 130 | str( netstrt ) + ".1.1" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 131 | self.handle.sendline( "sudo fping -S " + str( netsrc ) + "." + |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 132 | str( netstrt ) + ".1.1 -f /tmp/ip_table" + |
| 133 | str( netdst ) + ".txt" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 134 | while 1: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 135 | i = self.handle.expect( [ |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 136 | "reachable", |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 137 | "unreachable", |
| 138 | "\$", |
| 139 | "password", |
| 140 | pexpect.TIMEOUT, |
| 141 | "not installed" ], |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 142 | timeout=45 ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 143 | if i == 0: |
| 144 | result = main.TRUE |
| 145 | elif i == 1: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 146 | main.log.error( "An interface was unreachable" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 147 | result = main.FALSE |
| 148 | return result |
| 149 | elif i == 2: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 150 | main.log.info( "All interfaces reachable" ) |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 151 | result = main.FALSE |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 152 | return result |
| 153 | elif i == 3: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 154 | self.handle.sendline( self.pwd ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 155 | elif i == 4: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 156 | main.log.error( "Unable to fping" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 157 | result = main.FALSE |
| 158 | return result |
| 159 | elif i == 5: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 160 | main.log.info( "fping not installed, installing fping" ) |
| 161 | self.handle.sendline( "sudo apt-get install fping" ) |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 162 | i = self.handle.expect( [ "password", |
| 163 | "\$", |
| 164 | pexpect.TIMEOUT ], |
| 165 | timeout=60 ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 166 | if i == 0: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 167 | self.handle.sendline( self.pwd ) |
| 168 | self.handle.expect( "\$", timeout=30 ) |
| 169 | main.log.info( "fping installed, now pinging interfaces" ) |
| 170 | self.handle.sendline( |
| 171 | "sudo fping -S " + str( |
| 172 | netsrc ) + "." + str( |
| 173 | netstrt ) + ".1.1 -f /tmp/ip_table" + str( |
| 174 | netdst ) + ".txt" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 175 | elif i == 1: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 176 | main.log.info( "fping installed, now pinging interfaces" ) |
| 177 | self.handle.sendline( |
| 178 | "sudo fping -S " + str( |
| 179 | netsrc ) + "." + str( |
| 180 | netstrt ) + ".1.1 -f /tmp/ip_table" + str( |
| 181 | netdst ) + ".txt" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 182 | elif i == 2: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 183 | main.log.error( "Could not install fping" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 184 | result = main.FALSE |
| 185 | return result |
| 186 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 187 | def disconnect( self ): |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 188 | response = '' |
| 189 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 190 | self.handle.sendline( "exit" ) |
| 191 | self.handle.expect( "closed" ) |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 192 | except pexpect.ExceptionPexpect: |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 193 | main.log.exception( "Connection failed to the host" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 194 | response = main.FALSE |
| 195 | return response |
| 196 | |