Package TestON :: Package drivers :: Package common :: Package cli :: Module dpclidriver
[hide private]
[frames] | no frames]

Source Code for Module TestON.drivers.common.cli.dpclidriver

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