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