blob: 40c07db295d550d98325d2a7fe98bcd0f015aec8 [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
admin2a9548d2014-06-17 14:08:07 -070028import urllib2
29from urllib2 import URLError, HTTPError
adminbae64d82013-08-01 10:50:15 -070030sys.path.append("../")
31from drivers.common.clidriver import CLI
32
33class OnosCliDriver(CLI):
34
35 def __init__(self):
36 super(CLI, self).__init__()
37
38 def connect(self,**connectargs):
Jon Halld8dc5772014-04-08 16:26:29 -070039 '''
40 Creates ssh handle for ONOS.
41 '''
Jon Hallf89c8552014-04-02 13:14:06 -070042 try:
43 for key in connectargs:
admine0eeea22014-04-14 10:22:46 -070044 vars(self)[key] = connectargs[key]
Jon Hallf89c8552014-04-02 13:14:06 -070045 self.home = "~/ONOS"
46 for key in self.options:
admine0eeea22014-04-14 10:22:46 -070047 if key == "home":
48 self.home = self.options['home']
49 break
adminbae64d82013-08-01 10:50:15 -070050
Jon Hallf89c8552014-04-02 13:14:06 -070051
52 self.name = self.options['name']
53 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 -070054
Jon Hallf89c8552014-04-02 13:14:06 -070055 if self.handle:
Jon Hallf89c8552014-04-02 13:14:06 -070056 return self.handle
57 else :
58 main.log.info("NO ONOS HANDLE")
59 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -070060 except pexpect.EOF:
61 main.log.error(self.name + ": EOF exception found")
62 main.log.error(self.name + ": " + self.handle.before)
63 main.cleanup()
64 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -070065 except:
66 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
67 main.log.error( traceback.print_exc() )
68 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
69 main.cleanup()
70 main.exit()
admin680b78c2014-08-08 11:46:45 -070071
72 def portKill(self, port):
73 try:
74 self.handle.sendline("")
75 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
76 cmd = "sudo tcpkill -i eth0 port " + str(port) + " 2>/dev/null 1>/dev/null &"
77 self.handle.sendline(cmd)
78 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
79 except pexpect.EOF:
80 main.log.error(self.name + ": EOF exception found")
81 main.log.error(self.name + ": " + self.handle.before)
82 main.cleanup()
83 main.exit()
84 except:
85 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
86 main.log.error( traceback.print_exc() )
87 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
88 main.cleanup()
89 main.exit()
90
91 def endPortKill(self,port):
92 try:
93 self.handle.sendline("")
94 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
95 self.handle.sendline("sudo pkill tcpkill")
96 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
97 except pexpect.EOF:
98 main.log.error(self.name + ": EOF exception found")
99 main.log.error(self.name + ": " + self.handle.before)
100 main.cleanup()
101 main.exit()
102 except:
103 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
104 main.log.error( traceback.print_exc() )
105 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
106 main.cleanup()
107 main.exit()
adminbae64d82013-08-01 10:50:15 -0700108
Jon Hallf0a494f2014-06-23 15:37:40 -0700109 def start(self, env = ''):
Jon Halld8dc5772014-04-08 16:26:29 -0700110 '''
111 Starts ONOS on remote machine.
112 Returns false if any errors were encountered.
113 '''
James Leec9cacaf2014-04-08 09:17:39 -0700114 try:
Jon Hallf89c8552014-04-02 13:14:06 -0700115 self.handle.sendline("")
Jon Hallae05dc22014-04-16 10:56:28 -0700116 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
Jon Hall4a2b0482014-04-18 16:29:26 -0700117 self.handle.sendline("cd "+self.home)
Jon Hallf0a494f2014-06-23 15:37:40 -0700118 self.handle.sendline(env + "./onos.sh core start")
Jon Hallae05dc22014-04-16 10:56:28 -0700119 i=self.handle.expect(["STARTED","FAILED",pexpect.EOF,pexpect.TIMEOUT])
120 response = self.handle.before + str(self.handle.after)
Jon Hallf89c8552014-04-02 13:14:06 -0700121 if i==0:
Jon Hallae05dc22014-04-16 10:56:28 -0700122 j = self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT], timeout=60)
123 if re.search("Killed",response):
124 main.log.warn(self.name + ": Killed existing process")
125 if j==0:
Jon Hallf89c8552014-04-02 13:14:06 -0700126 main.log.info(self.name + ": ONOS Started ")
Jon Hallae05dc22014-04-16 10:56:28 -0700127 return main.TRUE
128 elif j==1:
129 main.log.error(self.name + ": EOF exception found")
130 main.log.error(self.name + ": " + self.handle.before)
131 main.cleanup()
132 main.exit()
133 elif j==2:
Jon Hallf89c8552014-04-02 13:14:06 -0700134 main.log.info(self.name + ": ONOS NOT Started, stuck while waiting for it to start ")
135 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700136 else:
137 main.log.warn(self.name +": Unexpected response in start")
138 return main.TRUE
Jon Hallf89c8552014-04-02 13:14:06 -0700139 elif i==1:
Jon Hallae05dc22014-04-16 10:56:28 -0700140 main.log.error(self.name + ": ONOS Failed to start")
adminbae64d82013-08-01 10:50:15 -0700141 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700142 elif i==2:
143 main.log.error(self.name + ": EOF exception found")
144 main.log.error(self.name + ": " + self.handle.before)
145 main.cleanup()
146 main.exit()
147 elif i==3:
148 main.log.error(self.name + ": ONOS timedout while starting")
149 return main.FALSE
150 else:
151 main.log.error(self.name + ": ONOS start expect script missed something... ")
adminbae64d82013-08-01 10:50:15 -0700152 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700153 except pexpect.EOF:
154 main.log.error(self.name + ": EOF exception found")
155 main.log.error(self.name + ": " + self.handle.before)
156 main.cleanup()
157 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700158 except:
159 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
160 main.log.error( traceback.print_exc() )
161 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
162 main.cleanup()
163 main.exit()
Jon Halle80ef8c2014-04-29 15:29:13 -0700164
165 def start_all(self):
166 '''
167 starts ZK, RC, and ONOS
168 '''
169 self.handle.sendline("cd "+self.home)
170 self.handle.sendline("./onos.sh start")
171 self.handle.expect("./onos.sh start")
172 self.handle.expect(["\$",pexpect.TIMEOUT])
173
174
175
adminbae64d82013-08-01 10:50:15 -0700176 def start_rest(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700177 '''
178 Starts the rest server on ONOS.
179 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700180 try:
Jon Hall4a2b0482014-04-18 16:29:26 -0700181 self.handle.sendline("cd "+self.home)
182 response = self.execute(cmd= "./start-rest.sh start",prompt="\$",timeout=10)
Jon Hallf89c8552014-04-02 13:14:06 -0700183 if re.search("admin",response):
184 main.log.info(self.name + ": Rest Server Started Successfully")
185 time.sleep(5)
186 return main.TRUE
187 else :
James Leec9cacaf2014-04-08 09:17:39 -0700188 main.log.warn(self.name + ": Failed to start Rest Server")
189 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700190 except pexpect.EOF:
191 main.log.error(self.name + ": EOF exception found")
192 main.log.error(self.name + ": " + self.handle.before)
193 main.cleanup()
194 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700195 except:
196 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
197 main.log.error( traceback.print_exc() )
198 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
199 main.cleanup()
200 main.exit()
201
adminbae64d82013-08-01 10:50:15 -0700202 def status(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700203 '''
204 Called onos.sh core status and returns TRUE/FALSE accordingly
205 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700206 try:
207 self.execute(cmd="\n",prompt="\$",timeout=10)
Jon Hall4a2b0482014-04-18 16:29:26 -0700208 self.handle.sendline("cd "+self.home)
209 response = self.execute(cmd="./onos.sh core status ",prompt="\d+\sinstance\sof\sonos\srunning",timeout=10)
Jon Hallf89c8552014-04-02 13:14:06 -0700210 self.execute(cmd="\n",prompt="\$",timeout=10)
211 if re.search("1\sinstance\sof\sonos\srunning",response):
212 return main.TRUE
213 elif re.search("0\sinstance\sof\sonos\srunning",response):
214 return main.FALSE
Jon Hallbb650fe2014-07-14 14:54:48 -0700215 elif re.search("Expected\sPrompt\snot found\s,\sTime Out!!",response):
216 return main.ERROR
Jon Hallf89c8552014-04-02 13:14:06 -0700217 else :
Jon Hallf0a494f2014-06-23 15:37:40 -0700218 main.log.warn(self.name + " WARNING: status recieved unknown response")
219 main.log.warn(response)
Jon Hallf89c8552014-04-02 13:14:06 -0700220 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700221 except pexpect.EOF:
222 main.log.error(self.name + ": EOF exception found")
223 main.log.error(self.name + ": " + self.handle.before)
224 main.cleanup()
225 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700226 except:
227 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
228 main.log.error( traceback.print_exc() )
229 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
230 main.cleanup()
231 main.exit()
232
adminbae64d82013-08-01 10:50:15 -0700233
234 def isup(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700235 '''
236 A more complete check to see if ONOS is up and running properly.
237 First, it checks if the process is up.
238 Second, it reads the logs for "Exception: Connection refused"
239 Third, it makes sure the logs are actually moving.
240 returns TRUE/FALSE accordingly.
241 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700242 try:
243 self.execute(cmd="\n",prompt="\$",timeout=10)
Jon Hall4a2b0482014-04-18 16:29:26 -0700244 self.handle.sendline("cd "+self.home)
245 response = self.execute(cmd= "./onos.sh core status ",prompt="running",timeout=10)
Jon Hallf89c8552014-04-02 13:14:06 -0700246 self.execute(cmd="\n",prompt="\$",timeout=10)
247 tail1 = self.execute(cmd="tail " + self.home + "/onos-logs/onos.*.log",prompt="\$",timeout=10)
admine8c47d02014-06-03 11:59:16 -0700248 time.sleep(10)
Jon Hallf89c8552014-04-02 13:14:06 -0700249 self.execute(cmd="\n",prompt="\$",timeout=10)
250 tail2 = self.execute(cmd="tail " + self.home + "/onos-logs/onos.*.log",prompt="\$",timeout=10)
251 pattern = '(.*)1 instance(.*)'
252 pattern2 = '(.*)Exception: Connection refused(.*)'
253 # if utilities.assert_matches(expect=pattern,actual=response,onpass="ONOS process is running...",onfail="ONOS process not running..."):
admin2a9548d2014-06-17 14:08:07 -0700254 running = self.execute(cmd="cat "+self.home+"/onos-logs/onos.*.log | grep 'Sending LLDP out on all ports'",prompt="\$",timeout=10)
Jon Hallf89c8552014-04-02 13:14:06 -0700255 if re.search(pattern, response):
admin2a9548d2014-06-17 14:08:07 -0700256 if running != "":
Jon Halle80ef8c2014-04-29 15:29:13 -0700257 main.log.info(self.name + ": ONOS process is running...")
258 if tail1 == tail2:
259 main.log.error(self.name + ": ONOS is frozen...")#logs aren't moving
260 return main.FALSE
261 elif re.search( pattern2,tail1 ):
262 main.log.info(self.name + ": Connection Refused found in onos log")
263 return main.FALSE
264 elif re.search( pattern2,tail2 ):
265 main.log.info(self.name + ": Connection Refused found in onos log")
266 return main.FALSE
267 else:
268 main.log.info(self.name + ": Onos log is moving! It's looking good!")
269 return main.TRUE
Jon Hall55c79662014-05-19 15:03:40 -0700270 else:
271 main.log.info(self.name + ": ONOS not yet sending out LLDP messages")
272 return main.FALSE
adminbae64d82013-08-01 10:50:15 -0700273 else:
Jon Hallf89c8552014-04-02 13:14:06 -0700274 main.log.error(self.name + ": ONOS process not running...")
275 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700276 except pexpect.EOF:
277 main.log.error(self.name + ": EOF exception found")
278 main.log.error(self.name + ": " + self.handle.before)
279 main.cleanup()
280 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700281 except:
282 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
283 main.log.error( traceback.print_exc() )
284 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
285 main.cleanup()
286 main.exit()
adminbae64d82013-08-01 10:50:15 -0700287
Jon Hallf89c8552014-04-02 13:14:06 -0700288
289
James Leec9cacaf2014-04-08 09:17:39 -0700290 def rest_status(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700291 '''
292 Checks if the rest server is running.
293 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700294 try:
295 response = self.execute(cmd= self.home + "/start-rest.sh status ",prompt="running",timeout=10)
296 if re.search("rest\sserver\sis\srunning",response):
297 main.log.info(self.name + ": Rest Server is running")
Jon Hallae05dc22014-04-16 10:56:28 -0700298 return main.TRUE
Jon Hallf89c8552014-04-02 13:14:06 -0700299 elif re.search("rest\sserver\sis\snot\srunning",response):
300 main.log.warn(self.name + ": Rest Server is not Running")
Jon Hallae05dc22014-04-16 10:56:28 -0700301 return main.FALSE
Jon Hallf89c8552014-04-02 13:14:06 -0700302 else :
303 main.log.error(self.name + ": No response" +response)
Jon Hallae05dc22014-04-16 10:56:28 -0700304 return main.FALSE
305 except pexpect.EOF:
306 main.log.error(self.name + ": EOF exception found")
307 main.log.error(self.name + ": " + self.handle.before)
308 main.cleanup()
309 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700310 except:
311 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
312 main.log.error( traceback.print_exc() )
313 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
314 main.cleanup()
315 main.exit()
admine8c47d02014-06-03 11:59:16 -0700316
317 def stop_all(self):
318 '''
319 Runs ./onos.sh stop
320 '''
321 try:
322 self.handle.sendline("")
323 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
324 self.handle.sendline("cd "+self.home)
325 self.handle.sendline("./onos.sh stop")
Jon Halld79c7d02014-08-15 15:16:51 -0700326 self.handle.expect(["./onos.sh stop",pexpect.EOF,pexpect.TIMEOUT])
327 i=self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT],60)
admine8c47d02014-06-03 11:59:16 -0700328 result = self.handle.before
329 if re.search("Killed", result):
330 main.log.info(self.name + ": ONOS Killed Successfully")
331 return main.TRUE
332 else :
333 main.log.warn(self.name + ": ONOS wasn't running")
334 return main.FALSE
335 except pexpect.EOF:
336 main.log.error(self.name + ": EOF exception found")
337 main.log.error(self.name + ": " + self.handle.before)
338 main.cleanup()
339 main.exit()
340 except:
341 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
342 main.log.error( traceback.print_exc() )
343 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
344 main.cleanup()
345 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700346
347
adminbae64d82013-08-01 10:50:15 -0700348 def stop(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700349 '''
350 Runs ./onos.sh core stop to stop ONOS
351 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700352 try:
353 self.handle.sendline("")
Jon Hallae05dc22014-04-16 10:56:28 -0700354 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
Jon Hall4a2b0482014-04-18 16:29:26 -0700355 self.handle.sendline("cd "+self.home)
356 self.handle.sendline("./onos.sh core stop")
Jon Halld79c7d02014-08-15 15:16:51 -0700357 self.handle.expect(["./onos.sh stop",pexpect.EOF,pexpect.TIMEOUT])
358 i=self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT],60)
James Leec9cacaf2014-04-08 09:17:39 -0700359 result = self.handle.before
Jon Hallf89c8552014-04-02 13:14:06 -0700360 if re.search("Killed", result):
361 main.log.info(self.name + ": ONOS Killed Successfully")
362 return main.TRUE
363 else :
364 main.log.warn(self.name + ": ONOS wasn't running")
365 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700366 except pexpect.EOF:
367 main.log.error(self.name + ": EOF exception found")
368 main.log.error(self.name + ": " + self.handle.before)
369 main.cleanup()
370 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700371 except:
372 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
373 main.log.error( traceback.print_exc() )
374 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
375 main.cleanup()
376 main.exit()
admin6903e462014-07-22 15:30:54 -0700377#**********************************************************************************************
378#**********************************************************************************************
379# The purpose of comp_intents is to find if the high level intents have changed. preIntents
380# and postIntents should be the output of curl of the intents. preIntents being the original
381# and postIntents being the later. We are looking at the intents with the same id from both
382# and comparing the dst and src DPIDs and macs, and the state. If any of these are changed
383# we print that there are changes, then return a list of the intents that have changes`
384#**********************************************************************************************
385#**********************************************************************************************
386 def comp_intents(self,preIntents,postIntents):
387 import json
388 preDecoded = json.loads(preIntents)
389 postDecoded = json.loads(postIntents)
390 changes = []
391 if not preDecoded:
392 if postDecoded:
393 print "THERE ARE CHANGES TO THE HIGH LEVEL INTENTS!!!!"
394 return postDecoded
395 for k in preDecoded:
396 for l in postDecoded:
397 if l['id']==k['id']:
398 if k['dstSwitchDpid']==l['dstSwitchDpid'] and k['srcMac']==l['srcMac'] and k['dstMac']==l['dstMac'] and k['srcSwitchDpid']==l['srcSwitchDpid'] and k['state']==l['state']:
399 postDecoded.remove(l)
400 else:
401 changes.append(k)
402 print ("THERE ARE CHANGES TO THE HIGH LEVEL INTENTS!!!")
403 return changes
Jon Hallf89c8552014-04-02 13:14:06 -0700404
admin6903e462014-07-22 15:30:54 -0700405#**********************************************************************************************
406#**********************************************************************************************
407# the purpose of comp_low is to find if the low level intents have changed. The main idea
408# is to determine if the path has changed. Again, like with the comp_intents function, the
409# pre and post Intents variables are the json dumps of wm/onos/intent/low. The variables
410# that will be compared are the state, and the path.
411#**********************************************************************************************
412#**********************************************************************************************
413 def comp_low(self, preIntents,postIntents):
414 import json
415 preDecoded = json.loads(preIntents)
416 postDecoded = json.loads(postIntents)
417 changes = []
418 if not preDecoded:
419 if postDecoded:
420 print "THERE ARE CHANGES TO THE LOW LEVEL INTENTS!!!"
421 return postDecoded
422 for k in preDecoded:
423 for l in postDecoded:
424 if l['id']==k['id']:
425 if l['path']!=k['path']:
426 changes.append(l)
427 print "\n\n\n\nTHERE ARE CHANGES TO THE LOW LEVEL INTENTS!!!"
428 else:
429 if k['state']!=l['state']:
430 changes.append(l)
431 print "\n\n\n\nTHERE ARE CHANGES TO THE LOW LEVEL INTENTS!!!"
432 else:
433 print "NO CHANGES SO FAR\n\n\n"
434
435
436 return changes
437
438
adminbae64d82013-08-01 10:50:15 -0700439 def rest_stop(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700440 '''
441 Runs ./start-rest.sh stop to stop ONOS rest server
442 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700443 try:
444 response = self.execute(cmd= self.home + "/start-rest.sh stop ",prompt="killing",timeout=10)
445 self.execute(cmd="\n",prompt="\$",timeout=10)
446 if re.search("killing", response):
447 main.log.info(self.name + ": Rest Server Stopped")
448 return main.TRUE
449 else :
450 main.log.error(self.name + ": Failed to Stop, Rest Server is not Running")
451 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700452 except pexpect.EOF:
453 main.log.error(self.name + ": EOF exception found")
454 main.log.error(self.name + ": " + self.handle.before)
455 main.cleanup()
456 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700457 except:
458 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
459 main.log.error( traceback.print_exc() )
460 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
461 main.cleanup()
462 main.exit()
463
464
admin680b78c2014-08-08 11:46:45 -0700465 def kill(self):
466 import re
467 try:
468 self.handle.sendline("ps -ef |grep 'ONOS/conf/logback' |awk 'NR==1 {print $2}' |xargs sudo kill -9")
469 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
470 self.handle.sendline("ps -ef |grep 'ONOS/conf/logback' |wc -l")
471 self.handle.expect(["wc -l",pexpect.EOF,pexpect.TIMEOUT])
472 response = self.handle.after
473 if re.search("1",response):
474 return "ONOS Killed!"
475 else:
476 return "ERROR!!! ONOS MAY NOT HAVE BEEN KILLED PROPERLY!!!"
477 except pexpect.EOF:
478 main.log.error(self.name + ": EOF exception found")
479 main.log.error(self.hane + ": " + self.handle.before)
480 main.cleanup()
481 main.exit()
482 except:
483 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
484 main.log.error( traceback.print_exc() )
485 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
486 main.cleanup()
487 main.exit()
488
489
490
adminbae64d82013-08-01 10:50:15 -0700491 def disconnect(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700492 '''
493 Called when Test is complete to disconnect the ONOS handle.
494 '''
adminaeedddd2013-08-02 15:14:15 -0700495 response = ''
496 try:
adminbae64d82013-08-01 10:50:15 -0700497 self.handle.sendline("exit")
adminaeedddd2013-08-02 15:14:15 -0700498 self.handle.expect("closed")
Jon Hallae05dc22014-04-16 10:56:28 -0700499 except pexpect.EOF:
500 main.log.error(self.name + ": EOF exception found")
501 main.log.error(self.name + ": " + self.handle.before)
James Leec9cacaf2014-04-08 09:17:39 -0700502 except:
Jon Hallf89c8552014-04-02 13:14:06 -0700503 main.log.error(self.name + ": Connection failed to the host")
adminbae64d82013-08-01 10:50:15 -0700504 response = main.FALSE
adminaeedddd2013-08-02 15:14:15 -0700505 return response
506
Jon Hall76f2c462014-04-17 11:37:15 -0700507 def print_version(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700508 '''
509 Writes the COMMIT number to the report to be parsed by Jenkins data collecter.
510 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700511 try:
512 self.handle.sendline("export TERM=xterm-256color")
513 self.handle.expect("xterm-256color")
James Leec9cacaf2014-04-08 09:17:39 -0700514 self.handle.expect("\$")
Jon Hall09944cd2014-06-25 11:28:43 -0700515 self.handle.sendline("cd " + self.home + "; git log -1 --pretty=fuller | grep -A 5 \"commit\" --color=never; cd \.\.")
Jon Hallf89c8552014-04-02 13:14:06 -0700516 self.handle.expect("cd ..")
517 self.handle.expect("\$")
admine0eeea22014-04-14 10:22:46 -0700518 response=(self.name +": \n"+ str(self.handle.before + self.handle.after))
519 main.log.report(response)
Jon Hall76f2c462014-04-17 11:37:15 -0700520 except pexpect.EOF:
521 main.log.error(self.name + ": EOF exception found")
522 main.log.error(self.name + ": " + self.handle.before)
523 main.cleanup()
524 main.exit()
525 except:
526 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
527 main.log.error( traceback.print_exc() )
528 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
529 main.cleanup()
530 def get_version(self):
531 '''
532 Writes the COMMIT number to the report to be parsed by Jenkins data collecter.
533 '''
534 try:
535 self.handle.sendline("export TERM=xterm-256color")
536 self.handle.expect("xterm-256color")
537 self.handle.expect("\$")
Jon Hall09944cd2014-06-25 11:28:43 -0700538 self.handle.sendline("cd " + self.home + "; git log -1 --pretty=fuller | grep -A 5 \"commit\" --color=never; cd \.\.")
Jon Hall76f2c462014-04-17 11:37:15 -0700539 self.handle.expect("cd ..")
540 self.handle.expect("\$")
541 response=(self.name +": \n"+ str(self.handle.before + self.handle.after))
admine0eeea22014-04-14 10:22:46 -0700542 lines=response.splitlines()
543 for line in lines:
544 print line
545 return lines[2]
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
admin2a9548d2014-06-17 14:08:07 -0700558
admindc1c5072014-06-24 15:57:19 -0700559
560#*********************************************************************
561#*********************************************************************
562# shortest_path is a command to find the shortest path between two
563# switches. It is called using the IP, port, and source and
564# destination dpids
565#*********************************************************************
566#*********************************************************************
567
568 def shortest_path(self,ONOSIP,ONOSPort,srcDPID,dstDPID):
569 main.log.report("Finding the shortest Path between "+str(srcDPID) + " to " + str(dstDPID))
570 url = "http://%s:%s/wm/onos/intent/path/switch/%s/shortest-path/%s"%(ONOSIP,ONOSPort,srcDPID,dstDPID)
571 parsed_result = []
572 try:
573 response = urllib2.urlopen(url)
574 result = response.read()
575 response.close()
576 if len(result) != 0:
577 parsed_result = json.loads(result)
578 except HTTPError as exc:
579 print "ERROR:"
580 print " REST GET URL: %s" % url
581 # NOTE: exc.fp contains the object with the response payload
582 error_payload = json.loads(exc.fp.read())
583 print " REST Error Code: %s" % (error_payload['code'])
584 print " REST Error Summary: %s" % (error_payload['summary'])
585 print " REST Error Description: %s" % (error_payload['formattedDescription'])
586 print " HTTP Error Code: %s" % exc.code
587 print " HTTP Error Reason: %s" % exc.reason
588 except URLError as exc:
589 print "ERROR:"
590 print " REST GET URL: %s" % url
591 print " URL Error Reason: %s" % exc.reason
592
593 if len(parsed_result)==0:
594 return
595 result = json.dumps(parsed_result,indent=4)
596 print(str(result))
597 return result
598
599
600#*********************************************************************
601#*********************************************************************
602# show_intent is a command to show intents.
603# Parameters include intentIP, intentPort, intentURL, and intent_id
604# Based on the url, it will show either high or low intents
605# If intent_id is left blank, it will show all high or all low intents
606# Else it will show the intent with the id
607#*********************************************************************
608#*********************************************************************
609
610
611
612 def show_intent(self,intentIP,intentPort=8080,intentURL="wm/onos/intent",intent_type="high",intent_id="all"):
613 main.log.report("Getting (an) intent(s)")
614 if intent_id=="all":
615 url = "http://%s:%s/%s/%s"%(intentIP,intentPort,intentURL,intent_type)
616 else:
617 url = "http://%s:%s/%s/%s/%s"%(intentIP,intentPort,intentURL,intent_type,intent_id)
618 print(url)
619 parsed_result = []
620 try:
621 response = urllib2.urlopen(url)
622 result = response.read()
623 response.close()
624 if len(result) != 0:
625 parsed_result = json.loads(result)
626 except HTTPError as exc:
627 print "ERROR:"
628 print " REST GET URL: %s" % url
629 # NOTE: exc.fp contains the object with the response payload
630 error_payload = json.loads(exc.fp.read())
631 print " REST Error Code: %s" % (error_payload['code'])
632 print " REST Error Summary: %s" % (error_payload['summary'])
633 print " REST Error Description: %s" % (error_payload['formattedDescription'])
634 print " HTTP Error Code: %s" % exc.code
635 print " HTTP Error Reason: %s" % exc.reason
636 return str(error_payload['code'])
637 except URLError as exc:
638 print "ERROR:"
639 print " REST GET URL: %s" % url
640 print " URL Error Reason: %s" % exc.reason
641 return str(error_payload['code'])
642
643 if len(parsed_result)==0:
644 return
645 result = json.dumps(parsed_result,indent=4)
646 print(str(result))
647 return result
648
649
650#*********************************************************************
651#*********************************************************************
652# del_intent is to delete either all or some or one intents
653# if intent_id is left blank, it will delete all intents
654# else, intent_id should be of the form "intent_id=1,2,3"
655#*********************************************************************
656#*********************************************************************
657
658 def del_intent(self,intentIP,intentPort=8080,intentURL="wm/onos/intent",intent_id="all"):
659 main.log.report("Deleting (an) intent(s)")
660 if intent_id=="all":
661 url = "http://%s:%s/%s/high"%(intentIP,intentPort,intentURL)
662 else:
663 url = "http://%s:%s/%s/high?%s"%(intentIP,intentPort,intentURL,intent_id)
664
665 print(url)
666
667 parsed_result = []
668 try:
669 request = urllib2.Request(url)
670 request.get_method = lambda: 'DELETE'
671 response = urllib2.urlopen(request)
672 result = response.read()
673 response.close()
674 if len(result) != 0:
675 parsed_result = json.loads(result)
676 print(parsed_result)
677 except HTTPError as exc:
678 print "ERROR:"
679 print " REST DELETE URL: %s" % url
680 # NOTE: exc.fp contains the object with the response payload
681 error_payload = json.loads(exc.fp.read())
682 print " REST Error Code: %s" % (error_payload['code'])
683 print " REST Error Summary: %s" % (error_payload['summary'])
684 print " REST Error Description: %s" % (error_payload['formattedDescription'])
685 print " HTTP Error Code: %s" % exc.code
686 print " HTTP Error Reason: %s" % exc.reason
687 except URLError as exc:
688 print "ERROR:"
689 print " REST DELETE URL: %s" % url
690 print " URL Error Reason: %s" % exc.reason
691 return result
692
693#*********************************************************************
694#*********************************************************************
695# add_intent will add a single intent by using dpids and macs.
696#*********************************************************************
697#*********************************************************************
698
699
700 def add_intent(self, intent_id,src_dpid,dst_dpid,src_mac,dst_mac,intentIP,intentPort=8080,intentURL="wm/onos/intent" , intent_type = 'SHORTEST_PATH', static_path=False, src_port=1,dst_port=1):
admin2a9548d2014-06-17 14:08:07 -0700701 "CLI command callback: set intent"
702
703 intents = []
704 oper = {}
705 # Create the POST payload
706 oper['intentId'] = intent_id
707 oper['intentType'] = intent_type # XXX: Hardcoded
708 oper['staticPath'] = static_path # XXX: Hardcoded
709 oper['srcSwitchDpid'] = src_dpid
710 oper['srcSwitchPort'] = src_port
711 oper['dstSwitchDpid'] = dst_dpid
712 oper['dstSwitchPort'] = dst_port
713 oper['matchSrcMac'] = src_mac
714 oper['matchDstMac'] = dst_mac
715 intents.append(oper)
admindc1c5072014-06-24 15:57:19 -0700716 url = "http://%s:%s/%s/high"%(intentIP,intentPort,intentURL)
admin2a9548d2014-06-17 14:08:07 -0700717 parsed_result = []
718 data_json = json.dumps(intents)
Jon Hall43d1e962014-08-08 11:51:24 -0700719 result = main.FALSE
admin2a9548d2014-06-17 14:08:07 -0700720 try:
721 request = urllib2.Request(url,data_json)
722 request.add_header("Content-Type", "application/json")
723 response=urllib2.urlopen(request)
724 result = response.read()
725 response.close()
726 if len(result) != 0:
727 parsed_result = json.loads(result)
728 except HTTPError as exc:
729 print "ERROR:"
730 print " REST GET URL: %s" % url
731 # NOTE: exc.fp contains the object with the response payload
732 error_payload = json.loads(exc.fp.read())
733 print " REST Error Code: %s" % (error_payload['code'])
734 print " REST Error Summary: %s" % (error_payload['summary'])
735 print " REST Error Description: %s" % (error_payload['formattedDescription'])
736 print " HTTP Error Code: %s" % exc.code
737 print " HTTP Error Reason: %s" % exc.reason
Jon Hall43d1e962014-08-08 11:51:24 -0700738 return " HTTP Error Code: %s, Reason: %s" % exc.code, exc.reason
admin2a9548d2014-06-17 14:08:07 -0700739 except URLError as exc:
740 print "ERROR:"
741 print " REST GET URL: %s" % url
742 print " URL Error Reason: %s" % exc.reason
Jon Hall43d1e962014-08-08 11:51:24 -0700743 return " HTTP Error Reason: %s" % exc.reason
admindc1c5072014-06-24 15:57:19 -0700744 return result
admin2a9548d2014-06-17 14:08:07 -0700745
746
747
748
749 def add_intents(self):
750 main.log.info("Sending new intents to ONOS")
adminc6cfc1c2014-04-21 13:55:21 -0700751 self.handle.sendline("cd "+self.home+ "/scripts")
752 self.handle.expect("scripts")
admin2a9548d2014-06-17 14:08:07 -0700753 main.log.info("Adding intents")
adminc6cfc1c2014-04-21 13:55:21 -0700754 self.handle.sendline("./pyintents.py")
Jon Hall9c6e2c02014-05-02 10:18:53 -0700755 self.handle.expect(["$",pexpect.EOF,pexpect.TIMEOUT])
756 response = self.handle.before
adminc6cfc1c2014-04-21 13:55:21 -0700757 self.handle.sendline("cd "+self.home)
758 return main.TRUE
759
admin2a9548d2014-06-17 14:08:07 -0700760 def rm_intents(self):
761 main.log.info("Deleteing Intents from ONOS")
adminc6cfc1c2014-04-21 13:55:21 -0700762 self.handle.sendline("cd "+self.home+ "/scripts")
763 self.handle.expect("scripts")
admin2a9548d2014-06-17 14:08:07 -0700764 main.log.info("Deleting Intnents")
adminc6cfc1c2014-04-21 13:55:21 -0700765 self.handle.sendline("./rmpyintents.py")
Jon Hall9c6e2c02014-05-02 10:18:53 -0700766 self.handle.expect(["$",pexpect.EOF,pexpect.TIMEOUT])
767 response = self.handle.before
adminc6cfc1c2014-04-21 13:55:21 -0700768 self.handle.sendline("cd "+self.home)
769 return main.TRUE
770
admin2a9548d2014-06-17 14:08:07 -0700771 def purge_intents(self):
Jon Hall265149f2014-04-25 13:39:52 -0700772 main.log.info("Purging dead intents")
773 self.handle.sendline("cd "+self.home+ "/scripts")
774 self.handle.expect("scripts")
admin2a9548d2014-06-17 14:08:07 -0700775 main.log.info("Sending Purge Intent Rest call to ONOS")
Jon Hall265149f2014-04-25 13:39:52 -0700776 self.handle.sendline("./purgeintents.py")
777 self.handle.sendline("cd "+self.home)
778 return main.TRUE
adminc6cfc1c2014-04-21 13:55:21 -0700779
780
781
Jon Hall4a2b0482014-04-18 16:29:26 -0700782 def add_flow(self, testONip, user = "admin", password = "", flowDef = "/flowdef.txt"):
Jon Halld8dc5772014-04-08 16:26:29 -0700783 '''
784 Copies the flowdef file from TestStation -> ONOS machine
785 Then runs ./add_flow.py to add the flows to ONOS
786 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700787 try:
788 main.log.info("Adding Flows...")
789 self.handle.sendline("scp %s@%s:%s /tmp/flowtmp" %(user,testONip,flowDef))
790 i=self.handle.expect(['[pP]assword:', '100%', pexpect.TIMEOUT],30)
791 if(i==0):
792 self.handle.sendline("%s" %(password))
793 self.handle.sendline("")
794 self.handle.expect("100%")
795 self.handle.expect("\$", 30)
796 self.handle.sendline(self.home + "/web/add_flow.py -m onos -f /tmp/flowtmp")
797 self.handle.expect("\$", 1000)
798 main.log.info("Flows added")
799 return main.TRUE
800
801 elif(i==1):
802 self.handle.sendline("")
803 self.handle.expect("\$", 10)
804 self.handle.sendline( self.home + "/web/add_flow.py -m onos -f /tmp/flowtmp")
805 self.handle.expect("\$", 1000)
806 main.log.info("Flows added")
807 return main.TRUE
808
809 elif(i==2):
810 main.log.error("Flow Def file SCP Timed out...")
811 return main.FALSE
812
813 else:
814 main.log.error("Failed to add flows...")
James Leec9cacaf2014-04-08 09:17:39 -0700815 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700816 except pexpect.EOF:
817 main.log.error(self.name + ": EOF exception found")
818 main.log.error(self.name + ": " + self.handle.before)
819 main.cleanup()
820 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700821 except:
822 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
823 main.log.error( traceback.print_exc() )
824 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
825 main.cleanup()
826 main.exit()
827
adminbae64d82013-08-01 10:50:15 -0700828
829 def delete_flow(self, *delParams):
Jon Halld8dc5772014-04-08 16:26:29 -0700830 '''
831 Deletes a specific flow, a range of flows, or all flows.
832 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700833 try:
834 if len(delParams)==1:
835 if str(delParams[0])=="all":
836 main.log.info(self.name + ": Deleting ALL flows...")
837 #self.execute(cmd="~/ONOS/scripts/TestON_delete_flow.sh all",prompt="done",timeout=150)
838 self.handle.sendline(self.home + "/web/delete_flow.py all")
839 self.handle.expect("delete_flow")
840 self.handle.expect("\$",1000)
841 main.log.info(self.name + ": Flows deleted")
842 else:
843 main.log.info(self.name + ": Deleting flow "+str(delParams[0])+"...")
844 #self.execute(cmd="~/ONOS/scripts/TestON_delete_flow.sh "+str(delParams[0]),prompt="done",timeout=150)
845 #self.execute(cmd="\n",prompt="\$",timeout=60)
846 self.handle.sendline(self.home +"/web/delete_flow.py %d" % int(delParams[0]))
847 self.handle.expect("delete_flow")
848 self.handle.expect("\$",60)
849 main.log.info(self.name + ": Flow deleted")
850 elif len(delParams)==2:
851 main.log.info(self.name + ": Deleting flows "+str(delParams[0])+" through "+str(delParams[1])+"...")
852 #self.execute(cmd="~/ONOS/scripts/TestON_delete_flow.sh "+str(delParams[0])+" "+str(delParams[1]),prompt="done",timeout=150)
853 #self.execute(cmd="\n",prompt="\$",timeout=60)
854 self.handle.sendline(self.home + "/web/delete_flow.py %d %d" % (int(delParams[0]), int(delParams[1])))
855 self.handle.expect("delete_flow")
856 self.handle.expect("\$",600)
857 main.log.info(self.name + ": Flows deleted")
Jon Hallae05dc22014-04-16 10:56:28 -0700858 except pexpect.EOF:
859 main.log.error(self.name + ": EOF exception found")
860 main.log.error(self.name + ": " + self.handle.before)
861 main.cleanup()
862 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700863 except:
864 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
865 main.log.error( traceback.print_exc() )
866 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
867 main.cleanup()
868 main.exit()
adminbae64d82013-08-01 10:50:15 -0700869
870 def check_flow(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700871 '''
872 Calls the ./get_flow.py all and checks:
873 - If each FlowPath has at least one FlowEntry
874 - That there are no "NOT"s found
875 returns TRUE/FALSE
876 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700877 try:
878 flowEntryDetect = 1
879 count = 0
880 self.handle.sendline("clear")
881 time.sleep(1)
882 self.handle.sendline(self.home + "/web/get_flow.py all")
883 self.handle.expect("get_flow")
Jon Hall3bd7c792014-05-30 09:05:21 -0700884 for x in range(15):
Jon Hallf89c8552014-04-02 13:14:06 -0700885 i=self.handle.expect(['FlowPath','FlowEntry','NOT','\$',pexpect.TIMEOUT],timeout=180)
886 if i==0:
887 count = count + 1
888 if flowEntryDetect == 0:
889 main.log.info(self.name + ": FlowPath without FlowEntry")
890 return main.FALSE
891 else:
892 flowEntryDetect = 0
893 elif i==1:
894 flowEntryDetect = 1
895 elif i==2:
896 main.log.error(self.name + ": Found a NOT")
adminbae64d82013-08-01 10:50:15 -0700897 return main.FALSE
Jon Hallf89c8552014-04-02 13:14:06 -0700898 elif i==3:
899 if count == 0:
900 main.log.info(self.name + ": There don't seem to be any flows here...")
901 return main.FALSE
902 else:
903 main.log.info(self.name + ": All flows pass")
904 main.log.info(self.name + ": Number of FlowPaths: "+str(count))
905 return main.TRUE
906 elif i==4:
James Leec9cacaf2014-04-08 09:17:39 -0700907 main.log.error(self.name + ":Check_flow() - Command Timeout!")
Jon Hallf89c8552014-04-02 13:14:06 -0700908 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700909 except pexpect.EOF:
910 main.log.error(self.name + ": EOF exception found")
911 main.log.error(self.name + ": " + self.handle.before)
912 main.cleanup()
913 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700914 except:
915 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
916 main.log.error( traceback.print_exc() )
917 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
918 main.cleanup()
919 main.exit()
adminbae64d82013-08-01 10:50:15 -0700920
921 def get_flow(self, *flowParams):
Jon Halld8dc5772014-04-08 16:26:29 -0700922 '''
923 Returns verbose output of ./get_flow.py
924 '''
925 try:
926 if len(flowParams)==1:
927 if str(flowParams[0])=="all":
928 self.execute(cmd="\n",prompt="\$",timeout=60)
929 main.log.info(self.name + ": Getting all flow data...")
930 data = self.execute(cmd=self.home + "/scripts/TestON_get_flow.sh all",prompt="done",timeout=150)
931 self.execute(cmd="\n",prompt="\$",timeout=60)
932 return data
933 else:
934 main.log.info(self.name + ": Retrieving flow "+str(flowParams[0])+" data...")
935 data = self.execute(cmd=self.home +"/scripts/TestON_get_flow.sh "+str(flowParams[0]),prompt="done",timeout=150)
936 self.execute(cmd="\n",prompt="\$",timeout=60)
937 return data
938 elif len(flowParams)==5:
939 main.log.info(self.name + ": Retrieving flow installer data...")
940 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)
941 self.execute(cmd="\n",prompt="\$",timeout=60)
942 return data
943 elif len(flowParams)==4:
944 main.log.info(self.name + ": Retrieving flow endpoints...")
945 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)
946 self.execute(cmd="\n",prompt="\$",timeout=60)
947 return data
Jon Hallae05dc22014-04-16 10:56:28 -0700948 except pexpect.EOF:
949 main.log.error(self.name + ": EOF exception found")
950 main.log.error(self.name + ": " + self.handle.before)
951 main.cleanup()
952 main.exit()
Jon Halld8dc5772014-04-08 16:26:29 -0700953 except:
Jon Hallf89c8552014-04-02 13:14:06 -0700954 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
955 main.log.error( traceback.print_exc() )
956 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
957 main.cleanup()
958 main.exit()
adminbae64d82013-08-01 10:50:15 -0700959
960
Jon Hall2f42a672014-05-28 10:13:18 -0700961# http://localhost:8080/wm/onos/topology/switches
962# http://localhost:8080/wm/onos/topology/links
Jon Hall8060af02014-04-14 14:17:58 -0700963# http://localhost:8080/wm/onos/registry/controllers/json
964# http://localhost:8080/wm/onos/registry/switches/json"
adminbae64d82013-08-01 10:50:15 -0700965
966 def get_json(self, url):
Jon Halld8dc5772014-04-08 16:26:29 -0700967 '''
968 Helper functions used to parse the json output of a rest call
969 '''
adminbae64d82013-08-01 10:50:15 -0700970 try:
Jon Hallf89c8552014-04-02 13:14:06 -0700971 try:
972 command = "curl -s %s" % (url)
973 result = os.popen(command).read()
974 parsedResult = json.loads(result)
975 except:
976 print "REST IF %s has issue" % command
977 parsedResult = ""
978
979 if type(parsedResult) == 'dict' and parsedResult.has_key('code'):
980 print "REST %s returned code %s" % (command, parsedResult['code'])
981 parsedResult = ""
James Leec9cacaf2014-04-08 09:17:39 -0700982 return parsedResult
Jon Hallae05dc22014-04-16 10:56:28 -0700983 except pexpect.EOF:
984 main.log.error(self.name + ": EOF exception found")
985 main.log.error(self.name + ": " + self.handle.before)
986 main.cleanup()
987 main.exit()
adminbae64d82013-08-01 10:50:15 -0700988 except:
Jon Hallf89c8552014-04-02 13:14:06 -0700989 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
990 main.log.error( traceback.print_exc() )
991 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
992 main.cleanup()
993 main.exit()
adminbae64d82013-08-01 10:50:15 -0700994
admin680b78c2014-08-08 11:46:45 -0700995 def num_switch(self,RestIP,RestPort="8080"):
996 url = "http://%s:%s/wm/onos/topology/switches" %(RestIP,RestPort)
997 parsedResult = self.get_json(url)
998 if parsedResult == "":
999 retcode = 1
1000 return (retcode, "RestAPI has an issue")
1001 url = "http://%s:%s/wm/onos/registry/switches/json" %(RestIP,RestPort)
1002 registry = self.get_json(url)
1003 if registry == "":
1004 retcode = 1
1005 return (retcode, "REST API has an Issue")
1006 cnt = 0
1007 active = 0
1008 for s in parsedResult:
1009 cnt +=1
1010 if s['state']=="ACTIVE":
1011 active+=1
1012 return (cnt,active)
1013
1014
Jon Hallf89c8552014-04-02 13:14:06 -07001015 def check_switch(self,RestIP,correct_nr_switch, RestPort ="8080" ):
Jon Halld8dc5772014-04-08 16:26:29 -07001016 '''
1017 Used by check_status
1018 '''
Jon Hallf89c8552014-04-02 13:14:06 -07001019 try:
1020 buf = ""
1021 retcode = 0
admin2e131ab2014-05-28 10:03:42 -07001022 url="http://%s:%s/wm/onos/topology/switches" % (RestIP, RestPort)
Jon Hallf89c8552014-04-02 13:14:06 -07001023 parsedResult = self.get_json(url)
1024 if parsedResult == "":
1025 retcode = 1
1026 return (retcode, "Rest API has an issue")
1027 url = "http://%s:%s/wm/onos/registry/switches/json" % (RestIP, RestPort)
1028 registry = self.get_json(url)
1029
1030 if registry == "":
1031 retcode = 1
1032 return (retcode, "Rest API has an issue")
1033
1034 cnt = 0
1035 active = 0
adminbae64d82013-08-01 10:50:15 -07001036
Jon Hallf89c8552014-04-02 13:14:06 -07001037 for s in parsedResult:
1038 cnt += 1
James Leec9cacaf2014-04-08 09:17:39 -07001039 if s['state'] == "ACTIVE":
Jon Hallf89c8552014-04-02 13:14:06 -07001040 active += 1
adminbae64d82013-08-01 10:50:15 -07001041
Jon Hallf89c8552014-04-02 13:14:06 -07001042 buf += "switch: network %d : %d switches %d active\n" % (0+1, cnt, active)
1043 if correct_nr_switch != cnt:
1044 buf += "switch fail: network %d should have %d switches but has %d\n" % (1, correct_nr_switch, cnt)
1045 retcode = 1
adminbae64d82013-08-01 10:50:15 -07001046
Jon Hallf89c8552014-04-02 13:14:06 -07001047 if correct_nr_switch != active:
1048 buf += "switch fail: network %d should have %d active switches but has %d\n" % (1, correct_nr_switch, active)
1049 retcode = 1
1050
1051 return (retcode, buf)
Jon Hallae05dc22014-04-16 10:56:28 -07001052 except pexpect.EOF:
1053 main.log.error(self.name + ": EOF exception found")
1054 main.log.error(self.name + ": " + self.handle.before)
1055 main.cleanup()
1056 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -07001057 except:
1058 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1059 main.log.error( traceback.print_exc() )
1060 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1061 main.cleanup()
1062 main.exit()
adminbae64d82013-08-01 10:50:15 -07001063
admin680b78c2014-08-08 11:46:45 -07001064 def num_link(self,RestIP,RestPort="8080"):
1065 url = "http://%s:%s/wm/onos/topology/links" % (RestIP,RestPort)
1066 parsedResult = self.get_json(url)
1067 if parsedResult == "":
1068 retcode = 1
1069 return (retcode,"RestAPI has an issue")
1070 intra = 0
1071 for s in parsedResult:
1072 intra+=1
1073 return intra
1074
Jon Hallf89c8552014-04-02 13:14:06 -07001075 def check_link(self,RestIP, nr_links, RestPort = "8080"):
Jon Halld8dc5772014-04-08 16:26:29 -07001076 '''
1077 Used by check_status
1078 '''
Jon Hallf89c8552014-04-02 13:14:06 -07001079 try:
1080 buf = ""
1081 retcode = 0
1082
admin2e131ab2014-05-28 10:03:42 -07001083 url = "http://%s:%s/wm/onos/topology/links" % (RestIP, RestPort)
Jon Hallf89c8552014-04-02 13:14:06 -07001084 parsedResult = self.get_json(url)
1085
1086 if parsedResult == "":
1087 retcode = 1
1088 return (retcode, "Rest API has an issue")
1089
1090 buf += "link: total %d links (correct : %d)\n" % (len(parsedResult), nr_links)
1091 intra = 0
1092 interlink=0
1093
1094 for s in parsedResult:
James Leec9cacaf2014-04-08 09:17:39 -07001095 intra = intra + 1
Jon Hallf89c8552014-04-02 13:14:06 -07001096
1097 if intra != nr_links:
1098 buf += "link fail\n"
1099 retcode = 1
1100
1101 return (retcode, buf)
Jon Hallae05dc22014-04-16 10:56:28 -07001102 except pexpect.EOF:
1103 main.log.error(self.name + ": EOF exception found")
1104 main.log.error(self.name + ": " + self.handle.before)
1105 main.cleanup()
1106 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -07001107 except:
1108 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1109 main.log.error( traceback.print_exc() )
1110 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1111 main.cleanup()
1112 main.exit()
adminbae64d82013-08-01 10:50:15 -07001113
Jon Hallf89c8552014-04-02 13:14:06 -07001114 def check_status_report(self, ip, numoswitch, numolink, port="8080"):
Jon Halld8dc5772014-04-08 16:26:29 -07001115 '''
1116 Checks the number of swithes & links that ONOS sees against the supplied values.
1117 Writes to the report log.
1118 '''
Jon Hallf89c8552014-04-02 13:14:06 -07001119 try:
James Leec9cacaf2014-04-08 09:17:39 -07001120 main.log.info(self.name + ": Making some rest calls...")
Jon Hallf89c8552014-04-02 13:14:06 -07001121 switch = self.check_switch(ip, int(numoswitch), port)
1122 link = self.check_link(ip, int(numolink), port)
1123 value = switch[0]
1124 value += link[0]
1125 main.log.report( self.name + ": \n-----\n%s%s-----\n" % ( switch[1], link[1]) )
1126 if value != 0:
1127 return main.FALSE
James Leec9cacaf2014-04-08 09:17:39 -07001128 else:
Jon Hallf89c8552014-04-02 13:14:06 -07001129 # "PASS"
1130 return main.TRUE
Jon Hallae05dc22014-04-16 10:56:28 -07001131 except pexpect.EOF:
1132 main.log.error(self.name + ": EOF exception found")
1133 main.log.error(self.name + ": " + self.handle.before)
1134 main.cleanup()
1135 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -07001136 except:
1137 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1138 main.log.error( traceback.print_exc() )
1139 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1140 main.cleanup()
1141 main.exit()
adminbae64d82013-08-01 10:50:15 -07001142
Jon Hallf89c8552014-04-02 13:14:06 -07001143 def check_status(self, ip, numoswitch, numolink, port = "8080"):
Jon Halld8dc5772014-04-08 16:26:29 -07001144 '''
1145 Checks the number of swithes & links that ONOS sees against the supplied values.
1146 Writes to the main log.
1147 '''
Jon Hallf89c8552014-04-02 13:14:06 -07001148 try:
James Leec9cacaf2014-04-08 09:17:39 -07001149 main.log.info(self.name + ": Making some rest calls...")
Jon Hallf89c8552014-04-02 13:14:06 -07001150 switch = self.check_switch(ip, int(numoswitch), port)
1151 link = self.check_link(ip, int(numolink), port)
1152 value = switch[0]
1153 value += link[0]
1154 main.log.info(self.name + ": \n-----\n%s%s-----\n" % ( switch[1], link[1]) )
1155 if value != 0:
1156 return main.FALSE
James Leec9cacaf2014-04-08 09:17:39 -07001157 else:
Jon Hallf89c8552014-04-02 13:14:06 -07001158 # "PASS"
1159 return main.TRUE
Jon Hallae05dc22014-04-16 10:56:28 -07001160 except pexpect.EOF:
1161 main.log.error(self.name + ": EOF exception found")
1162 main.log.error(self.name + ": " + self.handle.before)
1163 main.cleanup()
1164 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -07001165 except:
1166 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1167 main.log.error( traceback.print_exc() )
1168 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1169 main.cleanup()
1170 main.exit()
adminbae64d82013-08-01 10:50:15 -07001171
Jon Hallf89c8552014-04-02 13:14:06 -07001172
admine0eeea22014-04-14 10:22:46 -07001173 def git_pull(self, comp1=""):
Jon Halld8dc5772014-04-08 16:26:29 -07001174 '''
Jon Halld8dc5772014-04-08 16:26:29 -07001175 Assumes that "git pull" works without login
admine0eeea22014-04-14 10:22:46 -07001176
1177 This function will perform a git pull on the ONOS instance.
1178 If used as git_pull("NODE") it will do git pull + NODE. This is
1179 for the purpose of pulling from other nodes if necessary.
1180
1181 Otherwise, this function will perform a git pull in the
1182 ONOS repository. If it has any problems, it will return main.ERROR
1183 If it successfully does a git_pull, it will return a 1.
1184 If it has no updates, it will return a 0.
1185
Jon Halld8dc5772014-04-08 16:26:29 -07001186 '''
Jon Hallae05dc22014-04-16 10:56:28 -07001187 try:
Jon Halle80ef8c2014-04-29 15:29:13 -07001188 # main.log.info(self.name + ": Stopping ONOS")
1189 #self.stop()
Jon Hallae05dc22014-04-16 10:56:28 -07001190 self.handle.sendline("cd " + self.home)
1191 self.handle.expect("ONOS\$")
1192 if comp1=="":
1193 self.handle.sendline("git pull")
1194 else:
1195 self.handle.sendline("git pull " + comp1)
1196
1197 uptodate = 0
Jon Hall7dae6cf2014-09-11 15:09:48 -07001198 i=self.handle.expect(['fatal',
1199 'Username\sfor\s(.*):\s',
1200 '\sfile(s*) changed,\s',
1201 'Already up-to-date',
1202 'Aborting',
1203 'You\sare\snot\scurrently\son\sa\sbranch',
1204 'You\sasked\sme\sto\spull\swithout\stelling\sme\swhich\sbranch\syou',
1205 'Pull\sis\snot\spossible\sbecause\syou\shave\sunmerged\sfiles',
1206 pexpect.TIMEOUT],
1207 timeout=300)
Jon Hallae05dc22014-04-16 10:56:28 -07001208 #debug
1209 #main.log.report(self.name +": \n"+"git pull response: " + str(self.handle.before) + str(self.handle.after))
1210 if i==0:
1211 main.log.error(self.name + ": Git pull had some issue...")
1212 return main.ERROR
1213 elif i==1:
Jon Hall7dae6cf2014-09-11 15:09:48 -07001214 main.log.error(self.name + ": Git Pull Asking for username. ")
Jon Hallae05dc22014-04-16 10:56:28 -07001215 return main.ERROR
1216 elif i==2:
1217 main.log.info(self.name + ": Git Pull - pulling repository now")
1218 self.handle.expect("ONOS\$", 120)
1219 return 0
1220 elif i==3:
Jon Hallae05dc22014-04-16 10:56:28 -07001221 main.log.info(self.name + ": Git Pull - Already up to date")
1222 return 1
Jon Hall7dae6cf2014-09-11 15:09:48 -07001223 elif i==4:
Jon Hallae05dc22014-04-16 10:56:28 -07001224 main.log.info(self.name + ": Git Pull - Aborting... Are there conflicting git files?")
1225 return main.ERROR
Jon Hall7dae6cf2014-09-11 15:09:48 -07001226 elif i==5:
Jon Hall5a8aac62014-06-03 09:30:21 -07001227 main.log.info(self.name + ": Git Pull - You are not currently on a branch so git pull failed!")
1228 return main.ERROR
Jon Hall7dae6cf2014-09-11 15:09:48 -07001229 elif i==6:
Jon Hall847cfad2014-09-03 14:10:08 -07001230 main.log.info(self.name + ": Git Pull - You have not configured an upstream branch to pull from. Git pull failed!")
1231 return main.ERROR
Jon Hall7dae6cf2014-09-11 15:09:48 -07001232 elif i==7:
1233 main.log.info(self.name + ": Git Pull - Pull is not possible because you have unmerged files.")
1234 return main.ERROR
1235 elif i==8:
1236 main.log.error(self.name + ": Git Pull - TIMEOUT")
1237 main.log.error(self.name + " Response was: " + str(self.handle.before))
1238 return main.ERROR
Jon Hallae05dc22014-04-16 10:56:28 -07001239 else:
1240 main.log.error(self.name + ": Git Pull - Unexpected response, check for pull errors")
1241 return main.ERROR
1242 except pexpect.EOF:
1243 main.log.error(self.name + ": EOF exception found")
1244 main.log.error(self.name + ": " + self.handle.before)
1245 main.cleanup()
1246 main.exit()
1247 except:
1248 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1249 main.log.error( traceback.print_exc() )
1250 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1251 main.cleanup()
1252 main.exit()
admine0eeea22014-04-14 10:22:46 -07001253#********************************************************
1254
1255
admin680b78c2014-08-08 11:46:45 -07001256
1257
1258 def git_checkout(self, branch="onos13integration"):
1259 '''
1260 Assumes that "git pull" works without login
1261
1262 This function will perform a git pull on the ONOS instance.
1263 If used as git_pull("NODE") it will do git pull + NODE. This is
1264 for the purpose of pulling from other nodes if necessary.
1265
1266 Otherwise, this function will perform a git pull in the
1267 ONOS repository. If it has any problems, it will return main.ERROR
1268 If it successfully does a git_pull, it will return a 1.
1269 If it has no updates, it will return a 0.
1270
1271 '''
1272 try:
1273 # main.log.info(self.name + ": Stopping ONOS")
1274 #self.stop()
1275 self.handle.sendline("cd " + self.home)
1276 self.handle.expect("ONOS\$")
1277 if branch != 'master':
1278 #self.handle.sendline('git stash')
1279 #self.handle.expect('ONOS\$')
1280 #print "After issuing git stash cmnd: ", self.handle.before
1281 cmd = "git checkout "+branch
1282 print "checkout cmd = ", cmd
1283 self.handle.sendline(cmd)
1284 uptodate = 0
1285 i=self.handle.expect(['fatal','Username\sfor\s(.*):\s','Already\son\s\'onos13integration\'','Switched\sto\sbranch\s\'onos13integration\'', pexpect.TIMEOUT],timeout=60)
1286 else:
1287 #self.handle.sendline('git stash apply')
1288 #self.handle.expect('ONOS\$')
1289 #print "After issuing git stash apply cmnd: ", self.handle.before
1290 cmd = "git checkout "+branch
1291 print "checkout cmd = ", cmd
1292 self.handle.sendline(cmd)
1293 uptodate = 0
1294 switchedToMaster = 0
1295 i=self.handle.expect(['fatal','Username\sfor\s(.*):\s','Already\son\s\'master\'','Switched\sto\sbranch\s\'master\'', pexpect.TIMEOUT],timeout=60)
1296
1297
1298 if i==0:
1299 main.log.error(self.name + ": Git checkout had some issue...")
1300 return main.ERROR
1301 elif i==1:
1302 main.log.error(self.name + ": Git checkout Asking for username!!! BADD!")
1303 return main.ERROR
1304 elif i==2:
1305 main.log.info(self.name + ": Git Checkout %s : Already on this branch" %branch)
1306 self.handle.expect("ONOS\$")
1307 print "after checkout cmd = ", self.handle.before
1308 switchedToMaster = 1
1309 return 1
1310 elif i==3:
1311 main.log.info(self.name + ": Git checkout %s - Switched to this branch" %branch)
1312 self.handle.expect("ONOS\$")
1313 print "after checkout cmd = ", self.handle.before
1314 switchedToMaster = 1
1315 return 1
1316 elif i==4:
1317 main.log.error(self.name + ": Git Checkout- TIMEOUT")
1318 main.log.error(self.name + " Response was: " + str(self.handle.before))
1319 return main.ERROR
1320 else:
1321 main.log.error(self.name + ": Git Checkout - Unexpected response, check for pull errors")
1322 return main.ERROR
1323
1324 except pexpect.EOF:
1325 main.log.error(self.name + ": EOF exception found")
1326 main.log.error(self.name + ": " + self.handle.before)
1327 main.cleanup()
1328 main.exit()
1329 except:
1330 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1331 main.log.error( traceback.print_exc() )
1332 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1333 main.cleanup()
1334 main.exit()
1335#********************************************************
1336 self.handle.sendline("git branch")
1337 self.handle.expect("ONOS\$")
1338 print "git branch output = ", self.handle.before
1339 print "*****************************************"
1340 self.handle.sendline('cd\.\.')
1341 self.handle.expect("\$")
1342
1343
1344
1345
1346
1347
1348
1349
admin7373a812014-04-16 09:49:02 -07001350 def git_compile(self):
Jon Hallae05dc22014-04-16 10:56:28 -07001351 '''
1352 Compiles ONOS
1353 First runs mvn clean then mvn compile
1354 '''
1355 try:
1356 main.log.info(self.name + ": mvn clean")
admin8fc02822014-04-16 13:31:23 -07001357 self.handle.sendline("cd " + self.home)
Jon Hallae05dc22014-04-16 10:56:28 -07001358 self.handle.sendline("mvn clean")
1359 while 1:
Jon Hall1636f942014-04-17 10:07:23 -07001360 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 -07001361 if i == 0:
Jon Hall1636f942014-04-17 10:07:23 -07001362 main.log.error(self.name + ":There is insufficient memory for the Java Runtime Environment to continue.")
Jon Hallae05dc22014-04-16 10:56:28 -07001363 return main.FALSE
1364 elif i == 1:
Jon Hall1636f942014-04-17 10:07:23 -07001365 main.log.error(self.name + ": Clean failure!")
1366 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -07001367 elif i == 2:
Jon Hall1636f942014-04-17 10:07:23 -07001368 main.log.info(self.name + ": Clean success!")
1369 elif i == 3:
admin8fc02822014-04-16 13:31:23 -07001370 main.log.info(self.name + ": Clean complete")
Jon Hallae05dc22014-04-16 10:56:28 -07001371 break;
Jon Hall1636f942014-04-17 10:07:23 -07001372 elif i == 4:
Jon Hallae05dc22014-04-16 10:56:28 -07001373 main.log.error(self.name + ": mvn clean TIMEOUT!")
1374 return main.FALSE
Jon Hall1636f942014-04-17 10:07:23 -07001375 else:
1376 main.log.error(self.name + ": unexpected response from mvn clean")
1377 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -07001378
1379 main.log.info(self.name + ": mvn compile")
1380 self.handle.sendline("mvn compile")
1381 while 1:
Jon Hall1636f942014-04-17 10:07:23 -07001382 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 -07001383 if i == 0:
Jon Hall1636f942014-04-17 10:07:23 -07001384 main.log.error(self.name + ":There is insufficient memory for the Java Runtime Environment to continue.")
1385 return main.FALSE
1386 if i == 1:
Jon Hallae05dc22014-04-16 10:56:28 -07001387 main.log.error(self.name + ": Build failure!")
1388 return main.FALSE
Jon Hall1636f942014-04-17 10:07:23 -07001389 elif i == 2:
Jon Hallae05dc22014-04-16 10:56:28 -07001390 main.log.info(self.name + ": Build success!")
Jon Hall1636f942014-04-17 10:07:23 -07001391 elif i == 3:
Jon Hallae05dc22014-04-16 10:56:28 -07001392 main.log.info(self.name + ": Build complete")
Jon Hall010f5412014-05-21 15:10:12 -07001393 self.handle.expect("\$", timeout=60)
Jon Hallae05dc22014-04-16 10:56:28 -07001394 return main.TRUE
Jon Hall1636f942014-04-17 10:07:23 -07001395 elif i == 4:
Jon Hallae05dc22014-04-16 10:56:28 -07001396 main.log.error(self.name + ": mvn compile TIMEOUT!")
1397 return main.FALSE
1398 else:
Jon Hall1636f942014-04-17 10:07:23 -07001399 main.log.error(self.name + ": unexpected response from mvn compile")
1400 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -07001401 except pexpect.EOF:
1402 main.log.error(self.name + ": EOF exception found")
1403 main.log.error(self.name + ": " + self.handle.before)
1404 main.cleanup()
1405 main.exit()
1406 except:
1407 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1408 main.log.error( traceback.print_exc() )
1409 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1410 main.cleanup()
1411 main.exit()
admin4a58db92013-09-30 12:04:54 -07001412
Jon Hallf89c8552014-04-02 13:14:06 -07001413 def tcpdump(self, intf = "eth0"):
Jon Hallae05dc22014-04-16 10:56:28 -07001414 '''
1415 Runs tpdump on an intferface and saves in onos-logs under the ONOS home directory
1416 intf can be specified, or the default eth0 is used
1417 '''
Jon Hallf89c8552014-04-02 13:14:06 -07001418 try:
1419 self.handle.sendline("")
1420 self.handle.expect("\$")
Jon Hall26f316b2014-04-11 11:21:25 -07001421 self.handle.sendline("sudo tcpdump -n -i "+ intf + " -s0 -w " + self.home +"/onos-logs/tcpdump &")
Jon Hallf89c8552014-04-02 13:14:06 -07001422 i=self.handle.expect(['No\ssuch\device','listening\son',pexpect.TIMEOUT],timeout=10)
1423 if i == 0:
1424 main.log.error(self.name + ": tcpdump - No such device exists. tcpdump attempted on: " + intf)
1425 return main.FALSE
James Leec9cacaf2014-04-08 09:17:39 -07001426 elif i == 1:
Jon Hallf89c8552014-04-02 13:14:06 -07001427 main.log.info(self.name + ": tcpdump started on " + intf)
1428 return main.TRUE
James Leec9cacaf2014-04-08 09:17:39 -07001429 elif i == 2:
Jon Hallf89c8552014-04-02 13:14:06 -07001430 main.log.error(self.name + ": tcpdump command timed out! Check interface name, given interface was: " + intf)
1431 return main.FALSE
1432 else:
1433 main.log.error(self.name + ": tcpdump - unexpected response")
1434 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -07001435 except pexpect.EOF:
1436 main.log.error(self.name + ": EOF exception found")
1437 main.log.error(self.name + ": " + self.handle.before)
1438 main.cleanup()
1439 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -07001440 except:
1441 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1442 main.log.error( traceback.print_exc() )
1443 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1444 main.cleanup()
1445 main.exit()
1446
admin4a58db92013-09-30 12:04:54 -07001447 def kill_tcpdump(self):
Jon Hallae05dc22014-04-16 10:56:28 -07001448 '''
1449 Kills any tcpdump processes running
1450 '''
Jon Hallf89c8552014-04-02 13:14:06 -07001451 try:
1452 self.handle.sendline("")
1453 self.handle.expect("\$")
1454 self.handle.sendline("sudo kill -9 `ps -ef | grep \"tcpdump -n\" | grep -v grep | awk '{print $2}'`")
Jon Hallae05dc22014-04-16 10:56:28 -07001455 except pexpect.EOF:
1456 main.log.error(self.name + ": EOF exception found")
1457 main.log.error(self.name + ": " + self.handle.before)
1458 main.cleanup()
1459 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -07001460 except:
1461 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1462 main.log.error( traceback.print_exc() )
1463 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1464 main.cleanup()
1465 main.exit()
1466
Jon Hallf15f7852014-05-20 10:37:23 -07001467 def find_host(self,RestIP,RestPort,RestAPI,hostMAC):
admin2a9548d2014-06-17 14:08:07 -07001468 retcode = 0 # number of hosts found with given MAC
1469 retswitch = [] # Switch DPID's of hosts found with MAC
1470 retport = [] # Switch port connected to to hosts found with MAC
Jon Hallf15f7852014-05-20 10:37:23 -07001471 foundHost = []
Jon Hallf89c8552014-04-02 13:14:06 -07001472 try:
Jon Hall2f42a672014-05-28 10:13:18 -07001473 ##### device rest API is: 'host:8080/wm/onos/topology/switches' ###
Jon Hallf89c8552014-04-02 13:14:06 -07001474 url ="http://%s:%s%s" %(RestIP,RestPort,RestAPI)
1475
1476 try:
1477 command = "curl -s %s" % (url)
1478 result = os.popen(command).read()
1479 parsedResult = json.loads(result)
1480 # print parsedResult
1481 except:
1482 print "REST IF %s has issue" % command
1483 parsedResult = ""
1484
1485 if parsedResult == "":
Jon Hallf15f7852014-05-20 10:37:23 -07001486 return (retcode, "Rest API has an error", retport)
Jon Hallf89c8552014-04-02 13:14:06 -07001487 else:
Jon Hallf15f7852014-05-20 10:37:23 -07001488 for host in enumerate(parsedResult):
Jon Hallf15f7852014-05-20 10:37:23 -07001489 if (host[1] != []):
1490 try:
1491 foundHost = host[1]['mac']
1492 except:
1493 print "Error in detecting MAC address."
Jon Hallf15f7852014-05-20 10:37:23 -07001494 if foundHost == hostMAC:
1495 for switch in enumerate(host[1]['attachmentPoints']):
1496 retswitch.append(switch[1]['dpid'])
Jon Hallbb650fe2014-07-14 14:54:48 -07001497 retport.append(switch[1]['portNumber'])
Jon Hallf15f7852014-05-20 10:37:23 -07001498 retcode = retcode +1
1499 foundHost =''
1500 '''
Jon Hallf89c8552014-04-02 13:14:06 -07001501 for switch in enumerate(parsedResult):
1502 for port in enumerate(switch[1]['ports']):
admin2a9548d2014-06-17 14:08:07 -07001503 if ( port[1]['hosts'] != [] ):
Jon Hallf89c8552014-04-02 13:14:06 -07001504 try:
admin2a9548d2014-06-17 14:08:07 -07001505 foundHost = port[1]['hosts'][0]['ipv4addresses'][0]['ipv4']
Jon Hallf89c8552014-04-02 13:14:06 -07001506 except:
Jon Hallf15f7852014-05-20 10:37:23 -07001507 print "Error in detecting MAC address."
1508 if foundHost == hostMAC:
Jon Hallf89c8552014-04-02 13:14:06 -07001509 retswitch.append(switch[1]['dpid'])
1510 retport.append(port[1]['desc'])
admin2a9548d2014-06-17 14:08:07 -07001511 retmac.append(port[1]['hosts'][0]['mac'])
Jon Hallf89c8552014-04-02 13:14:06 -07001512 retcode = retcode +1
Jon Hallf15f7852014-05-20 10:37:23 -07001513 foundHost =''
1514 '''
1515 return(retcode, retswitch, retport)
Jon Hallae05dc22014-04-16 10:56:28 -07001516 except pexpect.EOF:
1517 main.log.error(self.name + ": EOF exception found")
1518 main.log.error(self.name + ": " + self.handle.before)
1519 main.cleanup()
1520 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -07001521 except:
1522 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1523 main.log.error( traceback.print_exc() )
1524 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1525 main.cleanup()
1526 main.exit()
SeanCorcoran29b70542014-05-14 14:53:42 -07001527
1528 def check_exceptions(self):
1529 '''
1530 Greps the logs for "xception"
1531 '''
1532 try:
1533 output = ''
1534 self.handle.sendline("")
Jon Halla78cf9a2014-05-16 10:49:30 -07001535 i = self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
Jon Hall2c4f5542014-08-05 13:45:29 -07001536 main.log.warn("first expect response: " +str(i))
SeanCorcoran29b70542014-05-14 14:53:42 -07001537 self.handle.sendline("cd "+self.home+"/onos-logs")
Jon Hall2c4f5542014-08-05 13:45:29 -07001538 i = self.handle.expect(["onos-logs\$",pexpect.EOF,pexpect.TIMEOUT])
1539 main.log.warn("second expect response: " +str(i))
1540
1541 self.handle.sendline("zgrep \"xception\" *.log *.log.gz *.stderr")
1542 #i = self.handle.expect(["\*.stdout",pexpect.EOF,pexpect.TIMEOUT])
Jon Halla78cf9a2014-05-16 10:49:30 -07001543 #main.log.warn("third expect response: " +str(i))
Jon Hall2c4f5542014-08-05 13:45:29 -07001544 print self.handle.before
1545 print
1546 print self.handle.after
1547 i = self.handle.expect(["ONOS/onos-logs\$",pexpect.EOF,pexpect.TIMEOUT],timeout=120)
1548 main.log.warn("fourth expect response: " +str(i))
SeanCorcoran29b70542014-05-14 14:53:42 -07001549 response = self.handle.before
admin6903e462014-07-22 15:30:54 -07001550 print response
Jon Halla78cf9a2014-05-16 10:49:30 -07001551 count = 0
Jon Hallbb650fe2014-07-14 14:54:48 -07001552 print response
SeanCorcoran29b70542014-05-14 14:53:42 -07001553 for line in response.splitlines():
Jon Hallbb650fe2014-07-14 14:54:48 -07001554 if re.search("gzip: \*\.log\.gz:", line):
Jon Hall2c4f5542014-08-05 13:45:29 -07001555 #gzip complaining about file not found
Jon Hallbb650fe2014-07-14 14:54:48 -07001556 pass
Jon Hall724a2f42014-06-23 16:04:22 -07001557 elif re.search("log\.gz:",line):
1558 output+="Exceptions found in " + line + "\n"
1559 count +=1
Jon Hall2c4f5542014-08-05 13:45:29 -07001560 elif re.search("log:", line):
1561 output +="Exceptions found in " + line + "\n"
1562 count +=1
SeanCorcoran29b70542014-05-14 14:53:42 -07001563 elif re.search("std...:",line):
1564 output+="Exceptions found in " + line + "\n"
Jon Halla78cf9a2014-05-16 10:49:30 -07001565 count +=1
SeanCorcoran29b70542014-05-14 14:53:42 -07001566 else:
1567 pass
1568 #these should be the old logs
admin1723f1c2014-05-19 16:08:39 -07001569 main.log.report(str(count) + " Exceptions were found on "+self.name)
SeanCorcoran29b70542014-05-14 14:53:42 -07001570 return output
1571 except pexpect.TIMEOUT:
1572 main.log.error(self.name + ": Timeout exception found in check_exceptions function")
1573 except pexpect.EOF:
1574 main.log.error(self.name + ": EOF exception found")
1575 main.log.error(self.name + ": " + self.handle.before)
1576 main.cleanup()
1577 main.exit()
1578 except:
1579 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1580 main.log.error( traceback.print_exc() )
1581 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1582 main.cleanup()
1583 main.exit()