blob: f3ea3e589b12ca8a5a7f5b5b0ac5d7a67e6bf149 [file] [log] [blame]
kelvin8ec71442015-01-15 16:57:00 -08001"""
2Driver for blank dataplane VMs. Created for SDNIP test.
Jeremy Songsterae01bba2016-07-11 15:39:17 -07003Modified 2015 by ON.Lab
4
5Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
6the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
7or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
kelvin8ec71442015-01-15 16:57:00 -08008"""
timlindbergef8d55d2013-09-27 12:50:13 -07009import pexpect
timlindbergef8d55d2013-09-27 12:50:13 -070010from drivers.common.clidriver import CLI
11
timlindbergef8d55d2013-09-27 12:50:13 -070012
kelvin8ec71442015-01-15 16:57:00 -080013class DPCliDriver( CLI ):
timlindbergef8d55d2013-09-27 12:50:13 -070014
kelvin8ec71442015-01-15 16:57:00 -080015 def __init__( self ):
16 super( CLI, self ).__init__()
17
18 def connect( self, **connectargs ):
timlindbergef8d55d2013-09-27 12:50:13 -070019 for key in connectargs:
kelvin8ec71442015-01-15 16:57:00 -080020 vars( self )[ key ] = connectargs[ key ]
timlindbergef8d55d2013-09-27 12:50:13 -070021
kelvin8ec71442015-01-15 16:57:00 -080022 self.name = self.options[ 'name' ]
23 self.handle = super( DPCliDriver, self ).connect( user_name=self.user_name,
Jon Hallefbd9792015-03-05 16:11:36 -080024 ip_address=self.ip_address,
25 port=self.port,
26 pwd=self.pwd )
timlindbergef8d55d2013-09-27 12:50:13 -070027
28 if self.handle:
29 return self.handle
kelvin8ec71442015-01-15 16:57:00 -080030 else:
31 main.log.info( "NO HANDLE" )
timlindbergef8d55d2013-09-27 12:50:13 -070032 return main.FALSE
33
kelvin8ec71442015-01-15 16:57:00 -080034 def create_interfaces( self, net, number, start ):
35 """
Jon Hallefbd9792015-03-05 16:11:36 -080036 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
kelvin8ec71442015-01-15 16:57:00 -080047 """
48 self.handle.sendline( "" )
49 self.handle.expect( "\$" )
SeanCorcoranf580d102013-09-27 15:13:21 -070050
kelvin8ec71442015-01-15 16:57:00 -080051 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( "\$" )
timlindbergef8d55d2013-09-27 12:50:13 -070055
kelvin8ec71442015-01-15 16:57:00 -080056 main.log.info( "Creating interfaces" )
timlindbergef8d55d2013-09-27 12:50:13 -070057 k = 0
58 intf = 0
59 while number != 0:
kelvin8ec71442015-01-15 16:57:00 -080060 k = k + 1
timlindbergef8d55d2013-09-27 12:50:13 -070061 if k == 256:
62 k = 1
63 start = start + 1
64 number = number - 1
65 intf = intf + 1
kelvin8ec71442015-01-15 16:57:00 -080066 ip = net + "." + str( start ) + "." + str( k ) + ".1"
67 self.handle.sendline(
68 "sudo ifconfig eth0:" + str(
69 intf ) + " " + ip + " netmask 255.255.255.0" )
timlindbergef8d55d2013-09-27 12:50:13 -070070
kelvin8ec71442015-01-15 16:57:00 -080071 i = self.handle.expect( [
Jon Hallefbd9792015-03-05 16:11:36 -080072 "\$",
kelvin8ec71442015-01-15 16:57:00 -080073 "password",
74 pexpect.TIMEOUT,
75 pexpect.EOF ],
Jon Hallefbd9792015-03-05 16:11:36 -080076 timeout=120 )
SeanCorcoranf580d102013-09-27 15:13:21 -070077
kelvin8ec71442015-01-15 16:57:00 -080078 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
SeanCorcoranf580d102013-09-27 15:13:21 -070089
kelvin8ec71442015-01-15 16:57:00 -080090 def pingall_interfaces( self, netsrc, netstrt, netdst, destlogin, destip ):
91 """
Jon Hallefbd9792015-03-05 16:11:36 -080092 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
kelvin8ec71442015-01-15 16:57:00 -080099 """
100 self.handle.sendline( "" )
101 self.handle.expect( "\$" )
SeanCorcoranf580d102013-09-27 15:13:21 -0700102
Jon Hallfebb1c72015-03-05 13:30:09 -0800103 self.handle.sendline( "scp " + str( destlogin ) + "@" +
Jon Hallefbd9792015-03-05 16:11:36 -0800104 str( destip ) +
105 ":/tmp/local_ip.txt /tmp/ip_table" +
Jon Hallfebb1c72015-03-05 13:30:09 -0800106 str( netsrc ) + ".txt" )
107
108 i = self.handle.expect( [
109 "100%",
kelvin8ec71442015-01-15 16:57:00 -0800110 "password",
111 pexpect.TIMEOUT ],
Jon Hallfebb1c72015-03-05 13:30:09 -0800112 timeout=30 )
kelvin8ec71442015-01-15 16:57:00 -0800113
SeanCorcoranf580d102013-09-27 15:13:21 -0700114 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -0800115 main.log.info( "Copied ping file successfully" )
SeanCorcoranf580d102013-09-27 15:13:21 -0700116 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800117 self.handle.sendline( self.pwd )
118 self.handle.expect( "100%" )
119 main.log.info( "Copied ping file successfully" )
SeanCorcoranf580d102013-09-27 15:13:21 -0700120 elif i == 2:
kelvin8ec71442015-01-15 16:57:00 -0800121 main.log.error( "COULD NOT COPY PING FILE FROM " + str( destip ) )
SeanCorcoranf580d102013-09-27 15:13:21 -0700122 result = main.FALSE
123 return result
SeanCorcoranf580d102013-09-27 15:13:21 -0700124
kelvin8ec71442015-01-15 16:57:00 -0800125 self.handle.sendline( "" )
126 self.handle.expect( "\$" )
127
128 main.log.info( "Pinging interfaces on the " + str( netdst ) +
Jon Hallfebb1c72015-03-05 13:30:09 -0800129 " network from " + str( netsrc ) + "." +
130 str( netstrt ) + ".1.1" )
kelvin8ec71442015-01-15 16:57:00 -0800131 self.handle.sendline( "sudo fping -S " + str( netsrc ) + "." +
Jon Hallfebb1c72015-03-05 13:30:09 -0800132 str( netstrt ) + ".1.1 -f /tmp/ip_table" +
133 str( netdst ) + ".txt" )
timlindbergef8d55d2013-09-27 12:50:13 -0700134 while 1:
kelvin8ec71442015-01-15 16:57:00 -0800135 i = self.handle.expect( [
Jon Hallfebb1c72015-03-05 13:30:09 -0800136 "reachable",
kelvin8ec71442015-01-15 16:57:00 -0800137 "unreachable",
138 "\$",
139 "password",
140 pexpect.TIMEOUT,
141 "not installed" ],
Jon Hallfebb1c72015-03-05 13:30:09 -0800142 timeout=45 )
timlindbergef8d55d2013-09-27 12:50:13 -0700143 if i == 0:
144 result = main.TRUE
145 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800146 main.log.error( "An interface was unreachable" )
timlindbergef8d55d2013-09-27 12:50:13 -0700147 result = main.FALSE
148 return result
149 elif i == 2:
kelvin8ec71442015-01-15 16:57:00 -0800150 main.log.info( "All interfaces reachable" )
Jon Hallfebb1c72015-03-05 13:30:09 -0800151 result = main.FALSE
timlindbergef8d55d2013-09-27 12:50:13 -0700152 return result
153 elif i == 3:
kelvin8ec71442015-01-15 16:57:00 -0800154 self.handle.sendline( self.pwd )
timlindbergef8d55d2013-09-27 12:50:13 -0700155 elif i == 4:
kelvin8ec71442015-01-15 16:57:00 -0800156 main.log.error( "Unable to fping" )
timlindbergef8d55d2013-09-27 12:50:13 -0700157 result = main.FALSE
158 return result
159 elif i == 5:
kelvin8ec71442015-01-15 16:57:00 -0800160 main.log.info( "fping not installed, installing fping" )
161 self.handle.sendline( "sudo apt-get install fping" )
Jon Hallefbd9792015-03-05 16:11:36 -0800162 i = self.handle.expect( [ "password",
163 "\$",
164 pexpect.TIMEOUT ],
165 timeout=60 )
timlindbergef8d55d2013-09-27 12:50:13 -0700166 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -0800167 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" )
timlindbergef8d55d2013-09-27 12:50:13 -0700175 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800176 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" )
timlindbergef8d55d2013-09-27 12:50:13 -0700182 elif i == 2:
kelvin8ec71442015-01-15 16:57:00 -0800183 main.log.error( "Could not install fping" )
timlindbergef8d55d2013-09-27 12:50:13 -0700184 result = main.FALSE
185 return result
186
kelvin8ec71442015-01-15 16:57:00 -0800187 def disconnect( self ):
timlindbergef8d55d2013-09-27 12:50:13 -0700188 response = ''
189 try:
kelvin8ec71442015-01-15 16:57:00 -0800190 self.handle.sendline( "exit" )
191 self.handle.expect( "closed" )
Jon Hallefbd9792015-03-05 16:11:36 -0800192 except pexpect.ExceptionPexpect:
Jon Hallfebb1c72015-03-05 13:30:09 -0800193 main.log.exception( "Connection failed to the host" )
timlindbergef8d55d2013-09-27 12:50:13 -0700194 response = main.FALSE
195 return response
196