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