blob: 87df2feabe050f92aab4619932f4fea25d2e4b31 [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()
admine0ae8202013-08-28 11:51:43 -0700125
adminbae64d82013-08-01 10:50:15 -0700126 def start_rest(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700127 '''
128 Starts the rest server on ONOS.
129 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700130 try:
Jon Hall4a2b0482014-04-18 16:29:26 -0700131 self.handle.sendline("cd "+self.home)
132 response = self.execute(cmd= "./start-rest.sh start",prompt="\$",timeout=10)
Jon Hallf89c8552014-04-02 13:14:06 -0700133 if re.search("admin",response):
134 main.log.info(self.name + ": Rest Server Started Successfully")
135 time.sleep(5)
136 return main.TRUE
137 else :
James Leec9cacaf2014-04-08 09:17:39 -0700138 main.log.warn(self.name + ": Failed to start Rest Server")
139 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700140 except pexpect.EOF:
141 main.log.error(self.name + ": EOF exception found")
142 main.log.error(self.name + ": " + self.handle.before)
143 main.cleanup()
144 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700145 except:
146 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
147 main.log.error( traceback.print_exc() )
148 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
149 main.cleanup()
150 main.exit()
151
adminbae64d82013-08-01 10:50:15 -0700152 def status(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700153 '''
154 Called onos.sh core status and returns TRUE/FALSE accordingly
155 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700156 try:
157 self.execute(cmd="\n",prompt="\$",timeout=10)
Jon Hall4a2b0482014-04-18 16:29:26 -0700158 self.handle.sendline("cd "+self.home)
159 response = self.execute(cmd="./onos.sh core status ",prompt="\d+\sinstance\sof\sonos\srunning",timeout=10)
Jon Hallf89c8552014-04-02 13:14:06 -0700160 self.execute(cmd="\n",prompt="\$",timeout=10)
161 if re.search("1\sinstance\sof\sonos\srunning",response):
162 return main.TRUE
163 elif re.search("0\sinstance\sof\sonos\srunning",response):
164 return main.FALSE
165 else :
166 main.log.info( self.name + " WARNING: status recieved unknown response")
167 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700168 except pexpect.EOF:
169 main.log.error(self.name + ": EOF exception found")
170 main.log.error(self.name + ": " + self.handle.before)
171 main.cleanup()
172 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700173 except:
174 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
175 main.log.error( traceback.print_exc() )
176 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
177 main.cleanup()
178 main.exit()
179
adminbae64d82013-08-01 10:50:15 -0700180
181 def isup(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700182 '''
183 A more complete check to see if ONOS is up and running properly.
184 First, it checks if the process is up.
185 Second, it reads the logs for "Exception: Connection refused"
186 Third, it makes sure the logs are actually moving.
187 returns TRUE/FALSE accordingly.
188 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700189 try:
190 self.execute(cmd="\n",prompt="\$",timeout=10)
Jon Hall4a2b0482014-04-18 16:29:26 -0700191 self.handle.sendline("cd "+self.home)
192 response = self.execute(cmd= "./onos.sh core status ",prompt="running",timeout=10)
Jon Hallf89c8552014-04-02 13:14:06 -0700193 self.execute(cmd="\n",prompt="\$",timeout=10)
194 tail1 = self.execute(cmd="tail " + self.home + "/onos-logs/onos.*.log",prompt="\$",timeout=10)
195 time.sleep(30)
196 self.execute(cmd="\n",prompt="\$",timeout=10)
197 tail2 = self.execute(cmd="tail " + self.home + "/onos-logs/onos.*.log",prompt="\$",timeout=10)
198 pattern = '(.*)1 instance(.*)'
199 pattern2 = '(.*)Exception: Connection refused(.*)'
200 # if utilities.assert_matches(expect=pattern,actual=response,onpass="ONOS process is running...",onfail="ONOS process not running..."):
201
202 if re.search(pattern, response):
203 main.log.info(self.name + ": ONOS process is running...")
204 if tail1 == tail2:
205 main.log.error(self.name + ": ONOS is frozen...")#logs aren't moving
206 return main.FALSE
207 elif re.search( pattern2,tail1 ):
James Leec9cacaf2014-04-08 09:17:39 -0700208 main.log.info(self.name + ": Connection Refused found in onos log")
Jon Hallf89c8552014-04-02 13:14:06 -0700209 return main.FALSE
210 elif re.search( pattern2,tail2 ):
James Leec9cacaf2014-04-08 09:17:39 -0700211 main.log.info(self.name + ": Connection Refused found in onos log")
Jon Hallf89c8552014-04-02 13:14:06 -0700212 return main.FALSE
213 else:
214 main.log.info(self.name + ": Onos log is moving! It's looking good!")
215 return main.TRUE
adminbae64d82013-08-01 10:50:15 -0700216 else:
Jon Hallf89c8552014-04-02 13:14:06 -0700217 main.log.error(self.name + ": ONOS process not running...")
218 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700219 except pexpect.EOF:
220 main.log.error(self.name + ": EOF exception found")
221 main.log.error(self.name + ": " + self.handle.before)
222 main.cleanup()
223 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700224 except:
225 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
226 main.log.error( traceback.print_exc() )
227 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
228 main.cleanup()
229 main.exit()
adminbae64d82013-08-01 10:50:15 -0700230
Jon Hallf89c8552014-04-02 13:14:06 -0700231
232
James Leec9cacaf2014-04-08 09:17:39 -0700233 def rest_status(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700234 '''
235 Checks if the rest server is running.
236 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700237 try:
238 response = self.execute(cmd= self.home + "/start-rest.sh status ",prompt="running",timeout=10)
239 if re.search("rest\sserver\sis\srunning",response):
240 main.log.info(self.name + ": Rest Server is running")
Jon Hallae05dc22014-04-16 10:56:28 -0700241 return main.TRUE
Jon Hallf89c8552014-04-02 13:14:06 -0700242 elif re.search("rest\sserver\sis\snot\srunning",response):
243 main.log.warn(self.name + ": Rest Server is not Running")
Jon Hallae05dc22014-04-16 10:56:28 -0700244 return main.FALSE
Jon Hallf89c8552014-04-02 13:14:06 -0700245 else :
246 main.log.error(self.name + ": No response" +response)
Jon Hallae05dc22014-04-16 10:56:28 -0700247 return main.FALSE
248 except pexpect.EOF:
249 main.log.error(self.name + ": EOF exception found")
250 main.log.error(self.name + ": " + self.handle.before)
251 main.cleanup()
252 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700253 except:
254 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
255 main.log.error( traceback.print_exc() )
256 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
257 main.cleanup()
258 main.exit()
259
260
adminbae64d82013-08-01 10:50:15 -0700261 def stop(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700262 '''
263 Runs ./onos.sh core stop to stop ONOS
264 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700265 try:
266 self.handle.sendline("")
Jon Hallae05dc22014-04-16 10:56:28 -0700267 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
Jon Hall4a2b0482014-04-18 16:29:26 -0700268 self.handle.sendline("cd "+self.home)
269 self.handle.sendline("./onos.sh core stop")
Jon Hallae05dc22014-04-16 10:56:28 -0700270 i=self.handle.expect(["Stop",pexpect.EOF,pexpect.TIMEOUT])
271 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT], 60)
James Leec9cacaf2014-04-08 09:17:39 -0700272 result = self.handle.before
Jon Hallf89c8552014-04-02 13:14:06 -0700273 if re.search("Killed", result):
274 main.log.info(self.name + ": ONOS Killed Successfully")
275 return main.TRUE
276 else :
277 main.log.warn(self.name + ": ONOS wasn't running")
278 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700279 except pexpect.EOF:
280 main.log.error(self.name + ": EOF exception found")
281 main.log.error(self.name + ": " + self.handle.before)
282 main.cleanup()
283 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700284 except:
285 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
286 main.log.error( traceback.print_exc() )
287 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
288 main.cleanup()
289 main.exit()
290
adminbae64d82013-08-01 10:50:15 -0700291
292 def rest_stop(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700293 '''
294 Runs ./start-rest.sh stop to stop ONOS rest server
295 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700296 try:
297 response = self.execute(cmd= self.home + "/start-rest.sh stop ",prompt="killing",timeout=10)
298 self.execute(cmd="\n",prompt="\$",timeout=10)
299 if re.search("killing", response):
300 main.log.info(self.name + ": Rest Server Stopped")
301 return main.TRUE
302 else :
303 main.log.error(self.name + ": Failed to Stop, Rest Server is not Running")
304 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700305 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()
316
317
adminbae64d82013-08-01 10:50:15 -0700318 def disconnect(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700319 '''
320 Called when Test is complete to disconnect the ONOS handle.
321 '''
adminaeedddd2013-08-02 15:14:15 -0700322 response = ''
323 try:
adminbae64d82013-08-01 10:50:15 -0700324 self.handle.sendline("exit")
adminaeedddd2013-08-02 15:14:15 -0700325 self.handle.expect("closed")
Jon Hallae05dc22014-04-16 10:56:28 -0700326 except pexpect.EOF:
327 main.log.error(self.name + ": EOF exception found")
328 main.log.error(self.name + ": " + self.handle.before)
James Leec9cacaf2014-04-08 09:17:39 -0700329 except:
Jon Hallf89c8552014-04-02 13:14:06 -0700330 main.log.error(self.name + ": Connection failed to the host")
adminbae64d82013-08-01 10:50:15 -0700331 response = main.FALSE
adminaeedddd2013-08-02 15:14:15 -0700332 return response
333
Jon Hall76f2c462014-04-17 11:37:15 -0700334 def print_version(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700335 '''
336 Writes the COMMIT number to the report to be parsed by Jenkins data collecter.
337 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700338 try:
339 self.handle.sendline("export TERM=xterm-256color")
340 self.handle.expect("xterm-256color")
James Leec9cacaf2014-04-08 09:17:39 -0700341 self.handle.expect("\$")
adminf939f8b2014-04-03 17:22:56 -0700342 self.handle.sendline("cd " + self.home + "; git log -1 --pretty=fuller | grep -A 5 \"commit\"; cd \.\.")
Jon Hallf89c8552014-04-02 13:14:06 -0700343 self.handle.expect("cd ..")
344 self.handle.expect("\$")
admine0eeea22014-04-14 10:22:46 -0700345 response=(self.name +": \n"+ str(self.handle.before + self.handle.after))
346 main.log.report(response)
Jon Hall76f2c462014-04-17 11:37:15 -0700347 except pexpect.EOF:
348 main.log.error(self.name + ": EOF exception found")
349 main.log.error(self.name + ": " + self.handle.before)
350 main.cleanup()
351 main.exit()
352 except:
353 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
354 main.log.error( traceback.print_exc() )
355 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
356 main.cleanup()
357 def get_version(self):
358 '''
359 Writes the COMMIT number to the report to be parsed by Jenkins data collecter.
360 '''
361 try:
362 self.handle.sendline("export TERM=xterm-256color")
363 self.handle.expect("xterm-256color")
364 self.handle.expect("\$")
365 self.handle.sendline("cd " + self.home + "; git log -1 --pretty=fuller | grep -A 5 \"commit\"; cd \.\.")
366 self.handle.expect("cd ..")
367 self.handle.expect("\$")
368 response=(self.name +": \n"+ str(self.handle.before + self.handle.after))
admine0eeea22014-04-14 10:22:46 -0700369 lines=response.splitlines()
370 for line in lines:
371 print line
372 return lines[2]
Jon Hallae05dc22014-04-16 10:56:28 -0700373 except pexpect.EOF:
374 main.log.error(self.name + ": EOF exception found")
375 main.log.error(self.name + ": " + self.handle.before)
376 main.cleanup()
377 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700378 except:
379 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
380 main.log.error( traceback.print_exc() )
381 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
382 main.cleanup()
383 main.exit()
adminbae64d82013-08-01 10:50:15 -0700384
adminc6cfc1c2014-04-21 13:55:21 -0700385 def ad_flow(self):
386 main.log.info("AD_FLOW RUNNING!!!!")
387 self.handle.sendline("cd "+self.home+ "/scripts")
388 self.handle.expect("scripts")
389 print("Adding flows")
390 self.handle.sendline("./pyintents.py")
391 self.handle.sendline("cd "+self.home)
392 return main.TRUE
393
394 def rm_flow(self):
395 main.log.info("RM_FLOW RUNNING!!!")
396 self.handle.sendline("cd "+self.home+ "/scripts")
397 self.handle.expect("scripts")
398 print("Removing flows")
399 self.handle.sendline("./rmpyintents.py")
400 self.handle.sendline("cd "+self.home)
401 return main.TRUE
402
403
404
405
Jon Hall4a2b0482014-04-18 16:29:26 -0700406 def add_flow(self, testONip, user = "admin", password = "", flowDef = "/flowdef.txt"):
Jon Halld8dc5772014-04-08 16:26:29 -0700407 '''
408 Copies the flowdef file from TestStation -> ONOS machine
409 Then runs ./add_flow.py to add the flows to ONOS
410 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700411 try:
412 main.log.info("Adding Flows...")
413 self.handle.sendline("scp %s@%s:%s /tmp/flowtmp" %(user,testONip,flowDef))
414 i=self.handle.expect(['[pP]assword:', '100%', pexpect.TIMEOUT],30)
415 if(i==0):
416 self.handle.sendline("%s" %(password))
417 self.handle.sendline("")
418 self.handle.expect("100%")
419 self.handle.expect("\$", 30)
420 self.handle.sendline(self.home + "/web/add_flow.py -m onos -f /tmp/flowtmp")
421 self.handle.expect("\$", 1000)
422 main.log.info("Flows added")
423 return main.TRUE
424
425 elif(i==1):
426 self.handle.sendline("")
427 self.handle.expect("\$", 10)
428 self.handle.sendline( self.home + "/web/add_flow.py -m onos -f /tmp/flowtmp")
429 self.handle.expect("\$", 1000)
430 main.log.info("Flows added")
431 return main.TRUE
432
433 elif(i==2):
434 main.log.error("Flow Def file SCP Timed out...")
435 return main.FALSE
436
437 else:
438 main.log.error("Failed to add flows...")
James Leec9cacaf2014-04-08 09:17:39 -0700439 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700440 except pexpect.EOF:
441 main.log.error(self.name + ": EOF exception found")
442 main.log.error(self.name + ": " + self.handle.before)
443 main.cleanup()
444 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700445 except:
446 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
447 main.log.error( traceback.print_exc() )
448 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
449 main.cleanup()
450 main.exit()
451
adminbae64d82013-08-01 10:50:15 -0700452
453 def delete_flow(self, *delParams):
Jon Halld8dc5772014-04-08 16:26:29 -0700454 '''
455 Deletes a specific flow, a range of flows, or all flows.
456 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700457 try:
458 if len(delParams)==1:
459 if str(delParams[0])=="all":
460 main.log.info(self.name + ": Deleting ALL flows...")
461 #self.execute(cmd="~/ONOS/scripts/TestON_delete_flow.sh all",prompt="done",timeout=150)
462 self.handle.sendline(self.home + "/web/delete_flow.py all")
463 self.handle.expect("delete_flow")
464 self.handle.expect("\$",1000)
465 main.log.info(self.name + ": Flows deleted")
466 else:
467 main.log.info(self.name + ": Deleting flow "+str(delParams[0])+"...")
468 #self.execute(cmd="~/ONOS/scripts/TestON_delete_flow.sh "+str(delParams[0]),prompt="done",timeout=150)
469 #self.execute(cmd="\n",prompt="\$",timeout=60)
470 self.handle.sendline(self.home +"/web/delete_flow.py %d" % int(delParams[0]))
471 self.handle.expect("delete_flow")
472 self.handle.expect("\$",60)
473 main.log.info(self.name + ": Flow deleted")
474 elif len(delParams)==2:
475 main.log.info(self.name + ": Deleting flows "+str(delParams[0])+" through "+str(delParams[1])+"...")
476 #self.execute(cmd="~/ONOS/scripts/TestON_delete_flow.sh "+str(delParams[0])+" "+str(delParams[1]),prompt="done",timeout=150)
477 #self.execute(cmd="\n",prompt="\$",timeout=60)
478 self.handle.sendline(self.home + "/web/delete_flow.py %d %d" % (int(delParams[0]), int(delParams[1])))
479 self.handle.expect("delete_flow")
480 self.handle.expect("\$",600)
481 main.log.info(self.name + ": Flows deleted")
Jon Hallae05dc22014-04-16 10:56:28 -0700482 except pexpect.EOF:
483 main.log.error(self.name + ": EOF exception found")
484 main.log.error(self.name + ": " + self.handle.before)
485 main.cleanup()
486 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700487 except:
488 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
489 main.log.error( traceback.print_exc() )
490 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
491 main.cleanup()
492 main.exit()
adminbae64d82013-08-01 10:50:15 -0700493
494 def check_flow(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700495 '''
496 Calls the ./get_flow.py all and checks:
497 - If each FlowPath has at least one FlowEntry
498 - That there are no "NOT"s found
499 returns TRUE/FALSE
500 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700501 try:
502 flowEntryDetect = 1
503 count = 0
504 self.handle.sendline("clear")
505 time.sleep(1)
506 self.handle.sendline(self.home + "/web/get_flow.py all")
507 self.handle.expect("get_flow")
508 while 1:
509 i=self.handle.expect(['FlowPath','FlowEntry','NOT','\$',pexpect.TIMEOUT],timeout=180)
510 if i==0:
511 count = count + 1
512 if flowEntryDetect == 0:
513 main.log.info(self.name + ": FlowPath without FlowEntry")
514 return main.FALSE
515 else:
516 flowEntryDetect = 0
517 elif i==1:
518 flowEntryDetect = 1
519 elif i==2:
520 main.log.error(self.name + ": Found a NOT")
adminbae64d82013-08-01 10:50:15 -0700521 return main.FALSE
Jon Hallf89c8552014-04-02 13:14:06 -0700522 elif i==3:
523 if count == 0:
524 main.log.info(self.name + ": There don't seem to be any flows here...")
525 return main.FALSE
526 else:
527 main.log.info(self.name + ": All flows pass")
528 main.log.info(self.name + ": Number of FlowPaths: "+str(count))
529 return main.TRUE
530 elif i==4:
James Leec9cacaf2014-04-08 09:17:39 -0700531 main.log.error(self.name + ":Check_flow() - Command Timeout!")
Jon Hallf89c8552014-04-02 13:14:06 -0700532 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700533 except pexpect.EOF:
534 main.log.error(self.name + ": EOF exception found")
535 main.log.error(self.name + ": " + self.handle.before)
536 main.cleanup()
537 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700538 except:
539 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
540 main.log.error( traceback.print_exc() )
541 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
542 main.cleanup()
543 main.exit()
adminbae64d82013-08-01 10:50:15 -0700544
545 def get_flow(self, *flowParams):
Jon Halld8dc5772014-04-08 16:26:29 -0700546 '''
547 Returns verbose output of ./get_flow.py
548 '''
549 try:
550 if len(flowParams)==1:
551 if str(flowParams[0])=="all":
552 self.execute(cmd="\n",prompt="\$",timeout=60)
553 main.log.info(self.name + ": Getting all flow data...")
554 data = self.execute(cmd=self.home + "/scripts/TestON_get_flow.sh all",prompt="done",timeout=150)
555 self.execute(cmd="\n",prompt="\$",timeout=60)
556 return data
557 else:
558 main.log.info(self.name + ": Retrieving flow "+str(flowParams[0])+" data...")
559 data = self.execute(cmd=self.home +"/scripts/TestON_get_flow.sh "+str(flowParams[0]),prompt="done",timeout=150)
560 self.execute(cmd="\n",prompt="\$",timeout=60)
561 return data
562 elif len(flowParams)==5:
563 main.log.info(self.name + ": Retrieving flow installer data...")
564 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)
565 self.execute(cmd="\n",prompt="\$",timeout=60)
566 return data
567 elif len(flowParams)==4:
568 main.log.info(self.name + ": Retrieving flow endpoints...")
569 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)
570 self.execute(cmd="\n",prompt="\$",timeout=60)
571 return data
Jon Hallae05dc22014-04-16 10:56:28 -0700572 except pexpect.EOF:
573 main.log.error(self.name + ": EOF exception found")
574 main.log.error(self.name + ": " + self.handle.before)
575 main.cleanup()
576 main.exit()
Jon Halld8dc5772014-04-08 16:26:29 -0700577 except:
Jon Hallf89c8552014-04-02 13:14:06 -0700578 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
579 main.log.error( traceback.print_exc() )
580 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
581 main.cleanup()
582 main.exit()
adminbae64d82013-08-01 10:50:15 -0700583
584
SeanCorcoran83a653a2014-04-22 15:03:18 -0700585# http://localhost:8080/wm/onos/topology/switches/json
586# http://localhost:8080/wm/onos/topology/links/json
Jon Hall8060af02014-04-14 14:17:58 -0700587# http://localhost:8080/wm/onos/registry/controllers/json
588# http://localhost:8080/wm/onos/registry/switches/json"
adminbae64d82013-08-01 10:50:15 -0700589
590 def get_json(self, url):
Jon Halld8dc5772014-04-08 16:26:29 -0700591 '''
592 Helper functions used to parse the json output of a rest call
593 '''
adminbae64d82013-08-01 10:50:15 -0700594 try:
Jon Hallf89c8552014-04-02 13:14:06 -0700595 try:
596 command = "curl -s %s" % (url)
597 result = os.popen(command).read()
598 parsedResult = json.loads(result)
599 except:
600 print "REST IF %s has issue" % command
601 parsedResult = ""
602
603 if type(parsedResult) == 'dict' and parsedResult.has_key('code'):
604 print "REST %s returned code %s" % (command, parsedResult['code'])
605 parsedResult = ""
James Leec9cacaf2014-04-08 09:17:39 -0700606 return parsedResult
Jon Hallae05dc22014-04-16 10:56:28 -0700607 except pexpect.EOF:
608 main.log.error(self.name + ": EOF exception found")
609 main.log.error(self.name + ": " + self.handle.before)
610 main.cleanup()
611 main.exit()
adminbae64d82013-08-01 10:50:15 -0700612 except:
Jon Hallf89c8552014-04-02 13:14:06 -0700613 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
614 main.log.error( traceback.print_exc() )
615 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
616 main.cleanup()
617 main.exit()
adminbae64d82013-08-01 10:50:15 -0700618
Jon Hallf89c8552014-04-02 13:14:06 -0700619 def check_switch(self,RestIP,correct_nr_switch, RestPort ="8080" ):
Jon Halld8dc5772014-04-08 16:26:29 -0700620 '''
621 Used by check_status
622 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700623 try:
624 buf = ""
625 retcode = 0
SeanCorcoran83a653a2014-04-22 15:03:18 -0700626 url="http://%s:%s/wm/onos/topology/switches/json" % (RestIP, RestPort)
Jon Hallf89c8552014-04-02 13:14:06 -0700627 parsedResult = self.get_json(url)
628 if parsedResult == "":
629 retcode = 1
630 return (retcode, "Rest API has an issue")
631 url = "http://%s:%s/wm/onos/registry/switches/json" % (RestIP, RestPort)
632 registry = self.get_json(url)
633
634 if registry == "":
635 retcode = 1
636 return (retcode, "Rest API has an issue")
637
638 cnt = 0
639 active = 0
adminbae64d82013-08-01 10:50:15 -0700640
Jon Hallf89c8552014-04-02 13:14:06 -0700641 for s in parsedResult:
642 cnt += 1
James Leec9cacaf2014-04-08 09:17:39 -0700643 if s['state'] == "ACTIVE":
Jon Hallf89c8552014-04-02 13:14:06 -0700644 active += 1
adminbae64d82013-08-01 10:50:15 -0700645
Jon Hallf89c8552014-04-02 13:14:06 -0700646 buf += "switch: network %d : %d switches %d active\n" % (0+1, cnt, active)
647 if correct_nr_switch != cnt:
648 buf += "switch fail: network %d should have %d switches but has %d\n" % (1, correct_nr_switch, cnt)
649 retcode = 1
adminbae64d82013-08-01 10:50:15 -0700650
Jon Hallf89c8552014-04-02 13:14:06 -0700651 if correct_nr_switch != active:
652 buf += "switch fail: network %d should have %d active switches but has %d\n" % (1, correct_nr_switch, active)
653 retcode = 1
654
655 return (retcode, buf)
Jon Hallae05dc22014-04-16 10:56:28 -0700656 except pexpect.EOF:
657 main.log.error(self.name + ": EOF exception found")
658 main.log.error(self.name + ": " + self.handle.before)
659 main.cleanup()
660 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700661 except:
662 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
663 main.log.error( traceback.print_exc() )
664 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
665 main.cleanup()
666 main.exit()
adminbae64d82013-08-01 10:50:15 -0700667
Jon Hallf89c8552014-04-02 13:14:06 -0700668 def check_link(self,RestIP, nr_links, RestPort = "8080"):
Jon Halld8dc5772014-04-08 16:26:29 -0700669 '''
670 Used by check_status
671 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700672 try:
673 buf = ""
674 retcode = 0
675
SeanCorcoran83a653a2014-04-22 15:03:18 -0700676 url = "http://%s:%s/wm/onos/topology/links/json" % (RestIP, RestPort)
Jon Hallf89c8552014-04-02 13:14:06 -0700677 parsedResult = self.get_json(url)
678
679 if parsedResult == "":
680 retcode = 1
681 return (retcode, "Rest API has an issue")
682
683 buf += "link: total %d links (correct : %d)\n" % (len(parsedResult), nr_links)
684 intra = 0
685 interlink=0
686
687 for s in parsedResult:
James Leec9cacaf2014-04-08 09:17:39 -0700688 intra = intra + 1
Jon Hallf89c8552014-04-02 13:14:06 -0700689
690 if intra != nr_links:
691 buf += "link fail\n"
692 retcode = 1
693
694 return (retcode, buf)
Jon Hallae05dc22014-04-16 10:56:28 -0700695 except pexpect.EOF:
696 main.log.error(self.name + ": EOF exception found")
697 main.log.error(self.name + ": " + self.handle.before)
698 main.cleanup()
699 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700700 except:
701 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
702 main.log.error( traceback.print_exc() )
703 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
704 main.cleanup()
705 main.exit()
adminbae64d82013-08-01 10:50:15 -0700706
Jon Hallf89c8552014-04-02 13:14:06 -0700707 def check_status_report(self, ip, numoswitch, numolink, port="8080"):
Jon Halld8dc5772014-04-08 16:26:29 -0700708 '''
709 Checks the number of swithes & links that ONOS sees against the supplied values.
710 Writes to the report log.
711 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700712 try:
James Leec9cacaf2014-04-08 09:17:39 -0700713 main.log.info(self.name + ": Making some rest calls...")
Jon Hallf89c8552014-04-02 13:14:06 -0700714 switch = self.check_switch(ip, int(numoswitch), port)
715 link = self.check_link(ip, int(numolink), port)
716 value = switch[0]
717 value += link[0]
718 main.log.report( self.name + ": \n-----\n%s%s-----\n" % ( switch[1], link[1]) )
719 if value != 0:
720 return main.FALSE
James Leec9cacaf2014-04-08 09:17:39 -0700721 else:
Jon Hallf89c8552014-04-02 13:14:06 -0700722 # "PASS"
723 return main.TRUE
Jon Hallae05dc22014-04-16 10:56:28 -0700724 except pexpect.EOF:
725 main.log.error(self.name + ": EOF exception found")
726 main.log.error(self.name + ": " + self.handle.before)
727 main.cleanup()
728 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700729 except:
730 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
731 main.log.error( traceback.print_exc() )
732 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
733 main.cleanup()
734 main.exit()
adminbae64d82013-08-01 10:50:15 -0700735
Jon Hallf89c8552014-04-02 13:14:06 -0700736 def check_status(self, ip, numoswitch, numolink, port = "8080"):
Jon Halld8dc5772014-04-08 16:26:29 -0700737 '''
738 Checks the number of swithes & links that ONOS sees against the supplied values.
739 Writes to the main log.
740 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700741 try:
James Leec9cacaf2014-04-08 09:17:39 -0700742 main.log.info(self.name + ": Making some rest calls...")
Jon Hallf89c8552014-04-02 13:14:06 -0700743 switch = self.check_switch(ip, int(numoswitch), port)
744 link = self.check_link(ip, int(numolink), port)
745 value = switch[0]
746 value += link[0]
747 main.log.info(self.name + ": \n-----\n%s%s-----\n" % ( switch[1], link[1]) )
748 if value != 0:
749 return main.FALSE
James Leec9cacaf2014-04-08 09:17:39 -0700750 else:
Jon Hallf89c8552014-04-02 13:14:06 -0700751 # "PASS"
752 return main.TRUE
Jon Hallae05dc22014-04-16 10:56:28 -0700753 except pexpect.EOF:
754 main.log.error(self.name + ": EOF exception found")
755 main.log.error(self.name + ": " + self.handle.before)
756 main.cleanup()
757 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700758 except:
759 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
760 main.log.error( traceback.print_exc() )
761 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
762 main.cleanup()
763 main.exit()
adminbae64d82013-08-01 10:50:15 -0700764
adminbae64d82013-08-01 10:50:15 -0700765 def check_for_no_exceptions(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700766 '''
767 TODO: Rewrite
768 Used by CassndraCheck.py to scan ONOS logs for Exceptions
769 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700770 try:
771 self.handle.sendline("dsh 'grep Exception ~/ONOS/onos-logs/onos.*.log'")
James Leec9cacaf2014-04-08 09:17:39 -0700772 self.handle.expect("\$ dsh")
Jon Hallf89c8552014-04-02 13:14:06 -0700773 self.handle.expect("\$")
774 output = self.handle.before
James Leec9cacaf2014-04-08 09:17:39 -0700775 main.log.info(self.name + ": " + output )
Jon Hallf89c8552014-04-02 13:14:06 -0700776 if re.search("Exception",output):
777 return main.FALSE
778 else :
779 return main.TRUE
Jon Hallae05dc22014-04-16 10:56:28 -0700780 except pexpect.EOF:
781 main.log.error(self.name + ": EOF exception found")
782 main.log.error(self.name + ": " + self.handle.before)
783 main.cleanup()
784 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700785 except:
786 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
787 main.log.error( traceback.print_exc() )
788 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
789 main.cleanup()
790 main.exit()
791
792
admine0eeea22014-04-14 10:22:46 -0700793 def git_pull(self, comp1=""):
Jon Halld8dc5772014-04-08 16:26:29 -0700794 '''
Jon Halld8dc5772014-04-08 16:26:29 -0700795 Assumes that "git pull" works without login
admine0eeea22014-04-14 10:22:46 -0700796
797 This function will perform a git pull on the ONOS instance.
798 If used as git_pull("NODE") it will do git pull + NODE. This is
799 for the purpose of pulling from other nodes if necessary.
800
801 Otherwise, this function will perform a git pull in the
802 ONOS repository. If it has any problems, it will return main.ERROR
803 If it successfully does a git_pull, it will return a 1.
804 If it has no updates, it will return a 0.
805
Jon Halld8dc5772014-04-08 16:26:29 -0700806 '''
Jon Hallae05dc22014-04-16 10:56:28 -0700807 try:
808 main.log.info(self.name + ": Stopping ONOS")
809 self.stop()
810 self.handle.sendline("cd " + self.home)
811 self.handle.expect("ONOS\$")
812 if comp1=="":
813 self.handle.sendline("git pull")
814 else:
815 self.handle.sendline("git pull " + comp1)
816
817 uptodate = 0
SeanCorcoran20bd6fc2014-04-16 17:10:30 -0700818 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 -0700819 #debug
820 #main.log.report(self.name +": \n"+"git pull response: " + str(self.handle.before) + str(self.handle.after))
821 if i==0:
822 main.log.error(self.name + ": Git pull had some issue...")
823 return main.ERROR
824 elif i==1:
825 main.log.error(self.name + ": Git Pull Asking for username!!! BADD!")
826 return main.ERROR
827 elif i==2:
828 main.log.info(self.name + ": Git Pull - pulling repository now")
829 self.handle.expect("ONOS\$", 120)
830 return 0
831 elif i==3:
832 main.log.error(self.name + ": Git Pull - TIMEOUT")
833 return main.ERROR
834 elif i==4:
835 main.log.info(self.name + ": Git Pull - Already up to date")
836 return 1
837 elif i==5:
838 main.log.info(self.name + ": Git Pull - Aborting... Are there conflicting git files?")
839 return main.ERROR
840 else:
841 main.log.error(self.name + ": Git Pull - Unexpected response, check for pull errors")
842 return main.ERROR
843 except pexpect.EOF:
844 main.log.error(self.name + ": EOF exception found")
845 main.log.error(self.name + ": " + self.handle.before)
846 main.cleanup()
847 main.exit()
848 except:
849 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
850 main.log.error( traceback.print_exc() )
851 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
852 main.cleanup()
853 main.exit()
admine0eeea22014-04-14 10:22:46 -0700854#********************************************************
855
856
admin7373a812014-04-16 09:49:02 -0700857 def git_compile(self):
Jon Hallae05dc22014-04-16 10:56:28 -0700858 '''
859 Compiles ONOS
860 First runs mvn clean then mvn compile
861 '''
862 try:
863 main.log.info(self.name + ": mvn clean")
admin8fc02822014-04-16 13:31:23 -0700864 self.handle.sendline("cd " + self.home)
Jon Hallae05dc22014-04-16 10:56:28 -0700865 self.handle.sendline("mvn clean")
866 while 1:
Jon Hall1636f942014-04-17 10:07:23 -0700867 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 -0700868 if i == 0:
Jon Hall1636f942014-04-17 10:07:23 -0700869 main.log.error(self.name + ":There is insufficient memory for the Java Runtime Environment to continue.")
Jon Hallae05dc22014-04-16 10:56:28 -0700870 return main.FALSE
871 elif i == 1:
Jon Hall1636f942014-04-17 10:07:23 -0700872 main.log.error(self.name + ": Clean failure!")
873 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700874 elif i == 2:
Jon Hall1636f942014-04-17 10:07:23 -0700875 main.log.info(self.name + ": Clean success!")
876 elif i == 3:
admin8fc02822014-04-16 13:31:23 -0700877 main.log.info(self.name + ": Clean complete")
Jon Hallae05dc22014-04-16 10:56:28 -0700878 break;
Jon Hall1636f942014-04-17 10:07:23 -0700879 elif i == 4:
Jon Hallae05dc22014-04-16 10:56:28 -0700880 main.log.error(self.name + ": mvn clean TIMEOUT!")
881 return main.FALSE
Jon Hall1636f942014-04-17 10:07:23 -0700882 else:
883 main.log.error(self.name + ": unexpected response from mvn clean")
884 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700885
886 main.log.info(self.name + ": mvn compile")
887 self.handle.sendline("mvn compile")
888 while 1:
Jon Hall1636f942014-04-17 10:07:23 -0700889 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 -0700890 if i == 0:
Jon Hall1636f942014-04-17 10:07:23 -0700891 main.log.error(self.name + ":There is insufficient memory for the Java Runtime Environment to continue.")
892 return main.FALSE
893 if i == 1:
Jon Hallae05dc22014-04-16 10:56:28 -0700894 main.log.error(self.name + ": Build failure!")
895 return main.FALSE
Jon Hall1636f942014-04-17 10:07:23 -0700896 elif i == 2:
Jon Hallae05dc22014-04-16 10:56:28 -0700897 main.log.info(self.name + ": Build success!")
898 return main.TRUE
Jon Hall1636f942014-04-17 10:07:23 -0700899 elif i == 3:
Jon Hallae05dc22014-04-16 10:56:28 -0700900 main.log.info(self.name + ": Build complete")
901 return main.TRUE
Jon Hall1636f942014-04-17 10:07:23 -0700902 elif i == 4:
Jon Hallae05dc22014-04-16 10:56:28 -0700903 main.log.error(self.name + ": mvn compile TIMEOUT!")
904 return main.FALSE
905 else:
Jon Hall1636f942014-04-17 10:07:23 -0700906 main.log.error(self.name + ": unexpected response from mvn compile")
907 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700908 except pexpect.EOF:
909 main.log.error(self.name + ": EOF exception found")
910 main.log.error(self.name + ": " + self.handle.before)
911 main.cleanup()
912 main.exit()
913 except:
914 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
915 main.log.error( traceback.print_exc() )
916 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
917 main.cleanup()
918 main.exit()
admin4a58db92013-09-30 12:04:54 -0700919
Jon Hallf89c8552014-04-02 13:14:06 -0700920 def tcpdump(self, intf = "eth0"):
Jon Hallae05dc22014-04-16 10:56:28 -0700921 '''
922 Runs tpdump on an intferface and saves in onos-logs under the ONOS home directory
923 intf can be specified, or the default eth0 is used
924 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700925 try:
926 self.handle.sendline("")
927 self.handle.expect("\$")
Jon Hall26f316b2014-04-11 11:21:25 -0700928 self.handle.sendline("sudo tcpdump -n -i "+ intf + " -s0 -w " + self.home +"/onos-logs/tcpdump &")
Jon Hallf89c8552014-04-02 13:14:06 -0700929 i=self.handle.expect(['No\ssuch\device','listening\son',pexpect.TIMEOUT],timeout=10)
930 if i == 0:
931 main.log.error(self.name + ": tcpdump - No such device exists. tcpdump attempted on: " + intf)
932 return main.FALSE
James Leec9cacaf2014-04-08 09:17:39 -0700933 elif i == 1:
Jon Hallf89c8552014-04-02 13:14:06 -0700934 main.log.info(self.name + ": tcpdump started on " + intf)
935 return main.TRUE
James Leec9cacaf2014-04-08 09:17:39 -0700936 elif i == 2:
Jon Hallf89c8552014-04-02 13:14:06 -0700937 main.log.error(self.name + ": tcpdump command timed out! Check interface name, given interface was: " + intf)
938 return main.FALSE
939 else:
940 main.log.error(self.name + ": tcpdump - unexpected response")
941 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700942 except pexpect.EOF:
943 main.log.error(self.name + ": EOF exception found")
944 main.log.error(self.name + ": " + self.handle.before)
945 main.cleanup()
946 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700947 except:
948 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
949 main.log.error( traceback.print_exc() )
950 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
951 main.cleanup()
952 main.exit()
953
admin4a58db92013-09-30 12:04:54 -0700954 def kill_tcpdump(self):
Jon Hallae05dc22014-04-16 10:56:28 -0700955 '''
956 Kills any tcpdump processes running
957 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700958 try:
959 self.handle.sendline("")
960 self.handle.expect("\$")
961 self.handle.sendline("sudo kill -9 `ps -ef | grep \"tcpdump -n\" | grep -v grep | awk '{print $2}'`")
Jon Hallae05dc22014-04-16 10:56:28 -0700962 except pexpect.EOF:
963 main.log.error(self.name + ": EOF exception found")
964 main.log.error(self.name + ": " + self.handle.before)
965 main.cleanup()
966 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700967 except:
968 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
969 main.log.error( traceback.print_exc() )
970 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
971 main.cleanup()
972 main.exit()
973
974 def find_host(self,RestIP,RestPort,RestAPI,hostIP):
975 retcode = 0
976 retswitch = []
977 retport = []
978 retmac = []
979 foundIP = []
980 try:
SeanCorcoran83a653a2014-04-22 15:03:18 -0700981 ##### device rest API is: 'host:8080/wm/onos/topology/switches/json' ###
Jon Hallf89c8552014-04-02 13:14:06 -0700982 url ="http://%s:%s%s" %(RestIP,RestPort,RestAPI)
983
984 try:
985 command = "curl -s %s" % (url)
986 result = os.popen(command).read()
987 parsedResult = json.loads(result)
988 # print parsedResult
989 except:
990 print "REST IF %s has issue" % command
991 parsedResult = ""
992
993 if parsedResult == "":
Jon Hallae05dc22014-04-16 10:56:28 -0700994 return (retcode, "Rest API has an error", retport, retmac)
Jon Hallf89c8552014-04-02 13:14:06 -0700995 else:
996 for switch in enumerate(parsedResult):
997 for port in enumerate(switch[1]['ports']):
998 if ( port[1]['devices'] != [] ):
999 try:
James Leec9cacaf2014-04-08 09:17:39 -07001000 foundIP = port[1]['devices'][0]['ipv4addresses'][0]['ipv4']
Jon Hallf89c8552014-04-02 13:14:06 -07001001 except:
1002 print "Error in detecting IP address."
1003 if foundIP == hostIP:
1004 retswitch.append(switch[1]['dpid'])
1005 retport.append(port[1]['desc'])
1006 retmac.append(port[1]['devices'][0]['mac'])
1007 retcode = retcode +1
1008 foundIP =''
1009 return(retcode, retswitch, retport, retmac)
Jon Hallae05dc22014-04-16 10:56:28 -07001010 except pexpect.EOF:
1011 main.log.error(self.name + ": EOF exception found")
1012 main.log.error(self.name + ": " + self.handle.before)
1013 main.cleanup()
1014 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -07001015 except:
1016 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1017 main.log.error( traceback.print_exc() )
1018 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1019 main.cleanup()
1020 main.exit()