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