admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | ''' |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 3 | Created on 31-May-2013 |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 4 | |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 5 | @author: Anil Kumar (anilkumar.s@paxterrasolutions.com) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 6 | |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 7 | TestON is free software: you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License as published by |
| 9 | the Free Software Foundation, either version 2 of the License, or |
| 10 | (at your option) any later version. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 11 | |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 12 | TestON is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU General Public License for more details. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 16 | |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 17 | You should have received a copy of the GNU General Public License |
| 18 | along with TestON. If not, see <http://www.gnu.org/licenses/>. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 19 | |
| 20 | |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 21 | ''' |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 22 | import time |
| 23 | import pexpect |
| 24 | import struct, fcntl, os, sys, signal |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 25 | import re |
| 26 | import json |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 27 | import traceback |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 28 | sys.path.append("../") |
| 29 | from drivers.common.clidriver import CLI |
| 30 | |
| 31 | class OnosCliDriver(CLI): |
| 32 | |
| 33 | def __init__(self): |
| 34 | super(CLI, self).__init__() |
| 35 | |
| 36 | def connect(self,**connectargs): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 37 | ''' |
| 38 | Creates ssh handle for ONOS. |
| 39 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 40 | try: |
| 41 | for key in connectargs: |
admin | e0eeea2 | 2014-04-14 10:22:46 -0700 | [diff] [blame] | 42 | vars(self)[key] = connectargs[key] |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 43 | self.home = "~/ONOS" |
| 44 | for key in self.options: |
admin | e0eeea2 | 2014-04-14 10:22:46 -0700 | [diff] [blame] | 45 | if key == "home": |
| 46 | self.home = self.options['home'] |
| 47 | break |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 48 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 49 | |
| 50 | self.name = self.options['name'] |
| 51 | self.handle = super(OnosCliDriver,self).connect(user_name = self.user_name, ip_address = self.ip_address,port = self.port, pwd = self.pwd, home = self.home) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 52 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 53 | if self.handle: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 54 | return self.handle |
| 55 | else : |
| 56 | main.log.info("NO ONOS HANDLE") |
| 57 | return main.FALSE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 58 | except pexpect.EOF: |
| 59 | main.log.error(self.name + ": EOF exception found") |
| 60 | main.log.error(self.name + ": " + self.handle.before) |
| 61 | main.cleanup() |
| 62 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 63 | except: |
| 64 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 65 | main.log.error( traceback.print_exc() ) |
| 66 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 67 | main.cleanup() |
| 68 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 69 | |
| 70 | def start(self): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 71 | ''' |
| 72 | Starts ONOS on remote machine. |
| 73 | Returns false if any errors were encountered. |
| 74 | ''' |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 75 | try: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 76 | self.handle.sendline("") |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 77 | self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT]) |
Jon Hall | 4a2b048 | 2014-04-18 16:29:26 -0700 | [diff] [blame] | 78 | self.handle.sendline("cd "+self.home) |
| 79 | self.handle.sendline("./onos.sh core start") |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 80 | i=self.handle.expect(["STARTED","FAILED",pexpect.EOF,pexpect.TIMEOUT]) |
| 81 | response = self.handle.before + str(self.handle.after) |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 82 | if i==0: |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 83 | j = self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT], timeout=60) |
| 84 | if re.search("Killed",response): |
| 85 | main.log.warn(self.name + ": Killed existing process") |
| 86 | if j==0: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 87 | main.log.info(self.name + ": ONOS Started ") |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 88 | return main.TRUE |
| 89 | elif j==1: |
| 90 | main.log.error(self.name + ": EOF exception found") |
| 91 | main.log.error(self.name + ": " + self.handle.before) |
| 92 | main.cleanup() |
| 93 | main.exit() |
| 94 | elif j==2: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 95 | main.log.info(self.name + ": ONOS NOT Started, stuck while waiting for it to start ") |
| 96 | return main.FALSE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 97 | else: |
| 98 | main.log.warn(self.name +": Unexpected response in start") |
| 99 | return main.TRUE |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 100 | elif i==1: |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 101 | main.log.error(self.name + ": ONOS Failed to start") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 102 | return main.FALSE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 103 | elif i==2: |
| 104 | main.log.error(self.name + ": EOF exception found") |
| 105 | main.log.error(self.name + ": " + self.handle.before) |
| 106 | main.cleanup() |
| 107 | main.exit() |
| 108 | elif i==3: |
| 109 | main.log.error(self.name + ": ONOS timedout while starting") |
| 110 | return main.FALSE |
| 111 | else: |
| 112 | main.log.error(self.name + ": ONOS start expect script missed something... ") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 113 | return main.FALSE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 114 | except pexpect.EOF: |
| 115 | main.log.error(self.name + ": EOF exception found") |
| 116 | main.log.error(self.name + ": " + self.handle.before) |
| 117 | main.cleanup() |
| 118 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 119 | except: |
| 120 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 121 | main.log.error( traceback.print_exc() ) |
| 122 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 123 | main.cleanup() |
| 124 | main.exit() |
Jon Hall | e80ef8c | 2014-04-29 15:29:13 -0700 | [diff] [blame] | 125 | |
| 126 | def start_all(self): |
| 127 | ''' |
| 128 | starts ZK, RC, and ONOS |
| 129 | ''' |
| 130 | self.handle.sendline("cd "+self.home) |
| 131 | self.handle.sendline("./onos.sh start") |
| 132 | self.handle.expect("./onos.sh start") |
| 133 | self.handle.expect(["\$",pexpect.TIMEOUT]) |
| 134 | |
| 135 | |
| 136 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 137 | def start_rest(self): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 138 | ''' |
| 139 | Starts the rest server on ONOS. |
| 140 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 141 | try: |
Jon Hall | 4a2b048 | 2014-04-18 16:29:26 -0700 | [diff] [blame] | 142 | self.handle.sendline("cd "+self.home) |
| 143 | response = self.execute(cmd= "./start-rest.sh start",prompt="\$",timeout=10) |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 144 | if re.search("admin",response): |
| 145 | main.log.info(self.name + ": Rest Server Started Successfully") |
| 146 | time.sleep(5) |
| 147 | return main.TRUE |
| 148 | else : |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 149 | main.log.warn(self.name + ": Failed to start Rest Server") |
| 150 | return main.FALSE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 151 | except pexpect.EOF: |
| 152 | main.log.error(self.name + ": EOF exception found") |
| 153 | main.log.error(self.name + ": " + self.handle.before) |
| 154 | main.cleanup() |
| 155 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 156 | except: |
| 157 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 158 | main.log.error( traceback.print_exc() ) |
| 159 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 160 | main.cleanup() |
| 161 | main.exit() |
| 162 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 163 | def status(self): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 164 | ''' |
| 165 | Called onos.sh core status and returns TRUE/FALSE accordingly |
| 166 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 167 | try: |
| 168 | self.execute(cmd="\n",prompt="\$",timeout=10) |
Jon Hall | 4a2b048 | 2014-04-18 16:29:26 -0700 | [diff] [blame] | 169 | self.handle.sendline("cd "+self.home) |
| 170 | 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] | 171 | self.execute(cmd="\n",prompt="\$",timeout=10) |
| 172 | if re.search("1\sinstance\sof\sonos\srunning",response): |
| 173 | return main.TRUE |
| 174 | elif re.search("0\sinstance\sof\sonos\srunning",response): |
| 175 | return main.FALSE |
| 176 | else : |
| 177 | main.log.info( self.name + " WARNING: status recieved unknown response") |
| 178 | return main.FALSE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 179 | except pexpect.EOF: |
| 180 | main.log.error(self.name + ": EOF exception found") |
| 181 | main.log.error(self.name + ": " + self.handle.before) |
| 182 | main.cleanup() |
| 183 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 184 | except: |
| 185 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 186 | main.log.error( traceback.print_exc() ) |
| 187 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 188 | main.cleanup() |
| 189 | main.exit() |
| 190 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 191 | |
| 192 | def isup(self): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 193 | ''' |
| 194 | A more complete check to see if ONOS is up and running properly. |
| 195 | First, it checks if the process is up. |
| 196 | Second, it reads the logs for "Exception: Connection refused" |
| 197 | Third, it makes sure the logs are actually moving. |
| 198 | returns TRUE/FALSE accordingly. |
| 199 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 200 | try: |
| 201 | self.execute(cmd="\n",prompt="\$",timeout=10) |
Jon Hall | 4a2b048 | 2014-04-18 16:29:26 -0700 | [diff] [blame] | 202 | self.handle.sendline("cd "+self.home) |
| 203 | response = self.execute(cmd= "./onos.sh core status ",prompt="running",timeout=10) |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 204 | self.execute(cmd="\n",prompt="\$",timeout=10) |
| 205 | tail1 = self.execute(cmd="tail " + self.home + "/onos-logs/onos.*.log",prompt="\$",timeout=10) |
| 206 | time.sleep(30) |
| 207 | self.execute(cmd="\n",prompt="\$",timeout=10) |
| 208 | tail2 = self.execute(cmd="tail " + self.home + "/onos-logs/onos.*.log",prompt="\$",timeout=10) |
| 209 | pattern = '(.*)1 instance(.*)' |
Jon Hall | e80ef8c | 2014-04-29 15:29:13 -0700 | [diff] [blame] | 210 | patternUp = 'Sending LLDP out' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 211 | pattern2 = '(.*)Exception: Connection refused(.*)' |
| 212 | # if utilities.assert_matches(expect=pattern,actual=response,onpass="ONOS process is running...",onfail="ONOS process not running..."): |
| 213 | |
| 214 | if re.search(pattern, response): |
admin | aef0055 | 2014-05-08 09:18:36 -0700 | [diff] [blame] | 215 | time.sleep(10) |
Jon Hall | e80ef8c | 2014-04-29 15:29:13 -0700 | [diff] [blame] | 216 | if re.search(patternUp,tail2): |
| 217 | main.log.info(self.name + ": ONOS process is running...") |
| 218 | if tail1 == tail2: |
| 219 | main.log.error(self.name + ": ONOS is frozen...")#logs aren't moving |
| 220 | return main.FALSE |
| 221 | elif re.search( pattern2,tail1 ): |
| 222 | main.log.info(self.name + ": Connection Refused found in onos log") |
| 223 | return main.FALSE |
| 224 | elif re.search( pattern2,tail2 ): |
| 225 | main.log.info(self.name + ": Connection Refused found in onos log") |
| 226 | return main.FALSE |
| 227 | else: |
| 228 | main.log.info(self.name + ": Onos log is moving! It's looking good!") |
| 229 | return main.TRUE |
Jon Hall | 55c7966 | 2014-05-19 15:03:40 -0700 | [diff] [blame] | 230 | else: |
| 231 | main.log.info(self.name + ": ONOS not yet sending out LLDP messages") |
| 232 | return main.FALSE |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 233 | else: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 234 | main.log.error(self.name + ": ONOS process not running...") |
| 235 | return main.FALSE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 236 | except pexpect.EOF: |
| 237 | main.log.error(self.name + ": EOF exception found") |
| 238 | main.log.error(self.name + ": " + self.handle.before) |
| 239 | main.cleanup() |
| 240 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 241 | except: |
| 242 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 243 | main.log.error( traceback.print_exc() ) |
| 244 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 245 | main.cleanup() |
| 246 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 247 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 248 | |
| 249 | |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 250 | def rest_status(self): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 251 | ''' |
| 252 | Checks if the rest server is running. |
| 253 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 254 | try: |
| 255 | response = self.execute(cmd= self.home + "/start-rest.sh status ",prompt="running",timeout=10) |
| 256 | if re.search("rest\sserver\sis\srunning",response): |
| 257 | main.log.info(self.name + ": Rest Server is running") |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 258 | return main.TRUE |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 259 | elif re.search("rest\sserver\sis\snot\srunning",response): |
| 260 | main.log.warn(self.name + ": Rest Server is not Running") |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 261 | return main.FALSE |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 262 | else : |
| 263 | main.log.error(self.name + ": No response" +response) |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 264 | return main.FALSE |
| 265 | except pexpect.EOF: |
| 266 | main.log.error(self.name + ": EOF exception found") |
| 267 | main.log.error(self.name + ": " + self.handle.before) |
| 268 | main.cleanup() |
| 269 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 270 | except: |
| 271 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 272 | main.log.error( traceback.print_exc() ) |
| 273 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 274 | main.cleanup() |
| 275 | main.exit() |
| 276 | |
| 277 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 278 | def stop(self): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 279 | ''' |
| 280 | Runs ./onos.sh core stop to stop ONOS |
| 281 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 282 | try: |
| 283 | self.handle.sendline("") |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 284 | self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT]) |
Jon Hall | 4a2b048 | 2014-04-18 16:29:26 -0700 | [diff] [blame] | 285 | self.handle.sendline("cd "+self.home) |
| 286 | self.handle.sendline("./onos.sh core stop") |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 287 | i=self.handle.expect(["Stop",pexpect.EOF,pexpect.TIMEOUT]) |
| 288 | self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT], 60) |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 289 | result = self.handle.before |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 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 |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 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() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 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() |
| 307 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 308 | |
| 309 | def rest_stop(self): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 310 | ''' |
| 311 | Runs ./start-rest.sh stop to stop ONOS rest server |
| 312 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 313 | try: |
| 314 | response = self.execute(cmd= self.home + "/start-rest.sh stop ",prompt="killing",timeout=10) |
| 315 | self.execute(cmd="\n",prompt="\$",timeout=10) |
| 316 | if re.search("killing", response): |
| 317 | main.log.info(self.name + ": Rest Server Stopped") |
| 318 | return main.TRUE |
| 319 | else : |
| 320 | main.log.error(self.name + ": Failed to Stop, Rest Server is not Running") |
| 321 | return main.FALSE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 322 | except pexpect.EOF: |
| 323 | main.log.error(self.name + ": EOF exception found") |
| 324 | main.log.error(self.name + ": " + self.handle.before) |
| 325 | main.cleanup() |
| 326 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 327 | except: |
| 328 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 329 | main.log.error( traceback.print_exc() ) |
| 330 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 331 | main.cleanup() |
| 332 | main.exit() |
| 333 | |
| 334 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 335 | def disconnect(self): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 336 | ''' |
| 337 | Called when Test is complete to disconnect the ONOS handle. |
| 338 | ''' |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 339 | response = '' |
| 340 | try: |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 341 | self.handle.sendline("exit") |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 342 | self.handle.expect("closed") |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 343 | except pexpect.EOF: |
| 344 | main.log.error(self.name + ": EOF exception found") |
| 345 | main.log.error(self.name + ": " + self.handle.before) |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 346 | except: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 347 | main.log.error(self.name + ": Connection failed to the host") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 348 | response = main.FALSE |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 349 | return response |
| 350 | |
Jon Hall | 76f2c46 | 2014-04-17 11:37:15 -0700 | [diff] [blame] | 351 | def print_version(self): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 352 | ''' |
| 353 | Writes the COMMIT number to the report to be parsed by Jenkins data collecter. |
| 354 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 355 | try: |
| 356 | self.handle.sendline("export TERM=xterm-256color") |
| 357 | self.handle.expect("xterm-256color") |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 358 | self.handle.expect("\$") |
admin | f939f8b | 2014-04-03 17:22:56 -0700 | [diff] [blame] | 359 | self.handle.sendline("cd " + self.home + "; git log -1 --pretty=fuller | grep -A 5 \"commit\"; cd \.\.") |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 360 | self.handle.expect("cd ..") |
| 361 | self.handle.expect("\$") |
admin | e0eeea2 | 2014-04-14 10:22:46 -0700 | [diff] [blame] | 362 | response=(self.name +": \n"+ str(self.handle.before + self.handle.after)) |
| 363 | main.log.report(response) |
Jon Hall | 76f2c46 | 2014-04-17 11:37:15 -0700 | [diff] [blame] | 364 | except pexpect.EOF: |
| 365 | main.log.error(self.name + ": EOF exception found") |
| 366 | main.log.error(self.name + ": " + self.handle.before) |
| 367 | main.cleanup() |
| 368 | main.exit() |
| 369 | except: |
| 370 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 371 | main.log.error( traceback.print_exc() ) |
| 372 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 373 | main.cleanup() |
| 374 | def get_version(self): |
| 375 | ''' |
| 376 | Writes the COMMIT number to the report to be parsed by Jenkins data collecter. |
| 377 | ''' |
| 378 | try: |
| 379 | self.handle.sendline("export TERM=xterm-256color") |
| 380 | self.handle.expect("xterm-256color") |
| 381 | self.handle.expect("\$") |
| 382 | self.handle.sendline("cd " + self.home + "; git log -1 --pretty=fuller | grep -A 5 \"commit\"; cd \.\.") |
| 383 | self.handle.expect("cd ..") |
| 384 | self.handle.expect("\$") |
| 385 | response=(self.name +": \n"+ str(self.handle.before + self.handle.after)) |
admin | e0eeea2 | 2014-04-14 10:22:46 -0700 | [diff] [blame] | 386 | lines=response.splitlines() |
| 387 | for line in lines: |
| 388 | print line |
| 389 | return lines[2] |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 390 | except pexpect.EOF: |
| 391 | main.log.error(self.name + ": EOF exception found") |
| 392 | main.log.error(self.name + ": " + self.handle.before) |
| 393 | main.cleanup() |
| 394 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 395 | except: |
| 396 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 397 | main.log.error( traceback.print_exc() ) |
| 398 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 399 | main.cleanup() |
| 400 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 401 | |
admin | c6cfc1c | 2014-04-21 13:55:21 -0700 | [diff] [blame] | 402 | def ad_flow(self): |
| 403 | main.log.info("AD_FLOW RUNNING!!!!") |
| 404 | self.handle.sendline("cd "+self.home+ "/scripts") |
| 405 | self.handle.expect("scripts") |
Jon Hall | 9c6e2c0 | 2014-05-02 10:18:53 -0700 | [diff] [blame] | 406 | main.log.info("Adding flows") |
admin | c6cfc1c | 2014-04-21 13:55:21 -0700 | [diff] [blame] | 407 | self.handle.sendline("./pyintents.py") |
Jon Hall | 9c6e2c0 | 2014-05-02 10:18:53 -0700 | [diff] [blame] | 408 | self.handle.expect(["$",pexpect.EOF,pexpect.TIMEOUT]) |
| 409 | response = self.handle.before |
admin | c6cfc1c | 2014-04-21 13:55:21 -0700 | [diff] [blame] | 410 | self.handle.sendline("cd "+self.home) |
| 411 | return main.TRUE |
| 412 | |
| 413 | def rm_flow(self): |
| 414 | main.log.info("RM_FLOW RUNNING!!!") |
| 415 | self.handle.sendline("cd "+self.home+ "/scripts") |
| 416 | self.handle.expect("scripts") |
Jon Hall | 9c6e2c0 | 2014-05-02 10:18:53 -0700 | [diff] [blame] | 417 | main.log.info("Removing flows") |
admin | c6cfc1c | 2014-04-21 13:55:21 -0700 | [diff] [blame] | 418 | self.handle.sendline("./rmpyintents.py") |
Jon Hall | 9c6e2c0 | 2014-05-02 10:18:53 -0700 | [diff] [blame] | 419 | self.handle.expect(["$",pexpect.EOF,pexpect.TIMEOUT]) |
| 420 | response = self.handle.before |
admin | c6cfc1c | 2014-04-21 13:55:21 -0700 | [diff] [blame] | 421 | self.handle.sendline("cd "+self.home) |
| 422 | return main.TRUE |
| 423 | |
Jon Hall | 265149f | 2014-04-25 13:39:52 -0700 | [diff] [blame] | 424 | def purge(self): |
| 425 | main.log.info("Purging dead intents") |
| 426 | self.handle.sendline("cd "+self.home+ "/scripts") |
| 427 | self.handle.expect("scripts") |
| 428 | print("Purging Intents") |
| 429 | self.handle.sendline("./purgeintents.py") |
| 430 | self.handle.sendline("cd "+self.home) |
| 431 | return main.TRUE |
admin | c6cfc1c | 2014-04-21 13:55:21 -0700 | [diff] [blame] | 432 | |
| 433 | |
| 434 | |
Jon Hall | 4a2b048 | 2014-04-18 16:29:26 -0700 | [diff] [blame] | 435 | def add_flow(self, testONip, user = "admin", password = "", flowDef = "/flowdef.txt"): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 436 | ''' |
| 437 | Copies the flowdef file from TestStation -> ONOS machine |
| 438 | Then runs ./add_flow.py to add the flows to ONOS |
| 439 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 440 | try: |
| 441 | main.log.info("Adding Flows...") |
| 442 | self.handle.sendline("scp %s@%s:%s /tmp/flowtmp" %(user,testONip,flowDef)) |
| 443 | i=self.handle.expect(['[pP]assword:', '100%', pexpect.TIMEOUT],30) |
| 444 | if(i==0): |
| 445 | self.handle.sendline("%s" %(password)) |
| 446 | self.handle.sendline("") |
| 447 | self.handle.expect("100%") |
| 448 | self.handle.expect("\$", 30) |
| 449 | self.handle.sendline(self.home + "/web/add_flow.py -m onos -f /tmp/flowtmp") |
| 450 | self.handle.expect("\$", 1000) |
| 451 | main.log.info("Flows added") |
| 452 | return main.TRUE |
| 453 | |
| 454 | elif(i==1): |
| 455 | self.handle.sendline("") |
| 456 | self.handle.expect("\$", 10) |
| 457 | self.handle.sendline( self.home + "/web/add_flow.py -m onos -f /tmp/flowtmp") |
| 458 | self.handle.expect("\$", 1000) |
| 459 | main.log.info("Flows added") |
| 460 | return main.TRUE |
| 461 | |
| 462 | elif(i==2): |
| 463 | main.log.error("Flow Def file SCP Timed out...") |
| 464 | return main.FALSE |
| 465 | |
| 466 | else: |
| 467 | main.log.error("Failed to add flows...") |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 468 | return main.FALSE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 469 | except pexpect.EOF: |
| 470 | main.log.error(self.name + ": EOF exception found") |
| 471 | main.log.error(self.name + ": " + self.handle.before) |
| 472 | main.cleanup() |
| 473 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 474 | except: |
| 475 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 476 | main.log.error( traceback.print_exc() ) |
| 477 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 478 | main.cleanup() |
| 479 | main.exit() |
| 480 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 481 | |
| 482 | def delete_flow(self, *delParams): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 483 | ''' |
| 484 | Deletes a specific flow, a range of flows, or all flows. |
| 485 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 486 | try: |
| 487 | if len(delParams)==1: |
| 488 | if str(delParams[0])=="all": |
| 489 | main.log.info(self.name + ": Deleting ALL flows...") |
| 490 | #self.execute(cmd="~/ONOS/scripts/TestON_delete_flow.sh all",prompt="done",timeout=150) |
| 491 | self.handle.sendline(self.home + "/web/delete_flow.py all") |
| 492 | self.handle.expect("delete_flow") |
| 493 | self.handle.expect("\$",1000) |
| 494 | main.log.info(self.name + ": Flows deleted") |
| 495 | else: |
| 496 | main.log.info(self.name + ": Deleting flow "+str(delParams[0])+"...") |
| 497 | #self.execute(cmd="~/ONOS/scripts/TestON_delete_flow.sh "+str(delParams[0]),prompt="done",timeout=150) |
| 498 | #self.execute(cmd="\n",prompt="\$",timeout=60) |
| 499 | self.handle.sendline(self.home +"/web/delete_flow.py %d" % int(delParams[0])) |
| 500 | self.handle.expect("delete_flow") |
| 501 | self.handle.expect("\$",60) |
| 502 | main.log.info(self.name + ": Flow deleted") |
| 503 | elif len(delParams)==2: |
| 504 | main.log.info(self.name + ": Deleting flows "+str(delParams[0])+" through "+str(delParams[1])+"...") |
| 505 | #self.execute(cmd="~/ONOS/scripts/TestON_delete_flow.sh "+str(delParams[0])+" "+str(delParams[1]),prompt="done",timeout=150) |
| 506 | #self.execute(cmd="\n",prompt="\$",timeout=60) |
| 507 | self.handle.sendline(self.home + "/web/delete_flow.py %d %d" % (int(delParams[0]), int(delParams[1]))) |
| 508 | self.handle.expect("delete_flow") |
| 509 | self.handle.expect("\$",600) |
| 510 | main.log.info(self.name + ": Flows deleted") |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 511 | except pexpect.EOF: |
| 512 | main.log.error(self.name + ": EOF exception found") |
| 513 | main.log.error(self.name + ": " + self.handle.before) |
| 514 | main.cleanup() |
| 515 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 516 | except: |
| 517 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 518 | main.log.error( traceback.print_exc() ) |
| 519 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 520 | main.cleanup() |
| 521 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 522 | |
| 523 | def check_flow(self): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 524 | ''' |
| 525 | Calls the ./get_flow.py all and checks: |
| 526 | - If each FlowPath has at least one FlowEntry |
| 527 | - That there are no "NOT"s found |
| 528 | returns TRUE/FALSE |
| 529 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 530 | try: |
| 531 | flowEntryDetect = 1 |
| 532 | count = 0 |
| 533 | self.handle.sendline("clear") |
| 534 | time.sleep(1) |
| 535 | self.handle.sendline(self.home + "/web/get_flow.py all") |
| 536 | self.handle.expect("get_flow") |
Jon Hall | 3bd7c79 | 2014-05-30 09:05:21 -0700 | [diff] [blame^] | 537 | for x in range(15): |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 538 | i=self.handle.expect(['FlowPath','FlowEntry','NOT','\$',pexpect.TIMEOUT],timeout=180) |
| 539 | if i==0: |
| 540 | count = count + 1 |
| 541 | if flowEntryDetect == 0: |
| 542 | main.log.info(self.name + ": FlowPath without FlowEntry") |
| 543 | return main.FALSE |
| 544 | else: |
| 545 | flowEntryDetect = 0 |
| 546 | elif i==1: |
| 547 | flowEntryDetect = 1 |
| 548 | elif i==2: |
| 549 | main.log.error(self.name + ": Found a NOT") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 550 | return main.FALSE |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 551 | elif i==3: |
| 552 | if count == 0: |
| 553 | main.log.info(self.name + ": There don't seem to be any flows here...") |
| 554 | return main.FALSE |
| 555 | else: |
| 556 | main.log.info(self.name + ": All flows pass") |
| 557 | main.log.info(self.name + ": Number of FlowPaths: "+str(count)) |
| 558 | return main.TRUE |
| 559 | elif i==4: |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 560 | main.log.error(self.name + ":Check_flow() - Command Timeout!") |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 561 | return main.FALSE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 562 | except pexpect.EOF: |
| 563 | main.log.error(self.name + ": EOF exception found") |
| 564 | main.log.error(self.name + ": " + self.handle.before) |
| 565 | main.cleanup() |
| 566 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 567 | except: |
| 568 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 569 | main.log.error( traceback.print_exc() ) |
| 570 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 571 | main.cleanup() |
| 572 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 573 | |
| 574 | def get_flow(self, *flowParams): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 575 | ''' |
| 576 | Returns verbose output of ./get_flow.py |
| 577 | ''' |
| 578 | try: |
| 579 | if len(flowParams)==1: |
| 580 | if str(flowParams[0])=="all": |
| 581 | self.execute(cmd="\n",prompt="\$",timeout=60) |
| 582 | main.log.info(self.name + ": Getting all flow data...") |
| 583 | data = self.execute(cmd=self.home + "/scripts/TestON_get_flow.sh all",prompt="done",timeout=150) |
| 584 | self.execute(cmd="\n",prompt="\$",timeout=60) |
| 585 | return data |
| 586 | else: |
| 587 | main.log.info(self.name + ": Retrieving flow "+str(flowParams[0])+" data...") |
| 588 | data = self.execute(cmd=self.home +"/scripts/TestON_get_flow.sh "+str(flowParams[0]),prompt="done",timeout=150) |
| 589 | self.execute(cmd="\n",prompt="\$",timeout=60) |
| 590 | return data |
| 591 | elif len(flowParams)==5: |
| 592 | main.log.info(self.name + ": Retrieving flow installer data...") |
| 593 | 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) |
| 594 | self.execute(cmd="\n",prompt="\$",timeout=60) |
| 595 | return data |
| 596 | elif len(flowParams)==4: |
| 597 | main.log.info(self.name + ": Retrieving flow endpoints...") |
| 598 | 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) |
| 599 | self.execute(cmd="\n",prompt="\$",timeout=60) |
| 600 | return data |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 601 | except pexpect.EOF: |
| 602 | main.log.error(self.name + ": EOF exception found") |
| 603 | main.log.error(self.name + ": " + self.handle.before) |
| 604 | main.cleanup() |
| 605 | main.exit() |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 606 | except: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 607 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 608 | main.log.error( traceback.print_exc() ) |
| 609 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 610 | main.cleanup() |
| 611 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 612 | |
| 613 | |
SeanCorcoran | 83a653a | 2014-04-22 15:03:18 -0700 | [diff] [blame] | 614 | # http://localhost:8080/wm/onos/topology/switches/json |
| 615 | # http://localhost:8080/wm/onos/topology/links/json |
Jon Hall | 8060af0 | 2014-04-14 14:17:58 -0700 | [diff] [blame] | 616 | # http://localhost:8080/wm/onos/registry/controllers/json |
| 617 | # http://localhost:8080/wm/onos/registry/switches/json" |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 618 | |
| 619 | def get_json(self, url): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 620 | ''' |
| 621 | Helper functions used to parse the json output of a rest call |
| 622 | ''' |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 623 | try: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 624 | try: |
| 625 | command = "curl -s %s" % (url) |
| 626 | result = os.popen(command).read() |
| 627 | parsedResult = json.loads(result) |
| 628 | except: |
| 629 | print "REST IF %s has issue" % command |
| 630 | parsedResult = "" |
| 631 | |
| 632 | if type(parsedResult) == 'dict' and parsedResult.has_key('code'): |
| 633 | print "REST %s returned code %s" % (command, parsedResult['code']) |
| 634 | parsedResult = "" |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 635 | return parsedResult |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 636 | except pexpect.EOF: |
| 637 | main.log.error(self.name + ": EOF exception found") |
| 638 | main.log.error(self.name + ": " + self.handle.before) |
| 639 | main.cleanup() |
| 640 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 641 | except: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 642 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 643 | main.log.error( traceback.print_exc() ) |
| 644 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 645 | main.cleanup() |
| 646 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 647 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 648 | def check_switch(self,RestIP,correct_nr_switch, RestPort ="8080" ): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 649 | ''' |
| 650 | Used by check_status |
| 651 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 652 | try: |
| 653 | buf = "" |
| 654 | retcode = 0 |
admin | 2e131ab | 2014-05-28 10:03:42 -0700 | [diff] [blame] | 655 | url="http://%s:%s/wm/onos/topology/switches" % (RestIP, RestPort) |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 656 | parsedResult = self.get_json(url) |
| 657 | if parsedResult == "": |
| 658 | retcode = 1 |
| 659 | return (retcode, "Rest API has an issue") |
| 660 | url = "http://%s:%s/wm/onos/registry/switches/json" % (RestIP, RestPort) |
| 661 | registry = self.get_json(url) |
| 662 | |
| 663 | if registry == "": |
| 664 | retcode = 1 |
| 665 | return (retcode, "Rest API has an issue") |
| 666 | |
| 667 | cnt = 0 |
| 668 | active = 0 |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 669 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 670 | for s in parsedResult: |
| 671 | cnt += 1 |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 672 | if s['state'] == "ACTIVE": |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 673 | active += 1 |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 674 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 675 | buf += "switch: network %d : %d switches %d active\n" % (0+1, cnt, active) |
| 676 | if correct_nr_switch != cnt: |
| 677 | buf += "switch fail: network %d should have %d switches but has %d\n" % (1, correct_nr_switch, cnt) |
| 678 | retcode = 1 |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 679 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 680 | if correct_nr_switch != active: |
| 681 | buf += "switch fail: network %d should have %d active switches but has %d\n" % (1, correct_nr_switch, active) |
| 682 | retcode = 1 |
| 683 | |
| 684 | return (retcode, buf) |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 685 | except pexpect.EOF: |
| 686 | main.log.error(self.name + ": EOF exception found") |
| 687 | main.log.error(self.name + ": " + self.handle.before) |
| 688 | main.cleanup() |
| 689 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 690 | except: |
| 691 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 692 | main.log.error( traceback.print_exc() ) |
| 693 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 694 | main.cleanup() |
| 695 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 696 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 697 | def check_link(self,RestIP, nr_links, RestPort = "8080"): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 698 | ''' |
| 699 | Used by check_status |
| 700 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 701 | try: |
| 702 | buf = "" |
| 703 | retcode = 0 |
| 704 | |
admin | 2e131ab | 2014-05-28 10:03:42 -0700 | [diff] [blame] | 705 | url = "http://%s:%s/wm/onos/topology/links" % (RestIP, RestPort) |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 706 | parsedResult = self.get_json(url) |
| 707 | |
| 708 | if parsedResult == "": |
| 709 | retcode = 1 |
| 710 | return (retcode, "Rest API has an issue") |
| 711 | |
| 712 | buf += "link: total %d links (correct : %d)\n" % (len(parsedResult), nr_links) |
| 713 | intra = 0 |
| 714 | interlink=0 |
| 715 | |
| 716 | for s in parsedResult: |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 717 | intra = intra + 1 |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 718 | |
| 719 | if intra != nr_links: |
| 720 | buf += "link fail\n" |
| 721 | retcode = 1 |
| 722 | |
| 723 | return (retcode, buf) |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 724 | except pexpect.EOF: |
| 725 | main.log.error(self.name + ": EOF exception found") |
| 726 | main.log.error(self.name + ": " + self.handle.before) |
| 727 | main.cleanup() |
| 728 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 729 | except: |
| 730 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 731 | main.log.error( traceback.print_exc() ) |
| 732 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 733 | main.cleanup() |
| 734 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 735 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 736 | def check_status_report(self, ip, numoswitch, numolink, port="8080"): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 737 | ''' |
| 738 | Checks the number of swithes & links that ONOS sees against the supplied values. |
| 739 | Writes to the report log. |
| 740 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 741 | try: |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 742 | main.log.info(self.name + ": Making some rest calls...") |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 743 | switch = self.check_switch(ip, int(numoswitch), port) |
| 744 | link = self.check_link(ip, int(numolink), port) |
| 745 | value = switch[0] |
| 746 | value += link[0] |
| 747 | main.log.report( self.name + ": \n-----\n%s%s-----\n" % ( switch[1], link[1]) ) |
| 748 | if value != 0: |
| 749 | return main.FALSE |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 750 | else: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 751 | # "PASS" |
| 752 | return main.TRUE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 753 | except pexpect.EOF: |
| 754 | main.log.error(self.name + ": EOF exception found") |
| 755 | main.log.error(self.name + ": " + self.handle.before) |
| 756 | main.cleanup() |
| 757 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 758 | except: |
| 759 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 760 | main.log.error( traceback.print_exc() ) |
| 761 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 762 | main.cleanup() |
| 763 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 764 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 765 | def check_status(self, ip, numoswitch, numolink, port = "8080"): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 766 | ''' |
| 767 | Checks the number of swithes & links that ONOS sees against the supplied values. |
| 768 | Writes to the main log. |
| 769 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 770 | try: |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 771 | main.log.info(self.name + ": Making some rest calls...") |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 772 | switch = self.check_switch(ip, int(numoswitch), port) |
| 773 | link = self.check_link(ip, int(numolink), port) |
| 774 | value = switch[0] |
| 775 | value += link[0] |
| 776 | main.log.info(self.name + ": \n-----\n%s%s-----\n" % ( switch[1], link[1]) ) |
| 777 | if value != 0: |
| 778 | return main.FALSE |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 779 | else: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 780 | # "PASS" |
| 781 | return main.TRUE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 782 | except pexpect.EOF: |
| 783 | main.log.error(self.name + ": EOF exception found") |
| 784 | main.log.error(self.name + ": " + self.handle.before) |
| 785 | main.cleanup() |
| 786 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 787 | except: |
| 788 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 789 | main.log.error( traceback.print_exc() ) |
| 790 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 791 | main.cleanup() |
| 792 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 793 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 794 | def check_for_no_exceptions(self): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 795 | ''' |
| 796 | TODO: Rewrite |
| 797 | Used by CassndraCheck.py to scan ONOS logs for Exceptions |
| 798 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 799 | try: |
| 800 | self.handle.sendline("dsh 'grep Exception ~/ONOS/onos-logs/onos.*.log'") |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 801 | self.handle.expect("\$ dsh") |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 802 | self.handle.expect("\$") |
| 803 | output = self.handle.before |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 804 | main.log.info(self.name + ": " + output ) |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 805 | if re.search("Exception",output): |
| 806 | return main.FALSE |
| 807 | else : |
| 808 | return main.TRUE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 809 | except pexpect.EOF: |
| 810 | main.log.error(self.name + ": EOF exception found") |
| 811 | main.log.error(self.name + ": " + self.handle.before) |
| 812 | main.cleanup() |
| 813 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 814 | except: |
| 815 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 816 | main.log.error( traceback.print_exc() ) |
| 817 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 818 | main.cleanup() |
| 819 | main.exit() |
| 820 | |
| 821 | |
admin | e0eeea2 | 2014-04-14 10:22:46 -0700 | [diff] [blame] | 822 | def git_pull(self, comp1=""): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 823 | ''' |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 824 | Assumes that "git pull" works without login |
admin | e0eeea2 | 2014-04-14 10:22:46 -0700 | [diff] [blame] | 825 | |
| 826 | This function will perform a git pull on the ONOS instance. |
| 827 | If used as git_pull("NODE") it will do git pull + NODE. This is |
| 828 | for the purpose of pulling from other nodes if necessary. |
| 829 | |
| 830 | Otherwise, this function will perform a git pull in the |
| 831 | ONOS repository. If it has any problems, it will return main.ERROR |
| 832 | If it successfully does a git_pull, it will return a 1. |
| 833 | If it has no updates, it will return a 0. |
| 834 | |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 835 | ''' |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 836 | try: |
Jon Hall | e80ef8c | 2014-04-29 15:29:13 -0700 | [diff] [blame] | 837 | # main.log.info(self.name + ": Stopping ONOS") |
| 838 | #self.stop() |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 839 | self.handle.sendline("cd " + self.home) |
| 840 | self.handle.expect("ONOS\$") |
| 841 | if comp1=="": |
| 842 | self.handle.sendline("git pull") |
| 843 | else: |
| 844 | self.handle.sendline("git pull " + comp1) |
| 845 | |
| 846 | uptodate = 0 |
SeanCorcoran | 20bd6fc | 2014-04-16 17:10:30 -0700 | [diff] [blame] | 847 | i=self.handle.expect(['fatal','Username\sfor\s(.*):\s','Unpacking\sobjects',pexpect.TIMEOUT,'Already up-to-date','Aborting'],timeout=1800) |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 848 | #debug |
| 849 | #main.log.report(self.name +": \n"+"git pull response: " + str(self.handle.before) + str(self.handle.after)) |
| 850 | if i==0: |
| 851 | main.log.error(self.name + ": Git pull had some issue...") |
| 852 | return main.ERROR |
| 853 | elif i==1: |
| 854 | main.log.error(self.name + ": Git Pull Asking for username!!! BADD!") |
| 855 | return main.ERROR |
| 856 | elif i==2: |
| 857 | main.log.info(self.name + ": Git Pull - pulling repository now") |
| 858 | self.handle.expect("ONOS\$", 120) |
| 859 | return 0 |
| 860 | elif i==3: |
| 861 | main.log.error(self.name + ": Git Pull - TIMEOUT") |
| 862 | return main.ERROR |
| 863 | elif i==4: |
| 864 | main.log.info(self.name + ": Git Pull - Already up to date") |
| 865 | return 1 |
| 866 | elif i==5: |
| 867 | main.log.info(self.name + ": Git Pull - Aborting... Are there conflicting git files?") |
| 868 | return main.ERROR |
| 869 | else: |
| 870 | main.log.error(self.name + ": Git Pull - Unexpected response, check for pull errors") |
| 871 | return main.ERROR |
| 872 | except pexpect.EOF: |
| 873 | main.log.error(self.name + ": EOF exception found") |
| 874 | main.log.error(self.name + ": " + self.handle.before) |
| 875 | main.cleanup() |
| 876 | main.exit() |
| 877 | except: |
| 878 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 879 | main.log.error( traceback.print_exc() ) |
| 880 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 881 | main.cleanup() |
| 882 | main.exit() |
admin | e0eeea2 | 2014-04-14 10:22:46 -0700 | [diff] [blame] | 883 | #******************************************************** |
| 884 | |
| 885 | |
admin | 7373a81 | 2014-04-16 09:49:02 -0700 | [diff] [blame] | 886 | def git_compile(self): |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 887 | ''' |
| 888 | Compiles ONOS |
| 889 | First runs mvn clean then mvn compile |
| 890 | ''' |
| 891 | try: |
| 892 | main.log.info(self.name + ": mvn clean") |
admin | 8fc0282 | 2014-04-16 13:31:23 -0700 | [diff] [blame] | 893 | self.handle.sendline("cd " + self.home) |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 894 | self.handle.sendline("mvn clean") |
| 895 | while 1: |
Jon Hall | 1636f94 | 2014-04-17 10:07:23 -0700 | [diff] [blame] | 896 | 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] | 897 | if i == 0: |
Jon Hall | 1636f94 | 2014-04-17 10:07:23 -0700 | [diff] [blame] | 898 | 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] | 899 | return main.FALSE |
| 900 | elif i == 1: |
Jon Hall | 1636f94 | 2014-04-17 10:07:23 -0700 | [diff] [blame] | 901 | main.log.error(self.name + ": Clean failure!") |
| 902 | return main.FALSE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 903 | elif i == 2: |
Jon Hall | 1636f94 | 2014-04-17 10:07:23 -0700 | [diff] [blame] | 904 | main.log.info(self.name + ": Clean success!") |
| 905 | elif i == 3: |
admin | 8fc0282 | 2014-04-16 13:31:23 -0700 | [diff] [blame] | 906 | main.log.info(self.name + ": Clean complete") |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 907 | break; |
Jon Hall | 1636f94 | 2014-04-17 10:07:23 -0700 | [diff] [blame] | 908 | elif i == 4: |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 909 | main.log.error(self.name + ": mvn clean TIMEOUT!") |
| 910 | return main.FALSE |
Jon Hall | 1636f94 | 2014-04-17 10:07:23 -0700 | [diff] [blame] | 911 | else: |
| 912 | main.log.error(self.name + ": unexpected response from mvn clean") |
| 913 | return main.FALSE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 914 | |
| 915 | main.log.info(self.name + ": mvn compile") |
| 916 | self.handle.sendline("mvn compile") |
| 917 | while 1: |
Jon Hall | 1636f94 | 2014-04-17 10:07:23 -0700 | [diff] [blame] | 918 | 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] | 919 | if i == 0: |
Jon Hall | 1636f94 | 2014-04-17 10:07:23 -0700 | [diff] [blame] | 920 | main.log.error(self.name + ":There is insufficient memory for the Java Runtime Environment to continue.") |
| 921 | return main.FALSE |
| 922 | if i == 1: |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 923 | main.log.error(self.name + ": Build failure!") |
| 924 | return main.FALSE |
Jon Hall | 1636f94 | 2014-04-17 10:07:23 -0700 | [diff] [blame] | 925 | elif i == 2: |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 926 | main.log.info(self.name + ": Build success!") |
Jon Hall | 1636f94 | 2014-04-17 10:07:23 -0700 | [diff] [blame] | 927 | elif i == 3: |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 928 | main.log.info(self.name + ": Build complete") |
Jon Hall | a15739a | 2014-05-16 17:17:11 -0700 | [diff] [blame] | 929 | self.handle.sendline("./build-ramcloud-java-bindings.sh") |
Jon Hall | 010f541 | 2014-05-21 15:10:12 -0700 | [diff] [blame] | 930 | self.handle.expect("\$", timeout=60) |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 931 | return main.TRUE |
Jon Hall | 1636f94 | 2014-04-17 10:07:23 -0700 | [diff] [blame] | 932 | elif i == 4: |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 933 | main.log.error(self.name + ": mvn compile TIMEOUT!") |
| 934 | return main.FALSE |
| 935 | else: |
Jon Hall | 1636f94 | 2014-04-17 10:07:23 -0700 | [diff] [blame] | 936 | main.log.error(self.name + ": unexpected response from mvn compile") |
| 937 | return main.FALSE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 938 | except pexpect.EOF: |
| 939 | main.log.error(self.name + ": EOF exception found") |
| 940 | main.log.error(self.name + ": " + self.handle.before) |
| 941 | main.cleanup() |
| 942 | main.exit() |
| 943 | except: |
| 944 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 945 | main.log.error( traceback.print_exc() ) |
| 946 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 947 | main.cleanup() |
| 948 | main.exit() |
admin | 4a58db9 | 2013-09-30 12:04:54 -0700 | [diff] [blame] | 949 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 950 | def tcpdump(self, intf = "eth0"): |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 951 | ''' |
| 952 | Runs tpdump on an intferface and saves in onos-logs under the ONOS home directory |
| 953 | intf can be specified, or the default eth0 is used |
| 954 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 955 | try: |
| 956 | self.handle.sendline("") |
| 957 | self.handle.expect("\$") |
Jon Hall | 26f316b | 2014-04-11 11:21:25 -0700 | [diff] [blame] | 958 | 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] | 959 | i=self.handle.expect(['No\ssuch\device','listening\son',pexpect.TIMEOUT],timeout=10) |
| 960 | if i == 0: |
| 961 | main.log.error(self.name + ": tcpdump - No such device exists. tcpdump attempted on: " + intf) |
| 962 | return main.FALSE |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 963 | elif i == 1: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 964 | main.log.info(self.name + ": tcpdump started on " + intf) |
| 965 | return main.TRUE |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 966 | elif i == 2: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 967 | main.log.error(self.name + ": tcpdump command timed out! Check interface name, given interface was: " + intf) |
| 968 | return main.FALSE |
| 969 | else: |
| 970 | main.log.error(self.name + ": tcpdump - unexpected response") |
| 971 | return main.FALSE |
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() |
| 983 | |
admin | 4a58db9 | 2013-09-30 12:04:54 -0700 | [diff] [blame] | 984 | def kill_tcpdump(self): |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 985 | ''' |
| 986 | Kills any tcpdump processes running |
| 987 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 988 | try: |
| 989 | self.handle.sendline("") |
| 990 | self.handle.expect("\$") |
| 991 | 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] | 992 | except pexpect.EOF: |
| 993 | main.log.error(self.name + ": EOF exception found") |
| 994 | main.log.error(self.name + ": " + self.handle.before) |
| 995 | main.cleanup() |
| 996 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 997 | except: |
| 998 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 999 | main.log.error( traceback.print_exc() ) |
| 1000 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1001 | main.cleanup() |
| 1002 | main.exit() |
| 1003 | |
Jon Hall | f15f785 | 2014-05-20 10:37:23 -0700 | [diff] [blame] | 1004 | def find_host(self,RestIP,RestPort,RestAPI,hostMAC): |
| 1005 | retcode = 0 # number of devices found with given MAC |
| 1006 | retswitch = [] # Switch DPID's of devices found with MAC |
| 1007 | retport = [] # Switch port connected to to devices found with MAC |
| 1008 | foundHost = [] |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1009 | try: |
SeanCorcoran | 83a653a | 2014-04-22 15:03:18 -0700 | [diff] [blame] | 1010 | ##### device rest API is: 'host:8080/wm/onos/topology/switches/json' ### |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1011 | url ="http://%s:%s%s" %(RestIP,RestPort,RestAPI) |
| 1012 | |
| 1013 | try: |
| 1014 | command = "curl -s %s" % (url) |
| 1015 | result = os.popen(command).read() |
| 1016 | parsedResult = json.loads(result) |
| 1017 | # print parsedResult |
| 1018 | except: |
| 1019 | print "REST IF %s has issue" % command |
| 1020 | parsedResult = "" |
| 1021 | |
| 1022 | if parsedResult == "": |
Jon Hall | f15f785 | 2014-05-20 10:37:23 -0700 | [diff] [blame] | 1023 | return (retcode, "Rest API has an error", retport) |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1024 | else: |
Jon Hall | f15f785 | 2014-05-20 10:37:23 -0700 | [diff] [blame] | 1025 | for host in enumerate(parsedResult): |
| 1026 | print host |
| 1027 | if (host[1] != []): |
| 1028 | try: |
| 1029 | foundHost = host[1]['mac'] |
| 1030 | except: |
| 1031 | print "Error in detecting MAC address." |
| 1032 | print foundHost |
| 1033 | print hostMAC |
| 1034 | if foundHost == hostMAC: |
| 1035 | for switch in enumerate(host[1]['attachmentPoints']): |
| 1036 | retswitch.append(switch[1]['dpid']) |
| 1037 | retport.append(switch[1]['port']) |
| 1038 | retcode = retcode +1 |
| 1039 | foundHost ='' |
| 1040 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1041 | for switch in enumerate(parsedResult): |
| 1042 | for port in enumerate(switch[1]['ports']): |
| 1043 | if ( port[1]['devices'] != [] ): |
| 1044 | try: |
Jon Hall | f15f785 | 2014-05-20 10:37:23 -0700 | [diff] [blame] | 1045 | foundHost = port[1]['devices'][0]['ipv4addresses'][0]['ipv4'] |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1046 | except: |
Jon Hall | f15f785 | 2014-05-20 10:37:23 -0700 | [diff] [blame] | 1047 | print "Error in detecting MAC address." |
| 1048 | if foundHost == hostMAC: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1049 | retswitch.append(switch[1]['dpid']) |
| 1050 | retport.append(port[1]['desc']) |
| 1051 | retmac.append(port[1]['devices'][0]['mac']) |
| 1052 | retcode = retcode +1 |
Jon Hall | f15f785 | 2014-05-20 10:37:23 -0700 | [diff] [blame] | 1053 | foundHost ='' |
| 1054 | ''' |
| 1055 | return(retcode, retswitch, retport) |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1056 | except pexpect.EOF: |
| 1057 | main.log.error(self.name + ": EOF exception found") |
| 1058 | main.log.error(self.name + ": " + self.handle.before) |
| 1059 | main.cleanup() |
| 1060 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1061 | except: |
| 1062 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1063 | main.log.error( traceback.print_exc() ) |
| 1064 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1065 | main.cleanup() |
| 1066 | main.exit() |
SeanCorcoran | 29b7054 | 2014-05-14 14:53:42 -0700 | [diff] [blame] | 1067 | |
| 1068 | def check_exceptions(self): |
| 1069 | ''' |
| 1070 | Greps the logs for "xception" |
| 1071 | ''' |
| 1072 | try: |
| 1073 | output = '' |
| 1074 | self.handle.sendline("") |
Jon Hall | a78cf9a | 2014-05-16 10:49:30 -0700 | [diff] [blame] | 1075 | i = self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT]) |
| 1076 | #main.log.warn("first expect response: " +str(i)) |
SeanCorcoran | 29b7054 | 2014-05-14 14:53:42 -0700 | [diff] [blame] | 1077 | self.handle.sendline("cd "+self.home+"/onos-logs") |
Jon Hall | a78cf9a | 2014-05-16 10:49:30 -0700 | [diff] [blame] | 1078 | self.handle.sendline("grep \"xception\" *") |
| 1079 | i = self.handle.expect(["\*",pexpect.EOF,pexpect.TIMEOUT]) |
| 1080 | #main.log.warn("second expect response: " +str(i)) |
| 1081 | i = self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT]) |
| 1082 | #main.log.warn("third expect response: " +str(i)) |
SeanCorcoran | 29b7054 | 2014-05-14 14:53:42 -0700 | [diff] [blame] | 1083 | response = self.handle.before |
Jon Hall | a78cf9a | 2014-05-16 10:49:30 -0700 | [diff] [blame] | 1084 | count = 0 |
SeanCorcoran | 29b7054 | 2014-05-14 14:53:42 -0700 | [diff] [blame] | 1085 | for line in response.splitlines(): |
| 1086 | if re.search("log:", line): |
| 1087 | output +="Exceptions found in " + line + "\n" |
Jon Hall | a78cf9a | 2014-05-16 10:49:30 -0700 | [diff] [blame] | 1088 | count +=1 |
SeanCorcoran | 29b7054 | 2014-05-14 14:53:42 -0700 | [diff] [blame] | 1089 | elif re.search("std...:",line): |
| 1090 | output+="Exceptions found in " + line + "\n" |
Jon Hall | a78cf9a | 2014-05-16 10:49:30 -0700 | [diff] [blame] | 1091 | count +=1 |
SeanCorcoran | 29b7054 | 2014-05-14 14:53:42 -0700 | [diff] [blame] | 1092 | else: |
| 1093 | pass |
| 1094 | #these should be the old logs |
admin | 1723f1c | 2014-05-19 16:08:39 -0700 | [diff] [blame] | 1095 | main.log.report(str(count) + " Exceptions were found on "+self.name) |
SeanCorcoran | 29b7054 | 2014-05-14 14:53:42 -0700 | [diff] [blame] | 1096 | return output |
| 1097 | except pexpect.TIMEOUT: |
| 1098 | main.log.error(self.name + ": Timeout exception found in check_exceptions function") |
| 1099 | except pexpect.EOF: |
| 1100 | main.log.error(self.name + ": EOF exception found") |
| 1101 | main.log.error(self.name + ": " + self.handle.before) |
| 1102 | main.cleanup() |
| 1103 | main.exit() |
| 1104 | except: |
| 1105 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1106 | main.log.error( traceback.print_exc() ) |
| 1107 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1108 | main.cleanup() |
| 1109 | main.exit() |