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 | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 28 | import urllib2 |
| 29 | from urllib2 import URLError, HTTPError |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 30 | sys.path.append("../") |
| 31 | from drivers.common.clidriver import CLI |
| 32 | |
| 33 | class OnosCliDriver(CLI): |
| 34 | |
| 35 | def __init__(self): |
| 36 | super(CLI, self).__init__() |
| 37 | |
| 38 | def connect(self,**connectargs): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 39 | ''' |
| 40 | Creates ssh handle for ONOS. |
| 41 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 42 | try: |
| 43 | for key in connectargs: |
admin | e0eeea2 | 2014-04-14 10:22:46 -0700 | [diff] [blame] | 44 | vars(self)[key] = connectargs[key] |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 45 | self.home = "~/ONOS" |
| 46 | for key in self.options: |
admin | e0eeea2 | 2014-04-14 10:22:46 -0700 | [diff] [blame] | 47 | if key == "home": |
| 48 | self.home = self.options['home'] |
| 49 | break |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 50 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 51 | |
| 52 | self.name = self.options['name'] |
| 53 | self.handle = super(OnosCliDriver,self).connect(user_name = self.user_name, ip_address = self.ip_address,port = self.port, pwd = self.pwd, home = self.home) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 54 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 55 | if self.handle: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 56 | return self.handle |
| 57 | else : |
| 58 | main.log.info("NO ONOS HANDLE") |
| 59 | return main.FALSE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 60 | except pexpect.EOF: |
| 61 | main.log.error(self.name + ": EOF exception found") |
| 62 | main.log.error(self.name + ": " + self.handle.before) |
| 63 | main.cleanup() |
| 64 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 65 | except: |
| 66 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 67 | main.log.error( traceback.print_exc() ) |
| 68 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 69 | main.cleanup() |
| 70 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 71 | |
| 72 | def start(self): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 73 | ''' |
| 74 | Starts ONOS on remote machine. |
| 75 | Returns false if any errors were encountered. |
| 76 | ''' |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 77 | try: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 78 | self.handle.sendline("") |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 79 | self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT]) |
Jon Hall | 4a2b048 | 2014-04-18 16:29:26 -0700 | [diff] [blame] | 80 | self.handle.sendline("cd "+self.home) |
| 81 | self.handle.sendline("./onos.sh core start") |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 82 | i=self.handle.expect(["STARTED","FAILED",pexpect.EOF,pexpect.TIMEOUT]) |
| 83 | response = self.handle.before + str(self.handle.after) |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 84 | if i==0: |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 85 | j = self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT], timeout=60) |
| 86 | if re.search("Killed",response): |
| 87 | main.log.warn(self.name + ": Killed existing process") |
| 88 | if j==0: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 89 | main.log.info(self.name + ": ONOS Started ") |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 90 | return main.TRUE |
| 91 | elif j==1: |
| 92 | main.log.error(self.name + ": EOF exception found") |
| 93 | main.log.error(self.name + ": " + self.handle.before) |
| 94 | main.cleanup() |
| 95 | main.exit() |
| 96 | elif j==2: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 97 | main.log.info(self.name + ": ONOS NOT Started, stuck while waiting for it to start ") |
| 98 | return main.FALSE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 99 | else: |
| 100 | main.log.warn(self.name +": Unexpected response in start") |
| 101 | return main.TRUE |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 102 | elif i==1: |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 103 | main.log.error(self.name + ": ONOS Failed to start") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 104 | return main.FALSE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 105 | elif i==2: |
| 106 | main.log.error(self.name + ": EOF exception found") |
| 107 | main.log.error(self.name + ": " + self.handle.before) |
| 108 | main.cleanup() |
| 109 | main.exit() |
| 110 | elif i==3: |
| 111 | main.log.error(self.name + ": ONOS timedout while starting") |
| 112 | return main.FALSE |
| 113 | else: |
| 114 | main.log.error(self.name + ": ONOS start expect script missed something... ") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 115 | return main.FALSE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 116 | except pexpect.EOF: |
| 117 | main.log.error(self.name + ": EOF exception found") |
| 118 | main.log.error(self.name + ": " + self.handle.before) |
| 119 | main.cleanup() |
| 120 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 121 | except: |
| 122 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 123 | main.log.error( traceback.print_exc() ) |
| 124 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 125 | main.cleanup() |
| 126 | main.exit() |
Jon Hall | e80ef8c | 2014-04-29 15:29:13 -0700 | [diff] [blame] | 127 | |
| 128 | def start_all(self): |
| 129 | ''' |
| 130 | starts ZK, RC, and ONOS |
| 131 | ''' |
| 132 | self.handle.sendline("cd "+self.home) |
| 133 | self.handle.sendline("./onos.sh start") |
| 134 | self.handle.expect("./onos.sh start") |
| 135 | self.handle.expect(["\$",pexpect.TIMEOUT]) |
| 136 | |
| 137 | |
| 138 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 139 | def start_rest(self): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 140 | ''' |
| 141 | Starts the rest server on ONOS. |
| 142 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 143 | try: |
Jon Hall | 4a2b048 | 2014-04-18 16:29:26 -0700 | [diff] [blame] | 144 | self.handle.sendline("cd "+self.home) |
| 145 | response = self.execute(cmd= "./start-rest.sh start",prompt="\$",timeout=10) |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 146 | if re.search("admin",response): |
| 147 | main.log.info(self.name + ": Rest Server Started Successfully") |
| 148 | time.sleep(5) |
| 149 | return main.TRUE |
| 150 | else : |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 151 | main.log.warn(self.name + ": Failed to start Rest Server") |
| 152 | return main.FALSE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 153 | except pexpect.EOF: |
| 154 | main.log.error(self.name + ": EOF exception found") |
| 155 | main.log.error(self.name + ": " + self.handle.before) |
| 156 | main.cleanup() |
| 157 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 158 | except: |
| 159 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 160 | main.log.error( traceback.print_exc() ) |
| 161 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 162 | main.cleanup() |
| 163 | main.exit() |
| 164 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 165 | def status(self): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 166 | ''' |
| 167 | Called onos.sh core status and returns TRUE/FALSE accordingly |
| 168 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 169 | try: |
| 170 | self.execute(cmd="\n",prompt="\$",timeout=10) |
Jon Hall | 4a2b048 | 2014-04-18 16:29:26 -0700 | [diff] [blame] | 171 | self.handle.sendline("cd "+self.home) |
| 172 | response = self.execute(cmd="./onos.sh core status ",prompt="\d+\sinstance\sof\sonos\srunning",timeout=10) |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 173 | self.execute(cmd="\n",prompt="\$",timeout=10) |
| 174 | if re.search("1\sinstance\sof\sonos\srunning",response): |
| 175 | return main.TRUE |
| 176 | elif re.search("0\sinstance\sof\sonos\srunning",response): |
| 177 | return main.FALSE |
| 178 | else : |
| 179 | main.log.info( self.name + " WARNING: status recieved unknown response") |
| 180 | return main.FALSE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 181 | except pexpect.EOF: |
| 182 | main.log.error(self.name + ": EOF exception found") |
| 183 | main.log.error(self.name + ": " + self.handle.before) |
| 184 | main.cleanup() |
| 185 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 186 | except: |
| 187 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 188 | main.log.error( traceback.print_exc() ) |
| 189 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 190 | main.cleanup() |
| 191 | main.exit() |
| 192 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 193 | |
| 194 | def isup(self): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 195 | ''' |
| 196 | A more complete check to see if ONOS is up and running properly. |
| 197 | First, it checks if the process is up. |
| 198 | Second, it reads the logs for "Exception: Connection refused" |
| 199 | Third, it makes sure the logs are actually moving. |
| 200 | returns TRUE/FALSE accordingly. |
| 201 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 202 | try: |
| 203 | self.execute(cmd="\n",prompt="\$",timeout=10) |
Jon Hall | 4a2b048 | 2014-04-18 16:29:26 -0700 | [diff] [blame] | 204 | self.handle.sendline("cd "+self.home) |
| 205 | response = self.execute(cmd= "./onos.sh core status ",prompt="running",timeout=10) |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 206 | self.execute(cmd="\n",prompt="\$",timeout=10) |
| 207 | tail1 = self.execute(cmd="tail " + self.home + "/onos-logs/onos.*.log",prompt="\$",timeout=10) |
admin | e8c47d0 | 2014-06-03 11:59:16 -0700 | [diff] [blame] | 208 | time.sleep(10) |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 209 | self.execute(cmd="\n",prompt="\$",timeout=10) |
| 210 | tail2 = self.execute(cmd="tail " + self.home + "/onos-logs/onos.*.log",prompt="\$",timeout=10) |
| 211 | pattern = '(.*)1 instance(.*)' |
| 212 | pattern2 = '(.*)Exception: Connection refused(.*)' |
| 213 | # if utilities.assert_matches(expect=pattern,actual=response,onpass="ONOS process is running...",onfail="ONOS process not running..."): |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 214 | running = self.execute(cmd="cat "+self.home+"/onos-logs/onos.*.log | grep 'Sending LLDP out on all ports'",prompt="\$",timeout=10) |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 215 | if re.search(pattern, response): |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 216 | if running != "": |
Jon Hall | e80ef8c | 2014-04-29 15:29:13 -0700 | [diff] [blame] | 217 | main.log.info(self.name + ": ONOS process is running...") |
| 218 | if tail1 == tail2: |
| 219 | main.log.error(self.name + ": ONOS is frozen...")#logs aren't moving |
| 220 | return main.FALSE |
| 221 | elif re.search( pattern2,tail1 ): |
| 222 | main.log.info(self.name + ": Connection Refused found in onos log") |
| 223 | return main.FALSE |
| 224 | elif re.search( pattern2,tail2 ): |
| 225 | main.log.info(self.name + ": Connection Refused found in onos log") |
| 226 | return main.FALSE |
| 227 | else: |
| 228 | main.log.info(self.name + ": Onos log is moving! It's looking good!") |
| 229 | return main.TRUE |
Jon Hall | 55c7966 | 2014-05-19 15:03:40 -0700 | [diff] [blame] | 230 | else: |
| 231 | main.log.info(self.name + ": ONOS not yet sending out LLDP messages") |
| 232 | return main.FALSE |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 233 | else: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 234 | main.log.error(self.name + ": ONOS process not running...") |
| 235 | return main.FALSE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 236 | except pexpect.EOF: |
| 237 | main.log.error(self.name + ": EOF exception found") |
| 238 | main.log.error(self.name + ": " + self.handle.before) |
| 239 | main.cleanup() |
| 240 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 241 | except: |
| 242 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 243 | main.log.error( traceback.print_exc() ) |
| 244 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 245 | main.cleanup() |
| 246 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 247 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 248 | |
| 249 | |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 250 | def rest_status(self): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 251 | ''' |
| 252 | Checks if the rest server is running. |
| 253 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 254 | try: |
| 255 | response = self.execute(cmd= self.home + "/start-rest.sh status ",prompt="running",timeout=10) |
| 256 | if re.search("rest\sserver\sis\srunning",response): |
| 257 | main.log.info(self.name + ": Rest Server is running") |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 258 | return main.TRUE |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 259 | elif re.search("rest\sserver\sis\snot\srunning",response): |
| 260 | main.log.warn(self.name + ": Rest Server is not Running") |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 261 | return main.FALSE |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 262 | else : |
| 263 | main.log.error(self.name + ": No response" +response) |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 264 | return main.FALSE |
| 265 | except pexpect.EOF: |
| 266 | main.log.error(self.name + ": EOF exception found") |
| 267 | main.log.error(self.name + ": " + self.handle.before) |
| 268 | main.cleanup() |
| 269 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 270 | except: |
| 271 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 272 | main.log.error( traceback.print_exc() ) |
| 273 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 274 | main.cleanup() |
| 275 | main.exit() |
admin | e8c47d0 | 2014-06-03 11:59:16 -0700 | [diff] [blame] | 276 | |
| 277 | def stop_all(self): |
| 278 | ''' |
| 279 | Runs ./onos.sh stop |
| 280 | ''' |
| 281 | try: |
| 282 | self.handle.sendline("") |
| 283 | self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT]) |
| 284 | self.handle.sendline("cd "+self.home) |
| 285 | self.handle.sendline("./onos.sh stop") |
| 286 | i=self.handle.expect(["Stop",pexpect.EOF,pexpect.TIMEOUT]) |
| 287 | self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT], 60) |
| 288 | result = self.handle.before |
| 289 | if re.search("Killed", result): |
| 290 | main.log.info(self.name + ": ONOS Killed Successfully") |
| 291 | return main.TRUE |
| 292 | else : |
| 293 | main.log.warn(self.name + ": ONOS wasn't running") |
| 294 | return main.FALSE |
| 295 | except pexpect.EOF: |
| 296 | main.log.error(self.name + ": EOF exception found") |
| 297 | main.log.error(self.name + ": " + self.handle.before) |
| 298 | main.cleanup() |
| 299 | main.exit() |
| 300 | except: |
| 301 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 302 | main.log.error( traceback.print_exc() ) |
| 303 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 304 | main.cleanup() |
| 305 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 306 | |
| 307 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 308 | def stop(self): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 309 | ''' |
| 310 | Runs ./onos.sh core stop to stop ONOS |
| 311 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 312 | try: |
| 313 | self.handle.sendline("") |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 314 | self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT]) |
Jon Hall | 4a2b048 | 2014-04-18 16:29:26 -0700 | [diff] [blame] | 315 | self.handle.sendline("cd "+self.home) |
| 316 | self.handle.sendline("./onos.sh core stop") |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 317 | i=self.handle.expect(["Stop",pexpect.EOF,pexpect.TIMEOUT]) |
| 318 | self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT], 60) |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 319 | result = self.handle.before |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 320 | if re.search("Killed", result): |
| 321 | main.log.info(self.name + ": ONOS Killed Successfully") |
| 322 | return main.TRUE |
| 323 | else : |
| 324 | main.log.warn(self.name + ": ONOS wasn't running") |
| 325 | return main.FALSE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 326 | except pexpect.EOF: |
| 327 | main.log.error(self.name + ": EOF exception found") |
| 328 | main.log.error(self.name + ": " + self.handle.before) |
| 329 | main.cleanup() |
| 330 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 331 | except: |
| 332 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 333 | main.log.error( traceback.print_exc() ) |
| 334 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 335 | main.cleanup() |
| 336 | main.exit() |
| 337 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 338 | |
| 339 | def rest_stop(self): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 340 | ''' |
| 341 | Runs ./start-rest.sh stop to stop ONOS rest server |
| 342 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 343 | try: |
| 344 | response = self.execute(cmd= self.home + "/start-rest.sh stop ",prompt="killing",timeout=10) |
| 345 | self.execute(cmd="\n",prompt="\$",timeout=10) |
| 346 | if re.search("killing", response): |
| 347 | main.log.info(self.name + ": Rest Server Stopped") |
| 348 | return main.TRUE |
| 349 | else : |
| 350 | main.log.error(self.name + ": Failed to Stop, Rest Server is not Running") |
| 351 | return main.FALSE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 352 | except pexpect.EOF: |
| 353 | main.log.error(self.name + ": EOF exception found") |
| 354 | main.log.error(self.name + ": " + self.handle.before) |
| 355 | main.cleanup() |
| 356 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 357 | except: |
| 358 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 359 | main.log.error( traceback.print_exc() ) |
| 360 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 361 | main.cleanup() |
| 362 | main.exit() |
| 363 | |
| 364 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 365 | def disconnect(self): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 366 | ''' |
| 367 | Called when Test is complete to disconnect the ONOS handle. |
| 368 | ''' |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 369 | response = '' |
| 370 | try: |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 371 | self.handle.sendline("exit") |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 372 | self.handle.expect("closed") |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 373 | except pexpect.EOF: |
| 374 | main.log.error(self.name + ": EOF exception found") |
| 375 | main.log.error(self.name + ": " + self.handle.before) |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 376 | except: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 377 | main.log.error(self.name + ": Connection failed to the host") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 378 | response = main.FALSE |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 379 | return response |
| 380 | |
Jon Hall | 76f2c46 | 2014-04-17 11:37:15 -0700 | [diff] [blame] | 381 | def print_version(self): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 382 | ''' |
| 383 | Writes the COMMIT number to the report to be parsed by Jenkins data collecter. |
| 384 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 385 | try: |
| 386 | self.handle.sendline("export TERM=xterm-256color") |
| 387 | self.handle.expect("xterm-256color") |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 388 | self.handle.expect("\$") |
admin | f939f8b | 2014-04-03 17:22:56 -0700 | [diff] [blame] | 389 | 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] | 390 | self.handle.expect("cd ..") |
| 391 | self.handle.expect("\$") |
admin | e0eeea2 | 2014-04-14 10:22:46 -0700 | [diff] [blame] | 392 | response=(self.name +": \n"+ str(self.handle.before + self.handle.after)) |
| 393 | main.log.report(response) |
Jon Hall | 76f2c46 | 2014-04-17 11:37:15 -0700 | [diff] [blame] | 394 | except pexpect.EOF: |
| 395 | main.log.error(self.name + ": EOF exception found") |
| 396 | main.log.error(self.name + ": " + self.handle.before) |
| 397 | main.cleanup() |
| 398 | main.exit() |
| 399 | except: |
| 400 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 401 | main.log.error( traceback.print_exc() ) |
| 402 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 403 | main.cleanup() |
| 404 | def get_version(self): |
| 405 | ''' |
| 406 | Writes the COMMIT number to the report to be parsed by Jenkins data collecter. |
| 407 | ''' |
| 408 | try: |
| 409 | self.handle.sendline("export TERM=xterm-256color") |
| 410 | self.handle.expect("xterm-256color") |
| 411 | self.handle.expect("\$") |
| 412 | self.handle.sendline("cd " + self.home + "; git log -1 --pretty=fuller | grep -A 5 \"commit\"; cd \.\.") |
| 413 | self.handle.expect("cd ..") |
| 414 | self.handle.expect("\$") |
| 415 | response=(self.name +": \n"+ str(self.handle.before + self.handle.after)) |
admin | e0eeea2 | 2014-04-14 10:22:46 -0700 | [diff] [blame] | 416 | lines=response.splitlines() |
| 417 | for line in lines: |
| 418 | print line |
| 419 | return lines[2] |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 420 | except pexpect.EOF: |
| 421 | main.log.error(self.name + ": EOF exception found") |
| 422 | main.log.error(self.name + ": " + self.handle.before) |
| 423 | main.cleanup() |
| 424 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 425 | except: |
| 426 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 427 | main.log.error( traceback.print_exc() ) |
| 428 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 429 | main.cleanup() |
| 430 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 431 | |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 432 | |
admin | dc1c507 | 2014-06-24 15:57:19 -0700 | [diff] [blame^] | 433 | |
| 434 | #********************************************************************* |
| 435 | #********************************************************************* |
| 436 | # shortest_path is a command to find the shortest path between two |
| 437 | # switches. It is called using the IP, port, and source and |
| 438 | # destination dpids |
| 439 | #********************************************************************* |
| 440 | #********************************************************************* |
| 441 | |
| 442 | def shortest_path(self,ONOSIP,ONOSPort,srcDPID,dstDPID): |
| 443 | main.log.report("Finding the shortest Path between "+str(srcDPID) + " to " + str(dstDPID)) |
| 444 | url = "http://%s:%s/wm/onos/intent/path/switch/%s/shortest-path/%s"%(ONOSIP,ONOSPort,srcDPID,dstDPID) |
| 445 | parsed_result = [] |
| 446 | try: |
| 447 | response = urllib2.urlopen(url) |
| 448 | result = response.read() |
| 449 | response.close() |
| 450 | if len(result) != 0: |
| 451 | parsed_result = json.loads(result) |
| 452 | except HTTPError as exc: |
| 453 | print "ERROR:" |
| 454 | print " REST GET URL: %s" % url |
| 455 | # NOTE: exc.fp contains the object with the response payload |
| 456 | error_payload = json.loads(exc.fp.read()) |
| 457 | print " REST Error Code: %s" % (error_payload['code']) |
| 458 | print " REST Error Summary: %s" % (error_payload['summary']) |
| 459 | print " REST Error Description: %s" % (error_payload['formattedDescription']) |
| 460 | print " HTTP Error Code: %s" % exc.code |
| 461 | print " HTTP Error Reason: %s" % exc.reason |
| 462 | except URLError as exc: |
| 463 | print "ERROR:" |
| 464 | print " REST GET URL: %s" % url |
| 465 | print " URL Error Reason: %s" % exc.reason |
| 466 | |
| 467 | if len(parsed_result)==0: |
| 468 | return |
| 469 | result = json.dumps(parsed_result,indent=4) |
| 470 | print(str(result)) |
| 471 | return result |
| 472 | |
| 473 | |
| 474 | #********************************************************************* |
| 475 | #********************************************************************* |
| 476 | # show_intent is a command to show intents. |
| 477 | # Parameters include intentIP, intentPort, intentURL, and intent_id |
| 478 | # Based on the url, it will show either high or low intents |
| 479 | # If intent_id is left blank, it will show all high or all low intents |
| 480 | # Else it will show the intent with the id |
| 481 | #********************************************************************* |
| 482 | #********************************************************************* |
| 483 | |
| 484 | |
| 485 | |
| 486 | def show_intent(self,intentIP,intentPort=8080,intentURL="wm/onos/intent",intent_type="high",intent_id="all"): |
| 487 | main.log.report("Getting (an) intent(s)") |
| 488 | if intent_id=="all": |
| 489 | url = "http://%s:%s/%s/%s"%(intentIP,intentPort,intentURL,intent_type) |
| 490 | else: |
| 491 | url = "http://%s:%s/%s/%s/%s"%(intentIP,intentPort,intentURL,intent_type,intent_id) |
| 492 | print(url) |
| 493 | parsed_result = [] |
| 494 | try: |
| 495 | response = urllib2.urlopen(url) |
| 496 | result = response.read() |
| 497 | response.close() |
| 498 | if len(result) != 0: |
| 499 | parsed_result = json.loads(result) |
| 500 | except HTTPError as exc: |
| 501 | print "ERROR:" |
| 502 | print " REST GET URL: %s" % url |
| 503 | # NOTE: exc.fp contains the object with the response payload |
| 504 | error_payload = json.loads(exc.fp.read()) |
| 505 | print " REST Error Code: %s" % (error_payload['code']) |
| 506 | print " REST Error Summary: %s" % (error_payload['summary']) |
| 507 | print " REST Error Description: %s" % (error_payload['formattedDescription']) |
| 508 | print " HTTP Error Code: %s" % exc.code |
| 509 | print " HTTP Error Reason: %s" % exc.reason |
| 510 | return str(error_payload['code']) |
| 511 | except URLError as exc: |
| 512 | print "ERROR:" |
| 513 | print " REST GET URL: %s" % url |
| 514 | print " URL Error Reason: %s" % exc.reason |
| 515 | return str(error_payload['code']) |
| 516 | |
| 517 | if len(parsed_result)==0: |
| 518 | return |
| 519 | result = json.dumps(parsed_result,indent=4) |
| 520 | print(str(result)) |
| 521 | return result |
| 522 | |
| 523 | |
| 524 | #********************************************************************* |
| 525 | #********************************************************************* |
| 526 | # del_intent is to delete either all or some or one intents |
| 527 | # if intent_id is left blank, it will delete all intents |
| 528 | # else, intent_id should be of the form "intent_id=1,2,3" |
| 529 | #********************************************************************* |
| 530 | #********************************************************************* |
| 531 | |
| 532 | def del_intent(self,intentIP,intentPort=8080,intentURL="wm/onos/intent",intent_id="all"): |
| 533 | main.log.report("Deleting (an) intent(s)") |
| 534 | if intent_id=="all": |
| 535 | url = "http://%s:%s/%s/high"%(intentIP,intentPort,intentURL) |
| 536 | else: |
| 537 | url = "http://%s:%s/%s/high?%s"%(intentIP,intentPort,intentURL,intent_id) |
| 538 | |
| 539 | print(url) |
| 540 | |
| 541 | parsed_result = [] |
| 542 | try: |
| 543 | request = urllib2.Request(url) |
| 544 | request.get_method = lambda: 'DELETE' |
| 545 | response = urllib2.urlopen(request) |
| 546 | result = response.read() |
| 547 | response.close() |
| 548 | if len(result) != 0: |
| 549 | parsed_result = json.loads(result) |
| 550 | print(parsed_result) |
| 551 | except HTTPError as exc: |
| 552 | print "ERROR:" |
| 553 | print " REST DELETE URL: %s" % url |
| 554 | # NOTE: exc.fp contains the object with the response payload |
| 555 | error_payload = json.loads(exc.fp.read()) |
| 556 | print " REST Error Code: %s" % (error_payload['code']) |
| 557 | print " REST Error Summary: %s" % (error_payload['summary']) |
| 558 | print " REST Error Description: %s" % (error_payload['formattedDescription']) |
| 559 | print " HTTP Error Code: %s" % exc.code |
| 560 | print " HTTP Error Reason: %s" % exc.reason |
| 561 | except URLError as exc: |
| 562 | print "ERROR:" |
| 563 | print " REST DELETE URL: %s" % url |
| 564 | print " URL Error Reason: %s" % exc.reason |
| 565 | return result |
| 566 | |
| 567 | #********************************************************************* |
| 568 | #********************************************************************* |
| 569 | # add_intent will add a single intent by using dpids and macs. |
| 570 | #********************************************************************* |
| 571 | #********************************************************************* |
| 572 | |
| 573 | |
| 574 | def add_intent(self, intent_id,src_dpid,dst_dpid,src_mac,dst_mac,intentIP,intentPort=8080,intentURL="wm/onos/intent" , intent_type = 'SHORTEST_PATH', static_path=False, src_port=1,dst_port=1): |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 575 | "CLI command callback: set intent" |
| 576 | |
| 577 | intents = [] |
| 578 | oper = {} |
| 579 | # Create the POST payload |
| 580 | oper['intentId'] = intent_id |
| 581 | oper['intentType'] = intent_type # XXX: Hardcoded |
| 582 | oper['staticPath'] = static_path # XXX: Hardcoded |
| 583 | oper['srcSwitchDpid'] = src_dpid |
| 584 | oper['srcSwitchPort'] = src_port |
| 585 | oper['dstSwitchDpid'] = dst_dpid |
| 586 | oper['dstSwitchPort'] = dst_port |
| 587 | oper['matchSrcMac'] = src_mac |
| 588 | oper['matchDstMac'] = dst_mac |
| 589 | intents.append(oper) |
admin | dc1c507 | 2014-06-24 15:57:19 -0700 | [diff] [blame^] | 590 | url = "http://%s:%s/%s/high"%(intentIP,intentPort,intentURL) |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 591 | parsed_result = [] |
| 592 | data_json = json.dumps(intents) |
| 593 | try: |
| 594 | request = urllib2.Request(url,data_json) |
| 595 | request.add_header("Content-Type", "application/json") |
| 596 | response=urllib2.urlopen(request) |
| 597 | result = response.read() |
| 598 | response.close() |
| 599 | if len(result) != 0: |
| 600 | parsed_result = json.loads(result) |
| 601 | except HTTPError as exc: |
| 602 | print "ERROR:" |
| 603 | print " REST GET URL: %s" % url |
| 604 | # NOTE: exc.fp contains the object with the response payload |
| 605 | error_payload = json.loads(exc.fp.read()) |
| 606 | print " REST Error Code: %s" % (error_payload['code']) |
| 607 | print " REST Error Summary: %s" % (error_payload['summary']) |
| 608 | print " REST Error Description: %s" % (error_payload['formattedDescription']) |
| 609 | print " HTTP Error Code: %s" % exc.code |
| 610 | print " HTTP Error Reason: %s" % exc.reason |
| 611 | except URLError as exc: |
| 612 | print "ERROR:" |
| 613 | print " REST GET URL: %s" % url |
| 614 | print " URL Error Reason: %s" % exc.reason |
admin | dc1c507 | 2014-06-24 15:57:19 -0700 | [diff] [blame^] | 615 | return result |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 616 | |
| 617 | |
| 618 | |
| 619 | |
| 620 | def add_intents(self): |
| 621 | main.log.info("Sending new intents to ONOS") |
admin | c6cfc1c | 2014-04-21 13:55:21 -0700 | [diff] [blame] | 622 | self.handle.sendline("cd "+self.home+ "/scripts") |
| 623 | self.handle.expect("scripts") |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 624 | main.log.info("Adding intents") |
admin | c6cfc1c | 2014-04-21 13:55:21 -0700 | [diff] [blame] | 625 | self.handle.sendline("./pyintents.py") |
Jon Hall | 9c6e2c0 | 2014-05-02 10:18:53 -0700 | [diff] [blame] | 626 | self.handle.expect(["$",pexpect.EOF,pexpect.TIMEOUT]) |
| 627 | response = self.handle.before |
admin | c6cfc1c | 2014-04-21 13:55:21 -0700 | [diff] [blame] | 628 | self.handle.sendline("cd "+self.home) |
| 629 | return main.TRUE |
| 630 | |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 631 | def rm_intents(self): |
| 632 | main.log.info("Deleteing Intents from ONOS") |
admin | c6cfc1c | 2014-04-21 13:55:21 -0700 | [diff] [blame] | 633 | self.handle.sendline("cd "+self.home+ "/scripts") |
| 634 | self.handle.expect("scripts") |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 635 | main.log.info("Deleting Intnents") |
admin | c6cfc1c | 2014-04-21 13:55:21 -0700 | [diff] [blame] | 636 | self.handle.sendline("./rmpyintents.py") |
Jon Hall | 9c6e2c0 | 2014-05-02 10:18:53 -0700 | [diff] [blame] | 637 | self.handle.expect(["$",pexpect.EOF,pexpect.TIMEOUT]) |
| 638 | response = self.handle.before |
admin | c6cfc1c | 2014-04-21 13:55:21 -0700 | [diff] [blame] | 639 | self.handle.sendline("cd "+self.home) |
| 640 | return main.TRUE |
| 641 | |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 642 | def purge_intents(self): |
Jon Hall | 265149f | 2014-04-25 13:39:52 -0700 | [diff] [blame] | 643 | main.log.info("Purging dead intents") |
| 644 | self.handle.sendline("cd "+self.home+ "/scripts") |
| 645 | self.handle.expect("scripts") |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 646 | main.log.info("Sending Purge Intent Rest call to ONOS") |
Jon Hall | 265149f | 2014-04-25 13:39:52 -0700 | [diff] [blame] | 647 | self.handle.sendline("./purgeintents.py") |
| 648 | self.handle.sendline("cd "+self.home) |
| 649 | return main.TRUE |
admin | c6cfc1c | 2014-04-21 13:55:21 -0700 | [diff] [blame] | 650 | |
| 651 | |
| 652 | |
Jon Hall | 4a2b048 | 2014-04-18 16:29:26 -0700 | [diff] [blame] | 653 | def add_flow(self, testONip, user = "admin", password = "", flowDef = "/flowdef.txt"): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 654 | ''' |
| 655 | Copies the flowdef file from TestStation -> ONOS machine |
| 656 | Then runs ./add_flow.py to add the flows to ONOS |
| 657 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 658 | try: |
| 659 | main.log.info("Adding Flows...") |
| 660 | self.handle.sendline("scp %s@%s:%s /tmp/flowtmp" %(user,testONip,flowDef)) |
| 661 | i=self.handle.expect(['[pP]assword:', '100%', pexpect.TIMEOUT],30) |
| 662 | if(i==0): |
| 663 | self.handle.sendline("%s" %(password)) |
| 664 | self.handle.sendline("") |
| 665 | self.handle.expect("100%") |
| 666 | self.handle.expect("\$", 30) |
| 667 | self.handle.sendline(self.home + "/web/add_flow.py -m onos -f /tmp/flowtmp") |
| 668 | self.handle.expect("\$", 1000) |
| 669 | main.log.info("Flows added") |
| 670 | return main.TRUE |
| 671 | |
| 672 | elif(i==1): |
| 673 | self.handle.sendline("") |
| 674 | self.handle.expect("\$", 10) |
| 675 | self.handle.sendline( self.home + "/web/add_flow.py -m onos -f /tmp/flowtmp") |
| 676 | self.handle.expect("\$", 1000) |
| 677 | main.log.info("Flows added") |
| 678 | return main.TRUE |
| 679 | |
| 680 | elif(i==2): |
| 681 | main.log.error("Flow Def file SCP Timed out...") |
| 682 | return main.FALSE |
| 683 | |
| 684 | else: |
| 685 | main.log.error("Failed to add flows...") |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 686 | return main.FALSE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 687 | except pexpect.EOF: |
| 688 | main.log.error(self.name + ": EOF exception found") |
| 689 | main.log.error(self.name + ": " + self.handle.before) |
| 690 | main.cleanup() |
| 691 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 692 | except: |
| 693 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 694 | main.log.error( traceback.print_exc() ) |
| 695 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 696 | main.cleanup() |
| 697 | main.exit() |
| 698 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 699 | |
| 700 | def delete_flow(self, *delParams): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 701 | ''' |
| 702 | Deletes a specific flow, a range of flows, or all flows. |
| 703 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 704 | try: |
| 705 | if len(delParams)==1: |
| 706 | if str(delParams[0])=="all": |
| 707 | main.log.info(self.name + ": Deleting ALL flows...") |
| 708 | #self.execute(cmd="~/ONOS/scripts/TestON_delete_flow.sh all",prompt="done",timeout=150) |
| 709 | self.handle.sendline(self.home + "/web/delete_flow.py all") |
| 710 | self.handle.expect("delete_flow") |
| 711 | self.handle.expect("\$",1000) |
| 712 | main.log.info(self.name + ": Flows deleted") |
| 713 | else: |
| 714 | main.log.info(self.name + ": Deleting flow "+str(delParams[0])+"...") |
| 715 | #self.execute(cmd="~/ONOS/scripts/TestON_delete_flow.sh "+str(delParams[0]),prompt="done",timeout=150) |
| 716 | #self.execute(cmd="\n",prompt="\$",timeout=60) |
| 717 | self.handle.sendline(self.home +"/web/delete_flow.py %d" % int(delParams[0])) |
| 718 | self.handle.expect("delete_flow") |
| 719 | self.handle.expect("\$",60) |
| 720 | main.log.info(self.name + ": Flow deleted") |
| 721 | elif len(delParams)==2: |
| 722 | main.log.info(self.name + ": Deleting flows "+str(delParams[0])+" through "+str(delParams[1])+"...") |
| 723 | #self.execute(cmd="~/ONOS/scripts/TestON_delete_flow.sh "+str(delParams[0])+" "+str(delParams[1]),prompt="done",timeout=150) |
| 724 | #self.execute(cmd="\n",prompt="\$",timeout=60) |
| 725 | self.handle.sendline(self.home + "/web/delete_flow.py %d %d" % (int(delParams[0]), int(delParams[1]))) |
| 726 | self.handle.expect("delete_flow") |
| 727 | self.handle.expect("\$",600) |
| 728 | main.log.info(self.name + ": Flows deleted") |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 729 | except pexpect.EOF: |
| 730 | main.log.error(self.name + ": EOF exception found") |
| 731 | main.log.error(self.name + ": " + self.handle.before) |
| 732 | main.cleanup() |
| 733 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 734 | except: |
| 735 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 736 | main.log.error( traceback.print_exc() ) |
| 737 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 738 | main.cleanup() |
| 739 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 740 | |
| 741 | def check_flow(self): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 742 | ''' |
| 743 | Calls the ./get_flow.py all and checks: |
| 744 | - If each FlowPath has at least one FlowEntry |
| 745 | - That there are no "NOT"s found |
| 746 | returns TRUE/FALSE |
| 747 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 748 | try: |
| 749 | flowEntryDetect = 1 |
| 750 | count = 0 |
| 751 | self.handle.sendline("clear") |
| 752 | time.sleep(1) |
| 753 | self.handle.sendline(self.home + "/web/get_flow.py all") |
| 754 | self.handle.expect("get_flow") |
Jon Hall | 3bd7c79 | 2014-05-30 09:05:21 -0700 | [diff] [blame] | 755 | for x in range(15): |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 756 | i=self.handle.expect(['FlowPath','FlowEntry','NOT','\$',pexpect.TIMEOUT],timeout=180) |
| 757 | if i==0: |
| 758 | count = count + 1 |
| 759 | if flowEntryDetect == 0: |
| 760 | main.log.info(self.name + ": FlowPath without FlowEntry") |
| 761 | return main.FALSE |
| 762 | else: |
| 763 | flowEntryDetect = 0 |
| 764 | elif i==1: |
| 765 | flowEntryDetect = 1 |
| 766 | elif i==2: |
| 767 | main.log.error(self.name + ": Found a NOT") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 768 | return main.FALSE |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 769 | elif i==3: |
| 770 | if count == 0: |
| 771 | main.log.info(self.name + ": There don't seem to be any flows here...") |
| 772 | return main.FALSE |
| 773 | else: |
| 774 | main.log.info(self.name + ": All flows pass") |
| 775 | main.log.info(self.name + ": Number of FlowPaths: "+str(count)) |
| 776 | return main.TRUE |
| 777 | elif i==4: |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 778 | main.log.error(self.name + ":Check_flow() - Command Timeout!") |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 779 | return main.FALSE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 780 | except pexpect.EOF: |
| 781 | main.log.error(self.name + ": EOF exception found") |
| 782 | main.log.error(self.name + ": " + self.handle.before) |
| 783 | main.cleanup() |
| 784 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 785 | except: |
| 786 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 787 | main.log.error( traceback.print_exc() ) |
| 788 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 789 | main.cleanup() |
| 790 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 791 | |
| 792 | def get_flow(self, *flowParams): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 793 | ''' |
| 794 | Returns verbose output of ./get_flow.py |
| 795 | ''' |
| 796 | try: |
| 797 | if len(flowParams)==1: |
| 798 | if str(flowParams[0])=="all": |
| 799 | self.execute(cmd="\n",prompt="\$",timeout=60) |
| 800 | main.log.info(self.name + ": Getting all flow data...") |
| 801 | data = self.execute(cmd=self.home + "/scripts/TestON_get_flow.sh all",prompt="done",timeout=150) |
| 802 | self.execute(cmd="\n",prompt="\$",timeout=60) |
| 803 | return data |
| 804 | else: |
| 805 | main.log.info(self.name + ": Retrieving flow "+str(flowParams[0])+" data...") |
| 806 | data = self.execute(cmd=self.home +"/scripts/TestON_get_flow.sh "+str(flowParams[0]),prompt="done",timeout=150) |
| 807 | self.execute(cmd="\n",prompt="\$",timeout=60) |
| 808 | return data |
| 809 | elif len(flowParams)==5: |
| 810 | main.log.info(self.name + ": Retrieving flow installer data...") |
| 811 | 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) |
| 812 | self.execute(cmd="\n",prompt="\$",timeout=60) |
| 813 | return data |
| 814 | elif len(flowParams)==4: |
| 815 | main.log.info(self.name + ": Retrieving flow endpoints...") |
| 816 | 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) |
| 817 | self.execute(cmd="\n",prompt="\$",timeout=60) |
| 818 | return data |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 819 | except pexpect.EOF: |
| 820 | main.log.error(self.name + ": EOF exception found") |
| 821 | main.log.error(self.name + ": " + self.handle.before) |
| 822 | main.cleanup() |
| 823 | main.exit() |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 824 | except: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 825 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 826 | main.log.error( traceback.print_exc() ) |
| 827 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 828 | main.cleanup() |
| 829 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 830 | |
| 831 | |
Jon Hall | 2f42a67 | 2014-05-28 10:13:18 -0700 | [diff] [blame] | 832 | # http://localhost:8080/wm/onos/topology/switches |
| 833 | # http://localhost:8080/wm/onos/topology/links |
Jon Hall | 8060af0 | 2014-04-14 14:17:58 -0700 | [diff] [blame] | 834 | # http://localhost:8080/wm/onos/registry/controllers/json |
| 835 | # http://localhost:8080/wm/onos/registry/switches/json" |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 836 | |
| 837 | def get_json(self, url): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 838 | ''' |
| 839 | Helper functions used to parse the json output of a rest call |
| 840 | ''' |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 841 | try: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 842 | try: |
| 843 | command = "curl -s %s" % (url) |
| 844 | result = os.popen(command).read() |
| 845 | parsedResult = json.loads(result) |
| 846 | except: |
| 847 | print "REST IF %s has issue" % command |
| 848 | parsedResult = "" |
| 849 | |
| 850 | if type(parsedResult) == 'dict' and parsedResult.has_key('code'): |
| 851 | print "REST %s returned code %s" % (command, parsedResult['code']) |
| 852 | parsedResult = "" |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 853 | return parsedResult |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 854 | except pexpect.EOF: |
| 855 | main.log.error(self.name + ": EOF exception found") |
| 856 | main.log.error(self.name + ": " + self.handle.before) |
| 857 | main.cleanup() |
| 858 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 859 | except: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 860 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 861 | main.log.error( traceback.print_exc() ) |
| 862 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 863 | main.cleanup() |
| 864 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 865 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 866 | def check_switch(self,RestIP,correct_nr_switch, RestPort ="8080" ): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 867 | ''' |
| 868 | Used by check_status |
| 869 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 870 | try: |
| 871 | buf = "" |
| 872 | retcode = 0 |
admin | 2e131ab | 2014-05-28 10:03:42 -0700 | [diff] [blame] | 873 | url="http://%s:%s/wm/onos/topology/switches" % (RestIP, RestPort) |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 874 | parsedResult = self.get_json(url) |
| 875 | if parsedResult == "": |
| 876 | retcode = 1 |
| 877 | return (retcode, "Rest API has an issue") |
| 878 | url = "http://%s:%s/wm/onos/registry/switches/json" % (RestIP, RestPort) |
| 879 | registry = self.get_json(url) |
| 880 | |
| 881 | if registry == "": |
| 882 | retcode = 1 |
| 883 | return (retcode, "Rest API has an issue") |
| 884 | |
| 885 | cnt = 0 |
| 886 | active = 0 |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 887 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 888 | for s in parsedResult: |
| 889 | cnt += 1 |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 890 | if s['state'] == "ACTIVE": |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 891 | active += 1 |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 892 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 893 | buf += "switch: network %d : %d switches %d active\n" % (0+1, cnt, active) |
| 894 | if correct_nr_switch != cnt: |
| 895 | buf += "switch fail: network %d should have %d switches but has %d\n" % (1, correct_nr_switch, cnt) |
| 896 | retcode = 1 |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 897 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 898 | if correct_nr_switch != active: |
| 899 | buf += "switch fail: network %d should have %d active switches but has %d\n" % (1, correct_nr_switch, active) |
| 900 | retcode = 1 |
| 901 | |
| 902 | return (retcode, buf) |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 903 | except pexpect.EOF: |
| 904 | main.log.error(self.name + ": EOF exception found") |
| 905 | main.log.error(self.name + ": " + self.handle.before) |
| 906 | main.cleanup() |
| 907 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 908 | except: |
| 909 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 910 | main.log.error( traceback.print_exc() ) |
| 911 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 912 | main.cleanup() |
| 913 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 914 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 915 | def check_link(self,RestIP, nr_links, RestPort = "8080"): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 916 | ''' |
| 917 | Used by check_status |
| 918 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 919 | try: |
| 920 | buf = "" |
| 921 | retcode = 0 |
| 922 | |
admin | 2e131ab | 2014-05-28 10:03:42 -0700 | [diff] [blame] | 923 | url = "http://%s:%s/wm/onos/topology/links" % (RestIP, RestPort) |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 924 | parsedResult = self.get_json(url) |
| 925 | |
| 926 | if parsedResult == "": |
| 927 | retcode = 1 |
| 928 | return (retcode, "Rest API has an issue") |
| 929 | |
| 930 | buf += "link: total %d links (correct : %d)\n" % (len(parsedResult), nr_links) |
| 931 | intra = 0 |
| 932 | interlink=0 |
| 933 | |
| 934 | for s in parsedResult: |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 935 | intra = intra + 1 |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 936 | |
| 937 | if intra != nr_links: |
| 938 | buf += "link fail\n" |
| 939 | retcode = 1 |
| 940 | |
| 941 | return (retcode, buf) |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 942 | except pexpect.EOF: |
| 943 | main.log.error(self.name + ": EOF exception found") |
| 944 | main.log.error(self.name + ": " + self.handle.before) |
| 945 | main.cleanup() |
| 946 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 947 | except: |
| 948 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 949 | main.log.error( traceback.print_exc() ) |
| 950 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 951 | main.cleanup() |
| 952 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 953 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 954 | def check_status_report(self, ip, numoswitch, numolink, port="8080"): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 955 | ''' |
| 956 | Checks the number of swithes & links that ONOS sees against the supplied values. |
| 957 | Writes to the report log. |
| 958 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 959 | try: |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 960 | main.log.info(self.name + ": Making some rest calls...") |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 961 | switch = self.check_switch(ip, int(numoswitch), port) |
| 962 | link = self.check_link(ip, int(numolink), port) |
| 963 | value = switch[0] |
| 964 | value += link[0] |
| 965 | main.log.report( self.name + ": \n-----\n%s%s-----\n" % ( switch[1], link[1]) ) |
| 966 | if value != 0: |
| 967 | return main.FALSE |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 968 | else: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 969 | # "PASS" |
| 970 | return main.TRUE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 971 | except pexpect.EOF: |
| 972 | main.log.error(self.name + ": EOF exception found") |
| 973 | main.log.error(self.name + ": " + self.handle.before) |
| 974 | main.cleanup() |
| 975 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 976 | except: |
| 977 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 978 | main.log.error( traceback.print_exc() ) |
| 979 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 980 | main.cleanup() |
| 981 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 982 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 983 | def check_status(self, ip, numoswitch, numolink, port = "8080"): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 984 | ''' |
| 985 | Checks the number of swithes & links that ONOS sees against the supplied values. |
| 986 | Writes to the main log. |
| 987 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 988 | try: |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 989 | main.log.info(self.name + ": Making some rest calls...") |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 990 | switch = self.check_switch(ip, int(numoswitch), port) |
| 991 | link = self.check_link(ip, int(numolink), port) |
| 992 | value = switch[0] |
| 993 | value += link[0] |
| 994 | main.log.info(self.name + ": \n-----\n%s%s-----\n" % ( switch[1], link[1]) ) |
| 995 | if value != 0: |
| 996 | return main.FALSE |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 997 | else: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 998 | # "PASS" |
| 999 | return main.TRUE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1000 | except pexpect.EOF: |
| 1001 | main.log.error(self.name + ": EOF exception found") |
| 1002 | main.log.error(self.name + ": " + self.handle.before) |
| 1003 | main.cleanup() |
| 1004 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1005 | except: |
| 1006 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1007 | main.log.error( traceback.print_exc() ) |
| 1008 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1009 | main.cleanup() |
| 1010 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 1011 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 1012 | def check_for_no_exceptions(self): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 1013 | ''' |
| 1014 | TODO: Rewrite |
| 1015 | Used by CassndraCheck.py to scan ONOS logs for Exceptions |
| 1016 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1017 | try: |
| 1018 | self.handle.sendline("dsh 'grep Exception ~/ONOS/onos-logs/onos.*.log'") |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 1019 | self.handle.expect("\$ dsh") |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1020 | self.handle.expect("\$") |
| 1021 | output = self.handle.before |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 1022 | main.log.info(self.name + ": " + output ) |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1023 | if re.search("Exception",output): |
| 1024 | return main.FALSE |
| 1025 | else : |
| 1026 | return main.TRUE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1027 | except pexpect.EOF: |
| 1028 | main.log.error(self.name + ": EOF exception found") |
| 1029 | main.log.error(self.name + ": " + self.handle.before) |
| 1030 | main.cleanup() |
| 1031 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1032 | except: |
| 1033 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1034 | main.log.error( traceback.print_exc() ) |
| 1035 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1036 | main.cleanup() |
| 1037 | main.exit() |
| 1038 | |
| 1039 | |
admin | e0eeea2 | 2014-04-14 10:22:46 -0700 | [diff] [blame] | 1040 | def git_pull(self, comp1=""): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 1041 | ''' |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 1042 | Assumes that "git pull" works without login |
admin | e0eeea2 | 2014-04-14 10:22:46 -0700 | [diff] [blame] | 1043 | |
| 1044 | This function will perform a git pull on the ONOS instance. |
| 1045 | If used as git_pull("NODE") it will do git pull + NODE. This is |
| 1046 | for the purpose of pulling from other nodes if necessary. |
| 1047 | |
| 1048 | Otherwise, this function will perform a git pull in the |
| 1049 | ONOS repository. If it has any problems, it will return main.ERROR |
| 1050 | If it successfully does a git_pull, it will return a 1. |
| 1051 | If it has no updates, it will return a 0. |
| 1052 | |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 1053 | ''' |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1054 | try: |
Jon Hall | e80ef8c | 2014-04-29 15:29:13 -0700 | [diff] [blame] | 1055 | # main.log.info(self.name + ": Stopping ONOS") |
| 1056 | #self.stop() |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1057 | self.handle.sendline("cd " + self.home) |
| 1058 | self.handle.expect("ONOS\$") |
| 1059 | if comp1=="": |
| 1060 | self.handle.sendline("git pull") |
| 1061 | else: |
| 1062 | self.handle.sendline("git pull " + comp1) |
| 1063 | |
| 1064 | uptodate = 0 |
Jon Hall | 5a8aac6 | 2014-06-03 09:30:21 -0700 | [diff] [blame] | 1065 | 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 Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1066 | #debug |
| 1067 | #main.log.report(self.name +": \n"+"git pull response: " + str(self.handle.before) + str(self.handle.after)) |
| 1068 | if i==0: |
| 1069 | main.log.error(self.name + ": Git pull had some issue...") |
| 1070 | return main.ERROR |
| 1071 | elif i==1: |
| 1072 | main.log.error(self.name + ": Git Pull Asking for username!!! BADD!") |
| 1073 | return main.ERROR |
| 1074 | elif i==2: |
| 1075 | main.log.info(self.name + ": Git Pull - pulling repository now") |
| 1076 | self.handle.expect("ONOS\$", 120) |
| 1077 | return 0 |
| 1078 | elif i==3: |
| 1079 | main.log.error(self.name + ": Git Pull - TIMEOUT") |
| 1080 | return main.ERROR |
| 1081 | elif i==4: |
| 1082 | main.log.info(self.name + ": Git Pull - Already up to date") |
| 1083 | return 1 |
| 1084 | elif i==5: |
| 1085 | main.log.info(self.name + ": Git Pull - Aborting... Are there conflicting git files?") |
| 1086 | return main.ERROR |
Jon Hall | 5a8aac6 | 2014-06-03 09:30:21 -0700 | [diff] [blame] | 1087 | elif i==6: |
| 1088 | main.log.info(self.name + ": Git Pull - You are not currently on a branch so git pull failed!") |
| 1089 | return main.ERROR |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1090 | else: |
| 1091 | main.log.error(self.name + ": Git Pull - Unexpected response, check for pull errors") |
| 1092 | return main.ERROR |
| 1093 | except pexpect.EOF: |
| 1094 | main.log.error(self.name + ": EOF exception found") |
| 1095 | main.log.error(self.name + ": " + self.handle.before) |
| 1096 | main.cleanup() |
| 1097 | main.exit() |
| 1098 | except: |
| 1099 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1100 | main.log.error( traceback.print_exc() ) |
| 1101 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1102 | main.cleanup() |
| 1103 | main.exit() |
admin | e0eeea2 | 2014-04-14 10:22:46 -0700 | [diff] [blame] | 1104 | #******************************************************** |
| 1105 | |
| 1106 | |
admin | 7373a81 | 2014-04-16 09:49:02 -0700 | [diff] [blame] | 1107 | def git_compile(self): |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1108 | ''' |
| 1109 | Compiles ONOS |
| 1110 | First runs mvn clean then mvn compile |
| 1111 | ''' |
| 1112 | try: |
| 1113 | main.log.info(self.name + ": mvn clean") |
admin | 8fc0282 | 2014-04-16 13:31:23 -0700 | [diff] [blame] | 1114 | self.handle.sendline("cd " + self.home) |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1115 | self.handle.sendline("mvn clean") |
| 1116 | while 1: |
Jon Hall | 1636f94 | 2014-04-17 10:07:23 -0700 | [diff] [blame] | 1117 | 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 Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1118 | if i == 0: |
Jon Hall | 1636f94 | 2014-04-17 10:07:23 -0700 | [diff] [blame] | 1119 | main.log.error(self.name + ":There is insufficient memory for the Java Runtime Environment to continue.") |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1120 | return main.FALSE |
| 1121 | elif i == 1: |
Jon Hall | 1636f94 | 2014-04-17 10:07:23 -0700 | [diff] [blame] | 1122 | main.log.error(self.name + ": Clean failure!") |
| 1123 | return main.FALSE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1124 | elif i == 2: |
Jon Hall | 1636f94 | 2014-04-17 10:07:23 -0700 | [diff] [blame] | 1125 | main.log.info(self.name + ": Clean success!") |
| 1126 | elif i == 3: |
admin | 8fc0282 | 2014-04-16 13:31:23 -0700 | [diff] [blame] | 1127 | main.log.info(self.name + ": Clean complete") |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1128 | break; |
Jon Hall | 1636f94 | 2014-04-17 10:07:23 -0700 | [diff] [blame] | 1129 | elif i == 4: |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1130 | main.log.error(self.name + ": mvn clean TIMEOUT!") |
| 1131 | return main.FALSE |
Jon Hall | 1636f94 | 2014-04-17 10:07:23 -0700 | [diff] [blame] | 1132 | else: |
| 1133 | main.log.error(self.name + ": unexpected response from mvn clean") |
| 1134 | return main.FALSE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1135 | |
| 1136 | main.log.info(self.name + ": mvn compile") |
| 1137 | self.handle.sendline("mvn compile") |
| 1138 | while 1: |
Jon Hall | 1636f94 | 2014-04-17 10:07:23 -0700 | [diff] [blame] | 1139 | 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 Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1140 | if i == 0: |
Jon Hall | 1636f94 | 2014-04-17 10:07:23 -0700 | [diff] [blame] | 1141 | main.log.error(self.name + ":There is insufficient memory for the Java Runtime Environment to continue.") |
| 1142 | return main.FALSE |
| 1143 | if i == 1: |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1144 | main.log.error(self.name + ": Build failure!") |
| 1145 | return main.FALSE |
Jon Hall | 1636f94 | 2014-04-17 10:07:23 -0700 | [diff] [blame] | 1146 | elif i == 2: |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1147 | main.log.info(self.name + ": Build success!") |
Jon Hall | 1636f94 | 2014-04-17 10:07:23 -0700 | [diff] [blame] | 1148 | elif i == 3: |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1149 | main.log.info(self.name + ": Build complete") |
Jon Hall | 010f541 | 2014-05-21 15:10:12 -0700 | [diff] [blame] | 1150 | self.handle.expect("\$", timeout=60) |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1151 | return main.TRUE |
Jon Hall | 1636f94 | 2014-04-17 10:07:23 -0700 | [diff] [blame] | 1152 | elif i == 4: |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1153 | main.log.error(self.name + ": mvn compile TIMEOUT!") |
| 1154 | return main.FALSE |
| 1155 | else: |
Jon Hall | 1636f94 | 2014-04-17 10:07:23 -0700 | [diff] [blame] | 1156 | main.log.error(self.name + ": unexpected response from mvn compile") |
| 1157 | return main.FALSE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1158 | except pexpect.EOF: |
| 1159 | main.log.error(self.name + ": EOF exception found") |
| 1160 | main.log.error(self.name + ": " + self.handle.before) |
| 1161 | main.cleanup() |
| 1162 | main.exit() |
| 1163 | except: |
| 1164 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1165 | main.log.error( traceback.print_exc() ) |
| 1166 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1167 | main.cleanup() |
| 1168 | main.exit() |
admin | 4a58db9 | 2013-09-30 12:04:54 -0700 | [diff] [blame] | 1169 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1170 | def tcpdump(self, intf = "eth0"): |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1171 | ''' |
| 1172 | Runs tpdump on an intferface and saves in onos-logs under the ONOS home directory |
| 1173 | intf can be specified, or the default eth0 is used |
| 1174 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1175 | try: |
| 1176 | self.handle.sendline("") |
| 1177 | self.handle.expect("\$") |
Jon Hall | 26f316b | 2014-04-11 11:21:25 -0700 | [diff] [blame] | 1178 | self.handle.sendline("sudo tcpdump -n -i "+ intf + " -s0 -w " + self.home +"/onos-logs/tcpdump &") |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1179 | i=self.handle.expect(['No\ssuch\device','listening\son',pexpect.TIMEOUT],timeout=10) |
| 1180 | if i == 0: |
| 1181 | main.log.error(self.name + ": tcpdump - No such device exists. tcpdump attempted on: " + intf) |
| 1182 | return main.FALSE |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 1183 | elif i == 1: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1184 | main.log.info(self.name + ": tcpdump started on " + intf) |
| 1185 | return main.TRUE |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 1186 | elif i == 2: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1187 | main.log.error(self.name + ": tcpdump command timed out! Check interface name, given interface was: " + intf) |
| 1188 | return main.FALSE |
| 1189 | else: |
| 1190 | main.log.error(self.name + ": tcpdump - unexpected response") |
| 1191 | return main.FALSE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1192 | except pexpect.EOF: |
| 1193 | main.log.error(self.name + ": EOF exception found") |
| 1194 | main.log.error(self.name + ": " + self.handle.before) |
| 1195 | main.cleanup() |
| 1196 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1197 | except: |
| 1198 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1199 | main.log.error( traceback.print_exc() ) |
| 1200 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1201 | main.cleanup() |
| 1202 | main.exit() |
| 1203 | |
admin | 4a58db9 | 2013-09-30 12:04:54 -0700 | [diff] [blame] | 1204 | def kill_tcpdump(self): |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1205 | ''' |
| 1206 | Kills any tcpdump processes running |
| 1207 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1208 | try: |
| 1209 | self.handle.sendline("") |
| 1210 | self.handle.expect("\$") |
| 1211 | self.handle.sendline("sudo kill -9 `ps -ef | grep \"tcpdump -n\" | grep -v grep | awk '{print $2}'`") |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1212 | except pexpect.EOF: |
| 1213 | main.log.error(self.name + ": EOF exception found") |
| 1214 | main.log.error(self.name + ": " + self.handle.before) |
| 1215 | main.cleanup() |
| 1216 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1217 | except: |
| 1218 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1219 | main.log.error( traceback.print_exc() ) |
| 1220 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1221 | main.cleanup() |
| 1222 | main.exit() |
| 1223 | |
Jon Hall | f15f785 | 2014-05-20 10:37:23 -0700 | [diff] [blame] | 1224 | def find_host(self,RestIP,RestPort,RestAPI,hostMAC): |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 1225 | retcode = 0 # number of hosts found with given MAC |
| 1226 | retswitch = [] # Switch DPID's of hosts found with MAC |
| 1227 | retport = [] # Switch port connected to to hosts found with MAC |
Jon Hall | f15f785 | 2014-05-20 10:37:23 -0700 | [diff] [blame] | 1228 | foundHost = [] |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1229 | try: |
Jon Hall | 2f42a67 | 2014-05-28 10:13:18 -0700 | [diff] [blame] | 1230 | ##### device rest API is: 'host:8080/wm/onos/topology/switches' ### |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1231 | url ="http://%s:%s%s" %(RestIP,RestPort,RestAPI) |
| 1232 | |
| 1233 | try: |
| 1234 | command = "curl -s %s" % (url) |
| 1235 | result = os.popen(command).read() |
| 1236 | parsedResult = json.loads(result) |
| 1237 | # print parsedResult |
| 1238 | except: |
| 1239 | print "REST IF %s has issue" % command |
| 1240 | parsedResult = "" |
| 1241 | |
| 1242 | if parsedResult == "": |
Jon Hall | f15f785 | 2014-05-20 10:37:23 -0700 | [diff] [blame] | 1243 | return (retcode, "Rest API has an error", retport) |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1244 | else: |
Jon Hall | f15f785 | 2014-05-20 10:37:23 -0700 | [diff] [blame] | 1245 | for host in enumerate(parsedResult): |
| 1246 | print host |
| 1247 | if (host[1] != []): |
| 1248 | try: |
| 1249 | foundHost = host[1]['mac'] |
| 1250 | except: |
| 1251 | print "Error in detecting MAC address." |
| 1252 | print foundHost |
| 1253 | print hostMAC |
| 1254 | if foundHost == hostMAC: |
| 1255 | for switch in enumerate(host[1]['attachmentPoints']): |
| 1256 | retswitch.append(switch[1]['dpid']) |
| 1257 | retport.append(switch[1]['port']) |
| 1258 | retcode = retcode +1 |
| 1259 | foundHost ='' |
| 1260 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1261 | for switch in enumerate(parsedResult): |
| 1262 | for port in enumerate(switch[1]['ports']): |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 1263 | if ( port[1]['hosts'] != [] ): |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1264 | try: |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 1265 | foundHost = port[1]['hosts'][0]['ipv4addresses'][0]['ipv4'] |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1266 | except: |
Jon Hall | f15f785 | 2014-05-20 10:37:23 -0700 | [diff] [blame] | 1267 | print "Error in detecting MAC address." |
| 1268 | if foundHost == hostMAC: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1269 | retswitch.append(switch[1]['dpid']) |
| 1270 | retport.append(port[1]['desc']) |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 1271 | retmac.append(port[1]['hosts'][0]['mac']) |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1272 | retcode = retcode +1 |
Jon Hall | f15f785 | 2014-05-20 10:37:23 -0700 | [diff] [blame] | 1273 | foundHost ='' |
| 1274 | ''' |
| 1275 | return(retcode, retswitch, retport) |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1276 | except pexpect.EOF: |
| 1277 | main.log.error(self.name + ": EOF exception found") |
| 1278 | main.log.error(self.name + ": " + self.handle.before) |
| 1279 | main.cleanup() |
| 1280 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1281 | except: |
| 1282 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1283 | main.log.error( traceback.print_exc() ) |
| 1284 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1285 | main.cleanup() |
| 1286 | main.exit() |
SeanCorcoran | 29b7054 | 2014-05-14 14:53:42 -0700 | [diff] [blame] | 1287 | |
| 1288 | def check_exceptions(self): |
| 1289 | ''' |
| 1290 | Greps the logs for "xception" |
| 1291 | ''' |
| 1292 | try: |
| 1293 | output = '' |
| 1294 | self.handle.sendline("") |
Jon Hall | a78cf9a | 2014-05-16 10:49:30 -0700 | [diff] [blame] | 1295 | i = self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT]) |
| 1296 | #main.log.warn("first expect response: " +str(i)) |
SeanCorcoran | 29b7054 | 2014-05-14 14:53:42 -0700 | [diff] [blame] | 1297 | self.handle.sendline("cd "+self.home+"/onos-logs") |
Jon Hall | a78cf9a | 2014-05-16 10:49:30 -0700 | [diff] [blame] | 1298 | self.handle.sendline("grep \"xception\" *") |
| 1299 | i = self.handle.expect(["\*",pexpect.EOF,pexpect.TIMEOUT]) |
| 1300 | #main.log.warn("second expect response: " +str(i)) |
| 1301 | i = self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT]) |
| 1302 | #main.log.warn("third expect response: " +str(i)) |
SeanCorcoran | 29b7054 | 2014-05-14 14:53:42 -0700 | [diff] [blame] | 1303 | response = self.handle.before |
Jon Hall | a78cf9a | 2014-05-16 10:49:30 -0700 | [diff] [blame] | 1304 | count = 0 |
SeanCorcoran | 29b7054 | 2014-05-14 14:53:42 -0700 | [diff] [blame] | 1305 | for line in response.splitlines(): |
| 1306 | if re.search("log:", line): |
| 1307 | output +="Exceptions found in " + line + "\n" |
Jon Hall | a78cf9a | 2014-05-16 10:49:30 -0700 | [diff] [blame] | 1308 | count +=1 |
SeanCorcoran | 29b7054 | 2014-05-14 14:53:42 -0700 | [diff] [blame] | 1309 | elif re.search("std...:",line): |
| 1310 | output+="Exceptions found in " + line + "\n" |
Jon Hall | a78cf9a | 2014-05-16 10:49:30 -0700 | [diff] [blame] | 1311 | count +=1 |
SeanCorcoran | 29b7054 | 2014-05-14 14:53:42 -0700 | [diff] [blame] | 1312 | else: |
| 1313 | pass |
| 1314 | #these should be the old logs |
admin | 1723f1c | 2014-05-19 16:08:39 -0700 | [diff] [blame] | 1315 | main.log.report(str(count) + " Exceptions were found on "+self.name) |
SeanCorcoran | 29b7054 | 2014-05-14 14:53:42 -0700 | [diff] [blame] | 1316 | return output |
| 1317 | except pexpect.TIMEOUT: |
| 1318 | main.log.error(self.name + ": Timeout exception found in check_exceptions function") |
| 1319 | except pexpect.EOF: |
| 1320 | main.log.error(self.name + ": EOF exception found") |
| 1321 | main.log.error(self.name + ": " + self.handle.before) |
| 1322 | main.cleanup() |
| 1323 | main.exit() |
| 1324 | except: |
| 1325 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1326 | main.log.error( traceback.print_exc() ) |
| 1327 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1328 | main.cleanup() |
| 1329 | main.exit() |