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