blob: f5a70d45b05af724dd0eb2d6325c9f1f69da3483 [file] [log] [blame]
adminbae64d82013-08-01 10:50:15 -07001#!/usr/bin/env python
2'''
James Leec9cacaf2014-04-08 09:17:39 -07003Created on 31-May-2013
adminbae64d82013-08-01 10:50:15 -07004
James Leec9cacaf2014-04-08 09:17:39 -07005@author: Anil Kumar (anilkumar.s@paxterrasolutions.com)
adminbae64d82013-08-01 10:50:15 -07006
James Leec9cacaf2014-04-08 09:17:39 -07007TestON is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation, either version 2 of the License, or
10(at your option) any later version.
adminbae64d82013-08-01 10:50:15 -070011
James Leec9cacaf2014-04-08 09:17:39 -070012TestON is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
adminbae64d82013-08-01 10:50:15 -070016
James Leec9cacaf2014-04-08 09:17:39 -070017You should have received a copy of the GNU General Public License
18along with TestON. If not, see <http://www.gnu.org/licenses/>.
adminbae64d82013-08-01 10:50:15 -070019
20
James Leec9cacaf2014-04-08 09:17:39 -070021'''
adminbae64d82013-08-01 10:50:15 -070022import time
23import pexpect
24import struct, fcntl, os, sys, signal
adminbae64d82013-08-01 10:50:15 -070025import re
26import json
Jon Hallf89c8552014-04-02 13:14:06 -070027import traceback
adminbae64d82013-08-01 10:50:15 -070028sys.path.append("../")
29from drivers.common.clidriver import CLI
30
31class OnosCliDriver(CLI):
32
33 def __init__(self):
34 super(CLI, self).__init__()
35
36 def connect(self,**connectargs):
Jon Halld8dc5772014-04-08 16:26:29 -070037 '''
38 Creates ssh handle for ONOS.
39 '''
Jon Hallf89c8552014-04-02 13:14:06 -070040 try:
41 for key in connectargs:
admine0eeea22014-04-14 10:22:46 -070042 vars(self)[key] = connectargs[key]
Jon Hallf89c8552014-04-02 13:14:06 -070043 self.home = "~/ONOS"
44 for key in self.options:
admine0eeea22014-04-14 10:22:46 -070045 if key == "home":
46 self.home = self.options['home']
47 break
adminbae64d82013-08-01 10:50:15 -070048
Jon Hallf89c8552014-04-02 13:14:06 -070049
50 self.name = self.options['name']
51 self.handle = super(OnosCliDriver,self).connect(user_name = self.user_name, ip_address = self.ip_address,port = self.port, pwd = self.pwd, home = self.home)
adminbae64d82013-08-01 10:50:15 -070052
Jon Hallf89c8552014-04-02 13:14:06 -070053 if self.handle:
Jon Hallf89c8552014-04-02 13:14:06 -070054 return self.handle
55 else :
56 main.log.info("NO ONOS HANDLE")
57 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -070058 except pexpect.EOF:
59 main.log.error(self.name + ": EOF exception found")
60 main.log.error(self.name + ": " + self.handle.before)
61 main.cleanup()
62 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -070063 except:
64 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
65 main.log.error( traceback.print_exc() )
66 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
67 main.cleanup()
68 main.exit()
adminbae64d82013-08-01 10:50:15 -070069
70 def start(self):
Jon Halld8dc5772014-04-08 16:26:29 -070071 '''
72 Starts ONOS on remote machine.
73 Returns false if any errors were encountered.
74 '''
James Leec9cacaf2014-04-08 09:17:39 -070075 try:
Jon Hallf89c8552014-04-02 13:14:06 -070076 self.handle.sendline("")
Jon Hallae05dc22014-04-16 10:56:28 -070077 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
Jon Hall4a2b0482014-04-18 16:29:26 -070078 self.handle.sendline("cd "+self.home)
79 self.handle.sendline("./onos.sh core start")
Jon Hallae05dc22014-04-16 10:56:28 -070080 i=self.handle.expect(["STARTED","FAILED",pexpect.EOF,pexpect.TIMEOUT])
81 response = self.handle.before + str(self.handle.after)
Jon Hallf89c8552014-04-02 13:14:06 -070082 if i==0:
Jon Hallae05dc22014-04-16 10:56:28 -070083 j = self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT], timeout=60)
84 if re.search("Killed",response):
85 main.log.warn(self.name + ": Killed existing process")
86 if j==0:
Jon Hallf89c8552014-04-02 13:14:06 -070087 main.log.info(self.name + ": ONOS Started ")
Jon Hallae05dc22014-04-16 10:56:28 -070088 return main.TRUE
89 elif j==1:
90 main.log.error(self.name + ": EOF exception found")
91 main.log.error(self.name + ": " + self.handle.before)
92 main.cleanup()
93 main.exit()
94 elif j==2:
Jon Hallf89c8552014-04-02 13:14:06 -070095 main.log.info(self.name + ": ONOS NOT Started, stuck while waiting for it to start ")
96 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -070097 else:
98 main.log.warn(self.name +": Unexpected response in start")
99 return main.TRUE
Jon Hallf89c8552014-04-02 13:14:06 -0700100 elif i==1:
Jon Hallae05dc22014-04-16 10:56:28 -0700101 main.log.error(self.name + ": ONOS Failed to start")
adminbae64d82013-08-01 10:50:15 -0700102 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700103 elif i==2:
104 main.log.error(self.name + ": EOF exception found")
105 main.log.error(self.name + ": " + self.handle.before)
106 main.cleanup()
107 main.exit()
108 elif i==3:
109 main.log.error(self.name + ": ONOS timedout while starting")
110 return main.FALSE
111 else:
112 main.log.error(self.name + ": ONOS start expect script missed something... ")
adminbae64d82013-08-01 10:50:15 -0700113 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700114 except pexpect.EOF:
115 main.log.error(self.name + ": EOF exception found")
116 main.log.error(self.name + ": " + self.handle.before)
117 main.cleanup()
118 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700119 except:
120 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
121 main.log.error( traceback.print_exc() )
122 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
123 main.cleanup()
124 main.exit()
Jon Halle80ef8c2014-04-29 15:29:13 -0700125
126 def start_all(self):
127 '''
128 starts ZK, RC, and ONOS
129 '''
130 self.handle.sendline("cd "+self.home)
131 self.handle.sendline("./onos.sh start")
132 self.handle.expect("./onos.sh start")
133 self.handle.expect(["\$",pexpect.TIMEOUT])
134
135
136
adminbae64d82013-08-01 10:50:15 -0700137 def start_rest(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700138 '''
139 Starts the rest server on ONOS.
140 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700141 try:
Jon Hall4a2b0482014-04-18 16:29:26 -0700142 self.handle.sendline("cd "+self.home)
143 response = self.execute(cmd= "./start-rest.sh start",prompt="\$",timeout=10)
Jon Hallf89c8552014-04-02 13:14:06 -0700144 if re.search("admin",response):
145 main.log.info(self.name + ": Rest Server Started Successfully")
146 time.sleep(5)
147 return main.TRUE
148 else :
James Leec9cacaf2014-04-08 09:17:39 -0700149 main.log.warn(self.name + ": Failed to start Rest Server")
150 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700151 except pexpect.EOF:
152 main.log.error(self.name + ": EOF exception found")
153 main.log.error(self.name + ": " + self.handle.before)
154 main.cleanup()
155 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700156 except:
157 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
158 main.log.error( traceback.print_exc() )
159 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
160 main.cleanup()
161 main.exit()
162
adminbae64d82013-08-01 10:50:15 -0700163 def status(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700164 '''
165 Called onos.sh core status and returns TRUE/FALSE accordingly
166 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700167 try:
168 self.execute(cmd="\n",prompt="\$",timeout=10)
Jon Hall4a2b0482014-04-18 16:29:26 -0700169 self.handle.sendline("cd "+self.home)
170 response = self.execute(cmd="./onos.sh core status ",prompt="\d+\sinstance\sof\sonos\srunning",timeout=10)
Jon Hallf89c8552014-04-02 13:14:06 -0700171 self.execute(cmd="\n",prompt="\$",timeout=10)
172 if re.search("1\sinstance\sof\sonos\srunning",response):
173 return main.TRUE
174 elif re.search("0\sinstance\sof\sonos\srunning",response):
175 return main.FALSE
176 else :
177 main.log.info( self.name + " WARNING: status recieved unknown response")
178 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700179 except pexpect.EOF:
180 main.log.error(self.name + ": EOF exception found")
181 main.log.error(self.name + ": " + self.handle.before)
182 main.cleanup()
183 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700184 except:
185 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
186 main.log.error( traceback.print_exc() )
187 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
188 main.cleanup()
189 main.exit()
190
adminbae64d82013-08-01 10:50:15 -0700191
192 def isup(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700193 '''
194 A more complete check to see if ONOS is up and running properly.
195 First, it checks if the process is up.
196 Second, it reads the logs for "Exception: Connection refused"
197 Third, it makes sure the logs are actually moving.
198 returns TRUE/FALSE accordingly.
199 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700200 try:
201 self.execute(cmd="\n",prompt="\$",timeout=10)
Jon Hall4a2b0482014-04-18 16:29:26 -0700202 self.handle.sendline("cd "+self.home)
203 response = self.execute(cmd= "./onos.sh core status ",prompt="running",timeout=10)
Jon Hallf89c8552014-04-02 13:14:06 -0700204 self.execute(cmd="\n",prompt="\$",timeout=10)
205 tail1 = self.execute(cmd="tail " + self.home + "/onos-logs/onos.*.log",prompt="\$",timeout=10)
206 time.sleep(30)
207 self.execute(cmd="\n",prompt="\$",timeout=10)
208 tail2 = self.execute(cmd="tail " + self.home + "/onos-logs/onos.*.log",prompt="\$",timeout=10)
209 pattern = '(.*)1 instance(.*)'
Jon Halle80ef8c2014-04-29 15:29:13 -0700210 patternUp = 'Sending LLDP out'
Jon Hallf89c8552014-04-02 13:14:06 -0700211 pattern2 = '(.*)Exception: Connection refused(.*)'
212 # if utilities.assert_matches(expect=pattern,actual=response,onpass="ONOS process is running...",onfail="ONOS process not running..."):
213
214 if re.search(pattern, response):
adminaef00552014-05-08 09:18:36 -0700215 time.sleep(10)
Jon Halle80ef8c2014-04-29 15:29:13 -0700216 if re.search(patternUp,tail2):
217 main.log.info(self.name + ": ONOS process is running...")
218 if tail1 == tail2:
219 main.log.error(self.name + ": ONOS is frozen...")#logs aren't moving
220 return main.FALSE
221 elif re.search( pattern2,tail1 ):
222 main.log.info(self.name + ": Connection Refused found in onos log")
223 return main.FALSE
224 elif re.search( pattern2,tail2 ):
225 main.log.info(self.name + ": Connection Refused found in onos log")
226 return main.FALSE
227 else:
228 main.log.info(self.name + ": Onos log is moving! It's looking good!")
229 return main.TRUE
Jon Hall55c79662014-05-19 15:03:40 -0700230 else:
231 main.log.info(self.name + ": ONOS not yet sending out LLDP messages")
232 return main.FALSE
adminbae64d82013-08-01 10:50:15 -0700233 else:
Jon Hallf89c8552014-04-02 13:14:06 -0700234 main.log.error(self.name + ": ONOS process not running...")
235 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700236 except pexpect.EOF:
237 main.log.error(self.name + ": EOF exception found")
238 main.log.error(self.name + ": " + self.handle.before)
239 main.cleanup()
240 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700241 except:
242 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
243 main.log.error( traceback.print_exc() )
244 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
245 main.cleanup()
246 main.exit()
adminbae64d82013-08-01 10:50:15 -0700247
Jon Hallf89c8552014-04-02 13:14:06 -0700248
249
James Leec9cacaf2014-04-08 09:17:39 -0700250 def rest_status(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700251 '''
252 Checks if the rest server is running.
253 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700254 try:
255 response = self.execute(cmd= self.home + "/start-rest.sh status ",prompt="running",timeout=10)
256 if re.search("rest\sserver\sis\srunning",response):
257 main.log.info(self.name + ": Rest Server is running")
Jon Hallae05dc22014-04-16 10:56:28 -0700258 return main.TRUE
Jon Hallf89c8552014-04-02 13:14:06 -0700259 elif re.search("rest\sserver\sis\snot\srunning",response):
260 main.log.warn(self.name + ": Rest Server is not Running")
Jon Hallae05dc22014-04-16 10:56:28 -0700261 return main.FALSE
Jon Hallf89c8552014-04-02 13:14:06 -0700262 else :
263 main.log.error(self.name + ": No response" +response)
Jon Hallae05dc22014-04-16 10:56:28 -0700264 return main.FALSE
265 except pexpect.EOF:
266 main.log.error(self.name + ": EOF exception found")
267 main.log.error(self.name + ": " + self.handle.before)
268 main.cleanup()
269 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700270 except:
271 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
272 main.log.error( traceback.print_exc() )
273 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
274 main.cleanup()
275 main.exit()
276
277
adminbae64d82013-08-01 10:50:15 -0700278 def stop(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700279 '''
280 Runs ./onos.sh core stop to stop ONOS
281 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700282 try:
283 self.handle.sendline("")
Jon Hallae05dc22014-04-16 10:56:28 -0700284 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
Jon Hall4a2b0482014-04-18 16:29:26 -0700285 self.handle.sendline("cd "+self.home)
286 self.handle.sendline("./onos.sh core stop")
Jon Hallae05dc22014-04-16 10:56:28 -0700287 i=self.handle.expect(["Stop",pexpect.EOF,pexpect.TIMEOUT])
288 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT], 60)
James Leec9cacaf2014-04-08 09:17:39 -0700289 result = self.handle.before
Jon Hallf89c8552014-04-02 13:14:06 -0700290 if re.search("Killed", result):
291 main.log.info(self.name + ": ONOS Killed Successfully")
292 return main.TRUE
293 else :
294 main.log.warn(self.name + ": ONOS wasn't running")
295 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700296 except pexpect.EOF:
297 main.log.error(self.name + ": EOF exception found")
298 main.log.error(self.name + ": " + self.handle.before)
299 main.cleanup()
300 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700301 except:
302 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
303 main.log.error( traceback.print_exc() )
304 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
305 main.cleanup()
306 main.exit()
307
adminbae64d82013-08-01 10:50:15 -0700308
309 def rest_stop(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700310 '''
311 Runs ./start-rest.sh stop to stop ONOS rest server
312 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700313 try:
314 response = self.execute(cmd= self.home + "/start-rest.sh stop ",prompt="killing",timeout=10)
315 self.execute(cmd="\n",prompt="\$",timeout=10)
316 if re.search("killing", response):
317 main.log.info(self.name + ": Rest Server Stopped")
318 return main.TRUE
319 else :
320 main.log.error(self.name + ": Failed to Stop, Rest Server is not Running")
321 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700322 except pexpect.EOF:
323 main.log.error(self.name + ": EOF exception found")
324 main.log.error(self.name + ": " + self.handle.before)
325 main.cleanup()
326 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700327 except:
328 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
329 main.log.error( traceback.print_exc() )
330 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
331 main.cleanup()
332 main.exit()
333
334
adminbae64d82013-08-01 10:50:15 -0700335 def disconnect(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700336 '''
337 Called when Test is complete to disconnect the ONOS handle.
338 '''
adminaeedddd2013-08-02 15:14:15 -0700339 response = ''
340 try:
adminbae64d82013-08-01 10:50:15 -0700341 self.handle.sendline("exit")
adminaeedddd2013-08-02 15:14:15 -0700342 self.handle.expect("closed")
Jon Hallae05dc22014-04-16 10:56:28 -0700343 except pexpect.EOF:
344 main.log.error(self.name + ": EOF exception found")
345 main.log.error(self.name + ": " + self.handle.before)
James Leec9cacaf2014-04-08 09:17:39 -0700346 except:
Jon Hallf89c8552014-04-02 13:14:06 -0700347 main.log.error(self.name + ": Connection failed to the host")
adminbae64d82013-08-01 10:50:15 -0700348 response = main.FALSE
adminaeedddd2013-08-02 15:14:15 -0700349 return response
350
Jon Hall76f2c462014-04-17 11:37:15 -0700351 def print_version(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700352 '''
353 Writes the COMMIT number to the report to be parsed by Jenkins data collecter.
354 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700355 try:
356 self.handle.sendline("export TERM=xterm-256color")
357 self.handle.expect("xterm-256color")
James Leec9cacaf2014-04-08 09:17:39 -0700358 self.handle.expect("\$")
adminf939f8b2014-04-03 17:22:56 -0700359 self.handle.sendline("cd " + self.home + "; git log -1 --pretty=fuller | grep -A 5 \"commit\"; cd \.\.")
Jon Hallf89c8552014-04-02 13:14:06 -0700360 self.handle.expect("cd ..")
361 self.handle.expect("\$")
admine0eeea22014-04-14 10:22:46 -0700362 response=(self.name +": \n"+ str(self.handle.before + self.handle.after))
363 main.log.report(response)
Jon Hall76f2c462014-04-17 11:37:15 -0700364 except pexpect.EOF:
365 main.log.error(self.name + ": EOF exception found")
366 main.log.error(self.name + ": " + self.handle.before)
367 main.cleanup()
368 main.exit()
369 except:
370 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
371 main.log.error( traceback.print_exc() )
372 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
373 main.cleanup()
374 def get_version(self):
375 '''
376 Writes the COMMIT number to the report to be parsed by Jenkins data collecter.
377 '''
378 try:
379 self.handle.sendline("export TERM=xterm-256color")
380 self.handle.expect("xterm-256color")
381 self.handle.expect("\$")
382 self.handle.sendline("cd " + self.home + "; git log -1 --pretty=fuller | grep -A 5 \"commit\"; cd \.\.")
383 self.handle.expect("cd ..")
384 self.handle.expect("\$")
385 response=(self.name +": \n"+ str(self.handle.before + self.handle.after))
admine0eeea22014-04-14 10:22:46 -0700386 lines=response.splitlines()
387 for line in lines:
388 print line
389 return lines[2]
Jon Hallae05dc22014-04-16 10:56:28 -0700390 except pexpect.EOF:
391 main.log.error(self.name + ": EOF exception found")
392 main.log.error(self.name + ": " + self.handle.before)
393 main.cleanup()
394 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700395 except:
396 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
397 main.log.error( traceback.print_exc() )
398 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
399 main.cleanup()
400 main.exit()
adminbae64d82013-08-01 10:50:15 -0700401
adminc6cfc1c2014-04-21 13:55:21 -0700402 def ad_flow(self):
403 main.log.info("AD_FLOW RUNNING!!!!")
404 self.handle.sendline("cd "+self.home+ "/scripts")
405 self.handle.expect("scripts")
Jon Hall9c6e2c02014-05-02 10:18:53 -0700406 main.log.info("Adding flows")
adminc6cfc1c2014-04-21 13:55:21 -0700407 self.handle.sendline("./pyintents.py")
Jon Hall9c6e2c02014-05-02 10:18:53 -0700408 self.handle.expect(["$",pexpect.EOF,pexpect.TIMEOUT])
409 response = self.handle.before
adminc6cfc1c2014-04-21 13:55:21 -0700410 self.handle.sendline("cd "+self.home)
411 return main.TRUE
412
413 def rm_flow(self):
414 main.log.info("RM_FLOW RUNNING!!!")
415 self.handle.sendline("cd "+self.home+ "/scripts")
416 self.handle.expect("scripts")
Jon Hall9c6e2c02014-05-02 10:18:53 -0700417 main.log.info("Removing flows")
adminc6cfc1c2014-04-21 13:55:21 -0700418 self.handle.sendline("./rmpyintents.py")
Jon Hall9c6e2c02014-05-02 10:18:53 -0700419 self.handle.expect(["$",pexpect.EOF,pexpect.TIMEOUT])
420 response = self.handle.before
adminc6cfc1c2014-04-21 13:55:21 -0700421 self.handle.sendline("cd "+self.home)
422 return main.TRUE
423
Jon Hall265149f2014-04-25 13:39:52 -0700424 def purge(self):
425 main.log.info("Purging dead intents")
426 self.handle.sendline("cd "+self.home+ "/scripts")
427 self.handle.expect("scripts")
428 print("Purging Intents")
429 self.handle.sendline("./purgeintents.py")
430 self.handle.sendline("cd "+self.home)
431 return main.TRUE
adminc6cfc1c2014-04-21 13:55:21 -0700432
433
434
Jon Hall4a2b0482014-04-18 16:29:26 -0700435 def add_flow(self, testONip, user = "admin", password = "", flowDef = "/flowdef.txt"):
Jon Halld8dc5772014-04-08 16:26:29 -0700436 '''
437 Copies the flowdef file from TestStation -> ONOS machine
438 Then runs ./add_flow.py to add the flows to ONOS
439 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700440 try:
441 main.log.info("Adding Flows...")
442 self.handle.sendline("scp %s@%s:%s /tmp/flowtmp" %(user,testONip,flowDef))
443 i=self.handle.expect(['[pP]assword:', '100%', pexpect.TIMEOUT],30)
444 if(i==0):
445 self.handle.sendline("%s" %(password))
446 self.handle.sendline("")
447 self.handle.expect("100%")
448 self.handle.expect("\$", 30)
449 self.handle.sendline(self.home + "/web/add_flow.py -m onos -f /tmp/flowtmp")
450 self.handle.expect("\$", 1000)
451 main.log.info("Flows added")
452 return main.TRUE
453
454 elif(i==1):
455 self.handle.sendline("")
456 self.handle.expect("\$", 10)
457 self.handle.sendline( self.home + "/web/add_flow.py -m onos -f /tmp/flowtmp")
458 self.handle.expect("\$", 1000)
459 main.log.info("Flows added")
460 return main.TRUE
461
462 elif(i==2):
463 main.log.error("Flow Def file SCP Timed out...")
464 return main.FALSE
465
466 else:
467 main.log.error("Failed to add flows...")
James Leec9cacaf2014-04-08 09:17:39 -0700468 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700469 except pexpect.EOF:
470 main.log.error(self.name + ": EOF exception found")
471 main.log.error(self.name + ": " + self.handle.before)
472 main.cleanup()
473 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700474 except:
475 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
476 main.log.error( traceback.print_exc() )
477 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
478 main.cleanup()
479 main.exit()
480
adminbae64d82013-08-01 10:50:15 -0700481
482 def delete_flow(self, *delParams):
Jon Halld8dc5772014-04-08 16:26:29 -0700483 '''
484 Deletes a specific flow, a range of flows, or all flows.
485 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700486 try:
487 if len(delParams)==1:
488 if str(delParams[0])=="all":
489 main.log.info(self.name + ": Deleting ALL flows...")
490 #self.execute(cmd="~/ONOS/scripts/TestON_delete_flow.sh all",prompt="done",timeout=150)
491 self.handle.sendline(self.home + "/web/delete_flow.py all")
492 self.handle.expect("delete_flow")
493 self.handle.expect("\$",1000)
494 main.log.info(self.name + ": Flows deleted")
495 else:
496 main.log.info(self.name + ": Deleting flow "+str(delParams[0])+"...")
497 #self.execute(cmd="~/ONOS/scripts/TestON_delete_flow.sh "+str(delParams[0]),prompt="done",timeout=150)
498 #self.execute(cmd="\n",prompt="\$",timeout=60)
499 self.handle.sendline(self.home +"/web/delete_flow.py %d" % int(delParams[0]))
500 self.handle.expect("delete_flow")
501 self.handle.expect("\$",60)
502 main.log.info(self.name + ": Flow deleted")
503 elif len(delParams)==2:
504 main.log.info(self.name + ": Deleting flows "+str(delParams[0])+" through "+str(delParams[1])+"...")
505 #self.execute(cmd="~/ONOS/scripts/TestON_delete_flow.sh "+str(delParams[0])+" "+str(delParams[1]),prompt="done",timeout=150)
506 #self.execute(cmd="\n",prompt="\$",timeout=60)
507 self.handle.sendline(self.home + "/web/delete_flow.py %d %d" % (int(delParams[0]), int(delParams[1])))
508 self.handle.expect("delete_flow")
509 self.handle.expect("\$",600)
510 main.log.info(self.name + ": Flows deleted")
Jon Hallae05dc22014-04-16 10:56:28 -0700511 except pexpect.EOF:
512 main.log.error(self.name + ": EOF exception found")
513 main.log.error(self.name + ": " + self.handle.before)
514 main.cleanup()
515 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700516 except:
517 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
518 main.log.error( traceback.print_exc() )
519 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
520 main.cleanup()
521 main.exit()
adminbae64d82013-08-01 10:50:15 -0700522
523 def check_flow(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700524 '''
525 Calls the ./get_flow.py all and checks:
526 - If each FlowPath has at least one FlowEntry
527 - That there are no "NOT"s found
528 returns TRUE/FALSE
529 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700530 try:
531 flowEntryDetect = 1
532 count = 0
533 self.handle.sendline("clear")
534 time.sleep(1)
535 self.handle.sendline(self.home + "/web/get_flow.py all")
536 self.handle.expect("get_flow")
537 while 1:
538 i=self.handle.expect(['FlowPath','FlowEntry','NOT','\$',pexpect.TIMEOUT],timeout=180)
539 if i==0:
540 count = count + 1
541 if flowEntryDetect == 0:
542 main.log.info(self.name + ": FlowPath without FlowEntry")
543 return main.FALSE
544 else:
545 flowEntryDetect = 0
546 elif i==1:
547 flowEntryDetect = 1
548 elif i==2:
549 main.log.error(self.name + ": Found a NOT")
adminbae64d82013-08-01 10:50:15 -0700550 return main.FALSE
Jon Hallf89c8552014-04-02 13:14:06 -0700551 elif i==3:
552 if count == 0:
553 main.log.info(self.name + ": There don't seem to be any flows here...")
554 return main.FALSE
555 else:
556 main.log.info(self.name + ": All flows pass")
557 main.log.info(self.name + ": Number of FlowPaths: "+str(count))
558 return main.TRUE
559 elif i==4:
James Leec9cacaf2014-04-08 09:17:39 -0700560 main.log.error(self.name + ":Check_flow() - Command Timeout!")
Jon Hallf89c8552014-04-02 13:14:06 -0700561 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700562 except pexpect.EOF:
563 main.log.error(self.name + ": EOF exception found")
564 main.log.error(self.name + ": " + self.handle.before)
565 main.cleanup()
566 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700567 except:
568 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
569 main.log.error( traceback.print_exc() )
570 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
571 main.cleanup()
572 main.exit()
adminbae64d82013-08-01 10:50:15 -0700573
574 def get_flow(self, *flowParams):
Jon Halld8dc5772014-04-08 16:26:29 -0700575 '''
576 Returns verbose output of ./get_flow.py
577 '''
578 try:
579 if len(flowParams)==1:
580 if str(flowParams[0])=="all":
581 self.execute(cmd="\n",prompt="\$",timeout=60)
582 main.log.info(self.name + ": Getting all flow data...")
583 data = self.execute(cmd=self.home + "/scripts/TestON_get_flow.sh all",prompt="done",timeout=150)
584 self.execute(cmd="\n",prompt="\$",timeout=60)
585 return data
586 else:
587 main.log.info(self.name + ": Retrieving flow "+str(flowParams[0])+" data...")
588 data = self.execute(cmd=self.home +"/scripts/TestON_get_flow.sh "+str(flowParams[0]),prompt="done",timeout=150)
589 self.execute(cmd="\n",prompt="\$",timeout=60)
590 return data
591 elif len(flowParams)==5:
592 main.log.info(self.name + ": Retrieving flow installer data...")
593 data = self.execute(cmd=self.home + "/scripts/TestON_get_flow.sh "+str(flowParams[0])+" "+str(flowParams[1])+" "+str(flowParams[2])+" "+str(flowParams[3])+" "+str(flowParams[4]),prompt="done",timeout=150)
594 self.execute(cmd="\n",prompt="\$",timeout=60)
595 return data
596 elif len(flowParams)==4:
597 main.log.info(self.name + ": Retrieving flow endpoints...")
598 data = self.execute(cmd=self.home + "/scripts/TestON_get_flow.sh "+str(flowParams[0])+" "+str(flowParams[1])+" "+str(flowParams[2])+" "+str(flowParams[3]),prompt="done",timeout=150)
599 self.execute(cmd="\n",prompt="\$",timeout=60)
600 return data
Jon Hallae05dc22014-04-16 10:56:28 -0700601 except pexpect.EOF:
602 main.log.error(self.name + ": EOF exception found")
603 main.log.error(self.name + ": " + self.handle.before)
604 main.cleanup()
605 main.exit()
Jon Halld8dc5772014-04-08 16:26:29 -0700606 except:
Jon Hallf89c8552014-04-02 13:14:06 -0700607 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
608 main.log.error( traceback.print_exc() )
609 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
610 main.cleanup()
611 main.exit()
adminbae64d82013-08-01 10:50:15 -0700612
613
SeanCorcoran83a653a2014-04-22 15:03:18 -0700614# http://localhost:8080/wm/onos/topology/switches/json
615# http://localhost:8080/wm/onos/topology/links/json
Jon Hall8060af02014-04-14 14:17:58 -0700616# http://localhost:8080/wm/onos/registry/controllers/json
617# http://localhost:8080/wm/onos/registry/switches/json"
adminbae64d82013-08-01 10:50:15 -0700618
619 def get_json(self, url):
Jon Halld8dc5772014-04-08 16:26:29 -0700620 '''
621 Helper functions used to parse the json output of a rest call
622 '''
adminbae64d82013-08-01 10:50:15 -0700623 try:
Jon Hallf89c8552014-04-02 13:14:06 -0700624 try:
625 command = "curl -s %s" % (url)
626 result = os.popen(command).read()
627 parsedResult = json.loads(result)
628 except:
629 print "REST IF %s has issue" % command
630 parsedResult = ""
631
632 if type(parsedResult) == 'dict' and parsedResult.has_key('code'):
633 print "REST %s returned code %s" % (command, parsedResult['code'])
634 parsedResult = ""
James Leec9cacaf2014-04-08 09:17:39 -0700635 return parsedResult
Jon Hallae05dc22014-04-16 10:56:28 -0700636 except pexpect.EOF:
637 main.log.error(self.name + ": EOF exception found")
638 main.log.error(self.name + ": " + self.handle.before)
639 main.cleanup()
640 main.exit()
adminbae64d82013-08-01 10:50:15 -0700641 except:
Jon Hallf89c8552014-04-02 13:14:06 -0700642 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
643 main.log.error( traceback.print_exc() )
644 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
645 main.cleanup()
646 main.exit()
adminbae64d82013-08-01 10:50:15 -0700647
Jon Hallf89c8552014-04-02 13:14:06 -0700648 def check_switch(self,RestIP,correct_nr_switch, RestPort ="8080" ):
Jon Halld8dc5772014-04-08 16:26:29 -0700649 '''
650 Used by check_status
651 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700652 try:
653 buf = ""
654 retcode = 0
SeanCorcoran83a653a2014-04-22 15:03:18 -0700655 url="http://%s:%s/wm/onos/topology/switches/json" % (RestIP, RestPort)
Jon Hallf89c8552014-04-02 13:14:06 -0700656 parsedResult = self.get_json(url)
657 if parsedResult == "":
658 retcode = 1
659 return (retcode, "Rest API has an issue")
660 url = "http://%s:%s/wm/onos/registry/switches/json" % (RestIP, RestPort)
661 registry = self.get_json(url)
662
663 if registry == "":
664 retcode = 1
665 return (retcode, "Rest API has an issue")
666
667 cnt = 0
668 active = 0
adminbae64d82013-08-01 10:50:15 -0700669
Jon Hallf89c8552014-04-02 13:14:06 -0700670 for s in parsedResult:
671 cnt += 1
James Leec9cacaf2014-04-08 09:17:39 -0700672 if s['state'] == "ACTIVE":
Jon Hallf89c8552014-04-02 13:14:06 -0700673 active += 1
adminbae64d82013-08-01 10:50:15 -0700674
Jon Hallf89c8552014-04-02 13:14:06 -0700675 buf += "switch: network %d : %d switches %d active\n" % (0+1, cnt, active)
676 if correct_nr_switch != cnt:
677 buf += "switch fail: network %d should have %d switches but has %d\n" % (1, correct_nr_switch, cnt)
678 retcode = 1
adminbae64d82013-08-01 10:50:15 -0700679
Jon Hallf89c8552014-04-02 13:14:06 -0700680 if correct_nr_switch != active:
681 buf += "switch fail: network %d should have %d active switches but has %d\n" % (1, correct_nr_switch, active)
682 retcode = 1
683
684 return (retcode, buf)
Jon Hallae05dc22014-04-16 10:56:28 -0700685 except pexpect.EOF:
686 main.log.error(self.name + ": EOF exception found")
687 main.log.error(self.name + ": " + self.handle.before)
688 main.cleanup()
689 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700690 except:
691 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
692 main.log.error( traceback.print_exc() )
693 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
694 main.cleanup()
695 main.exit()
adminbae64d82013-08-01 10:50:15 -0700696
Jon Hallf89c8552014-04-02 13:14:06 -0700697 def check_link(self,RestIP, nr_links, RestPort = "8080"):
Jon Halld8dc5772014-04-08 16:26:29 -0700698 '''
699 Used by check_status
700 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700701 try:
702 buf = ""
703 retcode = 0
704
SeanCorcoran83a653a2014-04-22 15:03:18 -0700705 url = "http://%s:%s/wm/onos/topology/links/json" % (RestIP, RestPort)
Jon Hallf89c8552014-04-02 13:14:06 -0700706 parsedResult = self.get_json(url)
707
708 if parsedResult == "":
709 retcode = 1
710 return (retcode, "Rest API has an issue")
711
712 buf += "link: total %d links (correct : %d)\n" % (len(parsedResult), nr_links)
713 intra = 0
714 interlink=0
715
716 for s in parsedResult:
James Leec9cacaf2014-04-08 09:17:39 -0700717 intra = intra + 1
Jon Hallf89c8552014-04-02 13:14:06 -0700718
719 if intra != nr_links:
720 buf += "link fail\n"
721 retcode = 1
722
723 return (retcode, buf)
Jon Hallae05dc22014-04-16 10:56:28 -0700724 except pexpect.EOF:
725 main.log.error(self.name + ": EOF exception found")
726 main.log.error(self.name + ": " + self.handle.before)
727 main.cleanup()
728 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700729 except:
730 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
731 main.log.error( traceback.print_exc() )
732 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
733 main.cleanup()
734 main.exit()
adminbae64d82013-08-01 10:50:15 -0700735
Jon Hallf89c8552014-04-02 13:14:06 -0700736 def check_status_report(self, ip, numoswitch, numolink, port="8080"):
Jon Halld8dc5772014-04-08 16:26:29 -0700737 '''
738 Checks the number of swithes & links that ONOS sees against the supplied values.
739 Writes to the report log.
740 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700741 try:
James Leec9cacaf2014-04-08 09:17:39 -0700742 main.log.info(self.name + ": Making some rest calls...")
Jon Hallf89c8552014-04-02 13:14:06 -0700743 switch = self.check_switch(ip, int(numoswitch), port)
744 link = self.check_link(ip, int(numolink), port)
745 value = switch[0]
746 value += link[0]
747 main.log.report( self.name + ": \n-----\n%s%s-----\n" % ( switch[1], link[1]) )
748 if value != 0:
749 return main.FALSE
James Leec9cacaf2014-04-08 09:17:39 -0700750 else:
Jon Hallf89c8552014-04-02 13:14:06 -0700751 # "PASS"
752 return main.TRUE
Jon Hallae05dc22014-04-16 10:56:28 -0700753 except pexpect.EOF:
754 main.log.error(self.name + ": EOF exception found")
755 main.log.error(self.name + ": " + self.handle.before)
756 main.cleanup()
757 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700758 except:
759 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
760 main.log.error( traceback.print_exc() )
761 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
762 main.cleanup()
763 main.exit()
adminbae64d82013-08-01 10:50:15 -0700764
Jon Hallf89c8552014-04-02 13:14:06 -0700765 def check_status(self, ip, numoswitch, numolink, port = "8080"):
Jon Halld8dc5772014-04-08 16:26:29 -0700766 '''
767 Checks the number of swithes & links that ONOS sees against the supplied values.
768 Writes to the main log.
769 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700770 try:
James Leec9cacaf2014-04-08 09:17:39 -0700771 main.log.info(self.name + ": Making some rest calls...")
Jon Hallf89c8552014-04-02 13:14:06 -0700772 switch = self.check_switch(ip, int(numoswitch), port)
773 link = self.check_link(ip, int(numolink), port)
774 value = switch[0]
775 value += link[0]
776 main.log.info(self.name + ": \n-----\n%s%s-----\n" % ( switch[1], link[1]) )
777 if value != 0:
778 return main.FALSE
James Leec9cacaf2014-04-08 09:17:39 -0700779 else:
Jon Hallf89c8552014-04-02 13:14:06 -0700780 # "PASS"
781 return main.TRUE
Jon Hallae05dc22014-04-16 10:56:28 -0700782 except pexpect.EOF:
783 main.log.error(self.name + ": EOF exception found")
784 main.log.error(self.name + ": " + self.handle.before)
785 main.cleanup()
786 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700787 except:
788 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
789 main.log.error( traceback.print_exc() )
790 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
791 main.cleanup()
792 main.exit()
adminbae64d82013-08-01 10:50:15 -0700793
adminbae64d82013-08-01 10:50:15 -0700794 def check_for_no_exceptions(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700795 '''
796 TODO: Rewrite
797 Used by CassndraCheck.py to scan ONOS logs for Exceptions
798 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700799 try:
800 self.handle.sendline("dsh 'grep Exception ~/ONOS/onos-logs/onos.*.log'")
James Leec9cacaf2014-04-08 09:17:39 -0700801 self.handle.expect("\$ dsh")
Jon Hallf89c8552014-04-02 13:14:06 -0700802 self.handle.expect("\$")
803 output = self.handle.before
James Leec9cacaf2014-04-08 09:17:39 -0700804 main.log.info(self.name + ": " + output )
Jon Hallf89c8552014-04-02 13:14:06 -0700805 if re.search("Exception",output):
806 return main.FALSE
807 else :
808 return main.TRUE
Jon Hallae05dc22014-04-16 10:56:28 -0700809 except pexpect.EOF:
810 main.log.error(self.name + ": EOF exception found")
811 main.log.error(self.name + ": " + self.handle.before)
812 main.cleanup()
813 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700814 except:
815 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
816 main.log.error( traceback.print_exc() )
817 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
818 main.cleanup()
819 main.exit()
820
821
admine0eeea22014-04-14 10:22:46 -0700822 def git_pull(self, comp1=""):
Jon Halld8dc5772014-04-08 16:26:29 -0700823 '''
Jon Halld8dc5772014-04-08 16:26:29 -0700824 Assumes that "git pull" works without login
admine0eeea22014-04-14 10:22:46 -0700825
826 This function will perform a git pull on the ONOS instance.
827 If used as git_pull("NODE") it will do git pull + NODE. This is
828 for the purpose of pulling from other nodes if necessary.
829
830 Otherwise, this function will perform a git pull in the
831 ONOS repository. If it has any problems, it will return main.ERROR
832 If it successfully does a git_pull, it will return a 1.
833 If it has no updates, it will return a 0.
834
Jon Halld8dc5772014-04-08 16:26:29 -0700835 '''
Jon Hallae05dc22014-04-16 10:56:28 -0700836 try:
Jon Halle80ef8c2014-04-29 15:29:13 -0700837 # main.log.info(self.name + ": Stopping ONOS")
838 #self.stop()
Jon Hallae05dc22014-04-16 10:56:28 -0700839 self.handle.sendline("cd " + self.home)
840 self.handle.expect("ONOS\$")
841 if comp1=="":
842 self.handle.sendline("git pull")
843 else:
844 self.handle.sendline("git pull " + comp1)
845
846 uptodate = 0
SeanCorcoran20bd6fc2014-04-16 17:10:30 -0700847 i=self.handle.expect(['fatal','Username\sfor\s(.*):\s','Unpacking\sobjects',pexpect.TIMEOUT,'Already up-to-date','Aborting'],timeout=1800)
Jon Hallae05dc22014-04-16 10:56:28 -0700848 #debug
849 #main.log.report(self.name +": \n"+"git pull response: " + str(self.handle.before) + str(self.handle.after))
850 if i==0:
851 main.log.error(self.name + ": Git pull had some issue...")
852 return main.ERROR
853 elif i==1:
854 main.log.error(self.name + ": Git Pull Asking for username!!! BADD!")
855 return main.ERROR
856 elif i==2:
857 main.log.info(self.name + ": Git Pull - pulling repository now")
858 self.handle.expect("ONOS\$", 120)
859 return 0
860 elif i==3:
861 main.log.error(self.name + ": Git Pull - TIMEOUT")
862 return main.ERROR
863 elif i==4:
864 main.log.info(self.name + ": Git Pull - Already up to date")
865 return 1
866 elif i==5:
867 main.log.info(self.name + ": Git Pull - Aborting... Are there conflicting git files?")
868 return main.ERROR
869 else:
870 main.log.error(self.name + ": Git Pull - Unexpected response, check for pull errors")
871 return main.ERROR
872 except pexpect.EOF:
873 main.log.error(self.name + ": EOF exception found")
874 main.log.error(self.name + ": " + self.handle.before)
875 main.cleanup()
876 main.exit()
877 except:
878 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
879 main.log.error( traceback.print_exc() )
880 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
881 main.cleanup()
882 main.exit()
admine0eeea22014-04-14 10:22:46 -0700883#********************************************************
884
885
admin7373a812014-04-16 09:49:02 -0700886 def git_compile(self):
Jon Hallae05dc22014-04-16 10:56:28 -0700887 '''
888 Compiles ONOS
889 First runs mvn clean then mvn compile
890 '''
891 try:
892 main.log.info(self.name + ": mvn clean")
admin8fc02822014-04-16 13:31:23 -0700893 self.handle.sendline("cd " + self.home)
Jon Hallae05dc22014-04-16 10:56:28 -0700894 self.handle.sendline("mvn clean")
895 while 1:
Jon Hall1636f942014-04-17 10:07:23 -0700896 i=self.handle.expect(['There\sis\sinsufficient\smemory\sfor\sthe\sJava\sRuntime\sEnvironment\sto\scontinue','BUILD\sFAILURE','BUILD\sSUCCESS','ONOS\$',pexpect.TIMEOUT],timeout=30)
Jon Hallae05dc22014-04-16 10:56:28 -0700897 if i == 0:
Jon Hall1636f942014-04-17 10:07:23 -0700898 main.log.error(self.name + ":There is insufficient memory for the Java Runtime Environment to continue.")
Jon Hallae05dc22014-04-16 10:56:28 -0700899 return main.FALSE
900 elif i == 1:
Jon Hall1636f942014-04-17 10:07:23 -0700901 main.log.error(self.name + ": Clean failure!")
902 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700903 elif i == 2:
Jon Hall1636f942014-04-17 10:07:23 -0700904 main.log.info(self.name + ": Clean success!")
905 elif i == 3:
admin8fc02822014-04-16 13:31:23 -0700906 main.log.info(self.name + ": Clean complete")
Jon Hallae05dc22014-04-16 10:56:28 -0700907 break;
Jon Hall1636f942014-04-17 10:07:23 -0700908 elif i == 4:
Jon Hallae05dc22014-04-16 10:56:28 -0700909 main.log.error(self.name + ": mvn clean TIMEOUT!")
910 return main.FALSE
Jon Hall1636f942014-04-17 10:07:23 -0700911 else:
912 main.log.error(self.name + ": unexpected response from mvn clean")
913 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700914
915 main.log.info(self.name + ": mvn compile")
916 self.handle.sendline("mvn compile")
917 while 1:
Jon Hall1636f942014-04-17 10:07:23 -0700918 i=self.handle.expect(['There\sis\sinsufficient\smemory\sfor\sthe\sJava\sRuntime\sEnvironment\sto\scontinue','BUILD\sFAILURE','BUILD\sSUCCESS','ONOS\$',pexpect.TIMEOUT],timeout=60)
Jon Hallae05dc22014-04-16 10:56:28 -0700919 if i == 0:
Jon Hall1636f942014-04-17 10:07:23 -0700920 main.log.error(self.name + ":There is insufficient memory for the Java Runtime Environment to continue.")
921 return main.FALSE
922 if i == 1:
Jon Hallae05dc22014-04-16 10:56:28 -0700923 main.log.error(self.name + ": Build failure!")
924 return main.FALSE
Jon Hall1636f942014-04-17 10:07:23 -0700925 elif i == 2:
Jon Hallae05dc22014-04-16 10:56:28 -0700926 main.log.info(self.name + ": Build success!")
Jon Hall1636f942014-04-17 10:07:23 -0700927 elif i == 3:
Jon Hallae05dc22014-04-16 10:56:28 -0700928 main.log.info(self.name + ": Build complete")
Jon Halla15739a2014-05-16 17:17:11 -0700929 self.handle.sendline("./build-ramcloud-java-bindings.sh")
930 self.handle.expect("\$")
Jon Hallae05dc22014-04-16 10:56:28 -0700931 return main.TRUE
Jon Hall1636f942014-04-17 10:07:23 -0700932 elif i == 4:
Jon Hallae05dc22014-04-16 10:56:28 -0700933 main.log.error(self.name + ": mvn compile TIMEOUT!")
934 return main.FALSE
935 else:
Jon Hall1636f942014-04-17 10:07:23 -0700936 main.log.error(self.name + ": unexpected response from mvn compile")
937 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700938 except pexpect.EOF:
939 main.log.error(self.name + ": EOF exception found")
940 main.log.error(self.name + ": " + self.handle.before)
941 main.cleanup()
942 main.exit()
943 except:
944 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
945 main.log.error( traceback.print_exc() )
946 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
947 main.cleanup()
948 main.exit()
admin4a58db92013-09-30 12:04:54 -0700949
Jon Hallf89c8552014-04-02 13:14:06 -0700950 def tcpdump(self, intf = "eth0"):
Jon Hallae05dc22014-04-16 10:56:28 -0700951 '''
952 Runs tpdump on an intferface and saves in onos-logs under the ONOS home directory
953 intf can be specified, or the default eth0 is used
954 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700955 try:
956 self.handle.sendline("")
957 self.handle.expect("\$")
Jon Hall26f316b2014-04-11 11:21:25 -0700958 self.handle.sendline("sudo tcpdump -n -i "+ intf + " -s0 -w " + self.home +"/onos-logs/tcpdump &")
Jon Hallf89c8552014-04-02 13:14:06 -0700959 i=self.handle.expect(['No\ssuch\device','listening\son',pexpect.TIMEOUT],timeout=10)
960 if i == 0:
961 main.log.error(self.name + ": tcpdump - No such device exists. tcpdump attempted on: " + intf)
962 return main.FALSE
James Leec9cacaf2014-04-08 09:17:39 -0700963 elif i == 1:
Jon Hallf89c8552014-04-02 13:14:06 -0700964 main.log.info(self.name + ": tcpdump started on " + intf)
965 return main.TRUE
James Leec9cacaf2014-04-08 09:17:39 -0700966 elif i == 2:
Jon Hallf89c8552014-04-02 13:14:06 -0700967 main.log.error(self.name + ": tcpdump command timed out! Check interface name, given interface was: " + intf)
968 return main.FALSE
969 else:
970 main.log.error(self.name + ": tcpdump - unexpected response")
971 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700972 except pexpect.EOF:
973 main.log.error(self.name + ": EOF exception found")
974 main.log.error(self.name + ": " + self.handle.before)
975 main.cleanup()
976 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700977 except:
978 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
979 main.log.error( traceback.print_exc() )
980 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
981 main.cleanup()
982 main.exit()
983
admin4a58db92013-09-30 12:04:54 -0700984 def kill_tcpdump(self):
Jon Hallae05dc22014-04-16 10:56:28 -0700985 '''
986 Kills any tcpdump processes running
987 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700988 try:
989 self.handle.sendline("")
990 self.handle.expect("\$")
991 self.handle.sendline("sudo kill -9 `ps -ef | grep \"tcpdump -n\" | grep -v grep | awk '{print $2}'`")
Jon Hallae05dc22014-04-16 10:56:28 -0700992 except pexpect.EOF:
993 main.log.error(self.name + ": EOF exception found")
994 main.log.error(self.name + ": " + self.handle.before)
995 main.cleanup()
996 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700997 except:
998 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
999 main.log.error( traceback.print_exc() )
1000 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1001 main.cleanup()
1002 main.exit()
1003
1004 def find_host(self,RestIP,RestPort,RestAPI,hostIP):
1005 retcode = 0
1006 retswitch = []
1007 retport = []
1008 retmac = []
1009 foundIP = []
1010 try:
SeanCorcoran83a653a2014-04-22 15:03:18 -07001011 ##### device rest API is: 'host:8080/wm/onos/topology/switches/json' ###
Jon Hallf89c8552014-04-02 13:14:06 -07001012 url ="http://%s:%s%s" %(RestIP,RestPort,RestAPI)
1013
1014 try:
1015 command = "curl -s %s" % (url)
1016 result = os.popen(command).read()
1017 parsedResult = json.loads(result)
1018 # print parsedResult
1019 except:
1020 print "REST IF %s has issue" % command
1021 parsedResult = ""
1022
1023 if parsedResult == "":
Jon Hallae05dc22014-04-16 10:56:28 -07001024 return (retcode, "Rest API has an error", retport, retmac)
Jon Hallf89c8552014-04-02 13:14:06 -07001025 else:
1026 for switch in enumerate(parsedResult):
1027 for port in enumerate(switch[1]['ports']):
1028 if ( port[1]['devices'] != [] ):
1029 try:
James Leec9cacaf2014-04-08 09:17:39 -07001030 foundIP = port[1]['devices'][0]['ipv4addresses'][0]['ipv4']
Jon Hallf89c8552014-04-02 13:14:06 -07001031 except:
1032 print "Error in detecting IP address."
1033 if foundIP == hostIP:
1034 retswitch.append(switch[1]['dpid'])
1035 retport.append(port[1]['desc'])
1036 retmac.append(port[1]['devices'][0]['mac'])
1037 retcode = retcode +1
1038 foundIP =''
1039 return(retcode, retswitch, retport, retmac)
Jon Hallae05dc22014-04-16 10:56:28 -07001040 except pexpect.EOF:
1041 main.log.error(self.name + ": EOF exception found")
1042 main.log.error(self.name + ": " + self.handle.before)
1043 main.cleanup()
1044 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -07001045 except:
1046 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1047 main.log.error( traceback.print_exc() )
1048 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1049 main.cleanup()
1050 main.exit()
SeanCorcoran29b70542014-05-14 14:53:42 -07001051
1052 def check_exceptions(self):
1053 '''
1054 Greps the logs for "xception"
1055 '''
1056 try:
1057 output = ''
1058 self.handle.sendline("")
Jon Halla78cf9a2014-05-16 10:49:30 -07001059 i = self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
1060 #main.log.warn("first expect response: " +str(i))
SeanCorcoran29b70542014-05-14 14:53:42 -07001061 self.handle.sendline("cd "+self.home+"/onos-logs")
Jon Halla78cf9a2014-05-16 10:49:30 -07001062 self.handle.sendline("grep \"xception\" *")
1063 i = self.handle.expect(["\*",pexpect.EOF,pexpect.TIMEOUT])
1064 #main.log.warn("second expect response: " +str(i))
1065 i = self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
1066 #main.log.warn("third expect response: " +str(i))
SeanCorcoran29b70542014-05-14 14:53:42 -07001067 response = self.handle.before
Jon Halla78cf9a2014-05-16 10:49:30 -07001068 count = 0
SeanCorcoran29b70542014-05-14 14:53:42 -07001069 for line in response.splitlines():
1070 if re.search("log:", line):
1071 output +="Exceptions found in " + line + "\n"
Jon Halla78cf9a2014-05-16 10:49:30 -07001072 count +=1
SeanCorcoran29b70542014-05-14 14:53:42 -07001073 elif re.search("std...:",line):
1074 output+="Exceptions found in " + line + "\n"
Jon Halla78cf9a2014-05-16 10:49:30 -07001075 count +=1
SeanCorcoran29b70542014-05-14 14:53:42 -07001076 else:
1077 pass
1078 #these should be the old logs
Jon Halla78cf9a2014-05-16 10:49:30 -07001079 main.log.report(str(count) + "Exceptions were found on "+self.name)
SeanCorcoran29b70542014-05-14 14:53:42 -07001080 return output
1081 except pexpect.TIMEOUT:
1082 main.log.error(self.name + ": Timeout exception found in check_exceptions function")
1083 except pexpect.EOF:
1084 main.log.error(self.name + ": EOF exception found")
1085 main.log.error(self.name + ": " + self.handle.before)
1086 main.cleanup()
1087 main.exit()
1088 except:
1089 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1090 main.log.error( traceback.print_exc() )
1091 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1092 main.cleanup()
1093 main.exit()