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