blob: 341b6938caaa84cd14a74e17d208b86214590954 [file] [log] [blame]
adminbae64d82013-08-01 10:50:15 -07001#!/usr/bin/env python
2'''
James Leec9cacaf2014-04-08 09:17:39 -07003Created on 31-May-2013
adminbae64d82013-08-01 10:50:15 -07004
James Leec9cacaf2014-04-08 09:17:39 -07005@author: Anil Kumar (anilkumar.s@paxterrasolutions.com)
adminbae64d82013-08-01 10:50:15 -07006
James Leec9cacaf2014-04-08 09:17:39 -07007TestON is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation, either version 2 of the License, or
10(at your option) any later version.
adminbae64d82013-08-01 10:50:15 -070011
James Leec9cacaf2014-04-08 09:17:39 -070012TestON is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
adminbae64d82013-08-01 10:50:15 -070016
James Leec9cacaf2014-04-08 09:17:39 -070017You should have received a copy of the GNU General Public License
18along with TestON. If not, see <http://www.gnu.org/licenses/>.
adminbae64d82013-08-01 10:50:15 -070019
20
James Leec9cacaf2014-04-08 09:17:39 -070021'''
adminbae64d82013-08-01 10:50:15 -070022import time
23import pexpect
24import struct, fcntl, os, sys, signal
adminbae64d82013-08-01 10:50:15 -070025import re
26import json
Jon Hallf89c8552014-04-02 13:14:06 -070027import traceback
adminbae64d82013-08-01 10:50:15 -070028sys.path.append("../")
29from drivers.common.clidriver import CLI
30
31class OnosCliDriver(CLI):
32
33 def __init__(self):
34 super(CLI, self).__init__()
35
36 def connect(self,**connectargs):
Jon Halld8dc5772014-04-08 16:26:29 -070037 '''
38 Creates ssh handle for ONOS.
39 '''
Jon Hallf89c8552014-04-02 13:14:06 -070040 try:
41 for key in connectargs:
admine0eeea22014-04-14 10:22:46 -070042 vars(self)[key] = connectargs[key]
Jon Hallf89c8552014-04-02 13:14:06 -070043 self.home = "~/ONOS"
44 for key in self.options:
admine0eeea22014-04-14 10:22:46 -070045 if key == "home":
46 self.home = self.options['home']
47 break
adminbae64d82013-08-01 10:50:15 -070048
Jon Hallf89c8552014-04-02 13:14:06 -070049
50 self.name = self.options['name']
51 self.handle = super(OnosCliDriver,self).connect(user_name = self.user_name, ip_address = self.ip_address,port = self.port, pwd = self.pwd, home = self.home)
adminbae64d82013-08-01 10:50:15 -070052
Jon Hallf89c8552014-04-02 13:14:06 -070053 if self.handle:
Jon Hallf89c8552014-04-02 13:14:06 -070054 return self.handle
55 else :
56 main.log.info("NO ONOS HANDLE")
57 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -070058 except pexpect.EOF:
59 main.log.error(self.name + ": EOF exception found")
60 main.log.error(self.name + ": " + self.handle.before)
61 main.cleanup()
62 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -070063 except:
64 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
65 main.log.error( traceback.print_exc() )
66 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
67 main.cleanup()
68 main.exit()
adminbae64d82013-08-01 10:50:15 -070069
70 def start(self):
Jon Halld8dc5772014-04-08 16:26:29 -070071 '''
72 Starts ONOS on remote machine.
73 Returns false if any errors were encountered.
74 '''
James Leec9cacaf2014-04-08 09:17:39 -070075 try:
Jon Hallf89c8552014-04-02 13:14:06 -070076 self.handle.sendline("")
Jon Hallae05dc22014-04-16 10:56:28 -070077 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
Jon Hall4a2b0482014-04-18 16:29:26 -070078 self.handle.sendline("cd "+self.home)
79 self.handle.sendline("./onos.sh core start")
Jon Hallae05dc22014-04-16 10:56:28 -070080 i=self.handle.expect(["STARTED","FAILED",pexpect.EOF,pexpect.TIMEOUT])
81 response = self.handle.before + str(self.handle.after)
Jon Hallf89c8552014-04-02 13:14:06 -070082 if i==0:
Jon Hallae05dc22014-04-16 10:56:28 -070083 j = self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT], timeout=60)
84 if re.search("Killed",response):
85 main.log.warn(self.name + ": Killed existing process")
86 if j==0:
Jon Hallf89c8552014-04-02 13:14:06 -070087 main.log.info(self.name + ": ONOS Started ")
Jon Hallae05dc22014-04-16 10:56:28 -070088 return main.TRUE
89 elif j==1:
90 main.log.error(self.name + ": EOF exception found")
91 main.log.error(self.name + ": " + self.handle.before)
92 main.cleanup()
93 main.exit()
94 elif j==2:
Jon Hallf89c8552014-04-02 13:14:06 -070095 main.log.info(self.name + ": ONOS NOT Started, stuck while waiting for it to start ")
96 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -070097 else:
98 main.log.warn(self.name +": Unexpected response in start")
99 return main.TRUE
Jon Hallf89c8552014-04-02 13:14:06 -0700100 elif i==1:
Jon Hallae05dc22014-04-16 10:56:28 -0700101 main.log.error(self.name + ": ONOS Failed to start")
adminbae64d82013-08-01 10:50:15 -0700102 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700103 elif i==2:
104 main.log.error(self.name + ": EOF exception found")
105 main.log.error(self.name + ": " + self.handle.before)
106 main.cleanup()
107 main.exit()
108 elif i==3:
109 main.log.error(self.name + ": ONOS timedout while starting")
110 return main.FALSE
111 else:
112 main.log.error(self.name + ": ONOS start expect script missed something... ")
adminbae64d82013-08-01 10:50:15 -0700113 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700114 except pexpect.EOF:
115 main.log.error(self.name + ": EOF exception found")
116 main.log.error(self.name + ": " + self.handle.before)
117 main.cleanup()
118 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700119 except:
120 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
121 main.log.error( traceback.print_exc() )
122 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
123 main.cleanup()
124 main.exit()
Jon Halle80ef8c2014-04-29 15:29:13 -0700125
126 def start_all(self):
127 '''
128 starts ZK, RC, and ONOS
129 '''
130 self.handle.sendline("cd "+self.home)
131 self.handle.sendline("./onos.sh start")
132 self.handle.expect("./onos.sh start")
133 self.handle.expect(["\$",pexpect.TIMEOUT])
134
135
136
adminbae64d82013-08-01 10:50:15 -0700137 def start_rest(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700138 '''
139 Starts the rest server on ONOS.
140 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700141 try:
Jon Hall4a2b0482014-04-18 16:29:26 -0700142 self.handle.sendline("cd "+self.home)
143 response = self.execute(cmd= "./start-rest.sh start",prompt="\$",timeout=10)
Jon Hallf89c8552014-04-02 13:14:06 -0700144 if re.search("admin",response):
145 main.log.info(self.name + ": Rest Server Started Successfully")
146 time.sleep(5)
147 return main.TRUE
148 else :
James Leec9cacaf2014-04-08 09:17:39 -0700149 main.log.warn(self.name + ": Failed to start Rest Server")
150 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700151 except pexpect.EOF:
152 main.log.error(self.name + ": EOF exception found")
153 main.log.error(self.name + ": " + self.handle.before)
154 main.cleanup()
155 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700156 except:
157 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
158 main.log.error( traceback.print_exc() )
159 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
160 main.cleanup()
161 main.exit()
162
adminbae64d82013-08-01 10:50:15 -0700163 def status(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700164 '''
165 Called onos.sh core status and returns TRUE/FALSE accordingly
166 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700167 try:
168 self.execute(cmd="\n",prompt="\$",timeout=10)
Jon Hall4a2b0482014-04-18 16:29:26 -0700169 self.handle.sendline("cd "+self.home)
170 response = self.execute(cmd="./onos.sh core status ",prompt="\d+\sinstance\sof\sonos\srunning",timeout=10)
Jon Hallf89c8552014-04-02 13:14:06 -0700171 self.execute(cmd="\n",prompt="\$",timeout=10)
172 if re.search("1\sinstance\sof\sonos\srunning",response):
173 return main.TRUE
174 elif re.search("0\sinstance\sof\sonos\srunning",response):
175 return main.FALSE
176 else :
177 main.log.info( self.name + " WARNING: status recieved unknown response")
178 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700179 except pexpect.EOF:
180 main.log.error(self.name + ": EOF exception found")
181 main.log.error(self.name + ": " + self.handle.before)
182 main.cleanup()
183 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700184 except:
185 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
186 main.log.error( traceback.print_exc() )
187 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
188 main.cleanup()
189 main.exit()
190
adminbae64d82013-08-01 10:50:15 -0700191
192 def isup(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700193 '''
194 A more complete check to see if ONOS is up and running properly.
195 First, it checks if the process is up.
196 Second, it reads the logs for "Exception: Connection refused"
197 Third, it makes sure the logs are actually moving.
198 returns TRUE/FALSE accordingly.
199 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700200 try:
201 self.execute(cmd="\n",prompt="\$",timeout=10)
Jon Hall4a2b0482014-04-18 16:29:26 -0700202 self.handle.sendline("cd "+self.home)
203 response = self.execute(cmd= "./onos.sh core status ",prompt="running",timeout=10)
Jon Hallf89c8552014-04-02 13:14:06 -0700204 self.execute(cmd="\n",prompt="\$",timeout=10)
205 tail1 = self.execute(cmd="tail " + self.home + "/onos-logs/onos.*.log",prompt="\$",timeout=10)
admine8c47d02014-06-03 11:59:16 -0700206 time.sleep(10)
Jon Hallf89c8552014-04-02 13:14:06 -0700207 self.execute(cmd="\n",prompt="\$",timeout=10)
208 tail2 = self.execute(cmd="tail " + self.home + "/onos-logs/onos.*.log",prompt="\$",timeout=10)
209 pattern = '(.*)1 instance(.*)'
Jon Halle80ef8c2014-04-29 15:29:13 -0700210 patternUp = 'Sending LLDP out'
Jon Hallf89c8552014-04-02 13:14:06 -0700211 pattern2 = '(.*)Exception: Connection refused(.*)'
212 # if utilities.assert_matches(expect=pattern,actual=response,onpass="ONOS process is running...",onfail="ONOS process not running..."):
213
214 if re.search(pattern, response):
Jon Halle80ef8c2014-04-29 15:29:13 -0700215 if re.search(patternUp,tail2):
216 main.log.info(self.name + ": ONOS process is running...")
217 if tail1 == tail2:
218 main.log.error(self.name + ": ONOS is frozen...")#logs aren't moving
219 return main.FALSE
220 elif re.search( pattern2,tail1 ):
221 main.log.info(self.name + ": Connection Refused found in onos log")
222 return main.FALSE
223 elif re.search( pattern2,tail2 ):
224 main.log.info(self.name + ": Connection Refused found in onos log")
225 return main.FALSE
226 else:
227 main.log.info(self.name + ": Onos log is moving! It's looking good!")
228 return main.TRUE
Jon Hall55c79662014-05-19 15:03:40 -0700229 else:
230 main.log.info(self.name + ": ONOS not yet sending out LLDP messages")
231 return main.FALSE
adminbae64d82013-08-01 10:50:15 -0700232 else:
Jon Hallf89c8552014-04-02 13:14:06 -0700233 main.log.error(self.name + ": ONOS process not running...")
234 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700235 except pexpect.EOF:
236 main.log.error(self.name + ": EOF exception found")
237 main.log.error(self.name + ": " + self.handle.before)
238 main.cleanup()
239 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700240 except:
241 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
242 main.log.error( traceback.print_exc() )
243 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
244 main.cleanup()
245 main.exit()
adminbae64d82013-08-01 10:50:15 -0700246
Jon Hallf89c8552014-04-02 13:14:06 -0700247
248
James Leec9cacaf2014-04-08 09:17:39 -0700249 def rest_status(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700250 '''
251 Checks if the rest server is running.
252 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700253 try:
254 response = self.execute(cmd= self.home + "/start-rest.sh status ",prompt="running",timeout=10)
255 if re.search("rest\sserver\sis\srunning",response):
256 main.log.info(self.name + ": Rest Server is running")
Jon Hallae05dc22014-04-16 10:56:28 -0700257 return main.TRUE
Jon Hallf89c8552014-04-02 13:14:06 -0700258 elif re.search("rest\sserver\sis\snot\srunning",response):
259 main.log.warn(self.name + ": Rest Server is not Running")
Jon Hallae05dc22014-04-16 10:56:28 -0700260 return main.FALSE
Jon Hallf89c8552014-04-02 13:14:06 -0700261 else :
262 main.log.error(self.name + ": No response" +response)
Jon Hallae05dc22014-04-16 10:56:28 -0700263 return main.FALSE
264 except pexpect.EOF:
265 main.log.error(self.name + ": EOF exception found")
266 main.log.error(self.name + ": " + self.handle.before)
267 main.cleanup()
268 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700269 except:
270 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
271 main.log.error( traceback.print_exc() )
272 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
273 main.cleanup()
274 main.exit()
admine8c47d02014-06-03 11:59:16 -0700275
276 def stop_all(self):
277 '''
278 Runs ./onos.sh stop
279 '''
280 try:
281 self.handle.sendline("")
282 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
283 self.handle.sendline("cd "+self.home)
284 self.handle.sendline("./onos.sh stop")
285 i=self.handle.expect(["Stop",pexpect.EOF,pexpect.TIMEOUT])
286 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT], 60)
287 result = self.handle.before
288 if re.search("Killed", result):
289 main.log.info(self.name + ": ONOS Killed Successfully")
290 return main.TRUE
291 else :
292 main.log.warn(self.name + ": ONOS wasn't running")
293 return main.FALSE
294 except pexpect.EOF:
295 main.log.error(self.name + ": EOF exception found")
296 main.log.error(self.name + ": " + self.handle.before)
297 main.cleanup()
298 main.exit()
299 except:
300 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
301 main.log.error( traceback.print_exc() )
302 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
303 main.cleanup()
304 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700305
306
adminbae64d82013-08-01 10:50:15 -0700307 def stop(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700308 '''
309 Runs ./onos.sh core stop to stop ONOS
310 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700311 try:
312 self.handle.sendline("")
Jon Hallae05dc22014-04-16 10:56:28 -0700313 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
Jon Hall4a2b0482014-04-18 16:29:26 -0700314 self.handle.sendline("cd "+self.home)
315 self.handle.sendline("./onos.sh core stop")
Jon Hallae05dc22014-04-16 10:56:28 -0700316 i=self.handle.expect(["Stop",pexpect.EOF,pexpect.TIMEOUT])
317 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT], 60)
James Leec9cacaf2014-04-08 09:17:39 -0700318 result = self.handle.before
Jon Hallf89c8552014-04-02 13:14:06 -0700319 if re.search("Killed", result):
320 main.log.info(self.name + ": ONOS Killed Successfully")
321 return main.TRUE
322 else :
323 main.log.warn(self.name + ": ONOS wasn't running")
324 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700325 except pexpect.EOF:
326 main.log.error(self.name + ": EOF exception found")
327 main.log.error(self.name + ": " + self.handle.before)
328 main.cleanup()
329 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700330 except:
331 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
332 main.log.error( traceback.print_exc() )
333 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
334 main.cleanup()
335 main.exit()
336
adminbae64d82013-08-01 10:50:15 -0700337
338 def rest_stop(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700339 '''
340 Runs ./start-rest.sh stop to stop ONOS rest server
341 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700342 try:
343 response = self.execute(cmd= self.home + "/start-rest.sh stop ",prompt="killing",timeout=10)
344 self.execute(cmd="\n",prompt="\$",timeout=10)
345 if re.search("killing", response):
346 main.log.info(self.name + ": Rest Server Stopped")
347 return main.TRUE
348 else :
349 main.log.error(self.name + ": Failed to Stop, Rest Server is not Running")
350 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700351 except pexpect.EOF:
352 main.log.error(self.name + ": EOF exception found")
353 main.log.error(self.name + ": " + self.handle.before)
354 main.cleanup()
355 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700356 except:
357 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
358 main.log.error( traceback.print_exc() )
359 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
360 main.cleanup()
361 main.exit()
362
363
adminbae64d82013-08-01 10:50:15 -0700364 def disconnect(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700365 '''
366 Called when Test is complete to disconnect the ONOS handle.
367 '''
adminaeedddd2013-08-02 15:14:15 -0700368 response = ''
369 try:
adminbae64d82013-08-01 10:50:15 -0700370 self.handle.sendline("exit")
adminaeedddd2013-08-02 15:14:15 -0700371 self.handle.expect("closed")
Jon Hallae05dc22014-04-16 10:56:28 -0700372 except pexpect.EOF:
373 main.log.error(self.name + ": EOF exception found")
374 main.log.error(self.name + ": " + self.handle.before)
James Leec9cacaf2014-04-08 09:17:39 -0700375 except:
Jon Hallf89c8552014-04-02 13:14:06 -0700376 main.log.error(self.name + ": Connection failed to the host")
adminbae64d82013-08-01 10:50:15 -0700377 response = main.FALSE
adminaeedddd2013-08-02 15:14:15 -0700378 return response
379
Jon Hall76f2c462014-04-17 11:37:15 -0700380 def print_version(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700381 '''
382 Writes the COMMIT number to the report to be parsed by Jenkins data collecter.
383 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700384 try:
385 self.handle.sendline("export TERM=xterm-256color")
386 self.handle.expect("xterm-256color")
James Leec9cacaf2014-04-08 09:17:39 -0700387 self.handle.expect("\$")
adminf939f8b2014-04-03 17:22:56 -0700388 self.handle.sendline("cd " + self.home + "; git log -1 --pretty=fuller | grep -A 5 \"commit\"; cd \.\.")
Jon Hallf89c8552014-04-02 13:14:06 -0700389 self.handle.expect("cd ..")
390 self.handle.expect("\$")
admine0eeea22014-04-14 10:22:46 -0700391 response=(self.name +": \n"+ str(self.handle.before + self.handle.after))
392 main.log.report(response)
Jon Hall76f2c462014-04-17 11:37:15 -0700393 except pexpect.EOF:
394 main.log.error(self.name + ": EOF exception found")
395 main.log.error(self.name + ": " + self.handle.before)
396 main.cleanup()
397 main.exit()
398 except:
399 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
400 main.log.error( traceback.print_exc() )
401 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
402 main.cleanup()
403 def get_version(self):
404 '''
405 Writes the COMMIT number to the report to be parsed by Jenkins data collecter.
406 '''
407 try:
408 self.handle.sendline("export TERM=xterm-256color")
409 self.handle.expect("xterm-256color")
410 self.handle.expect("\$")
411 self.handle.sendline("cd " + self.home + "; git log -1 --pretty=fuller | grep -A 5 \"commit\"; cd \.\.")
412 self.handle.expect("cd ..")
413 self.handle.expect("\$")
414 response=(self.name +": \n"+ str(self.handle.before + self.handle.after))
admine0eeea22014-04-14 10:22:46 -0700415 lines=response.splitlines()
416 for line in lines:
417 print line
418 return lines[2]
Jon Hallae05dc22014-04-16 10:56:28 -0700419 except pexpect.EOF:
420 main.log.error(self.name + ": EOF exception found")
421 main.log.error(self.name + ": " + self.handle.before)
422 main.cleanup()
423 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700424 except:
425 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
426 main.log.error( traceback.print_exc() )
427 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
428 main.cleanup()
429 main.exit()
adminbae64d82013-08-01 10:50:15 -0700430
adminc6cfc1c2014-04-21 13:55:21 -0700431 def ad_flow(self):
432 main.log.info("AD_FLOW RUNNING!!!!")
433 self.handle.sendline("cd "+self.home+ "/scripts")
434 self.handle.expect("scripts")
Jon Hall9c6e2c02014-05-02 10:18:53 -0700435 main.log.info("Adding flows")
adminc6cfc1c2014-04-21 13:55:21 -0700436 self.handle.sendline("./pyintents.py")
Jon Hall9c6e2c02014-05-02 10:18:53 -0700437 self.handle.expect(["$",pexpect.EOF,pexpect.TIMEOUT])
438 response = self.handle.before
adminc6cfc1c2014-04-21 13:55:21 -0700439 self.handle.sendline("cd "+self.home)
440 return main.TRUE
441
442 def rm_flow(self):
443 main.log.info("RM_FLOW RUNNING!!!")
444 self.handle.sendline("cd "+self.home+ "/scripts")
445 self.handle.expect("scripts")
Jon Hall9c6e2c02014-05-02 10:18:53 -0700446 main.log.info("Removing flows")
adminc6cfc1c2014-04-21 13:55:21 -0700447 self.handle.sendline("./rmpyintents.py")
Jon Hall9c6e2c02014-05-02 10:18:53 -0700448 self.handle.expect(["$",pexpect.EOF,pexpect.TIMEOUT])
449 response = self.handle.before
adminc6cfc1c2014-04-21 13:55:21 -0700450 self.handle.sendline("cd "+self.home)
451 return main.TRUE
452
Jon Hall265149f2014-04-25 13:39:52 -0700453 def purge(self):
454 main.log.info("Purging dead intents")
455 self.handle.sendline("cd "+self.home+ "/scripts")
456 self.handle.expect("scripts")
457 print("Purging Intents")
458 self.handle.sendline("./purgeintents.py")
459 self.handle.sendline("cd "+self.home)
460 return main.TRUE
adminc6cfc1c2014-04-21 13:55:21 -0700461
462
463
Jon Hall4a2b0482014-04-18 16:29:26 -0700464 def add_flow(self, testONip, user = "admin", password = "", flowDef = "/flowdef.txt"):
Jon Halld8dc5772014-04-08 16:26:29 -0700465 '''
466 Copies the flowdef file from TestStation -> ONOS machine
467 Then runs ./add_flow.py to add the flows to ONOS
468 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700469 try:
470 main.log.info("Adding Flows...")
471 self.handle.sendline("scp %s@%s:%s /tmp/flowtmp" %(user,testONip,flowDef))
472 i=self.handle.expect(['[pP]assword:', '100%', pexpect.TIMEOUT],30)
473 if(i==0):
474 self.handle.sendline("%s" %(password))
475 self.handle.sendline("")
476 self.handle.expect("100%")
477 self.handle.expect("\$", 30)
478 self.handle.sendline(self.home + "/web/add_flow.py -m onos -f /tmp/flowtmp")
479 self.handle.expect("\$", 1000)
480 main.log.info("Flows added")
481 return main.TRUE
482
483 elif(i==1):
484 self.handle.sendline("")
485 self.handle.expect("\$", 10)
486 self.handle.sendline( self.home + "/web/add_flow.py -m onos -f /tmp/flowtmp")
487 self.handle.expect("\$", 1000)
488 main.log.info("Flows added")
489 return main.TRUE
490
491 elif(i==2):
492 main.log.error("Flow Def file SCP Timed out...")
493 return main.FALSE
494
495 else:
496 main.log.error("Failed to add flows...")
James Leec9cacaf2014-04-08 09:17:39 -0700497 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700498 except pexpect.EOF:
499 main.log.error(self.name + ": EOF exception found")
500 main.log.error(self.name + ": " + self.handle.before)
501 main.cleanup()
502 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700503 except:
504 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
505 main.log.error( traceback.print_exc() )
506 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
507 main.cleanup()
508 main.exit()
509
adminbae64d82013-08-01 10:50:15 -0700510
511 def delete_flow(self, *delParams):
Jon Halld8dc5772014-04-08 16:26:29 -0700512 '''
513 Deletes a specific flow, a range of flows, or all flows.
514 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700515 try:
516 if len(delParams)==1:
517 if str(delParams[0])=="all":
518 main.log.info(self.name + ": Deleting ALL flows...")
519 #self.execute(cmd="~/ONOS/scripts/TestON_delete_flow.sh all",prompt="done",timeout=150)
520 self.handle.sendline(self.home + "/web/delete_flow.py all")
521 self.handle.expect("delete_flow")
522 self.handle.expect("\$",1000)
523 main.log.info(self.name + ": Flows deleted")
524 else:
525 main.log.info(self.name + ": Deleting flow "+str(delParams[0])+"...")
526 #self.execute(cmd="~/ONOS/scripts/TestON_delete_flow.sh "+str(delParams[0]),prompt="done",timeout=150)
527 #self.execute(cmd="\n",prompt="\$",timeout=60)
528 self.handle.sendline(self.home +"/web/delete_flow.py %d" % int(delParams[0]))
529 self.handle.expect("delete_flow")
530 self.handle.expect("\$",60)
531 main.log.info(self.name + ": Flow deleted")
532 elif len(delParams)==2:
533 main.log.info(self.name + ": Deleting flows "+str(delParams[0])+" through "+str(delParams[1])+"...")
534 #self.execute(cmd="~/ONOS/scripts/TestON_delete_flow.sh "+str(delParams[0])+" "+str(delParams[1]),prompt="done",timeout=150)
535 #self.execute(cmd="\n",prompt="\$",timeout=60)
536 self.handle.sendline(self.home + "/web/delete_flow.py %d %d" % (int(delParams[0]), int(delParams[1])))
537 self.handle.expect("delete_flow")
538 self.handle.expect("\$",600)
539 main.log.info(self.name + ": Flows deleted")
Jon Hallae05dc22014-04-16 10:56:28 -0700540 except pexpect.EOF:
541 main.log.error(self.name + ": EOF exception found")
542 main.log.error(self.name + ": " + self.handle.before)
543 main.cleanup()
544 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700545 except:
546 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
547 main.log.error( traceback.print_exc() )
548 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
549 main.cleanup()
550 main.exit()
adminbae64d82013-08-01 10:50:15 -0700551
552 def check_flow(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700553 '''
554 Calls the ./get_flow.py all and checks:
555 - If each FlowPath has at least one FlowEntry
556 - That there are no "NOT"s found
557 returns TRUE/FALSE
558 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700559 try:
560 flowEntryDetect = 1
561 count = 0
562 self.handle.sendline("clear")
563 time.sleep(1)
564 self.handle.sendline(self.home + "/web/get_flow.py all")
565 self.handle.expect("get_flow")
Jon Hall3bd7c792014-05-30 09:05:21 -0700566 for x in range(15):
Jon Hallf89c8552014-04-02 13:14:06 -0700567 i=self.handle.expect(['FlowPath','FlowEntry','NOT','\$',pexpect.TIMEOUT],timeout=180)
568 if i==0:
569 count = count + 1
570 if flowEntryDetect == 0:
571 main.log.info(self.name + ": FlowPath without FlowEntry")
572 return main.FALSE
573 else:
574 flowEntryDetect = 0
575 elif i==1:
576 flowEntryDetect = 1
577 elif i==2:
578 main.log.error(self.name + ": Found a NOT")
adminbae64d82013-08-01 10:50:15 -0700579 return main.FALSE
Jon Hallf89c8552014-04-02 13:14:06 -0700580 elif i==3:
581 if count == 0:
582 main.log.info(self.name + ": There don't seem to be any flows here...")
583 return main.FALSE
584 else:
585 main.log.info(self.name + ": All flows pass")
586 main.log.info(self.name + ": Number of FlowPaths: "+str(count))
587 return main.TRUE
588 elif i==4:
James Leec9cacaf2014-04-08 09:17:39 -0700589 main.log.error(self.name + ":Check_flow() - Command Timeout!")
Jon Hallf89c8552014-04-02 13:14:06 -0700590 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700591 except pexpect.EOF:
592 main.log.error(self.name + ": EOF exception found")
593 main.log.error(self.name + ": " + self.handle.before)
594 main.cleanup()
595 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700596 except:
597 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
598 main.log.error( traceback.print_exc() )
599 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
600 main.cleanup()
601 main.exit()
adminbae64d82013-08-01 10:50:15 -0700602
603 def get_flow(self, *flowParams):
Jon Halld8dc5772014-04-08 16:26:29 -0700604 '''
605 Returns verbose output of ./get_flow.py
606 '''
607 try:
608 if len(flowParams)==1:
609 if str(flowParams[0])=="all":
610 self.execute(cmd="\n",prompt="\$",timeout=60)
611 main.log.info(self.name + ": Getting all flow data...")
612 data = self.execute(cmd=self.home + "/scripts/TestON_get_flow.sh all",prompt="done",timeout=150)
613 self.execute(cmd="\n",prompt="\$",timeout=60)
614 return data
615 else:
616 main.log.info(self.name + ": Retrieving flow "+str(flowParams[0])+" data...")
617 data = self.execute(cmd=self.home +"/scripts/TestON_get_flow.sh "+str(flowParams[0]),prompt="done",timeout=150)
618 self.execute(cmd="\n",prompt="\$",timeout=60)
619 return data
620 elif len(flowParams)==5:
621 main.log.info(self.name + ": Retrieving flow installer data...")
622 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)
623 self.execute(cmd="\n",prompt="\$",timeout=60)
624 return data
625 elif len(flowParams)==4:
626 main.log.info(self.name + ": Retrieving flow endpoints...")
627 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)
628 self.execute(cmd="\n",prompt="\$",timeout=60)
629 return data
Jon Hallae05dc22014-04-16 10:56:28 -0700630 except pexpect.EOF:
631 main.log.error(self.name + ": EOF exception found")
632 main.log.error(self.name + ": " + self.handle.before)
633 main.cleanup()
634 main.exit()
Jon Halld8dc5772014-04-08 16:26:29 -0700635 except:
Jon Hallf89c8552014-04-02 13:14:06 -0700636 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
637 main.log.error( traceback.print_exc() )
638 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
639 main.cleanup()
640 main.exit()
adminbae64d82013-08-01 10:50:15 -0700641
642
Jon Hall2f42a672014-05-28 10:13:18 -0700643# http://localhost:8080/wm/onos/topology/switches
644# http://localhost:8080/wm/onos/topology/links
Jon Hall8060af02014-04-14 14:17:58 -0700645# http://localhost:8080/wm/onos/registry/controllers/json
646# http://localhost:8080/wm/onos/registry/switches/json"
adminbae64d82013-08-01 10:50:15 -0700647
648 def get_json(self, url):
Jon Halld8dc5772014-04-08 16:26:29 -0700649 '''
650 Helper functions used to parse the json output of a rest call
651 '''
adminbae64d82013-08-01 10:50:15 -0700652 try:
Jon Hallf89c8552014-04-02 13:14:06 -0700653 try:
654 command = "curl -s %s" % (url)
655 result = os.popen(command).read()
656 parsedResult = json.loads(result)
657 except:
658 print "REST IF %s has issue" % command
659 parsedResult = ""
660
661 if type(parsedResult) == 'dict' and parsedResult.has_key('code'):
662 print "REST %s returned code %s" % (command, parsedResult['code'])
663 parsedResult = ""
James Leec9cacaf2014-04-08 09:17:39 -0700664 return parsedResult
Jon Hallae05dc22014-04-16 10:56:28 -0700665 except pexpect.EOF:
666 main.log.error(self.name + ": EOF exception found")
667 main.log.error(self.name + ": " + self.handle.before)
668 main.cleanup()
669 main.exit()
adminbae64d82013-08-01 10:50:15 -0700670 except:
Jon Hallf89c8552014-04-02 13:14:06 -0700671 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
672 main.log.error( traceback.print_exc() )
673 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
674 main.cleanup()
675 main.exit()
adminbae64d82013-08-01 10:50:15 -0700676
Jon Hallf89c8552014-04-02 13:14:06 -0700677 def check_switch(self,RestIP,correct_nr_switch, RestPort ="8080" ):
Jon Halld8dc5772014-04-08 16:26:29 -0700678 '''
679 Used by check_status
680 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700681 try:
682 buf = ""
683 retcode = 0
admin2e131ab2014-05-28 10:03:42 -0700684 url="http://%s:%s/wm/onos/topology/switches" % (RestIP, RestPort)
Jon Hallf89c8552014-04-02 13:14:06 -0700685 parsedResult = self.get_json(url)
686 if parsedResult == "":
687 retcode = 1
688 return (retcode, "Rest API has an issue")
689 url = "http://%s:%s/wm/onos/registry/switches/json" % (RestIP, RestPort)
690 registry = self.get_json(url)
691
692 if registry == "":
693 retcode = 1
694 return (retcode, "Rest API has an issue")
695
696 cnt = 0
697 active = 0
adminbae64d82013-08-01 10:50:15 -0700698
Jon Hallf89c8552014-04-02 13:14:06 -0700699 for s in parsedResult:
700 cnt += 1
James Leec9cacaf2014-04-08 09:17:39 -0700701 if s['state'] == "ACTIVE":
Jon Hallf89c8552014-04-02 13:14:06 -0700702 active += 1
adminbae64d82013-08-01 10:50:15 -0700703
Jon Hallf89c8552014-04-02 13:14:06 -0700704 buf += "switch: network %d : %d switches %d active\n" % (0+1, cnt, active)
705 if correct_nr_switch != cnt:
706 buf += "switch fail: network %d should have %d switches but has %d\n" % (1, correct_nr_switch, cnt)
707 retcode = 1
adminbae64d82013-08-01 10:50:15 -0700708
Jon Hallf89c8552014-04-02 13:14:06 -0700709 if correct_nr_switch != active:
710 buf += "switch fail: network %d should have %d active switches but has %d\n" % (1, correct_nr_switch, active)
711 retcode = 1
712
713 return (retcode, buf)
Jon Hallae05dc22014-04-16 10:56:28 -0700714 except pexpect.EOF:
715 main.log.error(self.name + ": EOF exception found")
716 main.log.error(self.name + ": " + self.handle.before)
717 main.cleanup()
718 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700719 except:
720 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
721 main.log.error( traceback.print_exc() )
722 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
723 main.cleanup()
724 main.exit()
adminbae64d82013-08-01 10:50:15 -0700725
Jon Hallf89c8552014-04-02 13:14:06 -0700726 def check_link(self,RestIP, nr_links, RestPort = "8080"):
Jon Halld8dc5772014-04-08 16:26:29 -0700727 '''
728 Used by check_status
729 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700730 try:
731 buf = ""
732 retcode = 0
733
admin2e131ab2014-05-28 10:03:42 -0700734 url = "http://%s:%s/wm/onos/topology/links" % (RestIP, RestPort)
Jon Hallf89c8552014-04-02 13:14:06 -0700735 parsedResult = self.get_json(url)
736
737 if parsedResult == "":
738 retcode = 1
739 return (retcode, "Rest API has an issue")
740
741 buf += "link: total %d links (correct : %d)\n" % (len(parsedResult), nr_links)
742 intra = 0
743 interlink=0
744
745 for s in parsedResult:
James Leec9cacaf2014-04-08 09:17:39 -0700746 intra = intra + 1
Jon Hallf89c8552014-04-02 13:14:06 -0700747
748 if intra != nr_links:
749 buf += "link fail\n"
750 retcode = 1
751
752 return (retcode, buf)
Jon Hallae05dc22014-04-16 10:56:28 -0700753 except pexpect.EOF:
754 main.log.error(self.name + ": EOF exception found")
755 main.log.error(self.name + ": " + self.handle.before)
756 main.cleanup()
757 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700758 except:
759 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
760 main.log.error( traceback.print_exc() )
761 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
762 main.cleanup()
763 main.exit()
adminbae64d82013-08-01 10:50:15 -0700764
Jon Hallf89c8552014-04-02 13:14:06 -0700765 def check_status_report(self, ip, numoswitch, numolink, port="8080"):
Jon Halld8dc5772014-04-08 16:26:29 -0700766 '''
767 Checks the number of swithes & links that ONOS sees against the supplied values.
768 Writes to the report log.
769 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700770 try:
James Leec9cacaf2014-04-08 09:17:39 -0700771 main.log.info(self.name + ": Making some rest calls...")
Jon Hallf89c8552014-04-02 13:14:06 -0700772 switch = self.check_switch(ip, int(numoswitch), port)
773 link = self.check_link(ip, int(numolink), port)
774 value = switch[0]
775 value += link[0]
776 main.log.report( self.name + ": \n-----\n%s%s-----\n" % ( switch[1], link[1]) )
777 if value != 0:
778 return main.FALSE
James Leec9cacaf2014-04-08 09:17:39 -0700779 else:
Jon Hallf89c8552014-04-02 13:14:06 -0700780 # "PASS"
781 return main.TRUE
Jon Hallae05dc22014-04-16 10:56:28 -0700782 except pexpect.EOF:
783 main.log.error(self.name + ": EOF exception found")
784 main.log.error(self.name + ": " + self.handle.before)
785 main.cleanup()
786 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700787 except:
788 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
789 main.log.error( traceback.print_exc() )
790 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
791 main.cleanup()
792 main.exit()
adminbae64d82013-08-01 10:50:15 -0700793
Jon Hallf89c8552014-04-02 13:14:06 -0700794 def check_status(self, ip, numoswitch, numolink, port = "8080"):
Jon Halld8dc5772014-04-08 16:26:29 -0700795 '''
796 Checks the number of swithes & links that ONOS sees against the supplied values.
797 Writes to the main log.
798 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700799 try:
James Leec9cacaf2014-04-08 09:17:39 -0700800 main.log.info(self.name + ": Making some rest calls...")
Jon Hallf89c8552014-04-02 13:14:06 -0700801 switch = self.check_switch(ip, int(numoswitch), port)
802 link = self.check_link(ip, int(numolink), port)
803 value = switch[0]
804 value += link[0]
805 main.log.info(self.name + ": \n-----\n%s%s-----\n" % ( switch[1], link[1]) )
806 if value != 0:
807 return main.FALSE
James Leec9cacaf2014-04-08 09:17:39 -0700808 else:
Jon Hallf89c8552014-04-02 13:14:06 -0700809 # "PASS"
810 return main.TRUE
Jon Hallae05dc22014-04-16 10:56:28 -0700811 except pexpect.EOF:
812 main.log.error(self.name + ": EOF exception found")
813 main.log.error(self.name + ": " + self.handle.before)
814 main.cleanup()
815 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700816 except:
817 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
818 main.log.error( traceback.print_exc() )
819 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
820 main.cleanup()
821 main.exit()
adminbae64d82013-08-01 10:50:15 -0700822
adminbae64d82013-08-01 10:50:15 -0700823 def check_for_no_exceptions(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700824 '''
825 TODO: Rewrite
826 Used by CassndraCheck.py to scan ONOS logs for Exceptions
827 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700828 try:
829 self.handle.sendline("dsh 'grep Exception ~/ONOS/onos-logs/onos.*.log'")
James Leec9cacaf2014-04-08 09:17:39 -0700830 self.handle.expect("\$ dsh")
Jon Hallf89c8552014-04-02 13:14:06 -0700831 self.handle.expect("\$")
832 output = self.handle.before
James Leec9cacaf2014-04-08 09:17:39 -0700833 main.log.info(self.name + ": " + output )
Jon Hallf89c8552014-04-02 13:14:06 -0700834 if re.search("Exception",output):
835 return main.FALSE
836 else :
837 return main.TRUE
Jon Hallae05dc22014-04-16 10:56:28 -0700838 except pexpect.EOF:
839 main.log.error(self.name + ": EOF exception found")
840 main.log.error(self.name + ": " + self.handle.before)
841 main.cleanup()
842 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700843 except:
844 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
845 main.log.error( traceback.print_exc() )
846 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
847 main.cleanup()
848 main.exit()
849
850
admine0eeea22014-04-14 10:22:46 -0700851 def git_pull(self, comp1=""):
Jon Halld8dc5772014-04-08 16:26:29 -0700852 '''
Jon Halld8dc5772014-04-08 16:26:29 -0700853 Assumes that "git pull" works without login
admine0eeea22014-04-14 10:22:46 -0700854
855 This function will perform a git pull on the ONOS instance.
856 If used as git_pull("NODE") it will do git pull + NODE. This is
857 for the purpose of pulling from other nodes if necessary.
858
859 Otherwise, this function will perform a git pull in the
860 ONOS repository. If it has any problems, it will return main.ERROR
861 If it successfully does a git_pull, it will return a 1.
862 If it has no updates, it will return a 0.
863
Jon Halld8dc5772014-04-08 16:26:29 -0700864 '''
Jon Hallae05dc22014-04-16 10:56:28 -0700865 try:
Jon Halle80ef8c2014-04-29 15:29:13 -0700866 # main.log.info(self.name + ": Stopping ONOS")
867 #self.stop()
Jon Hallae05dc22014-04-16 10:56:28 -0700868 self.handle.sendline("cd " + self.home)
869 self.handle.expect("ONOS\$")
870 if comp1=="":
871 self.handle.sendline("git pull")
872 else:
873 self.handle.sendline("git pull " + comp1)
874
875 uptodate = 0
Jon Hall5a8aac62014-06-03 09:30:21 -0700876 i=self.handle.expect(['fatal','Username\sfor\s(.*):\s','Unpacking\sobjects',pexpect.TIMEOUT,'Already up-to-date','Aborting','You\sare\snot\scurrently\son\sa\sbranch'],timeout=1700)
Jon Hallae05dc22014-04-16 10:56:28 -0700877 #debug
878 #main.log.report(self.name +": \n"+"git pull response: " + str(self.handle.before) + str(self.handle.after))
879 if i==0:
880 main.log.error(self.name + ": Git pull had some issue...")
881 return main.ERROR
882 elif i==1:
883 main.log.error(self.name + ": Git Pull Asking for username!!! BADD!")
884 return main.ERROR
885 elif i==2:
886 main.log.info(self.name + ": Git Pull - pulling repository now")
887 self.handle.expect("ONOS\$", 120)
888 return 0
889 elif i==3:
890 main.log.error(self.name + ": Git Pull - TIMEOUT")
891 return main.ERROR
892 elif i==4:
893 main.log.info(self.name + ": Git Pull - Already up to date")
894 return 1
895 elif i==5:
896 main.log.info(self.name + ": Git Pull - Aborting... Are there conflicting git files?")
897 return main.ERROR
Jon Hall5a8aac62014-06-03 09:30:21 -0700898 elif i==6:
899 main.log.info(self.name + ": Git Pull - You are not currently on a branch so git pull failed!")
900 return main.ERROR
Jon Hallae05dc22014-04-16 10:56:28 -0700901 else:
902 main.log.error(self.name + ": Git Pull - Unexpected response, check for pull errors")
903 return main.ERROR
904 except pexpect.EOF:
905 main.log.error(self.name + ": EOF exception found")
906 main.log.error(self.name + ": " + self.handle.before)
907 main.cleanup()
908 main.exit()
909 except:
910 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
911 main.log.error( traceback.print_exc() )
912 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
913 main.cleanup()
914 main.exit()
admine0eeea22014-04-14 10:22:46 -0700915#********************************************************
916
917
admin7373a812014-04-16 09:49:02 -0700918 def git_compile(self):
Jon Hallae05dc22014-04-16 10:56:28 -0700919 '''
920 Compiles ONOS
921 First runs mvn clean then mvn compile
922 '''
923 try:
924 main.log.info(self.name + ": mvn clean")
admin8fc02822014-04-16 13:31:23 -0700925 self.handle.sendline("cd " + self.home)
Jon Hallae05dc22014-04-16 10:56:28 -0700926 self.handle.sendline("mvn clean")
927 while 1:
Jon Hall1636f942014-04-17 10:07:23 -0700928 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 -0700929 if i == 0:
Jon Hall1636f942014-04-17 10:07:23 -0700930 main.log.error(self.name + ":There is insufficient memory for the Java Runtime Environment to continue.")
Jon Hallae05dc22014-04-16 10:56:28 -0700931 return main.FALSE
932 elif i == 1:
Jon Hall1636f942014-04-17 10:07:23 -0700933 main.log.error(self.name + ": Clean failure!")
934 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700935 elif i == 2:
Jon Hall1636f942014-04-17 10:07:23 -0700936 main.log.info(self.name + ": Clean success!")
937 elif i == 3:
admin8fc02822014-04-16 13:31:23 -0700938 main.log.info(self.name + ": Clean complete")
Jon Hallae05dc22014-04-16 10:56:28 -0700939 break;
Jon Hall1636f942014-04-17 10:07:23 -0700940 elif i == 4:
Jon Hallae05dc22014-04-16 10:56:28 -0700941 main.log.error(self.name + ": mvn clean TIMEOUT!")
942 return main.FALSE
Jon Hall1636f942014-04-17 10:07:23 -0700943 else:
944 main.log.error(self.name + ": unexpected response from mvn clean")
945 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700946
947 main.log.info(self.name + ": mvn compile")
948 self.handle.sendline("mvn compile")
949 while 1:
Jon Hall1636f942014-04-17 10:07:23 -0700950 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 -0700951 if i == 0:
Jon Hall1636f942014-04-17 10:07:23 -0700952 main.log.error(self.name + ":There is insufficient memory for the Java Runtime Environment to continue.")
953 return main.FALSE
954 if i == 1:
Jon Hallae05dc22014-04-16 10:56:28 -0700955 main.log.error(self.name + ": Build failure!")
956 return main.FALSE
Jon Hall1636f942014-04-17 10:07:23 -0700957 elif i == 2:
Jon Hallae05dc22014-04-16 10:56:28 -0700958 main.log.info(self.name + ": Build success!")
Jon Hall1636f942014-04-17 10:07:23 -0700959 elif i == 3:
Jon Hallae05dc22014-04-16 10:56:28 -0700960 main.log.info(self.name + ": Build complete")
Jon Hall010f5412014-05-21 15:10:12 -0700961 self.handle.expect("\$", timeout=60)
Jon Hallae05dc22014-04-16 10:56:28 -0700962 return main.TRUE
Jon Hall1636f942014-04-17 10:07:23 -0700963 elif i == 4:
Jon Hallae05dc22014-04-16 10:56:28 -0700964 main.log.error(self.name + ": mvn compile TIMEOUT!")
965 return main.FALSE
966 else:
Jon Hall1636f942014-04-17 10:07:23 -0700967 main.log.error(self.name + ": unexpected response from mvn compile")
968 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700969 except pexpect.EOF:
970 main.log.error(self.name + ": EOF exception found")
971 main.log.error(self.name + ": " + self.handle.before)
972 main.cleanup()
973 main.exit()
974 except:
975 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
976 main.log.error( traceback.print_exc() )
977 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
978 main.cleanup()
979 main.exit()
admin4a58db92013-09-30 12:04:54 -0700980
Jon Hallf89c8552014-04-02 13:14:06 -0700981 def tcpdump(self, intf = "eth0"):
Jon Hallae05dc22014-04-16 10:56:28 -0700982 '''
983 Runs tpdump on an intferface and saves in onos-logs under the ONOS home directory
984 intf can be specified, or the default eth0 is used
985 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700986 try:
987 self.handle.sendline("")
988 self.handle.expect("\$")
Jon Hall26f316b2014-04-11 11:21:25 -0700989 self.handle.sendline("sudo tcpdump -n -i "+ intf + " -s0 -w " + self.home +"/onos-logs/tcpdump &")
Jon Hallf89c8552014-04-02 13:14:06 -0700990 i=self.handle.expect(['No\ssuch\device','listening\son',pexpect.TIMEOUT],timeout=10)
991 if i == 0:
992 main.log.error(self.name + ": tcpdump - No such device exists. tcpdump attempted on: " + intf)
993 return main.FALSE
James Leec9cacaf2014-04-08 09:17:39 -0700994 elif i == 1:
Jon Hallf89c8552014-04-02 13:14:06 -0700995 main.log.info(self.name + ": tcpdump started on " + intf)
996 return main.TRUE
James Leec9cacaf2014-04-08 09:17:39 -0700997 elif i == 2:
Jon Hallf89c8552014-04-02 13:14:06 -0700998 main.log.error(self.name + ": tcpdump command timed out! Check interface name, given interface was: " + intf)
999 return main.FALSE
1000 else:
1001 main.log.error(self.name + ": tcpdump - unexpected response")
1002 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -07001003 except pexpect.EOF:
1004 main.log.error(self.name + ": EOF exception found")
1005 main.log.error(self.name + ": " + self.handle.before)
1006 main.cleanup()
1007 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -07001008 except:
1009 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1010 main.log.error( traceback.print_exc() )
1011 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1012 main.cleanup()
1013 main.exit()
1014
admin4a58db92013-09-30 12:04:54 -07001015 def kill_tcpdump(self):
Jon Hallae05dc22014-04-16 10:56:28 -07001016 '''
1017 Kills any tcpdump processes running
1018 '''
Jon Hallf89c8552014-04-02 13:14:06 -07001019 try:
1020 self.handle.sendline("")
1021 self.handle.expect("\$")
1022 self.handle.sendline("sudo kill -9 `ps -ef | grep \"tcpdump -n\" | grep -v grep | awk '{print $2}'`")
Jon Hallae05dc22014-04-16 10:56:28 -07001023 except pexpect.EOF:
1024 main.log.error(self.name + ": EOF exception found")
1025 main.log.error(self.name + ": " + self.handle.before)
1026 main.cleanup()
1027 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -07001028 except:
1029 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1030 main.log.error( traceback.print_exc() )
1031 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1032 main.cleanup()
1033 main.exit()
1034
Jon Hallf15f7852014-05-20 10:37:23 -07001035 def find_host(self,RestIP,RestPort,RestAPI,hostMAC):
1036 retcode = 0 # number of devices found with given MAC
1037 retswitch = [] # Switch DPID's of devices found with MAC
1038 retport = [] # Switch port connected to to devices found with MAC
1039 foundHost = []
Jon Hallf89c8552014-04-02 13:14:06 -07001040 try:
Jon Hall2f42a672014-05-28 10:13:18 -07001041 ##### device rest API is: 'host:8080/wm/onos/topology/switches' ###
Jon Hallf89c8552014-04-02 13:14:06 -07001042 url ="http://%s:%s%s" %(RestIP,RestPort,RestAPI)
1043
1044 try:
1045 command = "curl -s %s" % (url)
1046 result = os.popen(command).read()
1047 parsedResult = json.loads(result)
1048 # print parsedResult
1049 except:
1050 print "REST IF %s has issue" % command
1051 parsedResult = ""
1052
1053 if parsedResult == "":
Jon Hallf15f7852014-05-20 10:37:23 -07001054 return (retcode, "Rest API has an error", retport)
Jon Hallf89c8552014-04-02 13:14:06 -07001055 else:
Jon Hallf15f7852014-05-20 10:37:23 -07001056 for host in enumerate(parsedResult):
1057 print host
1058 if (host[1] != []):
1059 try:
1060 foundHost = host[1]['mac']
1061 except:
1062 print "Error in detecting MAC address."
1063 print foundHost
1064 print hostMAC
1065 if foundHost == hostMAC:
1066 for switch in enumerate(host[1]['attachmentPoints']):
1067 retswitch.append(switch[1]['dpid'])
1068 retport.append(switch[1]['port'])
1069 retcode = retcode +1
1070 foundHost =''
1071 '''
Jon Hallf89c8552014-04-02 13:14:06 -07001072 for switch in enumerate(parsedResult):
1073 for port in enumerate(switch[1]['ports']):
1074 if ( port[1]['devices'] != [] ):
1075 try:
Jon Hallf15f7852014-05-20 10:37:23 -07001076 foundHost = port[1]['devices'][0]['ipv4addresses'][0]['ipv4']
Jon Hallf89c8552014-04-02 13:14:06 -07001077 except:
Jon Hallf15f7852014-05-20 10:37:23 -07001078 print "Error in detecting MAC address."
1079 if foundHost == hostMAC:
Jon Hallf89c8552014-04-02 13:14:06 -07001080 retswitch.append(switch[1]['dpid'])
1081 retport.append(port[1]['desc'])
1082 retmac.append(port[1]['devices'][0]['mac'])
1083 retcode = retcode +1
Jon Hallf15f7852014-05-20 10:37:23 -07001084 foundHost =''
1085 '''
1086 return(retcode, retswitch, retport)
Jon Hallae05dc22014-04-16 10:56:28 -07001087 except pexpect.EOF:
1088 main.log.error(self.name + ": EOF exception found")
1089 main.log.error(self.name + ": " + self.handle.before)
1090 main.cleanup()
1091 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -07001092 except:
1093 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1094 main.log.error( traceback.print_exc() )
1095 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1096 main.cleanup()
1097 main.exit()
SeanCorcoran29b70542014-05-14 14:53:42 -07001098
1099 def check_exceptions(self):
1100 '''
1101 Greps the logs for "xception"
1102 '''
1103 try:
1104 output = ''
1105 self.handle.sendline("")
Jon Halla78cf9a2014-05-16 10:49:30 -07001106 i = self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
1107 #main.log.warn("first expect response: " +str(i))
SeanCorcoran29b70542014-05-14 14:53:42 -07001108 self.handle.sendline("cd "+self.home+"/onos-logs")
Jon Halla78cf9a2014-05-16 10:49:30 -07001109 self.handle.sendline("grep \"xception\" *")
1110 i = self.handle.expect(["\*",pexpect.EOF,pexpect.TIMEOUT])
1111 #main.log.warn("second expect response: " +str(i))
1112 i = self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
1113 #main.log.warn("third expect response: " +str(i))
SeanCorcoran29b70542014-05-14 14:53:42 -07001114 response = self.handle.before
Jon Halla78cf9a2014-05-16 10:49:30 -07001115 count = 0
SeanCorcoran29b70542014-05-14 14:53:42 -07001116 for line in response.splitlines():
1117 if re.search("log:", line):
1118 output +="Exceptions found in " + line + "\n"
Jon Halla78cf9a2014-05-16 10:49:30 -07001119 count +=1
SeanCorcoran29b70542014-05-14 14:53:42 -07001120 elif re.search("std...:",line):
1121 output+="Exceptions found in " + line + "\n"
Jon Halla78cf9a2014-05-16 10:49:30 -07001122 count +=1
SeanCorcoran29b70542014-05-14 14:53:42 -07001123 else:
1124 pass
1125 #these should be the old logs
admin1723f1c2014-05-19 16:08:39 -07001126 main.log.report(str(count) + " Exceptions were found on "+self.name)
SeanCorcoran29b70542014-05-14 14:53:42 -07001127 return output
1128 except pexpect.TIMEOUT:
1129 main.log.error(self.name + ": Timeout exception found in check_exceptions function")
1130 except pexpect.EOF:
1131 main.log.error(self.name + ": EOF exception found")
1132 main.log.error(self.name + ": " + self.handle.before)
1133 main.cleanup()
1134 main.exit()
1135 except:
1136 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1137 main.log.error( traceback.print_exc() )
1138 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1139 main.cleanup()
1140 main.exit()