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