blob: 66c67338dc3cbe920b69439f762b216d78958d8a [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):
Jon Halle80ef8c2014-04-29 15:29:13 -0700215 if re.search(patternUp,tail2):
216 main.log.info(self.name + ": ONOS process is running...")
217 if tail1 == tail2:
218 main.log.error(self.name + ": ONOS is frozen...")#logs aren't moving
219 return main.FALSE
220 elif re.search( pattern2,tail1 ):
221 main.log.info(self.name + ": Connection Refused found in onos log")
222 return main.FALSE
223 elif re.search( pattern2,tail2 ):
224 main.log.info(self.name + ": Connection Refused found in onos log")
225 return main.FALSE
226 else:
227 main.log.info(self.name + ": Onos log is moving! It's looking good!")
228 return main.TRUE
adminbae64d82013-08-01 10:50:15 -0700229 else:
Jon Hallf89c8552014-04-02 13:14:06 -0700230 main.log.error(self.name + ": ONOS process not running...")
231 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700232 except pexpect.EOF:
233 main.log.error(self.name + ": EOF exception found")
234 main.log.error(self.name + ": " + self.handle.before)
235 main.cleanup()
236 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700237 except:
238 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
239 main.log.error( traceback.print_exc() )
240 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
241 main.cleanup()
242 main.exit()
adminbae64d82013-08-01 10:50:15 -0700243
Jon Hallf89c8552014-04-02 13:14:06 -0700244
245
James Leec9cacaf2014-04-08 09:17:39 -0700246 def rest_status(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700247 '''
248 Checks if the rest server is running.
249 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700250 try:
251 response = self.execute(cmd= self.home + "/start-rest.sh status ",prompt="running",timeout=10)
252 if re.search("rest\sserver\sis\srunning",response):
253 main.log.info(self.name + ": Rest Server is running")
Jon Hallae05dc22014-04-16 10:56:28 -0700254 return main.TRUE
Jon Hallf89c8552014-04-02 13:14:06 -0700255 elif re.search("rest\sserver\sis\snot\srunning",response):
256 main.log.warn(self.name + ": Rest Server is not Running")
Jon Hallae05dc22014-04-16 10:56:28 -0700257 return main.FALSE
Jon Hallf89c8552014-04-02 13:14:06 -0700258 else :
259 main.log.error(self.name + ": No response" +response)
Jon Hallae05dc22014-04-16 10:56:28 -0700260 return main.FALSE
261 except pexpect.EOF:
262 main.log.error(self.name + ": EOF exception found")
263 main.log.error(self.name + ": " + self.handle.before)
264 main.cleanup()
265 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700266 except:
267 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
268 main.log.error( traceback.print_exc() )
269 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
270 main.cleanup()
271 main.exit()
272
273
adminbae64d82013-08-01 10:50:15 -0700274 def stop(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700275 '''
276 Runs ./onos.sh core stop to stop ONOS
277 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700278 try:
279 self.handle.sendline("")
Jon Hallae05dc22014-04-16 10:56:28 -0700280 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
Jon Hall4a2b0482014-04-18 16:29:26 -0700281 self.handle.sendline("cd "+self.home)
282 self.handle.sendline("./onos.sh core stop")
Jon Hallae05dc22014-04-16 10:56:28 -0700283 i=self.handle.expect(["Stop",pexpect.EOF,pexpect.TIMEOUT])
284 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT], 60)
James Leec9cacaf2014-04-08 09:17:39 -0700285 result = self.handle.before
Jon Hallf89c8552014-04-02 13:14:06 -0700286 if re.search("Killed", result):
287 main.log.info(self.name + ": ONOS Killed Successfully")
288 return main.TRUE
289 else :
290 main.log.warn(self.name + ": ONOS wasn't running")
291 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700292 except pexpect.EOF:
293 main.log.error(self.name + ": EOF exception found")
294 main.log.error(self.name + ": " + self.handle.before)
295 main.cleanup()
296 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700297 except:
298 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
299 main.log.error( traceback.print_exc() )
300 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
301 main.cleanup()
302 main.exit()
303
adminbae64d82013-08-01 10:50:15 -0700304
305 def rest_stop(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700306 '''
307 Runs ./start-rest.sh stop to stop ONOS rest server
308 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700309 try:
310 response = self.execute(cmd= self.home + "/start-rest.sh stop ",prompt="killing",timeout=10)
311 self.execute(cmd="\n",prompt="\$",timeout=10)
312 if re.search("killing", response):
313 main.log.info(self.name + ": Rest Server Stopped")
314 return main.TRUE
315 else :
316 main.log.error(self.name + ": Failed to Stop, Rest Server is not Running")
317 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700318 except pexpect.EOF:
319 main.log.error(self.name + ": EOF exception found")
320 main.log.error(self.name + ": " + self.handle.before)
321 main.cleanup()
322 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700323 except:
324 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
325 main.log.error( traceback.print_exc() )
326 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
327 main.cleanup()
328 main.exit()
329
330
adminbae64d82013-08-01 10:50:15 -0700331 def disconnect(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700332 '''
333 Called when Test is complete to disconnect the ONOS handle.
334 '''
adminaeedddd2013-08-02 15:14:15 -0700335 response = ''
336 try:
adminbae64d82013-08-01 10:50:15 -0700337 self.handle.sendline("exit")
adminaeedddd2013-08-02 15:14:15 -0700338 self.handle.expect("closed")
Jon Hallae05dc22014-04-16 10:56:28 -0700339 except pexpect.EOF:
340 main.log.error(self.name + ": EOF exception found")
341 main.log.error(self.name + ": " + self.handle.before)
James Leec9cacaf2014-04-08 09:17:39 -0700342 except:
Jon Hallf89c8552014-04-02 13:14:06 -0700343 main.log.error(self.name + ": Connection failed to the host")
adminbae64d82013-08-01 10:50:15 -0700344 response = main.FALSE
adminaeedddd2013-08-02 15:14:15 -0700345 return response
346
Jon Hall76f2c462014-04-17 11:37:15 -0700347 def print_version(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700348 '''
349 Writes the COMMIT number to the report to be parsed by Jenkins data collecter.
350 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700351 try:
352 self.handle.sendline("export TERM=xterm-256color")
353 self.handle.expect("xterm-256color")
James Leec9cacaf2014-04-08 09:17:39 -0700354 self.handle.expect("\$")
adminf939f8b2014-04-03 17:22:56 -0700355 self.handle.sendline("cd " + self.home + "; git log -1 --pretty=fuller | grep -A 5 \"commit\"; cd \.\.")
Jon Hallf89c8552014-04-02 13:14:06 -0700356 self.handle.expect("cd ..")
357 self.handle.expect("\$")
admine0eeea22014-04-14 10:22:46 -0700358 response=(self.name +": \n"+ str(self.handle.before + self.handle.after))
359 main.log.report(response)
Jon Hall76f2c462014-04-17 11:37:15 -0700360 except pexpect.EOF:
361 main.log.error(self.name + ": EOF exception found")
362 main.log.error(self.name + ": " + self.handle.before)
363 main.cleanup()
364 main.exit()
365 except:
366 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
367 main.log.error( traceback.print_exc() )
368 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
369 main.cleanup()
370 def get_version(self):
371 '''
372 Writes the COMMIT number to the report to be parsed by Jenkins data collecter.
373 '''
374 try:
375 self.handle.sendline("export TERM=xterm-256color")
376 self.handle.expect("xterm-256color")
377 self.handle.expect("\$")
378 self.handle.sendline("cd " + self.home + "; git log -1 --pretty=fuller | grep -A 5 \"commit\"; cd \.\.")
379 self.handle.expect("cd ..")
380 self.handle.expect("\$")
381 response=(self.name +": \n"+ str(self.handle.before + self.handle.after))
admine0eeea22014-04-14 10:22:46 -0700382 lines=response.splitlines()
383 for line in lines:
384 print line
385 return lines[2]
Jon Hallae05dc22014-04-16 10:56:28 -0700386 except pexpect.EOF:
387 main.log.error(self.name + ": EOF exception found")
388 main.log.error(self.name + ": " + self.handle.before)
389 main.cleanup()
390 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700391 except:
392 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
393 main.log.error( traceback.print_exc() )
394 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
395 main.cleanup()
396 main.exit()
adminbae64d82013-08-01 10:50:15 -0700397
adminc6cfc1c2014-04-21 13:55:21 -0700398 def ad_flow(self):
399 main.log.info("AD_FLOW RUNNING!!!!")
400 self.handle.sendline("cd "+self.home+ "/scripts")
401 self.handle.expect("scripts")
402 print("Adding flows")
403 self.handle.sendline("./pyintents.py")
404 self.handle.sendline("cd "+self.home)
405 return main.TRUE
406
407 def rm_flow(self):
408 main.log.info("RM_FLOW RUNNING!!!")
409 self.handle.sendline("cd "+self.home+ "/scripts")
410 self.handle.expect("scripts")
411 print("Removing flows")
412 self.handle.sendline("./rmpyintents.py")
413 self.handle.sendline("cd "+self.home)
414 return main.TRUE
415
416
417
418
Jon Hall4a2b0482014-04-18 16:29:26 -0700419 def add_flow(self, testONip, user = "admin", password = "", flowDef = "/flowdef.txt"):
Jon Halld8dc5772014-04-08 16:26:29 -0700420 '''
421 Copies the flowdef file from TestStation -> ONOS machine
422 Then runs ./add_flow.py to add the flows to ONOS
423 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700424 try:
425 main.log.info("Adding Flows...")
426 self.handle.sendline("scp %s@%s:%s /tmp/flowtmp" %(user,testONip,flowDef))
427 i=self.handle.expect(['[pP]assword:', '100%', pexpect.TIMEOUT],30)
428 if(i==0):
429 self.handle.sendline("%s" %(password))
430 self.handle.sendline("")
431 self.handle.expect("100%")
432 self.handle.expect("\$", 30)
433 self.handle.sendline(self.home + "/web/add_flow.py -m onos -f /tmp/flowtmp")
434 self.handle.expect("\$", 1000)
435 main.log.info("Flows added")
436 return main.TRUE
437
438 elif(i==1):
439 self.handle.sendline("")
440 self.handle.expect("\$", 10)
441 self.handle.sendline( self.home + "/web/add_flow.py -m onos -f /tmp/flowtmp")
442 self.handle.expect("\$", 1000)
443 main.log.info("Flows added")
444 return main.TRUE
445
446 elif(i==2):
447 main.log.error("Flow Def file SCP Timed out...")
448 return main.FALSE
449
450 else:
451 main.log.error("Failed to add flows...")
James Leec9cacaf2014-04-08 09:17:39 -0700452 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700453 except pexpect.EOF:
454 main.log.error(self.name + ": EOF exception found")
455 main.log.error(self.name + ": " + self.handle.before)
456 main.cleanup()
457 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700458 except:
459 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
460 main.log.error( traceback.print_exc() )
461 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
462 main.cleanup()
463 main.exit()
464
adminbae64d82013-08-01 10:50:15 -0700465
466 def delete_flow(self, *delParams):
Jon Halld8dc5772014-04-08 16:26:29 -0700467 '''
468 Deletes a specific flow, a range of flows, or all flows.
469 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700470 try:
471 if len(delParams)==1:
472 if str(delParams[0])=="all":
473 main.log.info(self.name + ": Deleting ALL flows...")
474 #self.execute(cmd="~/ONOS/scripts/TestON_delete_flow.sh all",prompt="done",timeout=150)
475 self.handle.sendline(self.home + "/web/delete_flow.py all")
476 self.handle.expect("delete_flow")
477 self.handle.expect("\$",1000)
478 main.log.info(self.name + ": Flows deleted")
479 else:
480 main.log.info(self.name + ": Deleting flow "+str(delParams[0])+"...")
481 #self.execute(cmd="~/ONOS/scripts/TestON_delete_flow.sh "+str(delParams[0]),prompt="done",timeout=150)
482 #self.execute(cmd="\n",prompt="\$",timeout=60)
483 self.handle.sendline(self.home +"/web/delete_flow.py %d" % int(delParams[0]))
484 self.handle.expect("delete_flow")
485 self.handle.expect("\$",60)
486 main.log.info(self.name + ": Flow deleted")
487 elif len(delParams)==2:
488 main.log.info(self.name + ": Deleting flows "+str(delParams[0])+" through "+str(delParams[1])+"...")
489 #self.execute(cmd="~/ONOS/scripts/TestON_delete_flow.sh "+str(delParams[0])+" "+str(delParams[1]),prompt="done",timeout=150)
490 #self.execute(cmd="\n",prompt="\$",timeout=60)
491 self.handle.sendline(self.home + "/web/delete_flow.py %d %d" % (int(delParams[0]), int(delParams[1])))
492 self.handle.expect("delete_flow")
493 self.handle.expect("\$",600)
494 main.log.info(self.name + ": Flows deleted")
Jon Hallae05dc22014-04-16 10:56:28 -0700495 except pexpect.EOF:
496 main.log.error(self.name + ": EOF exception found")
497 main.log.error(self.name + ": " + self.handle.before)
498 main.cleanup()
499 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700500 except:
501 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
502 main.log.error( traceback.print_exc() )
503 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
504 main.cleanup()
505 main.exit()
adminbae64d82013-08-01 10:50:15 -0700506
507 def check_flow(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700508 '''
509 Calls the ./get_flow.py all and checks:
510 - If each FlowPath has at least one FlowEntry
511 - That there are no "NOT"s found
512 returns TRUE/FALSE
513 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700514 try:
515 flowEntryDetect = 1
516 count = 0
517 self.handle.sendline("clear")
518 time.sleep(1)
519 self.handle.sendline(self.home + "/web/get_flow.py all")
520 self.handle.expect("get_flow")
521 while 1:
522 i=self.handle.expect(['FlowPath','FlowEntry','NOT','\$',pexpect.TIMEOUT],timeout=180)
523 if i==0:
524 count = count + 1
525 if flowEntryDetect == 0:
526 main.log.info(self.name + ": FlowPath without FlowEntry")
527 return main.FALSE
528 else:
529 flowEntryDetect = 0
530 elif i==1:
531 flowEntryDetect = 1
532 elif i==2:
533 main.log.error(self.name + ": Found a NOT")
adminbae64d82013-08-01 10:50:15 -0700534 return main.FALSE
Jon Hallf89c8552014-04-02 13:14:06 -0700535 elif i==3:
536 if count == 0:
537 main.log.info(self.name + ": There don't seem to be any flows here...")
538 return main.FALSE
539 else:
540 main.log.info(self.name + ": All flows pass")
541 main.log.info(self.name + ": Number of FlowPaths: "+str(count))
542 return main.TRUE
543 elif i==4:
James Leec9cacaf2014-04-08 09:17:39 -0700544 main.log.error(self.name + ":Check_flow() - Command Timeout!")
Jon Hallf89c8552014-04-02 13:14:06 -0700545 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700546 except pexpect.EOF:
547 main.log.error(self.name + ": EOF exception found")
548 main.log.error(self.name + ": " + self.handle.before)
549 main.cleanup()
550 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700551 except:
552 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
553 main.log.error( traceback.print_exc() )
554 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
555 main.cleanup()
556 main.exit()
adminbae64d82013-08-01 10:50:15 -0700557
558 def get_flow(self, *flowParams):
Jon Halld8dc5772014-04-08 16:26:29 -0700559 '''
560 Returns verbose output of ./get_flow.py
561 '''
562 try:
563 if len(flowParams)==1:
564 if str(flowParams[0])=="all":
565 self.execute(cmd="\n",prompt="\$",timeout=60)
566 main.log.info(self.name + ": Getting all flow data...")
567 data = self.execute(cmd=self.home + "/scripts/TestON_get_flow.sh all",prompt="done",timeout=150)
568 self.execute(cmd="\n",prompt="\$",timeout=60)
569 return data
570 else:
571 main.log.info(self.name + ": Retrieving flow "+str(flowParams[0])+" data...")
572 data = self.execute(cmd=self.home +"/scripts/TestON_get_flow.sh "+str(flowParams[0]),prompt="done",timeout=150)
573 self.execute(cmd="\n",prompt="\$",timeout=60)
574 return data
575 elif len(flowParams)==5:
576 main.log.info(self.name + ": Retrieving flow installer data...")
577 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)
578 self.execute(cmd="\n",prompt="\$",timeout=60)
579 return data
580 elif len(flowParams)==4:
581 main.log.info(self.name + ": Retrieving flow endpoints...")
582 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)
583 self.execute(cmd="\n",prompt="\$",timeout=60)
584 return data
Jon Hallae05dc22014-04-16 10:56:28 -0700585 except pexpect.EOF:
586 main.log.error(self.name + ": EOF exception found")
587 main.log.error(self.name + ": " + self.handle.before)
588 main.cleanup()
589 main.exit()
Jon Halld8dc5772014-04-08 16:26:29 -0700590 except:
Jon Hallf89c8552014-04-02 13:14:06 -0700591 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
592 main.log.error( traceback.print_exc() )
593 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
594 main.cleanup()
595 main.exit()
adminbae64d82013-08-01 10:50:15 -0700596
597
SeanCorcoran83a653a2014-04-22 15:03:18 -0700598# http://localhost:8080/wm/onos/topology/switches/json
599# http://localhost:8080/wm/onos/topology/links/json
Jon Hall8060af02014-04-14 14:17:58 -0700600# http://localhost:8080/wm/onos/registry/controllers/json
601# http://localhost:8080/wm/onos/registry/switches/json"
adminbae64d82013-08-01 10:50:15 -0700602
603 def get_json(self, url):
Jon Halld8dc5772014-04-08 16:26:29 -0700604 '''
605 Helper functions used to parse the json output of a rest call
606 '''
adminbae64d82013-08-01 10:50:15 -0700607 try:
Jon Hallf89c8552014-04-02 13:14:06 -0700608 try:
609 command = "curl -s %s" % (url)
610 result = os.popen(command).read()
611 parsedResult = json.loads(result)
612 except:
613 print "REST IF %s has issue" % command
614 parsedResult = ""
615
616 if type(parsedResult) == 'dict' and parsedResult.has_key('code'):
617 print "REST %s returned code %s" % (command, parsedResult['code'])
618 parsedResult = ""
James Leec9cacaf2014-04-08 09:17:39 -0700619 return parsedResult
Jon Hallae05dc22014-04-16 10:56:28 -0700620 except pexpect.EOF:
621 main.log.error(self.name + ": EOF exception found")
622 main.log.error(self.name + ": " + self.handle.before)
623 main.cleanup()
624 main.exit()
adminbae64d82013-08-01 10:50:15 -0700625 except:
Jon Hallf89c8552014-04-02 13:14:06 -0700626 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
627 main.log.error( traceback.print_exc() )
628 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
629 main.cleanup()
630 main.exit()
adminbae64d82013-08-01 10:50:15 -0700631
Jon Hallf89c8552014-04-02 13:14:06 -0700632 def check_switch(self,RestIP,correct_nr_switch, RestPort ="8080" ):
Jon Halld8dc5772014-04-08 16:26:29 -0700633 '''
634 Used by check_status
635 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700636 try:
637 buf = ""
638 retcode = 0
SeanCorcoran83a653a2014-04-22 15:03:18 -0700639 url="http://%s:%s/wm/onos/topology/switches/json" % (RestIP, RestPort)
Jon Hallf89c8552014-04-02 13:14:06 -0700640 parsedResult = self.get_json(url)
641 if parsedResult == "":
642 retcode = 1
643 return (retcode, "Rest API has an issue")
644 url = "http://%s:%s/wm/onos/registry/switches/json" % (RestIP, RestPort)
645 registry = self.get_json(url)
646
647 if registry == "":
648 retcode = 1
649 return (retcode, "Rest API has an issue")
650
651 cnt = 0
652 active = 0
adminbae64d82013-08-01 10:50:15 -0700653
Jon Hallf89c8552014-04-02 13:14:06 -0700654 for s in parsedResult:
655 cnt += 1
James Leec9cacaf2014-04-08 09:17:39 -0700656 if s['state'] == "ACTIVE":
Jon Hallf89c8552014-04-02 13:14:06 -0700657 active += 1
adminbae64d82013-08-01 10:50:15 -0700658
Jon Hallf89c8552014-04-02 13:14:06 -0700659 buf += "switch: network %d : %d switches %d active\n" % (0+1, cnt, active)
660 if correct_nr_switch != cnt:
661 buf += "switch fail: network %d should have %d switches but has %d\n" % (1, correct_nr_switch, cnt)
662 retcode = 1
adminbae64d82013-08-01 10:50:15 -0700663
Jon Hallf89c8552014-04-02 13:14:06 -0700664 if correct_nr_switch != active:
665 buf += "switch fail: network %d should have %d active switches but has %d\n" % (1, correct_nr_switch, active)
666 retcode = 1
667
668 return (retcode, buf)
Jon Hallae05dc22014-04-16 10:56:28 -0700669 except pexpect.EOF:
670 main.log.error(self.name + ": EOF exception found")
671 main.log.error(self.name + ": " + self.handle.before)
672 main.cleanup()
673 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700674 except:
675 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
676 main.log.error( traceback.print_exc() )
677 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
678 main.cleanup()
679 main.exit()
adminbae64d82013-08-01 10:50:15 -0700680
Jon Hallf89c8552014-04-02 13:14:06 -0700681 def check_link(self,RestIP, nr_links, RestPort = "8080"):
Jon Halld8dc5772014-04-08 16:26:29 -0700682 '''
683 Used by check_status
684 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700685 try:
686 buf = ""
687 retcode = 0
688
SeanCorcoran83a653a2014-04-22 15:03:18 -0700689 url = "http://%s:%s/wm/onos/topology/links/json" % (RestIP, RestPort)
Jon Hallf89c8552014-04-02 13:14:06 -0700690 parsedResult = self.get_json(url)
691
692 if parsedResult == "":
693 retcode = 1
694 return (retcode, "Rest API has an issue")
695
696 buf += "link: total %d links (correct : %d)\n" % (len(parsedResult), nr_links)
697 intra = 0
698 interlink=0
699
700 for s in parsedResult:
James Leec9cacaf2014-04-08 09:17:39 -0700701 intra = intra + 1
Jon Hallf89c8552014-04-02 13:14:06 -0700702
703 if intra != nr_links:
704 buf += "link fail\n"
705 retcode = 1
706
707 return (retcode, buf)
Jon Hallae05dc22014-04-16 10:56:28 -0700708 except pexpect.EOF:
709 main.log.error(self.name + ": EOF exception found")
710 main.log.error(self.name + ": " + self.handle.before)
711 main.cleanup()
712 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700713 except:
714 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
715 main.log.error( traceback.print_exc() )
716 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
717 main.cleanup()
718 main.exit()
adminbae64d82013-08-01 10:50:15 -0700719
Jon Hallf89c8552014-04-02 13:14:06 -0700720 def check_status_report(self, ip, numoswitch, numolink, port="8080"):
Jon Halld8dc5772014-04-08 16:26:29 -0700721 '''
722 Checks the number of swithes & links that ONOS sees against the supplied values.
723 Writes to the report log.
724 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700725 try:
James Leec9cacaf2014-04-08 09:17:39 -0700726 main.log.info(self.name + ": Making some rest calls...")
Jon Hallf89c8552014-04-02 13:14:06 -0700727 switch = self.check_switch(ip, int(numoswitch), port)
728 link = self.check_link(ip, int(numolink), port)
729 value = switch[0]
730 value += link[0]
731 main.log.report( self.name + ": \n-----\n%s%s-----\n" % ( switch[1], link[1]) )
732 if value != 0:
733 return main.FALSE
James Leec9cacaf2014-04-08 09:17:39 -0700734 else:
Jon Hallf89c8552014-04-02 13:14:06 -0700735 # "PASS"
736 return main.TRUE
Jon Hallae05dc22014-04-16 10:56:28 -0700737 except pexpect.EOF:
738 main.log.error(self.name + ": EOF exception found")
739 main.log.error(self.name + ": " + self.handle.before)
740 main.cleanup()
741 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700742 except:
743 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
744 main.log.error( traceback.print_exc() )
745 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
746 main.cleanup()
747 main.exit()
adminbae64d82013-08-01 10:50:15 -0700748
Jon Hallf89c8552014-04-02 13:14:06 -0700749 def check_status(self, ip, numoswitch, numolink, port = "8080"):
Jon Halld8dc5772014-04-08 16:26:29 -0700750 '''
751 Checks the number of swithes & links that ONOS sees against the supplied values.
752 Writes to the main log.
753 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700754 try:
James Leec9cacaf2014-04-08 09:17:39 -0700755 main.log.info(self.name + ": Making some rest calls...")
Jon Hallf89c8552014-04-02 13:14:06 -0700756 switch = self.check_switch(ip, int(numoswitch), port)
757 link = self.check_link(ip, int(numolink), port)
758 value = switch[0]
759 value += link[0]
760 main.log.info(self.name + ": \n-----\n%s%s-----\n" % ( switch[1], link[1]) )
761 if value != 0:
762 return main.FALSE
James Leec9cacaf2014-04-08 09:17:39 -0700763 else:
Jon Hallf89c8552014-04-02 13:14:06 -0700764 # "PASS"
765 return main.TRUE
Jon Hallae05dc22014-04-16 10:56:28 -0700766 except pexpect.EOF:
767 main.log.error(self.name + ": EOF exception found")
768 main.log.error(self.name + ": " + self.handle.before)
769 main.cleanup()
770 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700771 except:
772 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
773 main.log.error( traceback.print_exc() )
774 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
775 main.cleanup()
776 main.exit()
adminbae64d82013-08-01 10:50:15 -0700777
adminbae64d82013-08-01 10:50:15 -0700778 def check_for_no_exceptions(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700779 '''
780 TODO: Rewrite
781 Used by CassndraCheck.py to scan ONOS logs for Exceptions
782 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700783 try:
784 self.handle.sendline("dsh 'grep Exception ~/ONOS/onos-logs/onos.*.log'")
James Leec9cacaf2014-04-08 09:17:39 -0700785 self.handle.expect("\$ dsh")
Jon Hallf89c8552014-04-02 13:14:06 -0700786 self.handle.expect("\$")
787 output = self.handle.before
James Leec9cacaf2014-04-08 09:17:39 -0700788 main.log.info(self.name + ": " + output )
Jon Hallf89c8552014-04-02 13:14:06 -0700789 if re.search("Exception",output):
790 return main.FALSE
791 else :
792 return main.TRUE
Jon Hallae05dc22014-04-16 10:56:28 -0700793 except pexpect.EOF:
794 main.log.error(self.name + ": EOF exception found")
795 main.log.error(self.name + ": " + self.handle.before)
796 main.cleanup()
797 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700798 except:
799 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
800 main.log.error( traceback.print_exc() )
801 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
802 main.cleanup()
803 main.exit()
804
805
admine0eeea22014-04-14 10:22:46 -0700806 def git_pull(self, comp1=""):
Jon Halld8dc5772014-04-08 16:26:29 -0700807 '''
Jon Halld8dc5772014-04-08 16:26:29 -0700808 Assumes that "git pull" works without login
admine0eeea22014-04-14 10:22:46 -0700809
810 This function will perform a git pull on the ONOS instance.
811 If used as git_pull("NODE") it will do git pull + NODE. This is
812 for the purpose of pulling from other nodes if necessary.
813
814 Otherwise, this function will perform a git pull in the
815 ONOS repository. If it has any problems, it will return main.ERROR
816 If it successfully does a git_pull, it will return a 1.
817 If it has no updates, it will return a 0.
818
Jon Halld8dc5772014-04-08 16:26:29 -0700819 '''
Jon Hallae05dc22014-04-16 10:56:28 -0700820 try:
Jon Halle80ef8c2014-04-29 15:29:13 -0700821 # main.log.info(self.name + ": Stopping ONOS")
822 #self.stop()
Jon Hallae05dc22014-04-16 10:56:28 -0700823 self.handle.sendline("cd " + self.home)
824 self.handle.expect("ONOS\$")
825 if comp1=="":
826 self.handle.sendline("git pull")
827 else:
828 self.handle.sendline("git pull " + comp1)
829
830 uptodate = 0
SeanCorcoran20bd6fc2014-04-16 17:10:30 -0700831 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 -0700832 #debug
833 #main.log.report(self.name +": \n"+"git pull response: " + str(self.handle.before) + str(self.handle.after))
834 if i==0:
835 main.log.error(self.name + ": Git pull had some issue...")
836 return main.ERROR
837 elif i==1:
838 main.log.error(self.name + ": Git Pull Asking for username!!! BADD!")
839 return main.ERROR
840 elif i==2:
841 main.log.info(self.name + ": Git Pull - pulling repository now")
842 self.handle.expect("ONOS\$", 120)
843 return 0
844 elif i==3:
845 main.log.error(self.name + ": Git Pull - TIMEOUT")
846 return main.ERROR
847 elif i==4:
848 main.log.info(self.name + ": Git Pull - Already up to date")
849 return 1
850 elif i==5:
851 main.log.info(self.name + ": Git Pull - Aborting... Are there conflicting git files?")
852 return main.ERROR
853 else:
854 main.log.error(self.name + ": Git Pull - Unexpected response, check for pull errors")
855 return main.ERROR
856 except pexpect.EOF:
857 main.log.error(self.name + ": EOF exception found")
858 main.log.error(self.name + ": " + self.handle.before)
859 main.cleanup()
860 main.exit()
861 except:
862 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
863 main.log.error( traceback.print_exc() )
864 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
865 main.cleanup()
866 main.exit()
admine0eeea22014-04-14 10:22:46 -0700867#********************************************************
868
869
admin7373a812014-04-16 09:49:02 -0700870 def git_compile(self):
Jon Hallae05dc22014-04-16 10:56:28 -0700871 '''
872 Compiles ONOS
873 First runs mvn clean then mvn compile
874 '''
875 try:
876 main.log.info(self.name + ": mvn clean")
admin8fc02822014-04-16 13:31:23 -0700877 self.handle.sendline("cd " + self.home)
Jon Hallae05dc22014-04-16 10:56:28 -0700878 self.handle.sendline("mvn clean")
879 while 1:
Jon Hall1636f942014-04-17 10:07:23 -0700880 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 -0700881 if i == 0:
Jon Hall1636f942014-04-17 10:07:23 -0700882 main.log.error(self.name + ":There is insufficient memory for the Java Runtime Environment to continue.")
Jon Hallae05dc22014-04-16 10:56:28 -0700883 return main.FALSE
884 elif i == 1:
Jon Hall1636f942014-04-17 10:07:23 -0700885 main.log.error(self.name + ": Clean failure!")
886 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700887 elif i == 2:
Jon Hall1636f942014-04-17 10:07:23 -0700888 main.log.info(self.name + ": Clean success!")
889 elif i == 3:
admin8fc02822014-04-16 13:31:23 -0700890 main.log.info(self.name + ": Clean complete")
Jon Hallae05dc22014-04-16 10:56:28 -0700891 break;
Jon Hall1636f942014-04-17 10:07:23 -0700892 elif i == 4:
Jon Hallae05dc22014-04-16 10:56:28 -0700893 main.log.error(self.name + ": mvn clean TIMEOUT!")
894 return main.FALSE
Jon Hall1636f942014-04-17 10:07:23 -0700895 else:
896 main.log.error(self.name + ": unexpected response from mvn clean")
897 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700898
899 main.log.info(self.name + ": mvn compile")
900 self.handle.sendline("mvn compile")
901 while 1:
Jon Hall1636f942014-04-17 10:07:23 -0700902 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 -0700903 if i == 0:
Jon Hall1636f942014-04-17 10:07:23 -0700904 main.log.error(self.name + ":There is insufficient memory for the Java Runtime Environment to continue.")
905 return main.FALSE
906 if i == 1:
Jon Hallae05dc22014-04-16 10:56:28 -0700907 main.log.error(self.name + ": Build failure!")
908 return main.FALSE
Jon Hall1636f942014-04-17 10:07:23 -0700909 elif i == 2:
Jon Hallae05dc22014-04-16 10:56:28 -0700910 main.log.info(self.name + ": Build success!")
911 return main.TRUE
Jon Hall1636f942014-04-17 10:07:23 -0700912 elif i == 3:
Jon Hallae05dc22014-04-16 10:56:28 -0700913 main.log.info(self.name + ": Build complete")
914 return main.TRUE
Jon Hall1636f942014-04-17 10:07:23 -0700915 elif i == 4:
Jon Hallae05dc22014-04-16 10:56:28 -0700916 main.log.error(self.name + ": mvn compile TIMEOUT!")
917 return main.FALSE
918 else:
Jon Hall1636f942014-04-17 10:07:23 -0700919 main.log.error(self.name + ": unexpected response from mvn compile")
920 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700921 except pexpect.EOF:
922 main.log.error(self.name + ": EOF exception found")
923 main.log.error(self.name + ": " + self.handle.before)
924 main.cleanup()
925 main.exit()
926 except:
927 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
928 main.log.error( traceback.print_exc() )
929 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
930 main.cleanup()
931 main.exit()
admin4a58db92013-09-30 12:04:54 -0700932
Jon Hallf89c8552014-04-02 13:14:06 -0700933 def tcpdump(self, intf = "eth0"):
Jon Hallae05dc22014-04-16 10:56:28 -0700934 '''
935 Runs tpdump on an intferface and saves in onos-logs under the ONOS home directory
936 intf can be specified, or the default eth0 is used
937 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700938 try:
939 self.handle.sendline("")
940 self.handle.expect("\$")
Jon Hall26f316b2014-04-11 11:21:25 -0700941 self.handle.sendline("sudo tcpdump -n -i "+ intf + " -s0 -w " + self.home +"/onos-logs/tcpdump &")
Jon Hallf89c8552014-04-02 13:14:06 -0700942 i=self.handle.expect(['No\ssuch\device','listening\son',pexpect.TIMEOUT],timeout=10)
943 if i == 0:
944 main.log.error(self.name + ": tcpdump - No such device exists. tcpdump attempted on: " + intf)
945 return main.FALSE
James Leec9cacaf2014-04-08 09:17:39 -0700946 elif i == 1:
Jon Hallf89c8552014-04-02 13:14:06 -0700947 main.log.info(self.name + ": tcpdump started on " + intf)
948 return main.TRUE
James Leec9cacaf2014-04-08 09:17:39 -0700949 elif i == 2:
Jon Hallf89c8552014-04-02 13:14:06 -0700950 main.log.error(self.name + ": tcpdump command timed out! Check interface name, given interface was: " + intf)
951 return main.FALSE
952 else:
953 main.log.error(self.name + ": tcpdump - unexpected response")
954 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700955 except pexpect.EOF:
956 main.log.error(self.name + ": EOF exception found")
957 main.log.error(self.name + ": " + self.handle.before)
958 main.cleanup()
959 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700960 except:
961 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
962 main.log.error( traceback.print_exc() )
963 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
964 main.cleanup()
965 main.exit()
966
admin4a58db92013-09-30 12:04:54 -0700967 def kill_tcpdump(self):
Jon Hallae05dc22014-04-16 10:56:28 -0700968 '''
969 Kills any tcpdump processes running
970 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700971 try:
972 self.handle.sendline("")
973 self.handle.expect("\$")
974 self.handle.sendline("sudo kill -9 `ps -ef | grep \"tcpdump -n\" | grep -v grep | awk '{print $2}'`")
Jon Hallae05dc22014-04-16 10:56:28 -0700975 except pexpect.EOF:
976 main.log.error(self.name + ": EOF exception found")
977 main.log.error(self.name + ": " + self.handle.before)
978 main.cleanup()
979 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700980 except:
981 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
982 main.log.error( traceback.print_exc() )
983 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
984 main.cleanup()
985 main.exit()
986
987 def find_host(self,RestIP,RestPort,RestAPI,hostIP):
988 retcode = 0
989 retswitch = []
990 retport = []
991 retmac = []
992 foundIP = []
993 try:
SeanCorcoran83a653a2014-04-22 15:03:18 -0700994 ##### device rest API is: 'host:8080/wm/onos/topology/switches/json' ###
Jon Hallf89c8552014-04-02 13:14:06 -0700995 url ="http://%s:%s%s" %(RestIP,RestPort,RestAPI)
996
997 try:
998 command = "curl -s %s" % (url)
999 result = os.popen(command).read()
1000 parsedResult = json.loads(result)
1001 # print parsedResult
1002 except:
1003 print "REST IF %s has issue" % command
1004 parsedResult = ""
1005
1006 if parsedResult == "":
Jon Hallae05dc22014-04-16 10:56:28 -07001007 return (retcode, "Rest API has an error", retport, retmac)
Jon Hallf89c8552014-04-02 13:14:06 -07001008 else:
1009 for switch in enumerate(parsedResult):
1010 for port in enumerate(switch[1]['ports']):
1011 if ( port[1]['devices'] != [] ):
1012 try:
James Leec9cacaf2014-04-08 09:17:39 -07001013 foundIP = port[1]['devices'][0]['ipv4addresses'][0]['ipv4']
Jon Hallf89c8552014-04-02 13:14:06 -07001014 except:
1015 print "Error in detecting IP address."
1016 if foundIP == hostIP:
1017 retswitch.append(switch[1]['dpid'])
1018 retport.append(port[1]['desc'])
1019 retmac.append(port[1]['devices'][0]['mac'])
1020 retcode = retcode +1
1021 foundIP =''
1022 return(retcode, retswitch, retport, retmac)
Jon Hallae05dc22014-04-16 10:56:28 -07001023 except pexpect.EOF:
1024 main.log.error(self.name + ": EOF exception found")
1025 main.log.error(self.name + ": " + self.handle.before)
1026 main.cleanup()
1027 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -07001028 except:
1029 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1030 main.log.error( traceback.print_exc() )
1031 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1032 main.cleanup()
1033 main.exit()