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