admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | ''' |
| 3 | Created on 31-May-2013 |
| 4 | |
| 5 | @author: Anil Kumar (anilkumar.s@paxterrasolutions.com) |
| 6 | |
| 7 | TestON is free software: you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License as published by |
| 9 | the Free Software Foundation, either version 2 of the License, or |
| 10 | (at your option) any later version. |
| 11 | |
| 12 | TestON is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
| 18 | along with TestON. If not, see <http://www.gnu.org/licenses/>. |
| 19 | |
| 20 | |
| 21 | ''' |
| 22 | import time |
| 23 | import pexpect |
| 24 | import struct, fcntl, os, sys, signal |
| 25 | import sys |
| 26 | import re |
| 27 | import json |
| 28 | sys.path.append("../") |
| 29 | from drivers.common.clidriver import CLI |
| 30 | |
| 31 | class OnosCliDriver(CLI): |
| 32 | |
| 33 | def __init__(self): |
| 34 | super(CLI, self).__init__() |
| 35 | |
| 36 | def connect(self,**connectargs): |
| 37 | ''' |
| 38 | Creates ssh handle for ONOS. |
| 39 | ''' |
| 40 | for key in connectargs: |
| 41 | vars(self)[key] = connectargs[key] |
| 42 | |
| 43 | |
| 44 | self.name = self.options['name'] |
| 45 | self.handle = super(OnosCliDriver,self).connect(user_name = self.user_name, ip_address = self.ip_address,port = self.port, pwd = self.pwd) |
| 46 | |
| 47 | if self.handle: |
| 48 | #self.start() |
| 49 | #self.start_rest() |
| 50 | return self.handle |
| 51 | else : |
| 52 | main.log.info("NO HANDLE") |
| 53 | return main.FALSE |
| 54 | |
| 55 | def start(self): |
| 56 | ''' |
| 57 | Starts ONOS on remote machine. |
| 58 | Returns false if any errors were encountered. |
| 59 | ''' |
| 60 | self.handle.sendline("") |
| 61 | self.handle.expect("\$") |
admin | 530b4c9 | 2013-08-14 16:54:35 -0700 | [diff] [blame] | 62 | self.handle.sendline("~/ONOS/start-onos.sh start") |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 63 | self.handle.expect("onos.sh start") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 64 | i=self.handle.expect(["Starting\sONOS\scontroller","Cassandra\sis\snot\srunning"]) |
| 65 | if i==0: |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 66 | try: |
admin | 530b4c9 | 2013-08-14 16:54:35 -0700 | [diff] [blame] | 67 | self.handle.expect("\$", timeout=60) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 68 | main.log.info("ONOS Started ") |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 69 | except: |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 70 | main.log.info("ONOS NOT Started, stuck while waiting for it to start ") |
| 71 | return main.FALSE |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 72 | return main.TRUE |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 73 | elif i==1: |
| 74 | main.log.error("ONOS didn't start because cassandra wasn't running.") |
| 75 | return main.FALSE |
| 76 | |
| 77 | main.log.error("ONOS expect script missed something... ") |
| 78 | return main.FALSE |
admin | e0ae820 | 2013-08-28 11:51:43 -0700 | [diff] [blame] | 79 | |
| 80 | def start_embedded(self): |
| 81 | self.handle.sendline("") |
| 82 | self.handle.expect("\$") |
| 83 | self.handle.sendline("~/ONOS/start-onos-embedded.sh start") |
| 84 | try: |
| 85 | self.handle.expect("start...") |
| 86 | main.log.info("Embedded ONOS started") |
| 87 | except: |
| 88 | main.log.info("Embedded ONOS failed to start") |
| 89 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 90 | def link_down(self, **linkParams): |
| 91 | ''' |
| 92 | Specifically used for the ONOS demo on the HW. |
| 93 | Should be replaced by actual switch drivers in the future. |
| 94 | ''' |
| 95 | args = utilities.parse_args(["SDPID","SPORT","DDPID","DPORT"], **linkParams) |
| 96 | sdpid = args["SDPID"] if args["SDPID"] != None else "00:00:00:00:ba:5e:ba:13" |
| 97 | sport = args["SPORT"] if args["SPORT"] != None else "22" |
| 98 | ddpid = args["DDPID"] if args["DDPID"] != None else "00:00:20:4e:7f:51:8a:35" |
| 99 | dport = args["DPORT"] if args["DPORT"] != None else "22" |
| 100 | |
| 101 | cmd = "curl -s 10.128.4.11:9000/gui/link/down/" + sdpid + "/" + sport + "/" + ddpid + "/" + dport + " > /tmp/log &" |
| 102 | os.popen( cmd ) |
| 103 | |
| 104 | def link_up(self, **linkParams): |
| 105 | ''' |
| 106 | Specifically used for the ONOS demo on the HW. |
| 107 | Should be replaced by actual switch drivers in the future. |
| 108 | ''' |
| 109 | args = utilities.parse_args(["SDPID","SPORT","DDPID","DPORT"], **linkParams) |
| 110 | sdpid = args["SDPID"] if args["SDPID"] != None else "00:00:00:00:ba:5e:ba:13" |
| 111 | sport = args["SPORT"] if args["SPORT"] != None else "22" |
| 112 | ddpid = args["DDPID"] if args["DDPID"] != None else "00:00:20:4e:7f:51:8a:35" |
| 113 | dport = args["DPORT"] if args["DPORT"] != None else "22" |
| 114 | |
| 115 | cmd = "curl -s 10.128.4.11:9000/gui/link/up/" + sdpid + "/" + sport + "/" + ddpid + "/" + dport + " > /tmp/log &" |
| 116 | os.popen( cmd ) |
| 117 | |
| 118 | def start_rest(self): |
| 119 | ''' |
| 120 | Starts the rest server on ONOS. |
| 121 | ''' |
admin | 530b4c9 | 2013-08-14 16:54:35 -0700 | [diff] [blame] | 122 | response = self.execute(cmd="~/ONOS/start-rest.sh start",prompt="\$",timeout=10) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 123 | if re.search("admin",response): |
| 124 | main.log.info("Rest Server Started Successfully") |
| 125 | time.sleep(5) |
| 126 | return main.TRUE |
| 127 | else : |
| 128 | main.log.warn("Failed to start Rest Server") |
| 129 | return main.FALSE |
| 130 | |
| 131 | def status(self): |
| 132 | ''' |
| 133 | Called start-onos.sh status and returns TRUE/FALSE accordingly |
| 134 | ''' |
| 135 | self.execute(cmd="\r",prompt="\$",timeout=10) |
| 136 | response = self.execute(cmd="~/ONOS/start-onos.sh status ",prompt="\d+\sinstance\sof\sonos\srunning",timeout=10) |
| 137 | self.execute(cmd="\r",prompt="\$",timeout=10) |
| 138 | if re.search("1\sinstance\sof\sonos\srunning",response): |
| 139 | return main.TRUE |
| 140 | elif re.search("0\sinstance\sof\sonos\srunning",response): |
| 141 | return main.FALSE |
| 142 | else : |
| 143 | return main.FALSE |
| 144 | |
| 145 | def isup(self): |
| 146 | ''' |
| 147 | A more complete check to see if ONOS is up and running properly. |
| 148 | First, it checks if the process is up. |
| 149 | Second, it reads the logs for "Exception: Connection refused" |
| 150 | Third, it makes sure the logs are actually moving. |
| 151 | returns TRUE/FALSE accordingly. |
| 152 | ''' |
| 153 | self.execute(cmd="\r",prompt="\$",timeout=10) |
| 154 | response = self.execute(cmd="~/ONOS/start-onos.sh status ",prompt="running",timeout=10) |
| 155 | self.execute(cmd="\r",prompt="\$",timeout=10) |
| 156 | tail1 = self.execute(cmd="tail ~/ONOS/onos-logs/onos.*.log",prompt="\$",timeout=10) |
admin | 0752993 | 2013-11-22 14:58:28 -0800 | [diff] [blame] | 157 | time.sleep(30) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 158 | self.execute(cmd="\r",prompt="\$",timeout=10) |
| 159 | tail2 = self.execute(cmd="tail ~/ONOS/onos-logs/onos.*.log",prompt="\$",timeout=10) |
| 160 | pattern = '(.*)1 instance(.*)' |
| 161 | pattern2 = '(.*)Exception: Connection refused(.*)' |
| 162 | if utilities.assert_matches(expect=pattern,actual=response,onpass="ONOS process is running...",onfail="ONOS process not running..."): |
| 163 | if tail1 == tail2: |
| 164 | main.log.error("ONOS is frozen...") |
| 165 | return main.FALSE |
| 166 | elif re.search( pattern2,tail1 ): |
| 167 | main.log.info("Connection Refused found in onos log") |
| 168 | return main.FALSE |
| 169 | elif re.search( pattern2,tail2 ): |
| 170 | main.log.info("Connection Refused found in onos log") |
| 171 | return main.FALSE |
| 172 | else: |
| 173 | main.log.info("Onos log is moving! It's looking good!") |
| 174 | return main.TRUE |
| 175 | else: |
| 176 | return main.FALSE |
| 177 | |
| 178 | |
| 179 | def rest_status(self): |
| 180 | ''' |
| 181 | Checks if the rest server is running. |
| 182 | ''' |
| 183 | response = self.execute(cmd="~/ONOS/start-rest.sh status ",prompt="running",timeout=10) |
| 184 | if re.search("rest\sserver\sis\srunning",response): |
| 185 | main.log.info("Rest Server is running") |
| 186 | elif re.search("rest\sserver\sis\snot\srunning",response): |
| 187 | main.log.warn("Rest Server is not Running") |
| 188 | else : |
| 189 | main.log.error("No response" +response) |
| 190 | self.execute(cmd="\r",prompt="\$",timeout=10) |
| 191 | |
| 192 | return response |
| 193 | |
| 194 | def stop(self): |
| 195 | ''' |
| 196 | Runs ./start-onos.sh stop to stop ONOS |
| 197 | ''' |
| 198 | self.handle.sendline("") |
| 199 | self.handle.expect("\$") |
admin | 530b4c9 | 2013-08-14 16:54:35 -0700 | [diff] [blame] | 200 | self.handle.sendline("~/ONOS/start-onos.sh stop") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 201 | self.handle.expect("stop", 2) |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 202 | result = self.handle.before |
admin | 530b4c9 | 2013-08-14 16:54:35 -0700 | [diff] [blame] | 203 | self.handle.expect("\$", 60) |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 204 | if re.search("Killed", result): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 205 | main.log.info("ONOS Killed Successfully") |
| 206 | return main.TRUE |
| 207 | else : |
| 208 | main.log.warn("ONOS wasn't running") |
| 209 | return main.FALSE |
| 210 | |
| 211 | def rest_stop(self): |
| 212 | ''' |
| 213 | Runs ./start-rest.sh stop to stop ONOS rest server |
| 214 | ''' |
| 215 | response = self.execute(cmd="~/ONOS/start-rest.sh stop ",prompt="killing",timeout=10) |
| 216 | self.execute(cmd="\r",prompt="\$",timeout=10) |
| 217 | if re.search("killing", response): |
| 218 | main.log.info("Rest Server Stopped") |
| 219 | return main.TRUE |
| 220 | else : |
| 221 | main.log.error("Failed to Stop, Rest Server is not Running") |
| 222 | return main.FALSE |
| 223 | |
| 224 | def disconnect(self): |
| 225 | ''' |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 226 | Called when Test is complete to disconnect the ONOS handle. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 227 | ''' |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 228 | response = '' |
| 229 | try: |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 230 | self.handle.sendline("exit") |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 231 | self.handle.expect("closed") |
| 232 | except: |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 233 | main.log.error("Connection failed to the host") |
| 234 | response = main.FALSE |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 235 | return response |
| 236 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 237 | def get_version(self): |
| 238 | ''' |
| 239 | Writes the COMMIT number to the report to be parsed by Jenkins data collecter. |
admin | 6845330 | 2013-12-16 15:40:04 -0800 | [diff] [blame] | 240 | ''' |
| 241 | self.handle.sendline("export TERM=xterm-256color") |
| 242 | self.handle.expect("xterm-256color") |
| 243 | self.handle.expect("\$") |
admin | 6e746e6 | 2013-12-18 12:01:46 -0800 | [diff] [blame] | 244 | self.handle.sendline("cd ONOS; git log -1 | grep -A 3 \"commit\"; cd \.\.") |
admin | 2a93ec2 | 2013-12-18 13:15:20 -0800 | [diff] [blame^] | 245 | self.handle.expect("cd ..") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 246 | self.handle.expect("\$") |
admin | 6845330 | 2013-12-16 15:40:04 -0800 | [diff] [blame] | 247 | main.log.report( str(self.handle.before + self.handle.after)) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 248 | |
| 249 | def add_flow(self, path): |
| 250 | ''' |
| 251 | Copies the flowdef file from TestStation -> ONOS machine |
| 252 | Then runs ./add_flow.py to add the flows to ONOS |
| 253 | ''' |
| 254 | main.log.info("Adding Flows...") |
| 255 | self.handle.sendline("scp admin@10.128.7.7:%s /tmp/flowtmp" % path) |
| 256 | self.handle.expect("100%") |
| 257 | self.handle.expect("\$", 30) |
| 258 | self.handle.sendline("~/ONOS/web/add_flow.py -m onos -f /tmp/flowtmp") |
| 259 | self.handle.expect("add_flow") |
| 260 | self.handle.expect("\$", 1000) |
| 261 | main.log.info("Flows added") |
| 262 | |
| 263 | def delete_flow(self, *delParams): |
| 264 | ''' |
| 265 | Deletes a specific flow, a range of flows, or all flows. |
| 266 | ''' |
| 267 | if len(delParams)==1: |
| 268 | if str(delParams[0])=="all": |
| 269 | main.log.info("Deleting ALL flows...") |
| 270 | #self.execute(cmd="~/ONOS/scripts/TestON_delete_flow.sh all",prompt="done",timeout=150) |
| 271 | self.handle.sendline("~/ONOS/web/delete_flow.py all") |
| 272 | self.handle.expect("delete_flow") |
| 273 | self.handle.expect("\$",1000) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 274 | main.log.info("Flows deleted") |
| 275 | else: |
| 276 | main.log.info("Deleting flow "+str(delParams[0])+"...") |
| 277 | #self.execute(cmd="~/ONOS/scripts/TestON_delete_flow.sh "+str(delParams[0]),prompt="done",timeout=150) |
| 278 | #self.execute(cmd="\n",prompt="\$",timeout=60) |
| 279 | self.handle.sendline("~/ONOS/web/delete_flow.py %d" % int(delParams[0])) |
| 280 | self.handle.expect("delete_flow") |
| 281 | self.handle.expect("\$",60) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 282 | main.log.info("Flow deleted") |
| 283 | elif len(delParams)==2: |
| 284 | main.log.info("Deleting flows "+str(delParams[0])+" through "+str(delParams[1])+"...") |
| 285 | #self.execute(cmd="~/ONOS/scripts/TestON_delete_flow.sh "+str(delParams[0])+" "+str(delParams[1]),prompt="done",timeout=150) |
| 286 | #self.execute(cmd="\n",prompt="\$",timeout=60) |
| 287 | self.handle.sendline("~/ONOS/web/delete_flow.py %d %d" % (int(delParams[0]), int(delParams[1]))) |
| 288 | self.handle.expect("delete_flow") |
| 289 | self.handle.expect("\$",600) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 290 | main.log.info("Flows deleted") |
| 291 | |
| 292 | def check_flow(self): |
| 293 | ''' |
| 294 | Calls the ./get_flow.py all and checks: |
| 295 | - If each FlowPath has at least one FlowEntry |
| 296 | - That there are no "NOT"s found |
| 297 | returns TRUE/FALSE |
| 298 | ''' |
| 299 | flowEntryDetect = 1 |
| 300 | count = 0 |
| 301 | self.handle.sendline("clear") |
| 302 | time.sleep(1) |
| 303 | self.handle.sendline("~/ONOS/web/get_flow.py all") |
| 304 | self.handle.expect("get_flow") |
| 305 | while 1: |
| 306 | i=self.handle.expect(['FlowPath','FlowEntry','NOT','\$',pexpect.TIMEOUT],timeout=180) |
| 307 | if i==0: |
| 308 | count = count + 1 |
| 309 | if flowEntryDetect == 0: |
| 310 | main.log.info("FlowPath without FlowEntry") |
| 311 | return main.FALSE |
| 312 | else: |
| 313 | flowEntryDetect = 0 |
| 314 | elif i==1: |
| 315 | flowEntryDetect = 1 |
| 316 | elif i==2: |
| 317 | main.log.error("Found a NOT") |
| 318 | return main.FALSE |
| 319 | elif i==3: |
| 320 | if count == 0: |
| 321 | main.log.info("There don't seem to be any flows here...") |
| 322 | return main.FALSE |
| 323 | else: |
| 324 | main.log.info("All flows pass") |
| 325 | main.log.info("Number of FlowPaths: "+str(count)) |
| 326 | return main.TRUE |
| 327 | elif i==4: |
| 328 | main.log.error("Command Timeout!") |
| 329 | return main.FALSE |
| 330 | |
| 331 | def get_flow(self, *flowParams): |
| 332 | ''' |
| 333 | Returns verbose output of ./get_flow.py |
| 334 | ''' |
| 335 | if len(flowParams)==1: |
| 336 | if str(flowParams[0])=="all": |
| 337 | self.execute(cmd="\n",prompt="\$",timeout=60) |
| 338 | main.log.info("Getting all flow data...") |
| 339 | data = self.execute(cmd="~/ONOS/scripts/TestON_get_flow.sh all",prompt="done",timeout=150) |
| 340 | self.execute(cmd="\n",prompt="\$",timeout=60) |
| 341 | return data |
| 342 | else: |
| 343 | main.log.info("Retrieving flow "+str(flowParams[0])+" data...") |
| 344 | data = self.execute(cmd="~/ONOS/scripts/TestON_get_flow.sh "+str(flowParams[0]),prompt="done",timeout=150) |
| 345 | self.execute(cmd="\n",prompt="\$",timeout=60) |
| 346 | return data |
| 347 | elif len(flowParams)==5: |
| 348 | main.log.info("Retrieving flow installer data...") |
| 349 | data = self.execute(cmd="~/ONOS/scripts/TestON_get_flow.sh "+str(flowParams[0])+" "+str(flowParams[1])+" "+str(flowParams[2])+" "+str(flowParams[3])+" "+str(flowParams[4]),prompt="done",timeout=150) |
| 350 | self.execute(cmd="\n",prompt="\$",timeout=60) |
| 351 | return data |
| 352 | elif len(flowParams)==4: |
| 353 | main.log.info("Retrieving flow endpoints...") |
| 354 | data = self.execute(cmd="~/ONOS/scripts/TestON_get_flow.sh "+str(flowParams[0])+" "+str(flowParams[1])+" "+str(flowParams[2])+" "+str(flowParams[3]),prompt="done",timeout=150) |
| 355 | self.execute(cmd="\n",prompt="\$",timeout=60) |
| 356 | return data |
| 357 | |
| 358 | |
| 359 | # http://localhost:8080/wm/core/topology/switches/all/json |
| 360 | # http://localhost:8080/wm/core/topology/links/json |
| 361 | # http://localhost:8080/wm/registry/controllers/json |
| 362 | # http://localhost:8080/wm/registry/switches/json" |
| 363 | |
| 364 | def get_json(self, url): |
| 365 | ''' |
| 366 | Helper functions used to parse the json output of a rest call |
| 367 | ''' |
| 368 | try: |
| 369 | command = "curl -s %s" % (url) |
| 370 | result = os.popen(command).read() |
| 371 | parsedResult = json.loads(result) |
| 372 | except: |
| 373 | print "REST IF %s has issue" % command |
| 374 | parsedResult = "" |
| 375 | |
| 376 | if type(parsedResult) == 'dict' and parsedResult.has_key('code'): |
| 377 | print "REST %s returned code %s" % (command, parsedResult['code']) |
| 378 | parsedResult = "" |
| 379 | return parsedResult |
| 380 | |
| 381 | def check_switch(self,RestIP,correct_nr_switch ): |
| 382 | ''' |
| 383 | Used by check_status |
| 384 | ''' |
| 385 | buf = "" |
| 386 | retcode = 0 |
| 387 | RestPort="8080" |
admin | 6845330 | 2013-12-16 15:40:04 -0800 | [diff] [blame] | 388 | url="http://%s:%s/wm/onos/topology/switches/all/json" % (RestIP, RestPort) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 389 | parsedResult = self.get_json(url) |
| 390 | if parsedResult == "": |
| 391 | retcode = 1 |
| 392 | return (retcode, "Rest API has an issue") |
admin | 6845330 | 2013-12-16 15:40:04 -0800 | [diff] [blame] | 393 | url = "http://%s:%s/wm/onos/registry/switches/json" % (RestIP, RestPort) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 394 | registry = self.get_json(url) |
| 395 | |
| 396 | if registry == "": |
| 397 | retcode = 1 |
| 398 | return (retcode, "Rest API has an issue") |
| 399 | |
| 400 | cnt = 0 |
| 401 | active = 0 |
| 402 | |
| 403 | for s in parsedResult: |
| 404 | cnt += 1 |
| 405 | if s['state'] == "ACTIVE": |
| 406 | active += 1 |
| 407 | |
| 408 | buf += "switch: network %d : %d switches %d active\n" % (0+1, cnt, active) |
| 409 | if correct_nr_switch != cnt: |
| 410 | buf += "switch fail: network %d should have %d switches but has %d\n" % (1, correct_nr_switch, cnt) |
| 411 | retcode = 1 |
| 412 | |
| 413 | if correct_nr_switch != active: |
| 414 | buf += "switch fail: network %d should have %d active switches but has %d\n" % (1, correct_nr_switch, active) |
| 415 | retcode = 1 |
| 416 | |
| 417 | return (retcode, buf) |
| 418 | |
| 419 | def check_link(self,RestIP, nr_links): |
| 420 | ''' |
| 421 | Used by check_status |
| 422 | ''' |
| 423 | RestPort = "8080" |
| 424 | buf = "" |
| 425 | retcode = 0 |
| 426 | |
admin | 6845330 | 2013-12-16 15:40:04 -0800 | [diff] [blame] | 427 | url = "http://%s:%s/wm/onos/topology/links/json" % (RestIP, RestPort) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 428 | parsedResult = self.get_json(url) |
| 429 | |
| 430 | if parsedResult == "": |
| 431 | retcode = 1 |
| 432 | return (retcode, "Rest API has an issue") |
| 433 | |
| 434 | buf += "link: total %d links (correct : %d)\n" % (len(parsedResult), nr_links) |
| 435 | intra = 0 |
| 436 | interlink=0 |
| 437 | |
| 438 | for s in parsedResult: |
| 439 | intra = intra + 1 |
| 440 | |
| 441 | if intra != nr_links: |
| 442 | buf += "link fail\n" |
| 443 | retcode = 1 |
| 444 | |
| 445 | return (retcode, buf) |
| 446 | |
| 447 | def check_status_report(self, ip, numoswitch, numolink): |
| 448 | ''' |
| 449 | Checks the number of swithes & links that ONOS sees against the supplied values. |
| 450 | Writes to the report log. |
| 451 | ''' |
| 452 | main.log.info("Making some rest calls...") |
| 453 | switch = self.check_switch(ip, int(numoswitch)) |
| 454 | link = self.check_link(ip, int(numolink)) |
| 455 | value = switch[0] |
| 456 | value += link[0] |
| 457 | main.log.report( "\n-----\n%s%s-----\n" % ( switch[1], link[1]) ) |
| 458 | if value != 0: |
| 459 | return 0 |
| 460 | else: |
| 461 | # "PASS" |
| 462 | return 1 |
| 463 | |
| 464 | def check_status(self, ip, numoswitch, numolink): |
| 465 | ''' |
| 466 | Checks the number of swithes & links that ONOS sees against the supplied values. |
| 467 | Writes to the main log. |
| 468 | ''' |
| 469 | main.log.info("Making some rest calls...") |
| 470 | switch = self.check_switch(ip, int(numoswitch)) |
| 471 | link = self.check_link(ip, int(numolink)) |
| 472 | value = switch[0] |
| 473 | value += link[0] |
| 474 | main.log.info( "\n-----\n%s%s-----\n" % ( switch[1], link[1]) ) |
| 475 | if value != 0: |
| 476 | return 0 |
| 477 | else: |
| 478 | # "PASS" |
| 479 | return 1 |
| 480 | |
| 481 | def drop_keyspace(self): |
| 482 | ''' |
| 483 | Drops the ONOS keyspace |
| 484 | ''' |
| 485 | self.handle.sendline("~/ONOS/scripts/test-drop-keyspace.sh") |
| 486 | self.handle.expect("keyspace") |
| 487 | self.handle.sendline("") |
| 488 | self.handle.expect("\$") |
| 489 | self.handle.expect("\$") |
admin | 0752993 | 2013-11-22 14:58:28 -0800 | [diff] [blame] | 490 | main.log.info("Keyspace dropped") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 491 | |
| 492 | def ctrl_none(self): |
| 493 | ''' |
| 494 | Points all the mininet swithces to no controllers |
| 495 | *NOTE will only work if CLUSTER is set up on ONOS nodes |
| 496 | ''' |
| 497 | self.execute(cmd="switch none", prompt="\$",timeout=10) |
| 498 | |
| 499 | def ctrl_one(self, ip): |
| 500 | ''' |
| 501 | Points all the mininet swithces to all controllers |
| 502 | *NOTE will only work if CLUSTER is set up on ONOS nodes |
| 503 | ''' |
| 504 | self.execute(cmd="switch one", prompt="\$",timeout=10) |
| 505 | |
| 506 | def check_for_no_exceptions(self): |
| 507 | ''' |
| 508 | Used by CassndraCheck.py to scan ONOS logs for Exceptions |
| 509 | ''' |
admin | 530b4c9 | 2013-08-14 16:54:35 -0700 | [diff] [blame] | 510 | self.handle.sendline("dsh 'grep Exception ~/ONOS/onos-logs/onos.*.log'") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 511 | self.handle.expect("\$ dsh") |
| 512 | self.handle.expect("\$") |
| 513 | output = self.handle.before |
| 514 | main.log.info( output ) |
| 515 | if re.search("Exception",output): |
| 516 | return main.FALSE |
| 517 | else : |
| 518 | return main.TRUE |
| 519 | |
| 520 | def git_pull(self): |
| 521 | ''' |
| 522 | Stops the ONOS, pulls the latest code, and builds with mvn. |
| 523 | Assumes that "git pull" works without login |
| 524 | ''' |
| 525 | main.log.info("Stopping onos") |
| 526 | self.stop() |
| 527 | self.handle.sendline("cd ~/ONOS") |
| 528 | self.handle.expect("ONOS\$") |
| 529 | self.handle.sendline("git pull") |
admin | 530b4c9 | 2013-08-14 16:54:35 -0700 | [diff] [blame] | 530 | |
| 531 | uptodate = 0 |
admin | 6845330 | 2013-12-16 15:40:04 -0800 | [diff] [blame] | 532 | i=self.handle.expect(['fatal','Username\sfor\s(.*):\s','Unpacking\sobjects',pexpect.TIMEOUT,'Already up-to-date','Aborting'],timeout=180) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 533 | if i==0: |
| 534 | main.log.error("Git pull had some issue...") |
| 535 | return main.FALSE |
| 536 | elif i==1: |
| 537 | main.log.error("Asking for username!!! BADD!") |
| 538 | return false |
| 539 | |
| 540 | self.handle.expect('Password\sfor\s(.*):\s') |
| 541 | j = self.handle.expect(['Unpacking\sobjects','Already up-to-date']) |
| 542 | if j == 0: |
| 543 | main.log.info("pulling repository now") |
| 544 | elif j == 1: |
| 545 | main.log.info("Up to date!") |
| 546 | else: |
| 547 | main.log.error("something went wrong") |
| 548 | return main.FALSE |
admin | 6845330 | 2013-12-16 15:40:04 -0800 | [diff] [blame] | 549 | self.handle.expect("ONOS\$", 120) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 550 | elif i==2: |
| 551 | main.log.info("pulling repository now") |
admin | 6845330 | 2013-12-16 15:40:04 -0800 | [diff] [blame] | 552 | self.handle.expect("ONOS\$", 120) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 553 | elif i==3: |
| 554 | main.log.error("TIMEOUT") |
| 555 | return main.FALSE |
| 556 | elif i==4: |
admin | 530b4c9 | 2013-08-14 16:54:35 -0700 | [diff] [blame] | 557 | main.log.info("Already up to date") |
| 558 | uptodate = 1 |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 559 | elif i==5: |
| 560 | main.log.info("Aborting... Are there conflicting git files?") |
| 561 | return main.FALSE |
| 562 | |
admin | 530b4c9 | 2013-08-14 16:54:35 -0700 | [diff] [blame] | 563 | ''' |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 564 | main.log.info("./setup-local-maven.sh") |
| 565 | self.handle.sendline("./setup-local-maven.sh") |
| 566 | self.handle.expect("local-maven.sh") |
| 567 | while 1: |
| 568 | i=self.handle.expect(['BUILD\sFAILURE','BUILD\sSUCCESS','ONOS\$',pexpect.TIMEOUT],timeout=90) |
| 569 | if i == 0: |
| 570 | main.log.error("Build failure!") |
| 571 | return main.FALSE |
| 572 | elif i == 1: |
| 573 | main.log.info("Build success!") |
| 574 | elif i == 2: |
| 575 | main.log.info("Build complete") |
| 576 | break; |
| 577 | elif i == 3: |
| 578 | main.log.error("TIMEOUT!") |
| 579 | return main.FALSE |
admin | 530b4c9 | 2013-08-14 16:54:35 -0700 | [diff] [blame] | 580 | ''' |
| 581 | if uptodate == 0: |
| 582 | main.log.info("mvn clean") |
| 583 | self.handle.sendline("mvn clean") |
| 584 | while 1: |
| 585 | i=self.handle.expect(['BUILD\sFAILURE','BUILD\sSUCCESS','ONOS\$',pexpect.TIMEOUT],timeout=30) |
| 586 | if i == 0: |
| 587 | main.log.error("Build failure!") |
| 588 | return main.FALSE |
| 589 | elif i == 1: |
| 590 | main.log.info("Build success!") |
| 591 | elif i == 2: |
| 592 | main.log.info("Build complete") |
| 593 | break; |
| 594 | elif i == 3: |
| 595 | main.log.error("TIMEOUT!") |
| 596 | return main.FALSE |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 597 | |
admin | 530b4c9 | 2013-08-14 16:54:35 -0700 | [diff] [blame] | 598 | main.log.info("mvn compile") |
| 599 | self.handle.sendline("mvn compile") |
| 600 | while 1: |
| 601 | i=self.handle.expect(['BUILD\sFAILURE','BUILD\sSUCCESS','ONOS\$',pexpect.TIMEOUT],timeout=30) |
| 602 | if i == 0: |
| 603 | main.log.error("Build failure!") |
| 604 | return main.FALSE |
| 605 | elif i == 1: |
| 606 | main.log.info("Build success!") |
| 607 | elif i == 2: |
| 608 | main.log.info("Build complete") |
| 609 | break; |
| 610 | elif i == 3: |
| 611 | main.log.error("TIMEOUT!") |
| 612 | return main.FALSE |
admin | 4a58db9 | 2013-09-30 12:04:54 -0700 | [diff] [blame] | 613 | |
| 614 | def tcpdump(self): |
| 615 | self.handle.sendline("") |
| 616 | self.handle.expect("\$") |
| 617 | self.handle.sendline("sudo tcpdump -n -i eth0 -s0 -w onos-logs/tcpdump &") |
| 618 | |
| 619 | def kill_tcpdump(self): |
| 620 | self.handle.sendline("") |
| 621 | self.handle.expect("\$") |
| 622 | self.handle.sendline("sudo kill -9 `ps -ef | grep \"tcpdump -n\" | grep -v grep | awk '{print $2}'`") |