admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | ''' |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 3 | Created on 31-May-2013 |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 4 | |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 5 | @author: Anil Kumar (anilkumar.s@paxterrasolutions.com) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 6 | |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 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. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 11 | |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 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. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 16 | |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 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/>. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 19 | |
| 20 | |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 21 | ''' |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 22 | import time |
| 23 | import pexpect |
| 24 | import struct, fcntl, os, sys, signal |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 25 | import re |
| 26 | import json |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 27 | import traceback |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 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): |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 37 | ''' |
| 38 | Creates ssh handle for ONOS. |
| 39 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 40 | try: |
| 41 | for key in connectargs: |
| 42 | vars(self)[key] = connectargs[key] |
| 43 | self.home = "~/ONOS" |
| 44 | for key in self.options: |
| 45 | if key == "home": |
| 46 | self.home = self.options['home'] |
| 47 | break |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 48 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 49 | |
| 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) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 52 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 53 | if self.handle: |
| 54 | #self.start() |
| 55 | #self.start_rest() |
| 56 | return self.handle |
| 57 | else : |
| 58 | main.log.info("NO ONOS HANDLE") |
| 59 | return main.FALSE |
| 60 | except: |
| 61 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 62 | main.log.error( traceback.print_exc() ) |
| 63 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 64 | main.cleanup() |
| 65 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 66 | |
| 67 | def start(self): |
| 68 | ''' |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 69 | Starts ONOS on remote machine. |
| 70 | Returns false if any errors were encountered. |
| 71 | ''' |
| 72 | try: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 73 | self.handle.sendline("") |
| 74 | self.handle.expect("\$") |
admin | f939f8b | 2014-04-03 17:22:56 -0700 | [diff] [blame] | 75 | self.handle.sendline(self.home + "/onos.sh core start") |
| 76 | self.handle.expect("onos.sh core start") |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 77 | i=self.handle.expect(["STARTED","FAILED"]) |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 78 | if i==0: |
| 79 | try: |
| 80 | self.handle.expect("\$", timeout=60) |
| 81 | main.log.info(self.name + ": ONOS Started ") |
| 82 | except: |
| 83 | main.log.info(self.name + ": ONOS NOT Started, stuck while waiting for it to start ") |
| 84 | return main.FALSE |
| 85 | return main.TRUE |
| 86 | elif i==1: |
admin | f939f8b | 2014-04-03 17:22:56 -0700 | [diff] [blame] | 87 | main.log.error(self.name + ": ONOS Failed ") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 88 | return main.FALSE |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 89 | raise |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 90 | main.log.error(self.name + ": ONOS expect script missed something... ") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 91 | return main.FALSE |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 92 | except: |
| 93 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 94 | main.log.error( traceback.print_exc() ) |
| 95 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 96 | main.cleanup() |
| 97 | main.exit() |
admin | e0ae820 | 2013-08-28 11:51:43 -0700 | [diff] [blame] | 98 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 99 | def start_rest(self): |
| 100 | ''' |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 101 | Starts the rest server on ONOS. |
| 102 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 103 | try: |
| 104 | response = self.execute(cmd= self.home + "/start-rest.sh start",prompt="\$",timeout=10) |
| 105 | if re.search("admin",response): |
| 106 | main.log.info(self.name + ": Rest Server Started Successfully") |
| 107 | time.sleep(5) |
| 108 | return main.TRUE |
| 109 | else : |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 110 | main.log.warn(self.name + ": Failed to start Rest Server") |
| 111 | return main.FALSE |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 112 | except: |
| 113 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 114 | main.log.error( traceback.print_exc() ) |
| 115 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 116 | main.cleanup() |
| 117 | main.exit() |
| 118 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 119 | def status(self): |
| 120 | ''' |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 121 | Called onos.sh core status and returns TRUE/FALSE accordingly |
| 122 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 123 | try: |
| 124 | self.execute(cmd="\n",prompt="\$",timeout=10) |
admin | f939f8b | 2014-04-03 17:22:56 -0700 | [diff] [blame] | 125 | response = self.execute(cmd= self.home + "/onos.sh core status ",prompt="\d+\sinstance\sof\sonos\srunning",timeout=10) |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 126 | self.execute(cmd="\n",prompt="\$",timeout=10) |
| 127 | if re.search("1\sinstance\sof\sonos\srunning",response): |
| 128 | return main.TRUE |
| 129 | elif re.search("0\sinstance\sof\sonos\srunning",response): |
| 130 | return main.FALSE |
| 131 | else : |
| 132 | main.log.info( self.name + " WARNING: status recieved unknown response") |
| 133 | return main.FALSE |
| 134 | except: |
| 135 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 136 | main.log.error( traceback.print_exc() ) |
| 137 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 138 | main.cleanup() |
| 139 | main.exit() |
| 140 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 141 | |
| 142 | def isup(self): |
| 143 | ''' |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 144 | A more complete check to see if ONOS is up and running properly. |
| 145 | First, it checks if the process is up. |
| 146 | Second, it reads the logs for "Exception: Connection refused" |
| 147 | Third, it makes sure the logs are actually moving. |
| 148 | returns TRUE/FALSE accordingly. |
| 149 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 150 | try: |
| 151 | self.execute(cmd="\n",prompt="\$",timeout=10) |
admin | f939f8b | 2014-04-03 17:22:56 -0700 | [diff] [blame] | 152 | response = self.execute(cmd= self.home + "/onos.sh core status ",prompt="running",timeout=10) |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 153 | self.execute(cmd="\n",prompt="\$",timeout=10) |
| 154 | tail1 = self.execute(cmd="tail " + self.home + "/onos-logs/onos.*.log",prompt="\$",timeout=10) |
| 155 | time.sleep(30) |
| 156 | self.execute(cmd="\n",prompt="\$",timeout=10) |
| 157 | tail2 = self.execute(cmd="tail " + self.home + "/onos-logs/onos.*.log",prompt="\$",timeout=10) |
| 158 | pattern = '(.*)1 instance(.*)' |
| 159 | pattern2 = '(.*)Exception: Connection refused(.*)' |
| 160 | # if utilities.assert_matches(expect=pattern,actual=response,onpass="ONOS process is running...",onfail="ONOS process not running..."): |
| 161 | |
| 162 | if re.search(pattern, response): |
| 163 | main.log.info(self.name + ": ONOS process is running...") |
| 164 | if tail1 == tail2: |
| 165 | main.log.error(self.name + ": ONOS is frozen...")#logs aren't moving |
| 166 | return main.FALSE |
| 167 | elif re.search( pattern2,tail1 ): |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 168 | main.log.info(self.name + ": Connection Refused found in onos log") |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 169 | return main.FALSE |
| 170 | elif re.search( pattern2,tail2 ): |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 171 | main.log.info(self.name + ": Connection Refused found in onos log") |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 172 | return main.FALSE |
| 173 | else: |
| 174 | main.log.info(self.name + ": Onos log is moving! It's looking good!") |
| 175 | return main.TRUE |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 176 | else: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 177 | main.log.error(self.name + ": ONOS process not running...") |
| 178 | return main.FALSE |
| 179 | except: |
| 180 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 181 | main.log.error( traceback.print_exc() ) |
| 182 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 183 | main.cleanup() |
| 184 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 185 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 186 | |
| 187 | |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 188 | def rest_status(self): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 189 | ''' |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 190 | Checks if the rest server is running. |
| 191 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 192 | try: |
| 193 | response = self.execute(cmd= self.home + "/start-rest.sh status ",prompt="running",timeout=10) |
| 194 | if re.search("rest\sserver\sis\srunning",response): |
| 195 | main.log.info(self.name + ": Rest Server is running") |
| 196 | elif re.search("rest\sserver\sis\snot\srunning",response): |
| 197 | main.log.warn(self.name + ": Rest Server is not Running") |
| 198 | else : |
| 199 | main.log.error(self.name + ": No response" +response) |
| 200 | self.execute(cmd="\n",prompt="\$",timeout=10) |
| 201 | |
| 202 | return response |
| 203 | except: |
| 204 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 205 | main.log.error( traceback.print_exc() ) |
| 206 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 207 | main.cleanup() |
| 208 | main.exit() |
| 209 | |
| 210 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 211 | def stop(self): |
| 212 | ''' |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 213 | Runs ./onos.sh core stop to stop ONOS |
| 214 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 215 | try: |
| 216 | self.handle.sendline("") |
| 217 | self.handle.expect("\$") |
admin | f939f8b | 2014-04-03 17:22:56 -0700 | [diff] [blame] | 218 | self.handle.sendline(self.home + "/onos.sh core stop") |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 219 | self.handle.expect("stop", 2) |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 220 | result = self.handle.before |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 221 | self.handle.expect("\$", 60) |
| 222 | if re.search("Killed", result): |
| 223 | main.log.info(self.name + ": ONOS Killed Successfully") |
| 224 | return main.TRUE |
| 225 | else : |
| 226 | main.log.warn(self.name + ": ONOS wasn't running") |
| 227 | return main.FALSE |
| 228 | except: |
| 229 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 230 | main.log.error( traceback.print_exc() ) |
| 231 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 232 | main.cleanup() |
| 233 | main.exit() |
| 234 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 235 | |
| 236 | def rest_stop(self): |
| 237 | ''' |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 238 | Runs ./start-rest.sh stop to stop ONOS rest server |
| 239 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 240 | try: |
| 241 | response = self.execute(cmd= self.home + "/start-rest.sh stop ",prompt="killing",timeout=10) |
| 242 | self.execute(cmd="\n",prompt="\$",timeout=10) |
| 243 | if re.search("killing", response): |
| 244 | main.log.info(self.name + ": Rest Server Stopped") |
| 245 | return main.TRUE |
| 246 | else : |
| 247 | main.log.error(self.name + ": Failed to Stop, Rest Server is not Running") |
| 248 | return main.FALSE |
| 249 | except: |
| 250 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 251 | main.log.error( traceback.print_exc() ) |
| 252 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 253 | main.cleanup() |
| 254 | main.exit() |
| 255 | |
| 256 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 257 | def disconnect(self): |
| 258 | ''' |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 259 | Called when Test is complete to disconnect the ONOS handle. |
| 260 | ''' |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 261 | response = '' |
| 262 | try: |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 263 | self.handle.sendline("exit") |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 264 | self.handle.expect("closed") |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 265 | except: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 266 | main.log.error(self.name + ": Connection failed to the host") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 267 | response = main.FALSE |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 268 | return response |
| 269 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 270 | def get_version(self): |
admin | 6845330 | 2013-12-16 15:40:04 -0800 | [diff] [blame] | 271 | ''' |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 272 | Writes the COMMIT number to the report to be parsed by Jenkins data collecter. |
| 273 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 274 | try: |
| 275 | self.handle.sendline("export TERM=xterm-256color") |
| 276 | self.handle.expect("xterm-256color") |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 277 | self.handle.expect("\$") |
admin | f939f8b | 2014-04-03 17:22:56 -0700 | [diff] [blame] | 278 | self.handle.sendline("cd " + self.home + "; git log -1 --pretty=fuller | grep -A 5 \"commit\"; cd \.\.") |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 279 | self.handle.expect("cd ..") |
| 280 | self.handle.expect("\$") |
| 281 | main.log.report(self.name +": \n"+ str(self.handle.before + self.handle.after)) |
| 282 | except: |
| 283 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 284 | main.log.error( traceback.print_exc() ) |
| 285 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 286 | main.cleanup() |
| 287 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 288 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 289 | def add_flow(self, testONip, user, password, flowDef): |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 290 | ''' |
| 291 | Copies the flowdef file from TestStation -> ONOS machine |
| 292 | Then runs ./add_flow.py to add the flows to ONOS |
| 293 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 294 | try: |
| 295 | main.log.info("Adding Flows...") |
| 296 | self.handle.sendline("scp %s@%s:%s /tmp/flowtmp" %(user,testONip,flowDef)) |
| 297 | i=self.handle.expect(['[pP]assword:', '100%', pexpect.TIMEOUT],30) |
| 298 | if(i==0): |
| 299 | self.handle.sendline("%s" %(password)) |
| 300 | self.handle.sendline("") |
| 301 | self.handle.expect("100%") |
| 302 | self.handle.expect("\$", 30) |
| 303 | self.handle.sendline(self.home + "/web/add_flow.py -m onos -f /tmp/flowtmp") |
| 304 | self.handle.expect("\$", 1000) |
| 305 | main.log.info("Flows added") |
| 306 | return main.TRUE |
| 307 | |
| 308 | elif(i==1): |
| 309 | self.handle.sendline("") |
| 310 | self.handle.expect("\$", 10) |
| 311 | self.handle.sendline( self.home + "/web/add_flow.py -m onos -f /tmp/flowtmp") |
| 312 | self.handle.expect("\$", 1000) |
| 313 | main.log.info("Flows added") |
| 314 | return main.TRUE |
| 315 | |
| 316 | elif(i==2): |
| 317 | main.log.error("Flow Def file SCP Timed out...") |
| 318 | return main.FALSE |
| 319 | |
| 320 | else: |
| 321 | main.log.error("Failed to add flows...") |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 322 | return main.FALSE |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 323 | except: |
| 324 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 325 | main.log.error( traceback.print_exc() ) |
| 326 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 327 | main.cleanup() |
| 328 | main.exit() |
| 329 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 330 | |
| 331 | def delete_flow(self, *delParams): |
| 332 | ''' |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 333 | Deletes a specific flow, a range of flows, or all flows. |
| 334 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 335 | try: |
| 336 | if len(delParams)==1: |
| 337 | if str(delParams[0])=="all": |
| 338 | main.log.info(self.name + ": Deleting ALL flows...") |
| 339 | #self.execute(cmd="~/ONOS/scripts/TestON_delete_flow.sh all",prompt="done",timeout=150) |
| 340 | self.handle.sendline(self.home + "/web/delete_flow.py all") |
| 341 | self.handle.expect("delete_flow") |
| 342 | self.handle.expect("\$",1000) |
| 343 | main.log.info(self.name + ": Flows deleted") |
| 344 | else: |
| 345 | main.log.info(self.name + ": Deleting flow "+str(delParams[0])+"...") |
| 346 | #self.execute(cmd="~/ONOS/scripts/TestON_delete_flow.sh "+str(delParams[0]),prompt="done",timeout=150) |
| 347 | #self.execute(cmd="\n",prompt="\$",timeout=60) |
| 348 | self.handle.sendline(self.home +"/web/delete_flow.py %d" % int(delParams[0])) |
| 349 | self.handle.expect("delete_flow") |
| 350 | self.handle.expect("\$",60) |
| 351 | main.log.info(self.name + ": Flow deleted") |
| 352 | elif len(delParams)==2: |
| 353 | main.log.info(self.name + ": Deleting flows "+str(delParams[0])+" through "+str(delParams[1])+"...") |
| 354 | #self.execute(cmd="~/ONOS/scripts/TestON_delete_flow.sh "+str(delParams[0])+" "+str(delParams[1]),prompt="done",timeout=150) |
| 355 | #self.execute(cmd="\n",prompt="\$",timeout=60) |
| 356 | self.handle.sendline(self.home + "/web/delete_flow.py %d %d" % (int(delParams[0]), int(delParams[1]))) |
| 357 | self.handle.expect("delete_flow") |
| 358 | self.handle.expect("\$",600) |
| 359 | main.log.info(self.name + ": Flows deleted") |
| 360 | except: |
| 361 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 362 | main.log.error( traceback.print_exc() ) |
| 363 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 364 | main.cleanup() |
| 365 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 366 | |
| 367 | def check_flow(self): |
| 368 | ''' |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 369 | Calls the ./get_flow.py all and checks: |
| 370 | - If each FlowPath has at least one FlowEntry |
| 371 | - That there are no "NOT"s found |
| 372 | returns TRUE/FALSE |
| 373 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 374 | try: |
| 375 | flowEntryDetect = 1 |
| 376 | count = 0 |
| 377 | self.handle.sendline("clear") |
| 378 | time.sleep(1) |
| 379 | self.handle.sendline(self.home + "/web/get_flow.py all") |
| 380 | self.handle.expect("get_flow") |
| 381 | while 1: |
| 382 | i=self.handle.expect(['FlowPath','FlowEntry','NOT','\$',pexpect.TIMEOUT],timeout=180) |
| 383 | if i==0: |
| 384 | count = count + 1 |
| 385 | if flowEntryDetect == 0: |
| 386 | main.log.info(self.name + ": FlowPath without FlowEntry") |
| 387 | return main.FALSE |
| 388 | else: |
| 389 | flowEntryDetect = 0 |
| 390 | elif i==1: |
| 391 | flowEntryDetect = 1 |
| 392 | elif i==2: |
| 393 | main.log.error(self.name + ": Found a NOT") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 394 | return main.FALSE |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 395 | elif i==3: |
| 396 | if count == 0: |
| 397 | main.log.info(self.name + ": There don't seem to be any flows here...") |
| 398 | return main.FALSE |
| 399 | else: |
| 400 | main.log.info(self.name + ": All flows pass") |
| 401 | main.log.info(self.name + ": Number of FlowPaths: "+str(count)) |
| 402 | return main.TRUE |
| 403 | elif i==4: |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 404 | main.log.error(self.name + ":Check_flow() - Command Timeout!") |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 405 | return main.FALSE |
| 406 | except: |
| 407 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 408 | main.log.error( traceback.print_exc() ) |
| 409 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 410 | main.cleanup() |
| 411 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 412 | |
| 413 | def get_flow(self, *flowParams): |
| 414 | ''' |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 415 | Returns verbose output of ./get_flow.py |
| 416 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 417 | try: |
| 418 | if len(flowParams)==1: |
| 419 | if str(flowParams[0])=="all": |
| 420 | self.execute(cmd="\n",prompt="\$",timeout=60) |
| 421 | main.log.info(self.name + ": Getting all flow data...") |
| 422 | data = self.execute(cmd=self.home + "/scripts/TestON_get_flow.sh all",prompt="done",timeout=150) |
| 423 | self.execute(cmd="\n",prompt="\$",timeout=60) |
| 424 | return data |
| 425 | else: |
| 426 | main.log.info(self.name + ": Retrieving flow "+str(flowParams[0])+" data...") |
| 427 | data = self.execute(cmd=self.home +"/scripts/TestON_get_flow.sh "+str(flowParams[0]),prompt="done",timeout=150) |
| 428 | self.execute(cmd="\n",prompt="\$",timeout=60) |
| 429 | return data |
| 430 | elif len(flowParams)==5: |
| 431 | main.log.info(self.name + ": Retrieving flow installer data...") |
| 432 | 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) |
| 433 | self.execute(cmd="\n",prompt="\$",timeout=60) |
| 434 | return data |
| 435 | elif len(flowParams)==4: |
| 436 | main.log.info(self.name + ": Retrieving flow endpoints...") |
| 437 | 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) |
| 438 | self.execute(cmd="\n",prompt="\$",timeout=60) |
| 439 | return data |
| 440 | except: |
| 441 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 442 | main.log.error( traceback.print_exc() ) |
| 443 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 444 | main.cleanup() |
| 445 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 446 | |
| 447 | |
| 448 | # http://localhost:8080/wm/core/topology/switches/all/json |
| 449 | # http://localhost:8080/wm/core/topology/links/json |
| 450 | # http://localhost:8080/wm/registry/controllers/json |
| 451 | # http://localhost:8080/wm/registry/switches/json" |
| 452 | |
| 453 | def get_json(self, url): |
| 454 | ''' |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 455 | Helper functions used to parse the json output of a rest call |
| 456 | ''' |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 457 | try: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 458 | try: |
| 459 | command = "curl -s %s" % (url) |
| 460 | result = os.popen(command).read() |
| 461 | parsedResult = json.loads(result) |
| 462 | except: |
| 463 | print "REST IF %s has issue" % command |
| 464 | parsedResult = "" |
| 465 | |
| 466 | if type(parsedResult) == 'dict' and parsedResult.has_key('code'): |
| 467 | print "REST %s returned code %s" % (command, parsedResult['code']) |
| 468 | parsedResult = "" |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 469 | return parsedResult |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 470 | except: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 471 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 472 | main.log.error( traceback.print_exc() ) |
| 473 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 474 | main.cleanup() |
| 475 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 476 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 477 | def check_switch(self,RestIP,correct_nr_switch, RestPort ="8080" ): |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 478 | ''' |
| 479 | Used by check_status |
| 480 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 481 | try: |
| 482 | buf = "" |
| 483 | retcode = 0 |
| 484 | #RestPort="8080" |
admin | f939f8b | 2014-04-03 17:22:56 -0700 | [diff] [blame] | 485 | url="http://%s:%s/wm/onos/topology/switches/json" % (RestIP, RestPort) |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 486 | parsedResult = self.get_json(url) |
| 487 | if parsedResult == "": |
| 488 | retcode = 1 |
| 489 | return (retcode, "Rest API has an issue") |
| 490 | url = "http://%s:%s/wm/onos/registry/switches/json" % (RestIP, RestPort) |
| 491 | registry = self.get_json(url) |
| 492 | |
| 493 | if registry == "": |
| 494 | retcode = 1 |
| 495 | return (retcode, "Rest API has an issue") |
| 496 | |
| 497 | cnt = 0 |
| 498 | active = 0 |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 499 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 500 | for s in parsedResult: |
| 501 | cnt += 1 |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 502 | if s['state'] == "ACTIVE": |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 503 | active += 1 |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 504 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 505 | buf += "switch: network %d : %d switches %d active\n" % (0+1, cnt, active) |
| 506 | if correct_nr_switch != cnt: |
| 507 | buf += "switch fail: network %d should have %d switches but has %d\n" % (1, correct_nr_switch, cnt) |
| 508 | retcode = 1 |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 509 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 510 | if correct_nr_switch != active: |
| 511 | buf += "switch fail: network %d should have %d active switches but has %d\n" % (1, correct_nr_switch, active) |
| 512 | retcode = 1 |
| 513 | |
| 514 | return (retcode, buf) |
| 515 | except: |
| 516 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 517 | main.log.error( traceback.print_exc() ) |
| 518 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 519 | main.cleanup() |
| 520 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 521 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 522 | def check_link(self,RestIP, nr_links, RestPort = "8080"): |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 523 | ''' |
| 524 | Used by check_status |
| 525 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 526 | try: |
| 527 | buf = "" |
| 528 | retcode = 0 |
| 529 | |
| 530 | url = "http://%s:%s/wm/onos/topology/links/json" % (RestIP, RestPort) |
| 531 | parsedResult = self.get_json(url) |
| 532 | |
| 533 | if parsedResult == "": |
| 534 | retcode = 1 |
| 535 | return (retcode, "Rest API has an issue") |
| 536 | |
| 537 | buf += "link: total %d links (correct : %d)\n" % (len(parsedResult), nr_links) |
| 538 | intra = 0 |
| 539 | interlink=0 |
| 540 | |
| 541 | for s in parsedResult: |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 542 | intra = intra + 1 |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 543 | |
| 544 | if intra != nr_links: |
| 545 | buf += "link fail\n" |
| 546 | retcode = 1 |
| 547 | |
| 548 | return (retcode, buf) |
| 549 | except: |
| 550 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 551 | main.log.error( traceback.print_exc() ) |
| 552 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 553 | main.cleanup() |
| 554 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 555 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 556 | def check_status_report(self, ip, numoswitch, numolink, port="8080"): |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 557 | ''' |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 558 | Checks the number of swithes & links that ONOS sees against the supplied values. |
| 559 | Writes to the report log. |
| 560 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 561 | try: |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 562 | main.log.info(self.name + ": Making some rest calls...") |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 563 | switch = self.check_switch(ip, int(numoswitch), port) |
| 564 | link = self.check_link(ip, int(numolink), port) |
| 565 | value = switch[0] |
| 566 | value += link[0] |
| 567 | main.log.report( self.name + ": \n-----\n%s%s-----\n" % ( switch[1], link[1]) ) |
| 568 | if value != 0: |
| 569 | return main.FALSE |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 570 | else: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 571 | # "PASS" |
| 572 | return main.TRUE |
| 573 | except: |
| 574 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 575 | main.log.error( traceback.print_exc() ) |
| 576 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 577 | main.cleanup() |
| 578 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 579 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 580 | def check_status(self, ip, numoswitch, numolink, port = "8080"): |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 581 | ''' |
| 582 | Checks the number of swithes & links that ONOS sees against the supplied values. |
| 583 | Writes to the main log. |
| 584 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 585 | try: |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 586 | main.log.info(self.name + ": Making some rest calls...") |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 587 | switch = self.check_switch(ip, int(numoswitch), port) |
| 588 | link = self.check_link(ip, int(numolink), port) |
| 589 | value = switch[0] |
| 590 | value += link[0] |
| 591 | main.log.info(self.name + ": \n-----\n%s%s-----\n" % ( switch[1], link[1]) ) |
| 592 | if value != 0: |
| 593 | return main.FALSE |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 594 | else: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 595 | # "PASS" |
| 596 | return main.TRUE |
| 597 | except: |
| 598 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 599 | main.log.error( traceback.print_exc() ) |
| 600 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 601 | main.cleanup() |
| 602 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 603 | |
| 604 | def drop_keyspace(self): |
| 605 | ''' |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 606 | Drops the ONOS keyspace |
| 607 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 608 | try: |
| 609 | self.handle.sendline(self.home + "/scripts/drop-keyspace.sh") |
| 610 | self.handle.expect("keyspace") |
| 611 | self.handle.sendline("") |
| 612 | self.handle.expect("\$") |
| 613 | self.handle.expect("\$") |
| 614 | main.log.info(self.name + ": Keyspace dropped") |
| 615 | except: |
| 616 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 617 | main.log.error( traceback.print_exc() ) |
| 618 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 619 | main.cleanup() |
| 620 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 621 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 622 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 623 | def check_for_no_exceptions(self): |
| 624 | ''' |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 625 | TODO: Rewrite |
| 626 | Used by CassndraCheck.py to scan ONOS logs for Exceptions |
| 627 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 628 | try: |
| 629 | self.handle.sendline("dsh 'grep Exception ~/ONOS/onos-logs/onos.*.log'") |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 630 | self.handle.expect("\$ dsh") |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 631 | self.handle.expect("\$") |
| 632 | output = self.handle.before |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 633 | main.log.info(self.name + ": " + output ) |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 634 | if re.search("Exception",output): |
| 635 | return main.FALSE |
| 636 | else : |
| 637 | return main.TRUE |
| 638 | except: |
| 639 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 640 | main.log.error( traceback.print_exc() ) |
| 641 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 642 | main.cleanup() |
| 643 | main.exit() |
| 644 | |
| 645 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 646 | def git_pull(self): |
| 647 | ''' |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 648 | Stops the ONOS, pulls the latest code, and builds with mvn. |
| 649 | Assumes that "git pull" works without login |
| 650 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 651 | try: |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 652 | main.log.info(self.name + ": Stopping ONOS") |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 653 | self.stop() |
| 654 | self.handle.sendline("cd " + self.home) |
| 655 | self.handle.expect("ONOS\$") |
| 656 | self.handle.sendline("git pull") |
| 657 | |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 658 | uptodate = 0 |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 659 | i=self.handle.expect(['fatal','Username\sfor\s(.*):\s','Unpacking\sobjects',pexpect.TIMEOUT,'Already up-to-date','Aborting'],timeout=180) |
| 660 | #debug |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 661 | #main.log.report(self.name +": \n"+"git pull response: " + str(self.handle.before) + str(self.handle.after)) |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 662 | if i==0: |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 663 | main.log.error(self.name + ": Git pull had some issue...") |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 664 | return main.FALSE |
| 665 | elif i==1: |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 666 | main.log.error(self.name + ": Git Pull Asking for username!!! BADD!") |
| 667 | return main.FALSE |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 668 | elif i==2: |
| 669 | main.log.info(self.name + ": Git Pull - pulling repository now") |
| 670 | self.handle.expect("ONOS\$", 120) |
| 671 | elif i==3: |
| 672 | main.log.error(self.name + ": Git Pull - TIMEOUT") |
| 673 | return main.FALSE |
| 674 | elif i==4: |
| 675 | main.log.info(self.name + ": Git Pull - Already up to date") |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 676 | uptodate = 1 |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 677 | elif i==5: |
| 678 | main.log.info(self.name + ": Git Pull - Aborting... Are there conflicting git files?") |
| 679 | return main.FALSE |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 680 | else: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 681 | main.log.error(self.name + ": Git Pull - Unexpected response, check for pull errors") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 682 | return main.FALSE |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 683 | |
| 684 | if uptodate == 0: |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 685 | main.log.info(self.name + ": mvn clean") |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 686 | self.handle.sendline("mvn clean") |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 687 | while 1: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 688 | i=self.handle.expect(['BUILD\sFAILURE','BUILD\sSUCCESS','ONOS\$',pexpect.TIMEOUT],timeout=30) |
| 689 | if i == 0: |
| 690 | main.log.error(self.name + ": Build failure!") |
| 691 | return main.FALSE |
| 692 | elif i == 1: |
| 693 | main.log.info(self.name + ": Build success!") |
| 694 | elif i == 2: |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 695 | main.log.info(self.name + ": Build complete") |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 696 | break; |
| 697 | elif i == 3: |
| 698 | main.log.error(self.name + ": mvn clean TIMEOUT!") |
| 699 | return main.FALSE |
| 700 | |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 701 | main.log.info(self.name + ": mvn compile") |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 702 | self.handle.sendline("mvn compile") |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 703 | while 1: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 704 | i=self.handle.expect(['BUILD\sFAILURE','BUILD\sSUCCESS','ONOS\$',pexpect.TIMEOUT],timeout=60) |
| 705 | if i == 0: |
| 706 | main.log.error(self.name + ": Build failure!") |
| 707 | return main.FALSE |
| 708 | elif i == 1: |
| 709 | main.log.info(self.name + ": Build success!") |
| 710 | return main.TRUE |
| 711 | elif i == 2: |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 712 | main.log.info(self.name + ": Build complete") |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 713 | return main.TRUE |
| 714 | elif i == 3: |
| 715 | main.log.error(self.name + ": mvn compile TIMEOUT!") |
| 716 | return main.FALSE |
| 717 | else: |
| 718 | pass |
| 719 | except: |
| 720 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 721 | main.log.error( traceback.print_exc() ) |
| 722 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 723 | main.cleanup() |
| 724 | main.exit() |
admin | 4a58db9 | 2013-09-30 12:04:54 -0700 | [diff] [blame] | 725 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 726 | |
| 727 | def tcpdump(self, intf = "eth0"): |
| 728 | try: |
| 729 | self.handle.sendline("") |
| 730 | self.handle.expect("\$") |
| 731 | self.handle.sendline("sudo tcpdump -n -i "+ intf + " -s0 -w onos-logs/tcpdump &") |
| 732 | i=self.handle.expect(['No\ssuch\device','listening\son',pexpect.TIMEOUT],timeout=10) |
| 733 | if i == 0: |
| 734 | main.log.error(self.name + ": tcpdump - No such device exists. tcpdump attempted on: " + intf) |
| 735 | return main.FALSE |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 736 | elif i == 1: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 737 | main.log.info(self.name + ": tcpdump started on " + intf) |
| 738 | return main.TRUE |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 739 | elif i == 2: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 740 | main.log.error(self.name + ": tcpdump command timed out! Check interface name, given interface was: " + intf) |
| 741 | return main.FALSE |
| 742 | else: |
| 743 | main.log.error(self.name + ": tcpdump - unexpected response") |
| 744 | return main.FALSE |
| 745 | except: |
| 746 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 747 | main.log.error( traceback.print_exc() ) |
| 748 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 749 | main.cleanup() |
| 750 | main.exit() |
| 751 | |
admin | 4a58db9 | 2013-09-30 12:04:54 -0700 | [diff] [blame] | 752 | def kill_tcpdump(self): |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 753 | try: |
| 754 | self.handle.sendline("") |
| 755 | self.handle.expect("\$") |
| 756 | self.handle.sendline("sudo kill -9 `ps -ef | grep \"tcpdump -n\" | grep -v grep | awk '{print $2}'`") |
| 757 | except: |
| 758 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 759 | main.log.error( traceback.print_exc() ) |
| 760 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 761 | main.cleanup() |
| 762 | main.exit() |
| 763 | |
| 764 | def find_host(self,RestIP,RestPort,RestAPI,hostIP): |
| 765 | retcode = 0 |
| 766 | retswitch = [] |
| 767 | retport = [] |
| 768 | retmac = [] |
| 769 | foundIP = [] |
| 770 | try: |
| 771 | ##### device rest API is: 'host:8080/wm/core/topology/switches/all/json' ### |
| 772 | url ="http://%s:%s%s" %(RestIP,RestPort,RestAPI) |
| 773 | |
| 774 | try: |
| 775 | command = "curl -s %s" % (url) |
| 776 | result = os.popen(command).read() |
| 777 | parsedResult = json.loads(result) |
| 778 | # print parsedResult |
| 779 | except: |
| 780 | print "REST IF %s has issue" % command |
| 781 | parsedResult = "" |
| 782 | |
| 783 | if parsedResult == "": |
| 784 | return (retcode, "Rest API has an error") |
| 785 | else: |
| 786 | for switch in enumerate(parsedResult): |
| 787 | for port in enumerate(switch[1]['ports']): |
| 788 | if ( port[1]['devices'] != [] ): |
| 789 | try: |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame^] | 790 | foundIP = port[1]['devices'][0]['ipv4addresses'][0]['ipv4'] |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 791 | except: |
| 792 | print "Error in detecting IP address." |
| 793 | if foundIP == hostIP: |
| 794 | retswitch.append(switch[1]['dpid']) |
| 795 | retport.append(port[1]['desc']) |
| 796 | retmac.append(port[1]['devices'][0]['mac']) |
| 797 | retcode = retcode +1 |
| 798 | foundIP ='' |
| 799 | return(retcode, retswitch, retport, retmac) |
| 800 | except: |
| 801 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 802 | main.log.error( traceback.print_exc() ) |
| 803 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 804 | main.cleanup() |
| 805 | main.exit() |