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 |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 230 | else: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 231 | main.log.error(self.name + ": ONOS process not running...") |
| 232 | return main.FALSE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 233 | except pexpect.EOF: |
| 234 | main.log.error(self.name + ": EOF exception found") |
| 235 | main.log.error(self.name + ": " + self.handle.before) |
| 236 | main.cleanup() |
| 237 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 238 | except: |
| 239 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 240 | main.log.error( traceback.print_exc() ) |
| 241 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 242 | main.cleanup() |
| 243 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 244 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 245 | |
| 246 | |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 247 | def rest_status(self): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 248 | ''' |
| 249 | Checks if the rest server is running. |
| 250 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 251 | try: |
| 252 | response = self.execute(cmd= self.home + "/start-rest.sh status ",prompt="running",timeout=10) |
| 253 | if re.search("rest\sserver\sis\srunning",response): |
| 254 | main.log.info(self.name + ": Rest Server is running") |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 255 | return main.TRUE |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 256 | elif re.search("rest\sserver\sis\snot\srunning",response): |
| 257 | main.log.warn(self.name + ": Rest Server is not Running") |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 258 | return main.FALSE |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 259 | else : |
| 260 | main.log.error(self.name + ": No response" +response) |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 261 | return main.FALSE |
| 262 | except pexpect.EOF: |
| 263 | main.log.error(self.name + ": EOF exception found") |
| 264 | main.log.error(self.name + ": " + self.handle.before) |
| 265 | main.cleanup() |
| 266 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 267 | except: |
| 268 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 269 | main.log.error( traceback.print_exc() ) |
| 270 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 271 | main.cleanup() |
| 272 | main.exit() |
| 273 | |
| 274 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 275 | def stop(self): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 276 | ''' |
| 277 | Runs ./onos.sh core stop to stop ONOS |
| 278 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 279 | try: |
| 280 | self.handle.sendline("") |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 281 | self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT]) |
Jon Hall | 4a2b048 | 2014-04-18 16:29:26 -0700 | [diff] [blame] | 282 | self.handle.sendline("cd "+self.home) |
| 283 | self.handle.sendline("./onos.sh core stop") |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 284 | i=self.handle.expect(["Stop",pexpect.EOF,pexpect.TIMEOUT]) |
| 285 | self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT], 60) |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 286 | result = self.handle.before |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 287 | if re.search("Killed", result): |
| 288 | main.log.info(self.name + ": ONOS Killed Successfully") |
| 289 | return main.TRUE |
| 290 | else : |
| 291 | main.log.warn(self.name + ": ONOS wasn't running") |
| 292 | return main.FALSE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 293 | except pexpect.EOF: |
| 294 | main.log.error(self.name + ": EOF exception found") |
| 295 | main.log.error(self.name + ": " + self.handle.before) |
| 296 | main.cleanup() |
| 297 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 298 | except: |
| 299 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 300 | main.log.error( traceback.print_exc() ) |
| 301 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 302 | main.cleanup() |
| 303 | main.exit() |
| 304 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 305 | |
| 306 | def rest_stop(self): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 307 | ''' |
| 308 | Runs ./start-rest.sh stop to stop ONOS rest server |
| 309 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 310 | try: |
| 311 | response = self.execute(cmd= self.home + "/start-rest.sh stop ",prompt="killing",timeout=10) |
| 312 | self.execute(cmd="\n",prompt="\$",timeout=10) |
| 313 | if re.search("killing", response): |
| 314 | main.log.info(self.name + ": Rest Server Stopped") |
| 315 | return main.TRUE |
| 316 | else : |
| 317 | main.log.error(self.name + ": Failed to Stop, Rest Server is not Running") |
| 318 | return main.FALSE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 319 | except pexpect.EOF: |
| 320 | main.log.error(self.name + ": EOF exception found") |
| 321 | main.log.error(self.name + ": " + self.handle.before) |
| 322 | main.cleanup() |
| 323 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 324 | except: |
| 325 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 326 | main.log.error( traceback.print_exc() ) |
| 327 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 328 | main.cleanup() |
| 329 | main.exit() |
| 330 | |
| 331 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 332 | def disconnect(self): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 333 | ''' |
| 334 | Called when Test is complete to disconnect the ONOS handle. |
| 335 | ''' |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 336 | response = '' |
| 337 | try: |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 338 | self.handle.sendline("exit") |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 339 | self.handle.expect("closed") |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 340 | except pexpect.EOF: |
| 341 | main.log.error(self.name + ": EOF exception found") |
| 342 | main.log.error(self.name + ": " + self.handle.before) |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 343 | except: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 344 | main.log.error(self.name + ": Connection failed to the host") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 345 | response = main.FALSE |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 346 | return response |
| 347 | |
Jon Hall | 76f2c46 | 2014-04-17 11:37:15 -0700 | [diff] [blame] | 348 | def print_version(self): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 349 | ''' |
| 350 | Writes the COMMIT number to the report to be parsed by Jenkins data collecter. |
| 351 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 352 | try: |
| 353 | self.handle.sendline("export TERM=xterm-256color") |
| 354 | self.handle.expect("xterm-256color") |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 355 | self.handle.expect("\$") |
admin | f939f8b | 2014-04-03 17:22:56 -0700 | [diff] [blame] | 356 | 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] | 357 | self.handle.expect("cd ..") |
| 358 | self.handle.expect("\$") |
admin | e0eeea2 | 2014-04-14 10:22:46 -0700 | [diff] [blame] | 359 | response=(self.name +": \n"+ str(self.handle.before + self.handle.after)) |
| 360 | main.log.report(response) |
Jon Hall | 76f2c46 | 2014-04-17 11:37:15 -0700 | [diff] [blame] | 361 | except pexpect.EOF: |
| 362 | main.log.error(self.name + ": EOF exception found") |
| 363 | main.log.error(self.name + ": " + self.handle.before) |
| 364 | main.cleanup() |
| 365 | main.exit() |
| 366 | except: |
| 367 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 368 | main.log.error( traceback.print_exc() ) |
| 369 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 370 | main.cleanup() |
| 371 | def get_version(self): |
| 372 | ''' |
| 373 | Writes the COMMIT number to the report to be parsed by Jenkins data collecter. |
| 374 | ''' |
| 375 | try: |
| 376 | self.handle.sendline("export TERM=xterm-256color") |
| 377 | self.handle.expect("xterm-256color") |
| 378 | self.handle.expect("\$") |
| 379 | self.handle.sendline("cd " + self.home + "; git log -1 --pretty=fuller | grep -A 5 \"commit\"; cd \.\.") |
| 380 | self.handle.expect("cd ..") |
| 381 | self.handle.expect("\$") |
| 382 | response=(self.name +": \n"+ str(self.handle.before + self.handle.after)) |
admin | e0eeea2 | 2014-04-14 10:22:46 -0700 | [diff] [blame] | 383 | lines=response.splitlines() |
| 384 | for line in lines: |
| 385 | print line |
| 386 | return lines[2] |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 387 | except pexpect.EOF: |
| 388 | main.log.error(self.name + ": EOF exception found") |
| 389 | main.log.error(self.name + ": " + self.handle.before) |
| 390 | main.cleanup() |
| 391 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 392 | except: |
| 393 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 394 | main.log.error( traceback.print_exc() ) |
| 395 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 396 | main.cleanup() |
| 397 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 398 | |
admin | c6cfc1c | 2014-04-21 13:55:21 -0700 | [diff] [blame] | 399 | def ad_flow(self): |
| 400 | main.log.info("AD_FLOW RUNNING!!!!") |
| 401 | self.handle.sendline("cd "+self.home+ "/scripts") |
| 402 | self.handle.expect("scripts") |
Jon Hall | 9c6e2c0 | 2014-05-02 10:18:53 -0700 | [diff] [blame] | 403 | main.log.info("Adding flows") |
admin | c6cfc1c | 2014-04-21 13:55:21 -0700 | [diff] [blame] | 404 | self.handle.sendline("./pyintents.py") |
Jon Hall | 9c6e2c0 | 2014-05-02 10:18:53 -0700 | [diff] [blame] | 405 | self.handle.expect(["$",pexpect.EOF,pexpect.TIMEOUT]) |
| 406 | response = self.handle.before |
admin | c6cfc1c | 2014-04-21 13:55:21 -0700 | [diff] [blame] | 407 | self.handle.sendline("cd "+self.home) |
| 408 | return main.TRUE |
| 409 | |
| 410 | def rm_flow(self): |
| 411 | main.log.info("RM_FLOW RUNNING!!!") |
| 412 | self.handle.sendline("cd "+self.home+ "/scripts") |
| 413 | self.handle.expect("scripts") |
Jon Hall | 9c6e2c0 | 2014-05-02 10:18:53 -0700 | [diff] [blame] | 414 | main.log.info("Removing flows") |
admin | c6cfc1c | 2014-04-21 13:55:21 -0700 | [diff] [blame] | 415 | self.handle.sendline("./rmpyintents.py") |
Jon Hall | 9c6e2c0 | 2014-05-02 10:18:53 -0700 | [diff] [blame] | 416 | self.handle.expect(["$",pexpect.EOF,pexpect.TIMEOUT]) |
| 417 | response = self.handle.before |
admin | c6cfc1c | 2014-04-21 13:55:21 -0700 | [diff] [blame] | 418 | self.handle.sendline("cd "+self.home) |
| 419 | return main.TRUE |
| 420 | |
Jon Hall | 265149f | 2014-04-25 13:39:52 -0700 | [diff] [blame] | 421 | def purge(self): |
| 422 | main.log.info("Purging dead intents") |
| 423 | self.handle.sendline("cd "+self.home+ "/scripts") |
| 424 | self.handle.expect("scripts") |
| 425 | print("Purging Intents") |
| 426 | self.handle.sendline("./purgeintents.py") |
| 427 | self.handle.sendline("cd "+self.home) |
| 428 | return main.TRUE |
admin | c6cfc1c | 2014-04-21 13:55:21 -0700 | [diff] [blame] | 429 | |
| 430 | |
| 431 | |
Jon Hall | 4a2b048 | 2014-04-18 16:29:26 -0700 | [diff] [blame] | 432 | def add_flow(self, testONip, user = "admin", password = "", flowDef = "/flowdef.txt"): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 433 | ''' |
| 434 | Copies the flowdef file from TestStation -> ONOS machine |
| 435 | Then runs ./add_flow.py to add the flows to ONOS |
| 436 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 437 | try: |
| 438 | main.log.info("Adding Flows...") |
| 439 | self.handle.sendline("scp %s@%s:%s /tmp/flowtmp" %(user,testONip,flowDef)) |
| 440 | i=self.handle.expect(['[pP]assword:', '100%', pexpect.TIMEOUT],30) |
| 441 | if(i==0): |
| 442 | self.handle.sendline("%s" %(password)) |
| 443 | self.handle.sendline("") |
| 444 | self.handle.expect("100%") |
| 445 | self.handle.expect("\$", 30) |
| 446 | self.handle.sendline(self.home + "/web/add_flow.py -m onos -f /tmp/flowtmp") |
| 447 | self.handle.expect("\$", 1000) |
| 448 | main.log.info("Flows added") |
| 449 | return main.TRUE |
| 450 | |
| 451 | elif(i==1): |
| 452 | self.handle.sendline("") |
| 453 | self.handle.expect("\$", 10) |
| 454 | self.handle.sendline( self.home + "/web/add_flow.py -m onos -f /tmp/flowtmp") |
| 455 | self.handle.expect("\$", 1000) |
| 456 | main.log.info("Flows added") |
| 457 | return main.TRUE |
| 458 | |
| 459 | elif(i==2): |
| 460 | main.log.error("Flow Def file SCP Timed out...") |
| 461 | return main.FALSE |
| 462 | |
| 463 | else: |
| 464 | main.log.error("Failed to add flows...") |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 465 | return main.FALSE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 466 | except pexpect.EOF: |
| 467 | main.log.error(self.name + ": EOF exception found") |
| 468 | main.log.error(self.name + ": " + self.handle.before) |
| 469 | main.cleanup() |
| 470 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 471 | except: |
| 472 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 473 | main.log.error( traceback.print_exc() ) |
| 474 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 475 | main.cleanup() |
| 476 | main.exit() |
| 477 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 478 | |
| 479 | def delete_flow(self, *delParams): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 480 | ''' |
| 481 | Deletes a specific flow, a range of flows, or all flows. |
| 482 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 483 | try: |
| 484 | if len(delParams)==1: |
| 485 | if str(delParams[0])=="all": |
| 486 | main.log.info(self.name + ": Deleting ALL flows...") |
| 487 | #self.execute(cmd="~/ONOS/scripts/TestON_delete_flow.sh all",prompt="done",timeout=150) |
| 488 | self.handle.sendline(self.home + "/web/delete_flow.py all") |
| 489 | self.handle.expect("delete_flow") |
| 490 | self.handle.expect("\$",1000) |
| 491 | main.log.info(self.name + ": Flows deleted") |
| 492 | else: |
| 493 | main.log.info(self.name + ": Deleting flow "+str(delParams[0])+"...") |
| 494 | #self.execute(cmd="~/ONOS/scripts/TestON_delete_flow.sh "+str(delParams[0]),prompt="done",timeout=150) |
| 495 | #self.execute(cmd="\n",prompt="\$",timeout=60) |
| 496 | self.handle.sendline(self.home +"/web/delete_flow.py %d" % int(delParams[0])) |
| 497 | self.handle.expect("delete_flow") |
| 498 | self.handle.expect("\$",60) |
| 499 | main.log.info(self.name + ": Flow deleted") |
| 500 | elif len(delParams)==2: |
| 501 | main.log.info(self.name + ": Deleting flows "+str(delParams[0])+" through "+str(delParams[1])+"...") |
| 502 | #self.execute(cmd="~/ONOS/scripts/TestON_delete_flow.sh "+str(delParams[0])+" "+str(delParams[1]),prompt="done",timeout=150) |
| 503 | #self.execute(cmd="\n",prompt="\$",timeout=60) |
| 504 | self.handle.sendline(self.home + "/web/delete_flow.py %d %d" % (int(delParams[0]), int(delParams[1]))) |
| 505 | self.handle.expect("delete_flow") |
| 506 | self.handle.expect("\$",600) |
| 507 | main.log.info(self.name + ": Flows deleted") |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 508 | except pexpect.EOF: |
| 509 | main.log.error(self.name + ": EOF exception found") |
| 510 | main.log.error(self.name + ": " + self.handle.before) |
| 511 | main.cleanup() |
| 512 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 513 | except: |
| 514 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 515 | main.log.error( traceback.print_exc() ) |
| 516 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 517 | main.cleanup() |
| 518 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 519 | |
| 520 | def check_flow(self): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 521 | ''' |
| 522 | Calls the ./get_flow.py all and checks: |
| 523 | - If each FlowPath has at least one FlowEntry |
| 524 | - That there are no "NOT"s found |
| 525 | returns TRUE/FALSE |
| 526 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 527 | try: |
| 528 | flowEntryDetect = 1 |
| 529 | count = 0 |
| 530 | self.handle.sendline("clear") |
| 531 | time.sleep(1) |
| 532 | self.handle.sendline(self.home + "/web/get_flow.py all") |
| 533 | self.handle.expect("get_flow") |
| 534 | while 1: |
| 535 | i=self.handle.expect(['FlowPath','FlowEntry','NOT','\$',pexpect.TIMEOUT],timeout=180) |
| 536 | if i==0: |
| 537 | count = count + 1 |
| 538 | if flowEntryDetect == 0: |
| 539 | main.log.info(self.name + ": FlowPath without FlowEntry") |
| 540 | return main.FALSE |
| 541 | else: |
| 542 | flowEntryDetect = 0 |
| 543 | elif i==1: |
| 544 | flowEntryDetect = 1 |
| 545 | elif i==2: |
| 546 | main.log.error(self.name + ": Found a NOT") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 547 | return main.FALSE |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 548 | elif i==3: |
| 549 | if count == 0: |
| 550 | main.log.info(self.name + ": There don't seem to be any flows here...") |
| 551 | return main.FALSE |
| 552 | else: |
| 553 | main.log.info(self.name + ": All flows pass") |
| 554 | main.log.info(self.name + ": Number of FlowPaths: "+str(count)) |
| 555 | return main.TRUE |
| 556 | elif i==4: |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 557 | main.log.error(self.name + ":Check_flow() - Command Timeout!") |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 558 | return main.FALSE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 559 | except pexpect.EOF: |
| 560 | main.log.error(self.name + ": EOF exception found") |
| 561 | main.log.error(self.name + ": " + self.handle.before) |
| 562 | main.cleanup() |
| 563 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 564 | except: |
| 565 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 566 | main.log.error( traceback.print_exc() ) |
| 567 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 568 | main.cleanup() |
| 569 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 570 | |
| 571 | def get_flow(self, *flowParams): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 572 | ''' |
| 573 | Returns verbose output of ./get_flow.py |
| 574 | ''' |
| 575 | try: |
| 576 | if len(flowParams)==1: |
| 577 | if str(flowParams[0])=="all": |
| 578 | self.execute(cmd="\n",prompt="\$",timeout=60) |
| 579 | main.log.info(self.name + ": Getting all flow data...") |
| 580 | data = self.execute(cmd=self.home + "/scripts/TestON_get_flow.sh all",prompt="done",timeout=150) |
| 581 | self.execute(cmd="\n",prompt="\$",timeout=60) |
| 582 | return data |
| 583 | else: |
| 584 | main.log.info(self.name + ": Retrieving flow "+str(flowParams[0])+" data...") |
| 585 | data = self.execute(cmd=self.home +"/scripts/TestON_get_flow.sh "+str(flowParams[0]),prompt="done",timeout=150) |
| 586 | self.execute(cmd="\n",prompt="\$",timeout=60) |
| 587 | return data |
| 588 | elif len(flowParams)==5: |
| 589 | main.log.info(self.name + ": Retrieving flow installer data...") |
| 590 | 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) |
| 591 | self.execute(cmd="\n",prompt="\$",timeout=60) |
| 592 | return data |
| 593 | elif len(flowParams)==4: |
| 594 | main.log.info(self.name + ": Retrieving flow endpoints...") |
| 595 | 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) |
| 596 | self.execute(cmd="\n",prompt="\$",timeout=60) |
| 597 | return data |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 598 | except pexpect.EOF: |
| 599 | main.log.error(self.name + ": EOF exception found") |
| 600 | main.log.error(self.name + ": " + self.handle.before) |
| 601 | main.cleanup() |
| 602 | main.exit() |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 603 | except: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 604 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 605 | main.log.error( traceback.print_exc() ) |
| 606 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 607 | main.cleanup() |
| 608 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 609 | |
| 610 | |
SeanCorcoran | 83a653a | 2014-04-22 15:03:18 -0700 | [diff] [blame] | 611 | # http://localhost:8080/wm/onos/topology/switches/json |
| 612 | # http://localhost:8080/wm/onos/topology/links/json |
Jon Hall | 8060af0 | 2014-04-14 14:17:58 -0700 | [diff] [blame] | 613 | # http://localhost:8080/wm/onos/registry/controllers/json |
| 614 | # http://localhost:8080/wm/onos/registry/switches/json" |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 615 | |
| 616 | def get_json(self, url): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 617 | ''' |
| 618 | Helper functions used to parse the json output of a rest call |
| 619 | ''' |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 620 | try: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 621 | try: |
| 622 | command = "curl -s %s" % (url) |
| 623 | result = os.popen(command).read() |
| 624 | parsedResult = json.loads(result) |
| 625 | except: |
| 626 | print "REST IF %s has issue" % command |
| 627 | parsedResult = "" |
| 628 | |
| 629 | if type(parsedResult) == 'dict' and parsedResult.has_key('code'): |
| 630 | print "REST %s returned code %s" % (command, parsedResult['code']) |
| 631 | parsedResult = "" |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 632 | return parsedResult |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 633 | except pexpect.EOF: |
| 634 | main.log.error(self.name + ": EOF exception found") |
| 635 | main.log.error(self.name + ": " + self.handle.before) |
| 636 | main.cleanup() |
| 637 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 638 | except: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 639 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 640 | main.log.error( traceback.print_exc() ) |
| 641 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 642 | main.cleanup() |
| 643 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 644 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 645 | def check_switch(self,RestIP,correct_nr_switch, RestPort ="8080" ): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 646 | ''' |
| 647 | Used by check_status |
| 648 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 649 | try: |
| 650 | buf = "" |
| 651 | retcode = 0 |
SeanCorcoran | 83a653a | 2014-04-22 15:03:18 -0700 | [diff] [blame] | 652 | url="http://%s:%s/wm/onos/topology/switches/json" % (RestIP, RestPort) |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 653 | parsedResult = self.get_json(url) |
| 654 | if parsedResult == "": |
| 655 | retcode = 1 |
| 656 | return (retcode, "Rest API has an issue") |
| 657 | url = "http://%s:%s/wm/onos/registry/switches/json" % (RestIP, RestPort) |
| 658 | registry = self.get_json(url) |
| 659 | |
| 660 | if registry == "": |
| 661 | retcode = 1 |
| 662 | return (retcode, "Rest API has an issue") |
| 663 | |
| 664 | cnt = 0 |
| 665 | active = 0 |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 666 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 667 | for s in parsedResult: |
| 668 | cnt += 1 |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 669 | if s['state'] == "ACTIVE": |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 670 | active += 1 |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 671 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 672 | buf += "switch: network %d : %d switches %d active\n" % (0+1, cnt, active) |
| 673 | if correct_nr_switch != cnt: |
| 674 | buf += "switch fail: network %d should have %d switches but has %d\n" % (1, correct_nr_switch, cnt) |
| 675 | retcode = 1 |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 676 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 677 | if correct_nr_switch != active: |
| 678 | buf += "switch fail: network %d should have %d active switches but has %d\n" % (1, correct_nr_switch, active) |
| 679 | retcode = 1 |
| 680 | |
| 681 | return (retcode, buf) |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 682 | except pexpect.EOF: |
| 683 | main.log.error(self.name + ": EOF exception found") |
| 684 | main.log.error(self.name + ": " + self.handle.before) |
| 685 | main.cleanup() |
| 686 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 687 | except: |
| 688 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 689 | main.log.error( traceback.print_exc() ) |
| 690 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 691 | main.cleanup() |
| 692 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 693 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 694 | def check_link(self,RestIP, nr_links, RestPort = "8080"): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 695 | ''' |
| 696 | Used by check_status |
| 697 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 698 | try: |
| 699 | buf = "" |
| 700 | retcode = 0 |
| 701 | |
SeanCorcoran | 83a653a | 2014-04-22 15:03:18 -0700 | [diff] [blame] | 702 | url = "http://%s:%s/wm/onos/topology/links/json" % (RestIP, RestPort) |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 703 | parsedResult = self.get_json(url) |
| 704 | |
| 705 | if parsedResult == "": |
| 706 | retcode = 1 |
| 707 | return (retcode, "Rest API has an issue") |
| 708 | |
| 709 | buf += "link: total %d links (correct : %d)\n" % (len(parsedResult), nr_links) |
| 710 | intra = 0 |
| 711 | interlink=0 |
| 712 | |
| 713 | for s in parsedResult: |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 714 | intra = intra + 1 |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 715 | |
| 716 | if intra != nr_links: |
| 717 | buf += "link fail\n" |
| 718 | retcode = 1 |
| 719 | |
| 720 | return (retcode, buf) |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 721 | except pexpect.EOF: |
| 722 | main.log.error(self.name + ": EOF exception found") |
| 723 | main.log.error(self.name + ": " + self.handle.before) |
| 724 | main.cleanup() |
| 725 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 726 | except: |
| 727 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 728 | main.log.error( traceback.print_exc() ) |
| 729 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 730 | main.cleanup() |
| 731 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 732 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 733 | def check_status_report(self, ip, numoswitch, numolink, port="8080"): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 734 | ''' |
| 735 | Checks the number of swithes & links that ONOS sees against the supplied values. |
| 736 | Writes to the report log. |
| 737 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 738 | try: |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 739 | main.log.info(self.name + ": Making some rest calls...") |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 740 | switch = self.check_switch(ip, int(numoswitch), port) |
| 741 | link = self.check_link(ip, int(numolink), port) |
| 742 | value = switch[0] |
| 743 | value += link[0] |
| 744 | main.log.report( self.name + ": \n-----\n%s%s-----\n" % ( switch[1], link[1]) ) |
| 745 | if value != 0: |
| 746 | return main.FALSE |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 747 | else: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 748 | # "PASS" |
| 749 | return main.TRUE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 750 | except pexpect.EOF: |
| 751 | main.log.error(self.name + ": EOF exception found") |
| 752 | main.log.error(self.name + ": " + self.handle.before) |
| 753 | main.cleanup() |
| 754 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 755 | except: |
| 756 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 757 | main.log.error( traceback.print_exc() ) |
| 758 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 759 | main.cleanup() |
| 760 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 761 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 762 | def check_status(self, ip, numoswitch, numolink, port = "8080"): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 763 | ''' |
| 764 | Checks the number of swithes & links that ONOS sees against the supplied values. |
| 765 | Writes to the main log. |
| 766 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 767 | try: |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 768 | main.log.info(self.name + ": Making some rest calls...") |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 769 | switch = self.check_switch(ip, int(numoswitch), port) |
| 770 | link = self.check_link(ip, int(numolink), port) |
| 771 | value = switch[0] |
| 772 | value += link[0] |
| 773 | main.log.info(self.name + ": \n-----\n%s%s-----\n" % ( switch[1], link[1]) ) |
| 774 | if value != 0: |
| 775 | return main.FALSE |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 776 | else: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 777 | # "PASS" |
| 778 | return main.TRUE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 779 | except pexpect.EOF: |
| 780 | main.log.error(self.name + ": EOF exception found") |
| 781 | main.log.error(self.name + ": " + self.handle.before) |
| 782 | main.cleanup() |
| 783 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 784 | except: |
| 785 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 786 | main.log.error( traceback.print_exc() ) |
| 787 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 788 | main.cleanup() |
| 789 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 790 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 791 | def check_for_no_exceptions(self): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 792 | ''' |
| 793 | TODO: Rewrite |
| 794 | Used by CassndraCheck.py to scan ONOS logs for Exceptions |
| 795 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 796 | try: |
| 797 | self.handle.sendline("dsh 'grep Exception ~/ONOS/onos-logs/onos.*.log'") |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 798 | self.handle.expect("\$ dsh") |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 799 | self.handle.expect("\$") |
| 800 | output = self.handle.before |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 801 | main.log.info(self.name + ": " + output ) |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 802 | if re.search("Exception",output): |
| 803 | return main.FALSE |
| 804 | else : |
| 805 | return main.TRUE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 806 | except pexpect.EOF: |
| 807 | main.log.error(self.name + ": EOF exception found") |
| 808 | main.log.error(self.name + ": " + self.handle.before) |
| 809 | main.cleanup() |
| 810 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 811 | except: |
| 812 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 813 | main.log.error( traceback.print_exc() ) |
| 814 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 815 | main.cleanup() |
| 816 | main.exit() |
| 817 | |
| 818 | |
admin | e0eeea2 | 2014-04-14 10:22:46 -0700 | [diff] [blame] | 819 | def git_pull(self, comp1=""): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 820 | ''' |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 821 | Assumes that "git pull" works without login |
admin | e0eeea2 | 2014-04-14 10:22:46 -0700 | [diff] [blame] | 822 | |
| 823 | This function will perform a git pull on the ONOS instance. |
| 824 | If used as git_pull("NODE") it will do git pull + NODE. This is |
| 825 | for the purpose of pulling from other nodes if necessary. |
| 826 | |
| 827 | Otherwise, this function will perform a git pull in the |
| 828 | ONOS repository. If it has any problems, it will return main.ERROR |
| 829 | If it successfully does a git_pull, it will return a 1. |
| 830 | If it has no updates, it will return a 0. |
| 831 | |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 832 | ''' |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 833 | try: |
Jon Hall | e80ef8c | 2014-04-29 15:29:13 -0700 | [diff] [blame] | 834 | # main.log.info(self.name + ": Stopping ONOS") |
| 835 | #self.stop() |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 836 | self.handle.sendline("cd " + self.home) |
| 837 | self.handle.expect("ONOS\$") |
| 838 | if comp1=="": |
| 839 | self.handle.sendline("git pull") |
| 840 | else: |
| 841 | self.handle.sendline("git pull " + comp1) |
| 842 | |
| 843 | uptodate = 0 |
SeanCorcoran | 20bd6fc | 2014-04-16 17:10:30 -0700 | [diff] [blame] | 844 | 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] | 845 | #debug |
| 846 | #main.log.report(self.name +": \n"+"git pull response: " + str(self.handle.before) + str(self.handle.after)) |
| 847 | if i==0: |
| 848 | main.log.error(self.name + ": Git pull had some issue...") |
| 849 | return main.ERROR |
| 850 | elif i==1: |
| 851 | main.log.error(self.name + ": Git Pull Asking for username!!! BADD!") |
| 852 | return main.ERROR |
| 853 | elif i==2: |
| 854 | main.log.info(self.name + ": Git Pull - pulling repository now") |
| 855 | self.handle.expect("ONOS\$", 120) |
| 856 | return 0 |
| 857 | elif i==3: |
| 858 | main.log.error(self.name + ": Git Pull - TIMEOUT") |
| 859 | return main.ERROR |
| 860 | elif i==4: |
| 861 | main.log.info(self.name + ": Git Pull - Already up to date") |
| 862 | return 1 |
| 863 | elif i==5: |
| 864 | main.log.info(self.name + ": Git Pull - Aborting... Are there conflicting git files?") |
| 865 | return main.ERROR |
| 866 | else: |
| 867 | main.log.error(self.name + ": Git Pull - Unexpected response, check for pull errors") |
| 868 | return main.ERROR |
| 869 | except pexpect.EOF: |
| 870 | main.log.error(self.name + ": EOF exception found") |
| 871 | main.log.error(self.name + ": " + self.handle.before) |
| 872 | main.cleanup() |
| 873 | main.exit() |
| 874 | except: |
| 875 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 876 | main.log.error( traceback.print_exc() ) |
| 877 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 878 | main.cleanup() |
| 879 | main.exit() |
admin | e0eeea2 | 2014-04-14 10:22:46 -0700 | [diff] [blame] | 880 | #******************************************************** |
| 881 | |
| 882 | |
admin | 7373a81 | 2014-04-16 09:49:02 -0700 | [diff] [blame] | 883 | def git_compile(self): |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 884 | ''' |
| 885 | Compiles ONOS |
| 886 | First runs mvn clean then mvn compile |
| 887 | ''' |
| 888 | try: |
| 889 | main.log.info(self.name + ": mvn clean") |
admin | 8fc0282 | 2014-04-16 13:31:23 -0700 | [diff] [blame] | 890 | self.handle.sendline("cd " + self.home) |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 891 | self.handle.sendline("mvn clean") |
| 892 | while 1: |
Jon Hall | 1636f94 | 2014-04-17 10:07:23 -0700 | [diff] [blame] | 893 | 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] | 894 | if i == 0: |
Jon Hall | 1636f94 | 2014-04-17 10:07:23 -0700 | [diff] [blame] | 895 | 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] | 896 | return main.FALSE |
| 897 | elif i == 1: |
Jon Hall | 1636f94 | 2014-04-17 10:07:23 -0700 | [diff] [blame] | 898 | main.log.error(self.name + ": Clean failure!") |
| 899 | return main.FALSE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 900 | elif i == 2: |
Jon Hall | 1636f94 | 2014-04-17 10:07:23 -0700 | [diff] [blame] | 901 | main.log.info(self.name + ": Clean success!") |
| 902 | elif i == 3: |
admin | 8fc0282 | 2014-04-16 13:31:23 -0700 | [diff] [blame] | 903 | main.log.info(self.name + ": Clean complete") |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 904 | break; |
Jon Hall | 1636f94 | 2014-04-17 10:07:23 -0700 | [diff] [blame] | 905 | elif i == 4: |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 906 | main.log.error(self.name + ": mvn clean TIMEOUT!") |
| 907 | return main.FALSE |
Jon Hall | 1636f94 | 2014-04-17 10:07:23 -0700 | [diff] [blame] | 908 | else: |
| 909 | main.log.error(self.name + ": unexpected response from mvn clean") |
| 910 | return main.FALSE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 911 | |
| 912 | main.log.info(self.name + ": mvn compile") |
| 913 | self.handle.sendline("mvn compile") |
| 914 | while 1: |
Jon Hall | 1636f94 | 2014-04-17 10:07:23 -0700 | [diff] [blame] | 915 | 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] | 916 | if i == 0: |
Jon Hall | 1636f94 | 2014-04-17 10:07:23 -0700 | [diff] [blame] | 917 | main.log.error(self.name + ":There is insufficient memory for the Java Runtime Environment to continue.") |
| 918 | return main.FALSE |
| 919 | if i == 1: |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 920 | main.log.error(self.name + ": Build failure!") |
| 921 | return main.FALSE |
Jon Hall | 1636f94 | 2014-04-17 10:07:23 -0700 | [diff] [blame] | 922 | elif i == 2: |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 923 | main.log.info(self.name + ": Build success!") |
Jon Hall | 1636f94 | 2014-04-17 10:07:23 -0700 | [diff] [blame] | 924 | elif i == 3: |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 925 | main.log.info(self.name + ": Build complete") |
| 926 | return main.TRUE |
Jon Hall | 1636f94 | 2014-04-17 10:07:23 -0700 | [diff] [blame] | 927 | elif i == 4: |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 928 | main.log.error(self.name + ": mvn compile TIMEOUT!") |
| 929 | return main.FALSE |
| 930 | else: |
Jon Hall | 1636f94 | 2014-04-17 10:07:23 -0700 | [diff] [blame] | 931 | main.log.error(self.name + ": unexpected response from mvn compile") |
| 932 | return main.FALSE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 933 | except pexpect.EOF: |
| 934 | main.log.error(self.name + ": EOF exception found") |
| 935 | main.log.error(self.name + ": " + self.handle.before) |
| 936 | main.cleanup() |
| 937 | main.exit() |
| 938 | except: |
| 939 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 940 | main.log.error( traceback.print_exc() ) |
| 941 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 942 | main.cleanup() |
| 943 | main.exit() |
admin | 4a58db9 | 2013-09-30 12:04:54 -0700 | [diff] [blame] | 944 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 945 | def tcpdump(self, intf = "eth0"): |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 946 | ''' |
| 947 | Runs tpdump on an intferface and saves in onos-logs under the ONOS home directory |
| 948 | intf can be specified, or the default eth0 is used |
| 949 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 950 | try: |
| 951 | self.handle.sendline("") |
| 952 | self.handle.expect("\$") |
Jon Hall | 26f316b | 2014-04-11 11:21:25 -0700 | [diff] [blame] | 953 | 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] | 954 | i=self.handle.expect(['No\ssuch\device','listening\son',pexpect.TIMEOUT],timeout=10) |
| 955 | if i == 0: |
| 956 | main.log.error(self.name + ": tcpdump - No such device exists. tcpdump attempted on: " + intf) |
| 957 | return main.FALSE |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 958 | elif i == 1: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 959 | main.log.info(self.name + ": tcpdump started on " + intf) |
| 960 | return main.TRUE |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 961 | elif i == 2: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 962 | main.log.error(self.name + ": tcpdump command timed out! Check interface name, given interface was: " + intf) |
| 963 | return main.FALSE |
| 964 | else: |
| 965 | main.log.error(self.name + ": tcpdump - unexpected response") |
| 966 | return main.FALSE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 967 | except pexpect.EOF: |
| 968 | main.log.error(self.name + ": EOF exception found") |
| 969 | main.log.error(self.name + ": " + self.handle.before) |
| 970 | main.cleanup() |
| 971 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 972 | except: |
| 973 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 974 | main.log.error( traceback.print_exc() ) |
| 975 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 976 | main.cleanup() |
| 977 | main.exit() |
| 978 | |
admin | 4a58db9 | 2013-09-30 12:04:54 -0700 | [diff] [blame] | 979 | def kill_tcpdump(self): |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 980 | ''' |
| 981 | Kills any tcpdump processes running |
| 982 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 983 | try: |
| 984 | self.handle.sendline("") |
| 985 | self.handle.expect("\$") |
| 986 | 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] | 987 | except pexpect.EOF: |
| 988 | main.log.error(self.name + ": EOF exception found") |
| 989 | main.log.error(self.name + ": " + self.handle.before) |
| 990 | main.cleanup() |
| 991 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 992 | except: |
| 993 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 994 | main.log.error( traceback.print_exc() ) |
| 995 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 996 | main.cleanup() |
| 997 | main.exit() |
| 998 | |
| 999 | def find_host(self,RestIP,RestPort,RestAPI,hostIP): |
| 1000 | retcode = 0 |
| 1001 | retswitch = [] |
| 1002 | retport = [] |
| 1003 | retmac = [] |
| 1004 | foundIP = [] |
| 1005 | try: |
SeanCorcoran | 83a653a | 2014-04-22 15:03:18 -0700 | [diff] [blame] | 1006 | ##### device rest API is: 'host:8080/wm/onos/topology/switches/json' ### |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1007 | url ="http://%s:%s%s" %(RestIP,RestPort,RestAPI) |
| 1008 | |
| 1009 | try: |
| 1010 | command = "curl -s %s" % (url) |
| 1011 | result = os.popen(command).read() |
| 1012 | parsedResult = json.loads(result) |
| 1013 | # print parsedResult |
| 1014 | except: |
| 1015 | print "REST IF %s has issue" % command |
| 1016 | parsedResult = "" |
| 1017 | |
| 1018 | if parsedResult == "": |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1019 | return (retcode, "Rest API has an error", retport, retmac) |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1020 | else: |
| 1021 | for switch in enumerate(parsedResult): |
| 1022 | for port in enumerate(switch[1]['ports']): |
| 1023 | if ( port[1]['devices'] != [] ): |
| 1024 | try: |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 1025 | foundIP = port[1]['devices'][0]['ipv4addresses'][0]['ipv4'] |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1026 | except: |
| 1027 | print "Error in detecting IP address." |
| 1028 | if foundIP == hostIP: |
| 1029 | retswitch.append(switch[1]['dpid']) |
| 1030 | retport.append(port[1]['desc']) |
| 1031 | retmac.append(port[1]['devices'][0]['mac']) |
| 1032 | retcode = retcode +1 |
| 1033 | foundIP ='' |
| 1034 | return(retcode, retswitch, retport, retmac) |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1035 | except pexpect.EOF: |
| 1036 | main.log.error(self.name + ": EOF exception found") |
| 1037 | main.log.error(self.name + ": " + self.handle.before) |
| 1038 | main.cleanup() |
| 1039 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1040 | except: |
| 1041 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1042 | main.log.error( traceback.print_exc() ) |
| 1043 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1044 | main.cleanup() |
| 1045 | main.exit() |
SeanCorcoran | 29b7054 | 2014-05-14 14:53:42 -0700 | [diff] [blame] | 1046 | |
| 1047 | def check_exceptions(self): |
| 1048 | ''' |
| 1049 | Greps the logs for "xception" |
| 1050 | ''' |
| 1051 | try: |
| 1052 | output = '' |
| 1053 | self.handle.sendline("") |
| 1054 | self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT]) |
| 1055 | self.handle.sendline("cd "+self.home+"/onos-logs") |
| 1056 | self.handle.sendline("grep \"xception\" * -c") |
| 1057 | self.handle.expect("\s-c") |
| 1058 | self.handle.expect("\$") |
| 1059 | response = self.handle.before |
| 1060 | for line in response.splitlines(): |
| 1061 | if re.search("log:", line): |
| 1062 | output +="Exceptions found in " + line + "\n" |
| 1063 | elif re.search("std...:",line): |
| 1064 | output+="Exceptions found in " + line + "\n" |
| 1065 | else: |
| 1066 | pass |
| 1067 | #these should be the old logs |
| 1068 | return output |
| 1069 | except pexpect.TIMEOUT: |
| 1070 | main.log.error(self.name + ": Timeout exception found in check_exceptions function") |
| 1071 | except pexpect.EOF: |
| 1072 | main.log.error(self.name + ": EOF exception found") |
| 1073 | main.log.error(self.name + ": " + self.handle.before) |
| 1074 | main.cleanup() |
| 1075 | main.exit() |
| 1076 | except: |
| 1077 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1078 | main.log.error( traceback.print_exc() ) |
| 1079 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1080 | main.cleanup() |
| 1081 | main.exit() |