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 | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 28 | import urllib2 |
| 29 | from urllib2 import URLError, HTTPError |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 30 | sys.path.append("../") |
| 31 | from drivers.common.clidriver import CLI |
| 32 | |
| 33 | class OnosCliDriver(CLI): |
| 34 | |
| 35 | def __init__(self): |
| 36 | super(CLI, self).__init__() |
| 37 | |
| 38 | def connect(self,**connectargs): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 39 | ''' |
| 40 | Creates ssh handle for ONOS. |
| 41 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 42 | try: |
| 43 | for key in connectargs: |
admin | e0eeea2 | 2014-04-14 10:22:46 -0700 | [diff] [blame] | 44 | vars(self)[key] = connectargs[key] |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 45 | self.home = "~/ONOS" |
| 46 | for key in self.options: |
admin | e0eeea2 | 2014-04-14 10:22:46 -0700 | [diff] [blame] | 47 | if key == "home": |
| 48 | self.home = self.options['home'] |
| 49 | break |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 50 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 51 | |
| 52 | self.name = self.options['name'] |
| 53 | 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] | 54 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 55 | if self.handle: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 56 | return self.handle |
| 57 | else : |
| 58 | main.log.info("NO ONOS HANDLE") |
| 59 | return main.FALSE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 60 | except pexpect.EOF: |
| 61 | main.log.error(self.name + ": EOF exception found") |
| 62 | main.log.error(self.name + ": " + self.handle.before) |
| 63 | main.cleanup() |
| 64 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 65 | except: |
| 66 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 67 | main.log.error( traceback.print_exc() ) |
| 68 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 69 | main.cleanup() |
| 70 | main.exit() |
admin | 680b78c | 2014-08-08 11:46:45 -0700 | [diff] [blame] | 71 | |
| 72 | def portKill(self, port): |
| 73 | try: |
| 74 | self.handle.sendline("") |
| 75 | self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT]) |
| 76 | cmd = "sudo tcpkill -i eth0 port " + str(port) + " 2>/dev/null 1>/dev/null &" |
| 77 | self.handle.sendline(cmd) |
| 78 | self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT]) |
| 79 | except pexpect.EOF: |
| 80 | main.log.error(self.name + ": EOF exception found") |
| 81 | main.log.error(self.name + ": " + self.handle.before) |
| 82 | main.cleanup() |
| 83 | main.exit() |
| 84 | except: |
| 85 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 86 | main.log.error( traceback.print_exc() ) |
| 87 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 88 | main.cleanup() |
| 89 | main.exit() |
| 90 | |
| 91 | def endPortKill(self,port): |
| 92 | try: |
| 93 | self.handle.sendline("") |
| 94 | self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT]) |
| 95 | self.handle.sendline("sudo pkill tcpkill") |
| 96 | self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT]) |
| 97 | except pexpect.EOF: |
| 98 | main.log.error(self.name + ": EOF exception found") |
| 99 | main.log.error(self.name + ": " + self.handle.before) |
| 100 | main.cleanup() |
| 101 | main.exit() |
| 102 | except: |
| 103 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 104 | main.log.error( traceback.print_exc() ) |
| 105 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 106 | main.cleanup() |
| 107 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 108 | |
Jon Hall | f0a494f | 2014-06-23 15:37:40 -0700 | [diff] [blame] | 109 | def start(self, env = ''): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 110 | ''' |
| 111 | Starts ONOS on remote machine. |
| 112 | Returns false if any errors were encountered. |
| 113 | ''' |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 114 | try: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 115 | self.handle.sendline("") |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 116 | self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT]) |
Jon Hall | 4a2b048 | 2014-04-18 16:29:26 -0700 | [diff] [blame] | 117 | self.handle.sendline("cd "+self.home) |
Jon Hall | f0a494f | 2014-06-23 15:37:40 -0700 | [diff] [blame] | 118 | self.handle.sendline(env + "./onos.sh core start") |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 119 | i=self.handle.expect(["STARTED","FAILED",pexpect.EOF,pexpect.TIMEOUT]) |
| 120 | response = self.handle.before + str(self.handle.after) |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 121 | if i==0: |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 122 | j = self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT], timeout=60) |
| 123 | if re.search("Killed",response): |
| 124 | main.log.warn(self.name + ": Killed existing process") |
| 125 | if j==0: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 126 | main.log.info(self.name + ": ONOS Started ") |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 127 | return main.TRUE |
| 128 | elif j==1: |
| 129 | main.log.error(self.name + ": EOF exception found") |
| 130 | main.log.error(self.name + ": " + self.handle.before) |
| 131 | main.cleanup() |
| 132 | main.exit() |
| 133 | elif j==2: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 134 | main.log.info(self.name + ": ONOS NOT Started, stuck while waiting for it to start ") |
| 135 | return main.FALSE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 136 | else: |
| 137 | main.log.warn(self.name +": Unexpected response in start") |
| 138 | return main.TRUE |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 139 | elif i==1: |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 140 | main.log.error(self.name + ": ONOS Failed to start") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 141 | return main.FALSE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 142 | elif i==2: |
| 143 | main.log.error(self.name + ": EOF exception found") |
| 144 | main.log.error(self.name + ": " + self.handle.before) |
| 145 | main.cleanup() |
| 146 | main.exit() |
| 147 | elif i==3: |
| 148 | main.log.error(self.name + ": ONOS timedout while starting") |
| 149 | return main.FALSE |
| 150 | else: |
| 151 | main.log.error(self.name + ": ONOS start expect script missed something... ") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 152 | return main.FALSE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 153 | except pexpect.EOF: |
| 154 | main.log.error(self.name + ": EOF exception found") |
| 155 | main.log.error(self.name + ": " + self.handle.before) |
| 156 | main.cleanup() |
| 157 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 158 | except: |
| 159 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 160 | main.log.error( traceback.print_exc() ) |
| 161 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 162 | main.cleanup() |
| 163 | main.exit() |
Jon Hall | e80ef8c | 2014-04-29 15:29:13 -0700 | [diff] [blame] | 164 | |
| 165 | def start_all(self): |
| 166 | ''' |
| 167 | starts ZK, RC, and ONOS |
| 168 | ''' |
| 169 | self.handle.sendline("cd "+self.home) |
| 170 | self.handle.sendline("./onos.sh start") |
| 171 | self.handle.expect("./onos.sh start") |
| 172 | self.handle.expect(["\$",pexpect.TIMEOUT]) |
| 173 | |
| 174 | |
| 175 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 176 | def start_rest(self): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 177 | ''' |
| 178 | Starts the rest server on ONOS. |
| 179 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 180 | try: |
Jon Hall | 4a2b048 | 2014-04-18 16:29:26 -0700 | [diff] [blame] | 181 | self.handle.sendline("cd "+self.home) |
| 182 | response = self.execute(cmd= "./start-rest.sh start",prompt="\$",timeout=10) |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 183 | if re.search("admin",response): |
| 184 | main.log.info(self.name + ": Rest Server Started Successfully") |
| 185 | time.sleep(5) |
| 186 | return main.TRUE |
| 187 | else : |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 188 | main.log.warn(self.name + ": Failed to start Rest Server") |
| 189 | return main.FALSE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 190 | except pexpect.EOF: |
| 191 | main.log.error(self.name + ": EOF exception found") |
| 192 | main.log.error(self.name + ": " + self.handle.before) |
| 193 | main.cleanup() |
| 194 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 195 | except: |
| 196 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 197 | main.log.error( traceback.print_exc() ) |
| 198 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 199 | main.cleanup() |
| 200 | main.exit() |
| 201 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 202 | def status(self): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 203 | ''' |
| 204 | Called onos.sh core status and returns TRUE/FALSE accordingly |
| 205 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 206 | try: |
| 207 | self.execute(cmd="\n",prompt="\$",timeout=10) |
Jon Hall | 4a2b048 | 2014-04-18 16:29:26 -0700 | [diff] [blame] | 208 | self.handle.sendline("cd "+self.home) |
| 209 | response = self.execute(cmd="./onos.sh core status ",prompt="\d+\sinstance\sof\sonos\srunning",timeout=10) |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 210 | self.execute(cmd="\n",prompt="\$",timeout=10) |
| 211 | if re.search("1\sinstance\sof\sonos\srunning",response): |
| 212 | return main.TRUE |
| 213 | elif re.search("0\sinstance\sof\sonos\srunning",response): |
| 214 | return main.FALSE |
Jon Hall | bb650fe | 2014-07-14 14:54:48 -0700 | [diff] [blame] | 215 | elif re.search("Expected\sPrompt\snot found\s,\sTime Out!!",response): |
| 216 | return main.ERROR |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 217 | else : |
Jon Hall | f0a494f | 2014-06-23 15:37:40 -0700 | [diff] [blame] | 218 | main.log.warn(self.name + " WARNING: status recieved unknown response") |
| 219 | main.log.warn(response) |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 220 | return main.FALSE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 221 | except pexpect.EOF: |
| 222 | main.log.error(self.name + ": EOF exception found") |
| 223 | main.log.error(self.name + ": " + self.handle.before) |
| 224 | main.cleanup() |
| 225 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 226 | except: |
| 227 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 228 | main.log.error( traceback.print_exc() ) |
| 229 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 230 | main.cleanup() |
| 231 | main.exit() |
| 232 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 233 | |
| 234 | def isup(self): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 235 | ''' |
| 236 | A more complete check to see if ONOS is up and running properly. |
| 237 | First, it checks if the process is up. |
| 238 | Second, it reads the logs for "Exception: Connection refused" |
| 239 | Third, it makes sure the logs are actually moving. |
| 240 | returns TRUE/FALSE accordingly. |
| 241 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 242 | try: |
| 243 | self.execute(cmd="\n",prompt="\$",timeout=10) |
Jon Hall | 4a2b048 | 2014-04-18 16:29:26 -0700 | [diff] [blame] | 244 | self.handle.sendline("cd "+self.home) |
| 245 | response = self.execute(cmd= "./onos.sh core status ",prompt="running",timeout=10) |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 246 | self.execute(cmd="\n",prompt="\$",timeout=10) |
| 247 | tail1 = self.execute(cmd="tail " + self.home + "/onos-logs/onos.*.log",prompt="\$",timeout=10) |
admin | e8c47d0 | 2014-06-03 11:59:16 -0700 | [diff] [blame] | 248 | time.sleep(10) |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 249 | self.execute(cmd="\n",prompt="\$",timeout=10) |
| 250 | tail2 = self.execute(cmd="tail " + self.home + "/onos-logs/onos.*.log",prompt="\$",timeout=10) |
| 251 | pattern = '(.*)1 instance(.*)' |
| 252 | pattern2 = '(.*)Exception: Connection refused(.*)' |
| 253 | # if utilities.assert_matches(expect=pattern,actual=response,onpass="ONOS process is running...",onfail="ONOS process not running..."): |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 254 | running = self.execute(cmd="cat "+self.home+"/onos-logs/onos.*.log | grep 'Sending LLDP out on all ports'",prompt="\$",timeout=10) |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 255 | if re.search(pattern, response): |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 256 | if running != "": |
Jon Hall | e80ef8c | 2014-04-29 15:29:13 -0700 | [diff] [blame] | 257 | main.log.info(self.name + ": ONOS process is running...") |
| 258 | if tail1 == tail2: |
| 259 | main.log.error(self.name + ": ONOS is frozen...")#logs aren't moving |
| 260 | return main.FALSE |
| 261 | elif re.search( pattern2,tail1 ): |
| 262 | main.log.info(self.name + ": Connection Refused found in onos log") |
| 263 | return main.FALSE |
| 264 | elif re.search( pattern2,tail2 ): |
| 265 | main.log.info(self.name + ": Connection Refused found in onos log") |
| 266 | return main.FALSE |
| 267 | else: |
| 268 | main.log.info(self.name + ": Onos log is moving! It's looking good!") |
| 269 | return main.TRUE |
Jon Hall | 55c7966 | 2014-05-19 15:03:40 -0700 | [diff] [blame] | 270 | else: |
| 271 | main.log.info(self.name + ": ONOS not yet sending out LLDP messages") |
| 272 | return main.FALSE |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 273 | else: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 274 | main.log.error(self.name + ": ONOS process not running...") |
| 275 | return main.FALSE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 276 | except pexpect.EOF: |
| 277 | main.log.error(self.name + ": EOF exception found") |
| 278 | main.log.error(self.name + ": " + self.handle.before) |
| 279 | main.cleanup() |
| 280 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 281 | except: |
| 282 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 283 | main.log.error( traceback.print_exc() ) |
| 284 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 285 | main.cleanup() |
| 286 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 287 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 288 | |
| 289 | |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 290 | def rest_status(self): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 291 | ''' |
| 292 | Checks if the rest server is running. |
| 293 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 294 | try: |
| 295 | response = self.execute(cmd= self.home + "/start-rest.sh status ",prompt="running",timeout=10) |
| 296 | if re.search("rest\sserver\sis\srunning",response): |
| 297 | main.log.info(self.name + ": Rest Server is running") |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 298 | return main.TRUE |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 299 | elif re.search("rest\sserver\sis\snot\srunning",response): |
| 300 | main.log.warn(self.name + ": Rest Server is not Running") |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 301 | return main.FALSE |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 302 | else : |
| 303 | main.log.error(self.name + ": No response" +response) |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 304 | return main.FALSE |
| 305 | except pexpect.EOF: |
| 306 | main.log.error(self.name + ": EOF exception found") |
| 307 | main.log.error(self.name + ": " + self.handle.before) |
| 308 | main.cleanup() |
| 309 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 310 | except: |
| 311 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 312 | main.log.error( traceback.print_exc() ) |
| 313 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 314 | main.cleanup() |
| 315 | main.exit() |
admin | e8c47d0 | 2014-06-03 11:59:16 -0700 | [diff] [blame] | 316 | |
| 317 | def stop_all(self): |
| 318 | ''' |
| 319 | Runs ./onos.sh stop |
| 320 | ''' |
| 321 | try: |
| 322 | self.handle.sendline("") |
| 323 | self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT]) |
| 324 | self.handle.sendline("cd "+self.home) |
| 325 | self.handle.sendline("./onos.sh stop") |
Jon Hall | d79c7d0 | 2014-08-15 15:16:51 -0700 | [diff] [blame] | 326 | self.handle.expect(["./onos.sh stop",pexpect.EOF,pexpect.TIMEOUT]) |
| 327 | i=self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT],60) |
admin | e8c47d0 | 2014-06-03 11:59:16 -0700 | [diff] [blame] | 328 | result = self.handle.before |
| 329 | if re.search("Killed", result): |
| 330 | main.log.info(self.name + ": ONOS Killed Successfully") |
| 331 | return main.TRUE |
| 332 | else : |
| 333 | main.log.warn(self.name + ": ONOS wasn't running") |
| 334 | return main.FALSE |
| 335 | except pexpect.EOF: |
| 336 | main.log.error(self.name + ": EOF exception found") |
| 337 | main.log.error(self.name + ": " + self.handle.before) |
| 338 | main.cleanup() |
| 339 | main.exit() |
| 340 | except: |
| 341 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 342 | main.log.error( traceback.print_exc() ) |
| 343 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 344 | main.cleanup() |
| 345 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 346 | |
| 347 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 348 | def stop(self): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 349 | ''' |
| 350 | Runs ./onos.sh core stop to stop ONOS |
| 351 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 352 | try: |
| 353 | self.handle.sendline("") |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 354 | self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT]) |
Jon Hall | 4a2b048 | 2014-04-18 16:29:26 -0700 | [diff] [blame] | 355 | self.handle.sendline("cd "+self.home) |
| 356 | self.handle.sendline("./onos.sh core stop") |
Jon Hall | d79c7d0 | 2014-08-15 15:16:51 -0700 | [diff] [blame] | 357 | self.handle.expect(["./onos.sh stop",pexpect.EOF,pexpect.TIMEOUT]) |
| 358 | i=self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT],60) |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 359 | result = self.handle.before |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 360 | if re.search("Killed", result): |
| 361 | main.log.info(self.name + ": ONOS Killed Successfully") |
| 362 | return main.TRUE |
| 363 | else : |
| 364 | main.log.warn(self.name + ": ONOS wasn't running") |
| 365 | return main.FALSE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 366 | except pexpect.EOF: |
| 367 | main.log.error(self.name + ": EOF exception found") |
| 368 | main.log.error(self.name + ": " + self.handle.before) |
| 369 | main.cleanup() |
| 370 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 371 | except: |
| 372 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 373 | main.log.error( traceback.print_exc() ) |
| 374 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 375 | main.cleanup() |
| 376 | main.exit() |
admin | 6903e46 | 2014-07-22 15:30:54 -0700 | [diff] [blame] | 377 | #********************************************************************************************** |
| 378 | #********************************************************************************************** |
| 379 | # The purpose of comp_intents is to find if the high level intents have changed. preIntents |
| 380 | # and postIntents should be the output of curl of the intents. preIntents being the original |
| 381 | # and postIntents being the later. We are looking at the intents with the same id from both |
| 382 | # and comparing the dst and src DPIDs and macs, and the state. If any of these are changed |
| 383 | # we print that there are changes, then return a list of the intents that have changes` |
| 384 | #********************************************************************************************** |
| 385 | #********************************************************************************************** |
| 386 | def comp_intents(self,preIntents,postIntents): |
| 387 | import json |
| 388 | preDecoded = json.loads(preIntents) |
| 389 | postDecoded = json.loads(postIntents) |
| 390 | changes = [] |
| 391 | if not preDecoded: |
| 392 | if postDecoded: |
| 393 | print "THERE ARE CHANGES TO THE HIGH LEVEL INTENTS!!!!" |
| 394 | return postDecoded |
| 395 | for k in preDecoded: |
| 396 | for l in postDecoded: |
| 397 | if l['id']==k['id']: |
| 398 | if k['dstSwitchDpid']==l['dstSwitchDpid'] and k['srcMac']==l['srcMac'] and k['dstMac']==l['dstMac'] and k['srcSwitchDpid']==l['srcSwitchDpid'] and k['state']==l['state']: |
| 399 | postDecoded.remove(l) |
| 400 | else: |
| 401 | changes.append(k) |
| 402 | print ("THERE ARE CHANGES TO THE HIGH LEVEL INTENTS!!!") |
| 403 | return changes |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 404 | |
admin | 6903e46 | 2014-07-22 15:30:54 -0700 | [diff] [blame] | 405 | #********************************************************************************************** |
| 406 | #********************************************************************************************** |
| 407 | # the purpose of comp_low is to find if the low level intents have changed. The main idea |
| 408 | # is to determine if the path has changed. Again, like with the comp_intents function, the |
| 409 | # pre and post Intents variables are the json dumps of wm/onos/intent/low. The variables |
| 410 | # that will be compared are the state, and the path. |
| 411 | #********************************************************************************************** |
| 412 | #********************************************************************************************** |
| 413 | def comp_low(self, preIntents,postIntents): |
| 414 | import json |
| 415 | preDecoded = json.loads(preIntents) |
| 416 | postDecoded = json.loads(postIntents) |
| 417 | changes = [] |
| 418 | if not preDecoded: |
| 419 | if postDecoded: |
| 420 | print "THERE ARE CHANGES TO THE LOW LEVEL INTENTS!!!" |
| 421 | return postDecoded |
| 422 | for k in preDecoded: |
| 423 | for l in postDecoded: |
| 424 | if l['id']==k['id']: |
| 425 | if l['path']!=k['path']: |
| 426 | changes.append(l) |
| 427 | print "\n\n\n\nTHERE ARE CHANGES TO THE LOW LEVEL INTENTS!!!" |
| 428 | else: |
| 429 | if k['state']!=l['state']: |
| 430 | changes.append(l) |
| 431 | print "\n\n\n\nTHERE ARE CHANGES TO THE LOW LEVEL INTENTS!!!" |
| 432 | else: |
| 433 | print "NO CHANGES SO FAR\n\n\n" |
| 434 | |
| 435 | |
| 436 | return changes |
| 437 | |
| 438 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 439 | def rest_stop(self): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 440 | ''' |
| 441 | Runs ./start-rest.sh stop to stop ONOS rest server |
| 442 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 443 | try: |
| 444 | response = self.execute(cmd= self.home + "/start-rest.sh stop ",prompt="killing",timeout=10) |
| 445 | self.execute(cmd="\n",prompt="\$",timeout=10) |
| 446 | if re.search("killing", response): |
| 447 | main.log.info(self.name + ": Rest Server Stopped") |
| 448 | return main.TRUE |
| 449 | else : |
| 450 | main.log.error(self.name + ": Failed to Stop, Rest Server is not Running") |
| 451 | return main.FALSE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 452 | except pexpect.EOF: |
| 453 | main.log.error(self.name + ": EOF exception found") |
| 454 | main.log.error(self.name + ": " + self.handle.before) |
| 455 | main.cleanup() |
| 456 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 457 | except: |
| 458 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 459 | main.log.error( traceback.print_exc() ) |
| 460 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 461 | main.cleanup() |
| 462 | main.exit() |
| 463 | |
| 464 | |
admin | 680b78c | 2014-08-08 11:46:45 -0700 | [diff] [blame] | 465 | def kill(self): |
| 466 | import re |
| 467 | try: |
| 468 | self.handle.sendline("ps -ef |grep 'ONOS/conf/logback' |awk 'NR==1 {print $2}' |xargs sudo kill -9") |
| 469 | self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT]) |
| 470 | self.handle.sendline("ps -ef |grep 'ONOS/conf/logback' |wc -l") |
| 471 | self.handle.expect(["wc -l",pexpect.EOF,pexpect.TIMEOUT]) |
| 472 | response = self.handle.after |
| 473 | if re.search("1",response): |
| 474 | return "ONOS Killed!" |
| 475 | else: |
| 476 | return "ERROR!!! ONOS MAY NOT HAVE BEEN KILLED PROPERLY!!!" |
| 477 | except pexpect.EOF: |
| 478 | main.log.error(self.name + ": EOF exception found") |
| 479 | main.log.error(self.hane + ": " + self.handle.before) |
| 480 | main.cleanup() |
| 481 | main.exit() |
| 482 | except: |
| 483 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 484 | main.log.error( traceback.print_exc() ) |
| 485 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 486 | main.cleanup() |
| 487 | main.exit() |
| 488 | |
| 489 | |
| 490 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 491 | def disconnect(self): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 492 | ''' |
| 493 | Called when Test is complete to disconnect the ONOS handle. |
| 494 | ''' |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 495 | response = '' |
| 496 | try: |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 497 | self.handle.sendline("exit") |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 498 | self.handle.expect("closed") |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 499 | except pexpect.EOF: |
| 500 | main.log.error(self.name + ": EOF exception found") |
| 501 | main.log.error(self.name + ": " + self.handle.before) |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 502 | except: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 503 | main.log.error(self.name + ": Connection failed to the host") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 504 | response = main.FALSE |
admin | aeedddd | 2013-08-02 15:14:15 -0700 | [diff] [blame] | 505 | return response |
| 506 | |
Jon Hall | 76f2c46 | 2014-04-17 11:37:15 -0700 | [diff] [blame] | 507 | def print_version(self): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 508 | ''' |
| 509 | Writes the COMMIT number to the report to be parsed by Jenkins data collecter. |
| 510 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 511 | try: |
| 512 | self.handle.sendline("export TERM=xterm-256color") |
| 513 | self.handle.expect("xterm-256color") |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 514 | self.handle.expect("\$") |
Jon Hall | 09944cd | 2014-06-25 11:28:43 -0700 | [diff] [blame] | 515 | self.handle.sendline("cd " + self.home + "; git log -1 --pretty=fuller | grep -A 5 \"commit\" --color=never; cd \.\.") |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 516 | self.handle.expect("cd ..") |
| 517 | self.handle.expect("\$") |
admin | e0eeea2 | 2014-04-14 10:22:46 -0700 | [diff] [blame] | 518 | response=(self.name +": \n"+ str(self.handle.before + self.handle.after)) |
| 519 | main.log.report(response) |
Jon Hall | 76f2c46 | 2014-04-17 11:37:15 -0700 | [diff] [blame] | 520 | except pexpect.EOF: |
| 521 | main.log.error(self.name + ": EOF exception found") |
| 522 | main.log.error(self.name + ": " + self.handle.before) |
| 523 | main.cleanup() |
| 524 | main.exit() |
| 525 | except: |
| 526 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 527 | main.log.error( traceback.print_exc() ) |
| 528 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 529 | main.cleanup() |
| 530 | def get_version(self): |
| 531 | ''' |
| 532 | Writes the COMMIT number to the report to be parsed by Jenkins data collecter. |
| 533 | ''' |
| 534 | try: |
| 535 | self.handle.sendline("export TERM=xterm-256color") |
| 536 | self.handle.expect("xterm-256color") |
| 537 | self.handle.expect("\$") |
Jon Hall | 09944cd | 2014-06-25 11:28:43 -0700 | [diff] [blame] | 538 | self.handle.sendline("cd " + self.home + "; git log -1 --pretty=fuller | grep -A 5 \"commit\" --color=never; cd \.\.") |
Jon Hall | 76f2c46 | 2014-04-17 11:37:15 -0700 | [diff] [blame] | 539 | self.handle.expect("cd ..") |
| 540 | self.handle.expect("\$") |
| 541 | response=(self.name +": \n"+ str(self.handle.before + self.handle.after)) |
admin | e0eeea2 | 2014-04-14 10:22:46 -0700 | [diff] [blame] | 542 | lines=response.splitlines() |
| 543 | for line in lines: |
| 544 | print line |
| 545 | return lines[2] |
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 | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 551 | except: |
| 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 | |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 558 | |
admin | dc1c507 | 2014-06-24 15:57:19 -0700 | [diff] [blame] | 559 | |
| 560 | #********************************************************************* |
| 561 | #********************************************************************* |
| 562 | # shortest_path is a command to find the shortest path between two |
| 563 | # switches. It is called using the IP, port, and source and |
| 564 | # destination dpids |
| 565 | #********************************************************************* |
| 566 | #********************************************************************* |
| 567 | |
| 568 | def shortest_path(self,ONOSIP,ONOSPort,srcDPID,dstDPID): |
| 569 | main.log.report("Finding the shortest Path between "+str(srcDPID) + " to " + str(dstDPID)) |
| 570 | url = "http://%s:%s/wm/onos/intent/path/switch/%s/shortest-path/%s"%(ONOSIP,ONOSPort,srcDPID,dstDPID) |
| 571 | parsed_result = [] |
| 572 | try: |
| 573 | response = urllib2.urlopen(url) |
| 574 | result = response.read() |
| 575 | response.close() |
| 576 | if len(result) != 0: |
| 577 | parsed_result = json.loads(result) |
| 578 | except HTTPError as exc: |
| 579 | print "ERROR:" |
| 580 | print " REST GET URL: %s" % url |
| 581 | # NOTE: exc.fp contains the object with the response payload |
| 582 | error_payload = json.loads(exc.fp.read()) |
| 583 | print " REST Error Code: %s" % (error_payload['code']) |
| 584 | print " REST Error Summary: %s" % (error_payload['summary']) |
| 585 | print " REST Error Description: %s" % (error_payload['formattedDescription']) |
| 586 | print " HTTP Error Code: %s" % exc.code |
| 587 | print " HTTP Error Reason: %s" % exc.reason |
| 588 | except URLError as exc: |
| 589 | print "ERROR:" |
| 590 | print " REST GET URL: %s" % url |
| 591 | print " URL Error Reason: %s" % exc.reason |
| 592 | |
| 593 | if len(parsed_result)==0: |
| 594 | return |
| 595 | result = json.dumps(parsed_result,indent=4) |
| 596 | print(str(result)) |
| 597 | return result |
| 598 | |
| 599 | |
| 600 | #********************************************************************* |
| 601 | #********************************************************************* |
| 602 | # show_intent is a command to show intents. |
| 603 | # Parameters include intentIP, intentPort, intentURL, and intent_id |
| 604 | # Based on the url, it will show either high or low intents |
| 605 | # If intent_id is left blank, it will show all high or all low intents |
| 606 | # Else it will show the intent with the id |
| 607 | #********************************************************************* |
| 608 | #********************************************************************* |
| 609 | |
| 610 | |
| 611 | |
| 612 | def show_intent(self,intentIP,intentPort=8080,intentURL="wm/onos/intent",intent_type="high",intent_id="all"): |
| 613 | main.log.report("Getting (an) intent(s)") |
| 614 | if intent_id=="all": |
| 615 | url = "http://%s:%s/%s/%s"%(intentIP,intentPort,intentURL,intent_type) |
| 616 | else: |
| 617 | url = "http://%s:%s/%s/%s/%s"%(intentIP,intentPort,intentURL,intent_type,intent_id) |
| 618 | print(url) |
| 619 | parsed_result = [] |
| 620 | try: |
| 621 | response = urllib2.urlopen(url) |
| 622 | result = response.read() |
| 623 | response.close() |
| 624 | if len(result) != 0: |
| 625 | parsed_result = json.loads(result) |
| 626 | except HTTPError as exc: |
| 627 | print "ERROR:" |
| 628 | print " REST GET URL: %s" % url |
| 629 | # NOTE: exc.fp contains the object with the response payload |
| 630 | error_payload = json.loads(exc.fp.read()) |
| 631 | print " REST Error Code: %s" % (error_payload['code']) |
| 632 | print " REST Error Summary: %s" % (error_payload['summary']) |
| 633 | print " REST Error Description: %s" % (error_payload['formattedDescription']) |
| 634 | print " HTTP Error Code: %s" % exc.code |
| 635 | print " HTTP Error Reason: %s" % exc.reason |
| 636 | return str(error_payload['code']) |
| 637 | except URLError as exc: |
| 638 | print "ERROR:" |
| 639 | print " REST GET URL: %s" % url |
| 640 | print " URL Error Reason: %s" % exc.reason |
| 641 | return str(error_payload['code']) |
| 642 | |
| 643 | if len(parsed_result)==0: |
| 644 | return |
| 645 | result = json.dumps(parsed_result,indent=4) |
| 646 | print(str(result)) |
| 647 | return result |
| 648 | |
| 649 | |
| 650 | #********************************************************************* |
| 651 | #********************************************************************* |
| 652 | # del_intent is to delete either all or some or one intents |
| 653 | # if intent_id is left blank, it will delete all intents |
| 654 | # else, intent_id should be of the form "intent_id=1,2,3" |
| 655 | #********************************************************************* |
| 656 | #********************************************************************* |
| 657 | |
| 658 | def del_intent(self,intentIP,intentPort=8080,intentURL="wm/onos/intent",intent_id="all"): |
| 659 | main.log.report("Deleting (an) intent(s)") |
| 660 | if intent_id=="all": |
| 661 | url = "http://%s:%s/%s/high"%(intentIP,intentPort,intentURL) |
| 662 | else: |
| 663 | url = "http://%s:%s/%s/high?%s"%(intentIP,intentPort,intentURL,intent_id) |
| 664 | |
| 665 | print(url) |
| 666 | |
| 667 | parsed_result = [] |
| 668 | try: |
| 669 | request = urllib2.Request(url) |
| 670 | request.get_method = lambda: 'DELETE' |
| 671 | response = urllib2.urlopen(request) |
| 672 | result = response.read() |
| 673 | response.close() |
| 674 | if len(result) != 0: |
| 675 | parsed_result = json.loads(result) |
| 676 | print(parsed_result) |
| 677 | except HTTPError as exc: |
| 678 | print "ERROR:" |
| 679 | print " REST DELETE URL: %s" % url |
| 680 | # NOTE: exc.fp contains the object with the response payload |
| 681 | error_payload = json.loads(exc.fp.read()) |
| 682 | print " REST Error Code: %s" % (error_payload['code']) |
| 683 | print " REST Error Summary: %s" % (error_payload['summary']) |
| 684 | print " REST Error Description: %s" % (error_payload['formattedDescription']) |
| 685 | print " HTTP Error Code: %s" % exc.code |
| 686 | print " HTTP Error Reason: %s" % exc.reason |
| 687 | except URLError as exc: |
| 688 | print "ERROR:" |
| 689 | print " REST DELETE URL: %s" % url |
| 690 | print " URL Error Reason: %s" % exc.reason |
| 691 | return result |
| 692 | |
| 693 | #********************************************************************* |
| 694 | #********************************************************************* |
| 695 | # add_intent will add a single intent by using dpids and macs. |
| 696 | #********************************************************************* |
| 697 | #********************************************************************* |
| 698 | |
| 699 | |
| 700 | def add_intent(self, intent_id,src_dpid,dst_dpid,src_mac,dst_mac,intentIP,intentPort=8080,intentURL="wm/onos/intent" , intent_type = 'SHORTEST_PATH', static_path=False, src_port=1,dst_port=1): |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 701 | "CLI command callback: set intent" |
| 702 | |
| 703 | intents = [] |
| 704 | oper = {} |
| 705 | # Create the POST payload |
| 706 | oper['intentId'] = intent_id |
| 707 | oper['intentType'] = intent_type # XXX: Hardcoded |
| 708 | oper['staticPath'] = static_path # XXX: Hardcoded |
| 709 | oper['srcSwitchDpid'] = src_dpid |
| 710 | oper['srcSwitchPort'] = src_port |
| 711 | oper['dstSwitchDpid'] = dst_dpid |
| 712 | oper['dstSwitchPort'] = dst_port |
| 713 | oper['matchSrcMac'] = src_mac |
| 714 | oper['matchDstMac'] = dst_mac |
| 715 | intents.append(oper) |
admin | dc1c507 | 2014-06-24 15:57:19 -0700 | [diff] [blame] | 716 | url = "http://%s:%s/%s/high"%(intentIP,intentPort,intentURL) |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 717 | parsed_result = [] |
| 718 | data_json = json.dumps(intents) |
Jon Hall | 43d1e96 | 2014-08-08 11:51:24 -0700 | [diff] [blame] | 719 | result = main.FALSE |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 720 | try: |
| 721 | request = urllib2.Request(url,data_json) |
| 722 | request.add_header("Content-Type", "application/json") |
| 723 | response=urllib2.urlopen(request) |
| 724 | result = response.read() |
| 725 | response.close() |
| 726 | if len(result) != 0: |
| 727 | parsed_result = json.loads(result) |
| 728 | except HTTPError as exc: |
| 729 | print "ERROR:" |
| 730 | print " REST GET URL: %s" % url |
| 731 | # NOTE: exc.fp contains the object with the response payload |
| 732 | error_payload = json.loads(exc.fp.read()) |
| 733 | print " REST Error Code: %s" % (error_payload['code']) |
| 734 | print " REST Error Summary: %s" % (error_payload['summary']) |
| 735 | print " REST Error Description: %s" % (error_payload['formattedDescription']) |
| 736 | print " HTTP Error Code: %s" % exc.code |
| 737 | print " HTTP Error Reason: %s" % exc.reason |
Jon Hall | 43d1e96 | 2014-08-08 11:51:24 -0700 | [diff] [blame] | 738 | return " HTTP Error Code: %s, Reason: %s" % exc.code, exc.reason |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 739 | except URLError as exc: |
| 740 | print "ERROR:" |
| 741 | print " REST GET URL: %s" % url |
| 742 | print " URL Error Reason: %s" % exc.reason |
Jon Hall | 43d1e96 | 2014-08-08 11:51:24 -0700 | [diff] [blame] | 743 | return " HTTP Error Reason: %s" % exc.reason |
admin | dc1c507 | 2014-06-24 15:57:19 -0700 | [diff] [blame] | 744 | return result |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 745 | |
| 746 | |
| 747 | |
| 748 | |
| 749 | def add_intents(self): |
| 750 | main.log.info("Sending new intents to ONOS") |
admin | c6cfc1c | 2014-04-21 13:55:21 -0700 | [diff] [blame] | 751 | self.handle.sendline("cd "+self.home+ "/scripts") |
| 752 | self.handle.expect("scripts") |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 753 | main.log.info("Adding intents") |
admin | c6cfc1c | 2014-04-21 13:55:21 -0700 | [diff] [blame] | 754 | self.handle.sendline("./pyintents.py") |
Jon Hall | 9c6e2c0 | 2014-05-02 10:18:53 -0700 | [diff] [blame] | 755 | self.handle.expect(["$",pexpect.EOF,pexpect.TIMEOUT]) |
| 756 | response = self.handle.before |
admin | c6cfc1c | 2014-04-21 13:55:21 -0700 | [diff] [blame] | 757 | self.handle.sendline("cd "+self.home) |
| 758 | return main.TRUE |
| 759 | |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 760 | def rm_intents(self): |
| 761 | main.log.info("Deleteing Intents from ONOS") |
admin | c6cfc1c | 2014-04-21 13:55:21 -0700 | [diff] [blame] | 762 | self.handle.sendline("cd "+self.home+ "/scripts") |
| 763 | self.handle.expect("scripts") |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 764 | main.log.info("Deleting Intnents") |
admin | c6cfc1c | 2014-04-21 13:55:21 -0700 | [diff] [blame] | 765 | self.handle.sendline("./rmpyintents.py") |
Jon Hall | 9c6e2c0 | 2014-05-02 10:18:53 -0700 | [diff] [blame] | 766 | self.handle.expect(["$",pexpect.EOF,pexpect.TIMEOUT]) |
| 767 | response = self.handle.before |
admin | c6cfc1c | 2014-04-21 13:55:21 -0700 | [diff] [blame] | 768 | self.handle.sendline("cd "+self.home) |
| 769 | return main.TRUE |
| 770 | |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 771 | def purge_intents(self): |
Jon Hall | 265149f | 2014-04-25 13:39:52 -0700 | [diff] [blame] | 772 | main.log.info("Purging dead intents") |
| 773 | self.handle.sendline("cd "+self.home+ "/scripts") |
| 774 | self.handle.expect("scripts") |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 775 | main.log.info("Sending Purge Intent Rest call to ONOS") |
Jon Hall | 265149f | 2014-04-25 13:39:52 -0700 | [diff] [blame] | 776 | self.handle.sendline("./purgeintents.py") |
| 777 | self.handle.sendline("cd "+self.home) |
| 778 | return main.TRUE |
admin | c6cfc1c | 2014-04-21 13:55:21 -0700 | [diff] [blame] | 779 | |
| 780 | |
| 781 | |
Jon Hall | 4a2b048 | 2014-04-18 16:29:26 -0700 | [diff] [blame] | 782 | def add_flow(self, testONip, user = "admin", password = "", flowDef = "/flowdef.txt"): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 783 | ''' |
| 784 | Copies the flowdef file from TestStation -> ONOS machine |
| 785 | Then runs ./add_flow.py to add the flows to ONOS |
| 786 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 787 | try: |
| 788 | main.log.info("Adding Flows...") |
| 789 | self.handle.sendline("scp %s@%s:%s /tmp/flowtmp" %(user,testONip,flowDef)) |
| 790 | i=self.handle.expect(['[pP]assword:', '100%', pexpect.TIMEOUT],30) |
| 791 | if(i==0): |
| 792 | self.handle.sendline("%s" %(password)) |
| 793 | self.handle.sendline("") |
| 794 | self.handle.expect("100%") |
| 795 | self.handle.expect("\$", 30) |
| 796 | self.handle.sendline(self.home + "/web/add_flow.py -m onos -f /tmp/flowtmp") |
| 797 | self.handle.expect("\$", 1000) |
| 798 | main.log.info("Flows added") |
| 799 | return main.TRUE |
| 800 | |
| 801 | elif(i==1): |
| 802 | self.handle.sendline("") |
| 803 | self.handle.expect("\$", 10) |
| 804 | self.handle.sendline( self.home + "/web/add_flow.py -m onos -f /tmp/flowtmp") |
| 805 | self.handle.expect("\$", 1000) |
| 806 | main.log.info("Flows added") |
| 807 | return main.TRUE |
| 808 | |
| 809 | elif(i==2): |
| 810 | main.log.error("Flow Def file SCP Timed out...") |
| 811 | return main.FALSE |
| 812 | |
| 813 | else: |
| 814 | main.log.error("Failed to add flows...") |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 815 | return main.FALSE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 816 | except pexpect.EOF: |
| 817 | main.log.error(self.name + ": EOF exception found") |
| 818 | main.log.error(self.name + ": " + self.handle.before) |
| 819 | main.cleanup() |
| 820 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 821 | except: |
| 822 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 823 | main.log.error( traceback.print_exc() ) |
| 824 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 825 | main.cleanup() |
| 826 | main.exit() |
| 827 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 828 | |
| 829 | def delete_flow(self, *delParams): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 830 | ''' |
| 831 | Deletes a specific flow, a range of flows, or all flows. |
| 832 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 833 | try: |
| 834 | if len(delParams)==1: |
| 835 | if str(delParams[0])=="all": |
| 836 | main.log.info(self.name + ": Deleting ALL flows...") |
| 837 | #self.execute(cmd="~/ONOS/scripts/TestON_delete_flow.sh all",prompt="done",timeout=150) |
| 838 | self.handle.sendline(self.home + "/web/delete_flow.py all") |
| 839 | self.handle.expect("delete_flow") |
| 840 | self.handle.expect("\$",1000) |
| 841 | main.log.info(self.name + ": Flows deleted") |
| 842 | else: |
| 843 | main.log.info(self.name + ": Deleting flow "+str(delParams[0])+"...") |
| 844 | #self.execute(cmd="~/ONOS/scripts/TestON_delete_flow.sh "+str(delParams[0]),prompt="done",timeout=150) |
| 845 | #self.execute(cmd="\n",prompt="\$",timeout=60) |
| 846 | self.handle.sendline(self.home +"/web/delete_flow.py %d" % int(delParams[0])) |
| 847 | self.handle.expect("delete_flow") |
| 848 | self.handle.expect("\$",60) |
| 849 | main.log.info(self.name + ": Flow deleted") |
| 850 | elif len(delParams)==2: |
| 851 | main.log.info(self.name + ": Deleting flows "+str(delParams[0])+" through "+str(delParams[1])+"...") |
| 852 | #self.execute(cmd="~/ONOS/scripts/TestON_delete_flow.sh "+str(delParams[0])+" "+str(delParams[1]),prompt="done",timeout=150) |
| 853 | #self.execute(cmd="\n",prompt="\$",timeout=60) |
| 854 | self.handle.sendline(self.home + "/web/delete_flow.py %d %d" % (int(delParams[0]), int(delParams[1]))) |
| 855 | self.handle.expect("delete_flow") |
| 856 | self.handle.expect("\$",600) |
| 857 | main.log.info(self.name + ": Flows deleted") |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 858 | except pexpect.EOF: |
| 859 | main.log.error(self.name + ": EOF exception found") |
| 860 | main.log.error(self.name + ": " + self.handle.before) |
| 861 | main.cleanup() |
| 862 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 863 | except: |
| 864 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 865 | main.log.error( traceback.print_exc() ) |
| 866 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 867 | main.cleanup() |
| 868 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 869 | |
| 870 | def check_flow(self): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 871 | ''' |
| 872 | Calls the ./get_flow.py all and checks: |
| 873 | - If each FlowPath has at least one FlowEntry |
| 874 | - That there are no "NOT"s found |
| 875 | returns TRUE/FALSE |
| 876 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 877 | try: |
| 878 | flowEntryDetect = 1 |
| 879 | count = 0 |
| 880 | self.handle.sendline("clear") |
| 881 | time.sleep(1) |
| 882 | self.handle.sendline(self.home + "/web/get_flow.py all") |
| 883 | self.handle.expect("get_flow") |
Jon Hall | 3bd7c79 | 2014-05-30 09:05:21 -0700 | [diff] [blame] | 884 | for x in range(15): |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 885 | i=self.handle.expect(['FlowPath','FlowEntry','NOT','\$',pexpect.TIMEOUT],timeout=180) |
| 886 | if i==0: |
| 887 | count = count + 1 |
| 888 | if flowEntryDetect == 0: |
| 889 | main.log.info(self.name + ": FlowPath without FlowEntry") |
| 890 | return main.FALSE |
| 891 | else: |
| 892 | flowEntryDetect = 0 |
| 893 | elif i==1: |
| 894 | flowEntryDetect = 1 |
| 895 | elif i==2: |
| 896 | main.log.error(self.name + ": Found a NOT") |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 897 | return main.FALSE |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 898 | elif i==3: |
| 899 | if count == 0: |
| 900 | main.log.info(self.name + ": There don't seem to be any flows here...") |
| 901 | return main.FALSE |
| 902 | else: |
| 903 | main.log.info(self.name + ": All flows pass") |
| 904 | main.log.info(self.name + ": Number of FlowPaths: "+str(count)) |
| 905 | return main.TRUE |
| 906 | elif i==4: |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 907 | main.log.error(self.name + ":Check_flow() - Command Timeout!") |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 908 | return main.FALSE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 909 | except pexpect.EOF: |
| 910 | main.log.error(self.name + ": EOF exception found") |
| 911 | main.log.error(self.name + ": " + self.handle.before) |
| 912 | main.cleanup() |
| 913 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 914 | except: |
| 915 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 916 | main.log.error( traceback.print_exc() ) |
| 917 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 918 | main.cleanup() |
| 919 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 920 | |
| 921 | def get_flow(self, *flowParams): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 922 | ''' |
| 923 | Returns verbose output of ./get_flow.py |
| 924 | ''' |
| 925 | try: |
| 926 | if len(flowParams)==1: |
| 927 | if str(flowParams[0])=="all": |
| 928 | self.execute(cmd="\n",prompt="\$",timeout=60) |
| 929 | main.log.info(self.name + ": Getting all flow data...") |
| 930 | data = self.execute(cmd=self.home + "/scripts/TestON_get_flow.sh all",prompt="done",timeout=150) |
| 931 | self.execute(cmd="\n",prompt="\$",timeout=60) |
| 932 | return data |
| 933 | else: |
| 934 | main.log.info(self.name + ": Retrieving flow "+str(flowParams[0])+" data...") |
| 935 | data = self.execute(cmd=self.home +"/scripts/TestON_get_flow.sh "+str(flowParams[0]),prompt="done",timeout=150) |
| 936 | self.execute(cmd="\n",prompt="\$",timeout=60) |
| 937 | return data |
| 938 | elif len(flowParams)==5: |
| 939 | main.log.info(self.name + ": Retrieving flow installer data...") |
| 940 | 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) |
| 941 | self.execute(cmd="\n",prompt="\$",timeout=60) |
| 942 | return data |
| 943 | elif len(flowParams)==4: |
| 944 | main.log.info(self.name + ": Retrieving flow endpoints...") |
| 945 | 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) |
| 946 | self.execute(cmd="\n",prompt="\$",timeout=60) |
| 947 | return data |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 948 | except pexpect.EOF: |
| 949 | main.log.error(self.name + ": EOF exception found") |
| 950 | main.log.error(self.name + ": " + self.handle.before) |
| 951 | main.cleanup() |
| 952 | main.exit() |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 953 | except: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 954 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 955 | main.log.error( traceback.print_exc() ) |
| 956 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 957 | main.cleanup() |
| 958 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 959 | |
| 960 | |
Jon Hall | 2f42a67 | 2014-05-28 10:13:18 -0700 | [diff] [blame] | 961 | # http://localhost:8080/wm/onos/topology/switches |
| 962 | # http://localhost:8080/wm/onos/topology/links |
Jon Hall | 8060af0 | 2014-04-14 14:17:58 -0700 | [diff] [blame] | 963 | # http://localhost:8080/wm/onos/registry/controllers/json |
| 964 | # http://localhost:8080/wm/onos/registry/switches/json" |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 965 | |
| 966 | def get_json(self, url): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 967 | ''' |
| 968 | Helper functions used to parse the json output of a rest call |
| 969 | ''' |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 970 | try: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 971 | try: |
| 972 | command = "curl -s %s" % (url) |
| 973 | result = os.popen(command).read() |
| 974 | parsedResult = json.loads(result) |
| 975 | except: |
| 976 | print "REST IF %s has issue" % command |
| 977 | parsedResult = "" |
| 978 | |
| 979 | if type(parsedResult) == 'dict' and parsedResult.has_key('code'): |
| 980 | print "REST %s returned code %s" % (command, parsedResult['code']) |
| 981 | parsedResult = "" |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 982 | return parsedResult |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 983 | except pexpect.EOF: |
| 984 | main.log.error(self.name + ": EOF exception found") |
| 985 | main.log.error(self.name + ": " + self.handle.before) |
| 986 | main.cleanup() |
| 987 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 988 | except: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 989 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 990 | main.log.error( traceback.print_exc() ) |
| 991 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 992 | main.cleanup() |
| 993 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 994 | |
admin | 680b78c | 2014-08-08 11:46:45 -0700 | [diff] [blame] | 995 | def num_switch(self,RestIP,RestPort="8080"): |
| 996 | url = "http://%s:%s/wm/onos/topology/switches" %(RestIP,RestPort) |
| 997 | parsedResult = self.get_json(url) |
| 998 | if parsedResult == "": |
| 999 | retcode = 1 |
| 1000 | return (retcode, "RestAPI has an issue") |
| 1001 | url = "http://%s:%s/wm/onos/registry/switches/json" %(RestIP,RestPort) |
| 1002 | registry = self.get_json(url) |
| 1003 | if registry == "": |
| 1004 | retcode = 1 |
| 1005 | return (retcode, "REST API has an Issue") |
| 1006 | cnt = 0 |
| 1007 | active = 0 |
| 1008 | for s in parsedResult: |
| 1009 | cnt +=1 |
| 1010 | if s['state']=="ACTIVE": |
| 1011 | active+=1 |
| 1012 | return (cnt,active) |
| 1013 | |
| 1014 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1015 | def check_switch(self,RestIP,correct_nr_switch, RestPort ="8080" ): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 1016 | ''' |
| 1017 | Used by check_status |
| 1018 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1019 | try: |
| 1020 | buf = "" |
| 1021 | retcode = 0 |
admin | 2e131ab | 2014-05-28 10:03:42 -0700 | [diff] [blame] | 1022 | url="http://%s:%s/wm/onos/topology/switches" % (RestIP, RestPort) |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1023 | parsedResult = self.get_json(url) |
| 1024 | if parsedResult == "": |
| 1025 | retcode = 1 |
| 1026 | return (retcode, "Rest API has an issue") |
| 1027 | url = "http://%s:%s/wm/onos/registry/switches/json" % (RestIP, RestPort) |
| 1028 | registry = self.get_json(url) |
| 1029 | |
| 1030 | if registry == "": |
| 1031 | retcode = 1 |
| 1032 | return (retcode, "Rest API has an issue") |
| 1033 | |
| 1034 | cnt = 0 |
| 1035 | active = 0 |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 1036 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1037 | for s in parsedResult: |
| 1038 | cnt += 1 |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 1039 | if s['state'] == "ACTIVE": |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1040 | active += 1 |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 1041 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1042 | buf += "switch: network %d : %d switches %d active\n" % (0+1, cnt, active) |
| 1043 | if correct_nr_switch != cnt: |
| 1044 | buf += "switch fail: network %d should have %d switches but has %d\n" % (1, correct_nr_switch, cnt) |
| 1045 | retcode = 1 |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 1046 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1047 | if correct_nr_switch != active: |
| 1048 | buf += "switch fail: network %d should have %d active switches but has %d\n" % (1, correct_nr_switch, active) |
| 1049 | retcode = 1 |
| 1050 | |
| 1051 | return (retcode, buf) |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1052 | except pexpect.EOF: |
| 1053 | main.log.error(self.name + ": EOF exception found") |
| 1054 | main.log.error(self.name + ": " + self.handle.before) |
| 1055 | main.cleanup() |
| 1056 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1057 | except: |
| 1058 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1059 | main.log.error( traceback.print_exc() ) |
| 1060 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1061 | main.cleanup() |
| 1062 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 1063 | |
admin | 680b78c | 2014-08-08 11:46:45 -0700 | [diff] [blame] | 1064 | def num_link(self,RestIP,RestPort="8080"): |
| 1065 | url = "http://%s:%s/wm/onos/topology/links" % (RestIP,RestPort) |
| 1066 | parsedResult = self.get_json(url) |
| 1067 | if parsedResult == "": |
| 1068 | retcode = 1 |
| 1069 | return (retcode,"RestAPI has an issue") |
| 1070 | intra = 0 |
| 1071 | for s in parsedResult: |
| 1072 | intra+=1 |
| 1073 | return intra |
| 1074 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1075 | def check_link(self,RestIP, nr_links, RestPort = "8080"): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 1076 | ''' |
| 1077 | Used by check_status |
| 1078 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1079 | try: |
| 1080 | buf = "" |
| 1081 | retcode = 0 |
| 1082 | |
admin | 2e131ab | 2014-05-28 10:03:42 -0700 | [diff] [blame] | 1083 | url = "http://%s:%s/wm/onos/topology/links" % (RestIP, RestPort) |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1084 | parsedResult = self.get_json(url) |
| 1085 | |
| 1086 | if parsedResult == "": |
| 1087 | retcode = 1 |
| 1088 | return (retcode, "Rest API has an issue") |
| 1089 | |
| 1090 | buf += "link: total %d links (correct : %d)\n" % (len(parsedResult), nr_links) |
| 1091 | intra = 0 |
| 1092 | interlink=0 |
| 1093 | |
| 1094 | for s in parsedResult: |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 1095 | intra = intra + 1 |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1096 | |
| 1097 | if intra != nr_links: |
| 1098 | buf += "link fail\n" |
| 1099 | retcode = 1 |
| 1100 | |
| 1101 | return (retcode, buf) |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1102 | except pexpect.EOF: |
| 1103 | main.log.error(self.name + ": EOF exception found") |
| 1104 | main.log.error(self.name + ": " + self.handle.before) |
| 1105 | main.cleanup() |
| 1106 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1107 | except: |
| 1108 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1109 | main.log.error( traceback.print_exc() ) |
| 1110 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1111 | main.cleanup() |
| 1112 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 1113 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1114 | def check_status_report(self, ip, numoswitch, numolink, port="8080"): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 1115 | ''' |
| 1116 | Checks the number of swithes & links that ONOS sees against the supplied values. |
| 1117 | Writes to the report log. |
| 1118 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1119 | try: |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 1120 | main.log.info(self.name + ": Making some rest calls...") |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1121 | switch = self.check_switch(ip, int(numoswitch), port) |
| 1122 | link = self.check_link(ip, int(numolink), port) |
| 1123 | value = switch[0] |
| 1124 | value += link[0] |
| 1125 | main.log.report( self.name + ": \n-----\n%s%s-----\n" % ( switch[1], link[1]) ) |
| 1126 | if value != 0: |
| 1127 | return main.FALSE |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 1128 | else: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1129 | # "PASS" |
| 1130 | return main.TRUE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1131 | except pexpect.EOF: |
| 1132 | main.log.error(self.name + ": EOF exception found") |
| 1133 | main.log.error(self.name + ": " + self.handle.before) |
| 1134 | main.cleanup() |
| 1135 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1136 | except: |
| 1137 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1138 | main.log.error( traceback.print_exc() ) |
| 1139 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1140 | main.cleanup() |
| 1141 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 1142 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1143 | def check_status(self, ip, numoswitch, numolink, port = "8080"): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 1144 | ''' |
| 1145 | Checks the number of swithes & links that ONOS sees against the supplied values. |
| 1146 | Writes to the main log. |
| 1147 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1148 | try: |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 1149 | main.log.info(self.name + ": Making some rest calls...") |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1150 | switch = self.check_switch(ip, int(numoswitch), port) |
| 1151 | link = self.check_link(ip, int(numolink), port) |
| 1152 | value = switch[0] |
| 1153 | value += link[0] |
| 1154 | main.log.info(self.name + ": \n-----\n%s%s-----\n" % ( switch[1], link[1]) ) |
| 1155 | if value != 0: |
| 1156 | return main.FALSE |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 1157 | else: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1158 | # "PASS" |
| 1159 | return main.TRUE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1160 | except pexpect.EOF: |
| 1161 | main.log.error(self.name + ": EOF exception found") |
| 1162 | main.log.error(self.name + ": " + self.handle.before) |
| 1163 | main.cleanup() |
| 1164 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1165 | except: |
| 1166 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1167 | main.log.error( traceback.print_exc() ) |
| 1168 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1169 | main.cleanup() |
| 1170 | main.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 1171 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1172 | |
admin | e0eeea2 | 2014-04-14 10:22:46 -0700 | [diff] [blame] | 1173 | def git_pull(self, comp1=""): |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 1174 | ''' |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 1175 | Assumes that "git pull" works without login |
admin | e0eeea2 | 2014-04-14 10:22:46 -0700 | [diff] [blame] | 1176 | |
| 1177 | This function will perform a git pull on the ONOS instance. |
| 1178 | If used as git_pull("NODE") it will do git pull + NODE. This is |
| 1179 | for the purpose of pulling from other nodes if necessary. |
| 1180 | |
| 1181 | Otherwise, this function will perform a git pull in the |
| 1182 | ONOS repository. If it has any problems, it will return main.ERROR |
| 1183 | If it successfully does a git_pull, it will return a 1. |
| 1184 | If it has no updates, it will return a 0. |
| 1185 | |
Jon Hall | d8dc577 | 2014-04-08 16:26:29 -0700 | [diff] [blame] | 1186 | ''' |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1187 | try: |
Jon Hall | e80ef8c | 2014-04-29 15:29:13 -0700 | [diff] [blame] | 1188 | # main.log.info(self.name + ": Stopping ONOS") |
| 1189 | #self.stop() |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1190 | self.handle.sendline("cd " + self.home) |
| 1191 | self.handle.expect("ONOS\$") |
| 1192 | if comp1=="": |
| 1193 | self.handle.sendline("git pull") |
| 1194 | else: |
| 1195 | self.handle.sendline("git pull " + comp1) |
| 1196 | |
| 1197 | uptodate = 0 |
Jon Hall | 9698363 | 2014-07-17 12:06:12 -0700 | [diff] [blame] | 1198 | i=self.handle.expect(['fatal','Username\sfor\s(.*):\s','\sfile(s*) changed,\s',pexpect.TIMEOUT,'Already up-to-date','Aborting','You\sare\snot\scurrently\son\sa\sbranch'],timeout=1700) |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1199 | #debug |
| 1200 | #main.log.report(self.name +": \n"+"git pull response: " + str(self.handle.before) + str(self.handle.after)) |
| 1201 | if i==0: |
| 1202 | main.log.error(self.name + ": Git pull had some issue...") |
| 1203 | return main.ERROR |
| 1204 | elif i==1: |
| 1205 | main.log.error(self.name + ": Git Pull Asking for username!!! BADD!") |
| 1206 | return main.ERROR |
| 1207 | elif i==2: |
| 1208 | main.log.info(self.name + ": Git Pull - pulling repository now") |
| 1209 | self.handle.expect("ONOS\$", 120) |
| 1210 | return 0 |
| 1211 | elif i==3: |
| 1212 | main.log.error(self.name + ": Git Pull - TIMEOUT") |
Jon Hall | 9698363 | 2014-07-17 12:06:12 -0700 | [diff] [blame] | 1213 | main.log.error(self.name + " Response was: " + str(self.handle.before)) |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1214 | return main.ERROR |
| 1215 | elif i==4: |
| 1216 | main.log.info(self.name + ": Git Pull - Already up to date") |
| 1217 | return 1 |
| 1218 | elif i==5: |
| 1219 | main.log.info(self.name + ": Git Pull - Aborting... Are there conflicting git files?") |
| 1220 | return main.ERROR |
Jon Hall | 5a8aac6 | 2014-06-03 09:30:21 -0700 | [diff] [blame] | 1221 | elif i==6: |
| 1222 | main.log.info(self.name + ": Git Pull - You are not currently on a branch so git pull failed!") |
| 1223 | return main.ERROR |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1224 | else: |
| 1225 | main.log.error(self.name + ": Git Pull - Unexpected response, check for pull errors") |
| 1226 | return main.ERROR |
| 1227 | except pexpect.EOF: |
| 1228 | main.log.error(self.name + ": EOF exception found") |
| 1229 | main.log.error(self.name + ": " + self.handle.before) |
| 1230 | main.cleanup() |
| 1231 | main.exit() |
| 1232 | except: |
| 1233 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1234 | main.log.error( traceback.print_exc() ) |
| 1235 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1236 | main.cleanup() |
| 1237 | main.exit() |
admin | e0eeea2 | 2014-04-14 10:22:46 -0700 | [diff] [blame] | 1238 | #******************************************************** |
| 1239 | |
| 1240 | |
admin | 680b78c | 2014-08-08 11:46:45 -0700 | [diff] [blame] | 1241 | |
| 1242 | |
| 1243 | def git_checkout(self, branch="onos13integration"): |
| 1244 | ''' |
| 1245 | Assumes that "git pull" works without login |
| 1246 | |
| 1247 | This function will perform a git pull on the ONOS instance. |
| 1248 | If used as git_pull("NODE") it will do git pull + NODE. This is |
| 1249 | for the purpose of pulling from other nodes if necessary. |
| 1250 | |
| 1251 | Otherwise, this function will perform a git pull in the |
| 1252 | ONOS repository. If it has any problems, it will return main.ERROR |
| 1253 | If it successfully does a git_pull, it will return a 1. |
| 1254 | If it has no updates, it will return a 0. |
| 1255 | |
| 1256 | ''' |
| 1257 | try: |
| 1258 | # main.log.info(self.name + ": Stopping ONOS") |
| 1259 | #self.stop() |
| 1260 | self.handle.sendline("cd " + self.home) |
| 1261 | self.handle.expect("ONOS\$") |
| 1262 | if branch != 'master': |
| 1263 | #self.handle.sendline('git stash') |
| 1264 | #self.handle.expect('ONOS\$') |
| 1265 | #print "After issuing git stash cmnd: ", self.handle.before |
| 1266 | cmd = "git checkout "+branch |
| 1267 | print "checkout cmd = ", cmd |
| 1268 | self.handle.sendline(cmd) |
| 1269 | uptodate = 0 |
| 1270 | i=self.handle.expect(['fatal','Username\sfor\s(.*):\s','Already\son\s\'onos13integration\'','Switched\sto\sbranch\s\'onos13integration\'', pexpect.TIMEOUT],timeout=60) |
| 1271 | else: |
| 1272 | #self.handle.sendline('git stash apply') |
| 1273 | #self.handle.expect('ONOS\$') |
| 1274 | #print "After issuing git stash apply cmnd: ", self.handle.before |
| 1275 | cmd = "git checkout "+branch |
| 1276 | print "checkout cmd = ", cmd |
| 1277 | self.handle.sendline(cmd) |
| 1278 | uptodate = 0 |
| 1279 | switchedToMaster = 0 |
| 1280 | i=self.handle.expect(['fatal','Username\sfor\s(.*):\s','Already\son\s\'master\'','Switched\sto\sbranch\s\'master\'', pexpect.TIMEOUT],timeout=60) |
| 1281 | |
| 1282 | |
| 1283 | if i==0: |
| 1284 | main.log.error(self.name + ": Git checkout had some issue...") |
| 1285 | return main.ERROR |
| 1286 | elif i==1: |
| 1287 | main.log.error(self.name + ": Git checkout Asking for username!!! BADD!") |
| 1288 | return main.ERROR |
| 1289 | elif i==2: |
| 1290 | main.log.info(self.name + ": Git Checkout %s : Already on this branch" %branch) |
| 1291 | self.handle.expect("ONOS\$") |
| 1292 | print "after checkout cmd = ", self.handle.before |
| 1293 | switchedToMaster = 1 |
| 1294 | return 1 |
| 1295 | elif i==3: |
| 1296 | main.log.info(self.name + ": Git checkout %s - Switched to this branch" %branch) |
| 1297 | self.handle.expect("ONOS\$") |
| 1298 | print "after checkout cmd = ", self.handle.before |
| 1299 | switchedToMaster = 1 |
| 1300 | return 1 |
| 1301 | elif i==4: |
| 1302 | main.log.error(self.name + ": Git Checkout- TIMEOUT") |
| 1303 | main.log.error(self.name + " Response was: " + str(self.handle.before)) |
| 1304 | return main.ERROR |
| 1305 | else: |
| 1306 | main.log.error(self.name + ": Git Checkout - Unexpected response, check for pull errors") |
| 1307 | return main.ERROR |
| 1308 | |
| 1309 | except pexpect.EOF: |
| 1310 | main.log.error(self.name + ": EOF exception found") |
| 1311 | main.log.error(self.name + ": " + self.handle.before) |
| 1312 | main.cleanup() |
| 1313 | main.exit() |
| 1314 | except: |
| 1315 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1316 | main.log.error( traceback.print_exc() ) |
| 1317 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1318 | main.cleanup() |
| 1319 | main.exit() |
| 1320 | #******************************************************** |
| 1321 | self.handle.sendline("git branch") |
| 1322 | self.handle.expect("ONOS\$") |
| 1323 | print "git branch output = ", self.handle.before |
| 1324 | print "*****************************************" |
| 1325 | self.handle.sendline('cd\.\.') |
| 1326 | self.handle.expect("\$") |
| 1327 | |
| 1328 | |
| 1329 | |
| 1330 | |
| 1331 | |
| 1332 | |
| 1333 | |
| 1334 | |
admin | 7373a81 | 2014-04-16 09:49:02 -0700 | [diff] [blame] | 1335 | def git_compile(self): |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1336 | ''' |
| 1337 | Compiles ONOS |
| 1338 | First runs mvn clean then mvn compile |
| 1339 | ''' |
| 1340 | try: |
| 1341 | main.log.info(self.name + ": mvn clean") |
admin | 8fc0282 | 2014-04-16 13:31:23 -0700 | [diff] [blame] | 1342 | self.handle.sendline("cd " + self.home) |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1343 | self.handle.sendline("mvn clean") |
| 1344 | while 1: |
Jon Hall | 1636f94 | 2014-04-17 10:07:23 -0700 | [diff] [blame] | 1345 | 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] | 1346 | if i == 0: |
Jon Hall | 1636f94 | 2014-04-17 10:07:23 -0700 | [diff] [blame] | 1347 | 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] | 1348 | return main.FALSE |
| 1349 | elif i == 1: |
Jon Hall | 1636f94 | 2014-04-17 10:07:23 -0700 | [diff] [blame] | 1350 | main.log.error(self.name + ": Clean failure!") |
| 1351 | return main.FALSE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1352 | elif i == 2: |
Jon Hall | 1636f94 | 2014-04-17 10:07:23 -0700 | [diff] [blame] | 1353 | main.log.info(self.name + ": Clean success!") |
| 1354 | elif i == 3: |
admin | 8fc0282 | 2014-04-16 13:31:23 -0700 | [diff] [blame] | 1355 | main.log.info(self.name + ": Clean complete") |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1356 | break; |
Jon Hall | 1636f94 | 2014-04-17 10:07:23 -0700 | [diff] [blame] | 1357 | elif i == 4: |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1358 | main.log.error(self.name + ": mvn clean TIMEOUT!") |
| 1359 | return main.FALSE |
Jon Hall | 1636f94 | 2014-04-17 10:07:23 -0700 | [diff] [blame] | 1360 | else: |
| 1361 | main.log.error(self.name + ": unexpected response from mvn clean") |
| 1362 | return main.FALSE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1363 | |
| 1364 | main.log.info(self.name + ": mvn compile") |
| 1365 | self.handle.sendline("mvn compile") |
| 1366 | while 1: |
Jon Hall | 1636f94 | 2014-04-17 10:07:23 -0700 | [diff] [blame] | 1367 | 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] | 1368 | if i == 0: |
Jon Hall | 1636f94 | 2014-04-17 10:07:23 -0700 | [diff] [blame] | 1369 | main.log.error(self.name + ":There is insufficient memory for the Java Runtime Environment to continue.") |
| 1370 | return main.FALSE |
| 1371 | if i == 1: |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1372 | main.log.error(self.name + ": Build failure!") |
| 1373 | return main.FALSE |
Jon Hall | 1636f94 | 2014-04-17 10:07:23 -0700 | [diff] [blame] | 1374 | elif i == 2: |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1375 | main.log.info(self.name + ": Build success!") |
Jon Hall | 1636f94 | 2014-04-17 10:07:23 -0700 | [diff] [blame] | 1376 | elif i == 3: |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1377 | main.log.info(self.name + ": Build complete") |
Jon Hall | 010f541 | 2014-05-21 15:10:12 -0700 | [diff] [blame] | 1378 | self.handle.expect("\$", timeout=60) |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1379 | return main.TRUE |
Jon Hall | 1636f94 | 2014-04-17 10:07:23 -0700 | [diff] [blame] | 1380 | elif i == 4: |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1381 | main.log.error(self.name + ": mvn compile TIMEOUT!") |
| 1382 | return main.FALSE |
| 1383 | else: |
Jon Hall | 1636f94 | 2014-04-17 10:07:23 -0700 | [diff] [blame] | 1384 | main.log.error(self.name + ": unexpected response from mvn compile") |
| 1385 | return main.FALSE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1386 | except pexpect.EOF: |
| 1387 | main.log.error(self.name + ": EOF exception found") |
| 1388 | main.log.error(self.name + ": " + self.handle.before) |
| 1389 | main.cleanup() |
| 1390 | main.exit() |
| 1391 | except: |
| 1392 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1393 | main.log.error( traceback.print_exc() ) |
| 1394 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1395 | main.cleanup() |
| 1396 | main.exit() |
admin | 4a58db9 | 2013-09-30 12:04:54 -0700 | [diff] [blame] | 1397 | |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1398 | def tcpdump(self, intf = "eth0"): |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1399 | ''' |
| 1400 | Runs tpdump on an intferface and saves in onos-logs under the ONOS home directory |
| 1401 | intf can be specified, or the default eth0 is used |
| 1402 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1403 | try: |
| 1404 | self.handle.sendline("") |
| 1405 | self.handle.expect("\$") |
Jon Hall | 26f316b | 2014-04-11 11:21:25 -0700 | [diff] [blame] | 1406 | 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] | 1407 | i=self.handle.expect(['No\ssuch\device','listening\son',pexpect.TIMEOUT],timeout=10) |
| 1408 | if i == 0: |
| 1409 | main.log.error(self.name + ": tcpdump - No such device exists. tcpdump attempted on: " + intf) |
| 1410 | return main.FALSE |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 1411 | elif i == 1: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1412 | main.log.info(self.name + ": tcpdump started on " + intf) |
| 1413 | return main.TRUE |
James Lee | c9cacaf | 2014-04-08 09:17:39 -0700 | [diff] [blame] | 1414 | elif i == 2: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1415 | main.log.error(self.name + ": tcpdump command timed out! Check interface name, given interface was: " + intf) |
| 1416 | return main.FALSE |
| 1417 | else: |
| 1418 | main.log.error(self.name + ": tcpdump - unexpected response") |
| 1419 | return main.FALSE |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1420 | except pexpect.EOF: |
| 1421 | main.log.error(self.name + ": EOF exception found") |
| 1422 | main.log.error(self.name + ": " + self.handle.before) |
| 1423 | main.cleanup() |
| 1424 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1425 | except: |
| 1426 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1427 | main.log.error( traceback.print_exc() ) |
| 1428 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1429 | main.cleanup() |
| 1430 | main.exit() |
| 1431 | |
admin | 4a58db9 | 2013-09-30 12:04:54 -0700 | [diff] [blame] | 1432 | def kill_tcpdump(self): |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1433 | ''' |
| 1434 | Kills any tcpdump processes running |
| 1435 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1436 | try: |
| 1437 | self.handle.sendline("") |
| 1438 | self.handle.expect("\$") |
| 1439 | 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] | 1440 | except pexpect.EOF: |
| 1441 | main.log.error(self.name + ": EOF exception found") |
| 1442 | main.log.error(self.name + ": " + self.handle.before) |
| 1443 | main.cleanup() |
| 1444 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1445 | except: |
| 1446 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1447 | main.log.error( traceback.print_exc() ) |
| 1448 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1449 | main.cleanup() |
| 1450 | main.exit() |
| 1451 | |
Jon Hall | f15f785 | 2014-05-20 10:37:23 -0700 | [diff] [blame] | 1452 | def find_host(self,RestIP,RestPort,RestAPI,hostMAC): |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 1453 | retcode = 0 # number of hosts found with given MAC |
| 1454 | retswitch = [] # Switch DPID's of hosts found with MAC |
| 1455 | retport = [] # Switch port connected to to hosts found with MAC |
Jon Hall | f15f785 | 2014-05-20 10:37:23 -0700 | [diff] [blame] | 1456 | foundHost = [] |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1457 | try: |
Jon Hall | 2f42a67 | 2014-05-28 10:13:18 -0700 | [diff] [blame] | 1458 | ##### device rest API is: 'host:8080/wm/onos/topology/switches' ### |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1459 | url ="http://%s:%s%s" %(RestIP,RestPort,RestAPI) |
| 1460 | |
| 1461 | try: |
| 1462 | command = "curl -s %s" % (url) |
| 1463 | result = os.popen(command).read() |
| 1464 | parsedResult = json.loads(result) |
| 1465 | # print parsedResult |
| 1466 | except: |
| 1467 | print "REST IF %s has issue" % command |
| 1468 | parsedResult = "" |
| 1469 | |
| 1470 | if parsedResult == "": |
Jon Hall | f15f785 | 2014-05-20 10:37:23 -0700 | [diff] [blame] | 1471 | return (retcode, "Rest API has an error", retport) |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1472 | else: |
Jon Hall | f15f785 | 2014-05-20 10:37:23 -0700 | [diff] [blame] | 1473 | for host in enumerate(parsedResult): |
| 1474 | print host |
| 1475 | if (host[1] != []): |
| 1476 | try: |
| 1477 | foundHost = host[1]['mac'] |
| 1478 | except: |
| 1479 | print "Error in detecting MAC address." |
| 1480 | print foundHost |
| 1481 | print hostMAC |
| 1482 | if foundHost == hostMAC: |
| 1483 | for switch in enumerate(host[1]['attachmentPoints']): |
| 1484 | retswitch.append(switch[1]['dpid']) |
Jon Hall | bb650fe | 2014-07-14 14:54:48 -0700 | [diff] [blame] | 1485 | retport.append(switch[1]['portNumber']) |
Jon Hall | f15f785 | 2014-05-20 10:37:23 -0700 | [diff] [blame] | 1486 | retcode = retcode +1 |
| 1487 | foundHost ='' |
| 1488 | ''' |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1489 | for switch in enumerate(parsedResult): |
| 1490 | for port in enumerate(switch[1]['ports']): |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 1491 | if ( port[1]['hosts'] != [] ): |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1492 | try: |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 1493 | foundHost = port[1]['hosts'][0]['ipv4addresses'][0]['ipv4'] |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1494 | except: |
Jon Hall | f15f785 | 2014-05-20 10:37:23 -0700 | [diff] [blame] | 1495 | print "Error in detecting MAC address." |
| 1496 | if foundHost == hostMAC: |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1497 | retswitch.append(switch[1]['dpid']) |
| 1498 | retport.append(port[1]['desc']) |
admin | 2a9548d | 2014-06-17 14:08:07 -0700 | [diff] [blame] | 1499 | retmac.append(port[1]['hosts'][0]['mac']) |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1500 | retcode = retcode +1 |
Jon Hall | f15f785 | 2014-05-20 10:37:23 -0700 | [diff] [blame] | 1501 | foundHost ='' |
| 1502 | ''' |
| 1503 | return(retcode, retswitch, retport) |
Jon Hall | ae05dc2 | 2014-04-16 10:56:28 -0700 | [diff] [blame] | 1504 | except pexpect.EOF: |
| 1505 | main.log.error(self.name + ": EOF exception found") |
| 1506 | main.log.error(self.name + ": " + self.handle.before) |
| 1507 | main.cleanup() |
| 1508 | main.exit() |
Jon Hall | f89c855 | 2014-04-02 13:14:06 -0700 | [diff] [blame] | 1509 | except: |
| 1510 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1511 | main.log.error( traceback.print_exc() ) |
| 1512 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1513 | main.cleanup() |
| 1514 | main.exit() |
SeanCorcoran | 29b7054 | 2014-05-14 14:53:42 -0700 | [diff] [blame] | 1515 | |
| 1516 | def check_exceptions(self): |
| 1517 | ''' |
| 1518 | Greps the logs for "xception" |
| 1519 | ''' |
| 1520 | try: |
| 1521 | output = '' |
| 1522 | self.handle.sendline("") |
Jon Hall | a78cf9a | 2014-05-16 10:49:30 -0700 | [diff] [blame] | 1523 | i = self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT]) |
Jon Hall | 2c4f554 | 2014-08-05 13:45:29 -0700 | [diff] [blame] | 1524 | main.log.warn("first expect response: " +str(i)) |
SeanCorcoran | 29b7054 | 2014-05-14 14:53:42 -0700 | [diff] [blame] | 1525 | self.handle.sendline("cd "+self.home+"/onos-logs") |
Jon Hall | 2c4f554 | 2014-08-05 13:45:29 -0700 | [diff] [blame] | 1526 | i = self.handle.expect(["onos-logs\$",pexpect.EOF,pexpect.TIMEOUT]) |
| 1527 | main.log.warn("second expect response: " +str(i)) |
| 1528 | |
| 1529 | self.handle.sendline("zgrep \"xception\" *.log *.log.gz *.stderr") |
| 1530 | #i = self.handle.expect(["\*.stdout",pexpect.EOF,pexpect.TIMEOUT]) |
Jon Hall | a78cf9a | 2014-05-16 10:49:30 -0700 | [diff] [blame] | 1531 | #main.log.warn("third expect response: " +str(i)) |
Jon Hall | 2c4f554 | 2014-08-05 13:45:29 -0700 | [diff] [blame] | 1532 | print self.handle.before |
| 1533 | print |
| 1534 | print self.handle.after |
| 1535 | i = self.handle.expect(["ONOS/onos-logs\$",pexpect.EOF,pexpect.TIMEOUT],timeout=120) |
| 1536 | main.log.warn("fourth expect response: " +str(i)) |
SeanCorcoran | 29b7054 | 2014-05-14 14:53:42 -0700 | [diff] [blame] | 1537 | response = self.handle.before |
admin | 6903e46 | 2014-07-22 15:30:54 -0700 | [diff] [blame] | 1538 | print response |
Jon Hall | a78cf9a | 2014-05-16 10:49:30 -0700 | [diff] [blame] | 1539 | count = 0 |
Jon Hall | bb650fe | 2014-07-14 14:54:48 -0700 | [diff] [blame] | 1540 | print response |
SeanCorcoran | 29b7054 | 2014-05-14 14:53:42 -0700 | [diff] [blame] | 1541 | for line in response.splitlines(): |
Jon Hall | bb650fe | 2014-07-14 14:54:48 -0700 | [diff] [blame] | 1542 | if re.search("gzip: \*\.log\.gz:", line): |
Jon Hall | 2c4f554 | 2014-08-05 13:45:29 -0700 | [diff] [blame] | 1543 | #gzip complaining about file not found |
Jon Hall | bb650fe | 2014-07-14 14:54:48 -0700 | [diff] [blame] | 1544 | pass |
Jon Hall | 724a2f4 | 2014-06-23 16:04:22 -0700 | [diff] [blame] | 1545 | elif re.search("log\.gz:",line): |
| 1546 | output+="Exceptions found in " + line + "\n" |
| 1547 | count +=1 |
Jon Hall | 2c4f554 | 2014-08-05 13:45:29 -0700 | [diff] [blame] | 1548 | elif re.search("log:", line): |
| 1549 | output +="Exceptions found in " + line + "\n" |
| 1550 | count +=1 |
SeanCorcoran | 29b7054 | 2014-05-14 14:53:42 -0700 | [diff] [blame] | 1551 | elif re.search("std...:",line): |
| 1552 | output+="Exceptions found in " + line + "\n" |
Jon Hall | a78cf9a | 2014-05-16 10:49:30 -0700 | [diff] [blame] | 1553 | count +=1 |
SeanCorcoran | 29b7054 | 2014-05-14 14:53:42 -0700 | [diff] [blame] | 1554 | else: |
| 1555 | pass |
| 1556 | #these should be the old logs |
admin | 1723f1c | 2014-05-19 16:08:39 -0700 | [diff] [blame] | 1557 | main.log.report(str(count) + " Exceptions were found on "+self.name) |
SeanCorcoran | 29b7054 | 2014-05-14 14:53:42 -0700 | [diff] [blame] | 1558 | return output |
| 1559 | except pexpect.TIMEOUT: |
| 1560 | main.log.error(self.name + ": Timeout exception found in check_exceptions function") |
| 1561 | except pexpect.EOF: |
| 1562 | main.log.error(self.name + ": EOF exception found") |
| 1563 | main.log.error(self.name + ": " + self.handle.before) |
| 1564 | main.cleanup() |
| 1565 | main.exit() |
| 1566 | except: |
| 1567 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1568 | main.log.error( traceback.print_exc() ) |
| 1569 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1570 | main.cleanup() |
| 1571 | main.exit() |
Ahmed El-Hassany | 41e70fd | 2014-07-02 14:59:36 -0700 | [diff] [blame] | 1572 | |
Ahmed El-Hassany | ab175ff | 2014-08-20 11:50:38 -0700 | [diff] [blame^] | 1573 | |
Ahmed El-Hassany | 41e70fd | 2014-07-02 14:59:36 -0700 | [diff] [blame] | 1574 | def block_peer(self, ip_address): |
| 1575 | ''' |
| 1576 | Block traffic to the destination IP address. |
| 1577 | ''' |
| 1578 | try: |
| 1579 | for chain in ['INPUT', 'OUTPUT']: |
| 1580 | check_block_cmd = "sudo iptables -L %s -n | grep \"DROP.*%s\"" % (chain, ip_address) |
| 1581 | add_block_cmd = "sudo iptables -I %s 1 -s %s -j DROP" % (chain, ip_address) |
| 1582 | response1 = self.execute(cmd=check_block_cmd,prompt="\$",timeout=10) |
| 1583 | if ip_address in response1: |
| 1584 | main.log.error("Already blocked: %s" % response1) |
| 1585 | return main.TRUE |
| 1586 | response2 = self.execute(cmd=add_block_cmd,prompt="\$",timeout=10) |
| 1587 | main.log.info("add_block_cmd: %s" % response2) |
| 1588 | return main.TRUE |
| 1589 | except pexpect.EOF: |
| 1590 | main.log.error(self.name + ": EOF exception found") |
| 1591 | main.log.error(self.name + ": " + self.handle.before) |
| 1592 | main.cleanup() |
| 1593 | main.exit() |
| 1594 | except: |
| 1595 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1596 | main.log.error( traceback.print_exc() ) |
| 1597 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1598 | main.cleanup() |
| 1599 | main.exit() |
| 1600 | |
| 1601 | def unblock_peer(self, ip_address): |
| 1602 | ''' |
| 1603 | Unblock traffic to the destination IP address. |
| 1604 | ''' |
| 1605 | try: |
| 1606 | for chain in ['INPUT', 'OUTPUT']: |
| 1607 | # To make sure all rules are deleted in case there were multiple |
| 1608 | # installed in the iptables |
| 1609 | max_iterations = 10 |
| 1610 | for i in range(max_iterations): |
| 1611 | check_block_cmd = "sudo iptables -L %s -n | grep \"DROP.*%s\"" % (chain, ip_address) |
| 1612 | remove_block_cmd = "sudo iptables -D %s -s %s -j DROP" % (chain, ip_address) |
| 1613 | response1 = self.execute(cmd=check_block_cmd,prompt="\$",timeout=10) |
| 1614 | if ip_address not in response1: |
| 1615 | main.log.warn("Already unblocked: %s" % response1) |
| 1616 | return main.TRUE |
| 1617 | response2 = self.execute(cmd=remove_block_cmd,prompt="\$",timeout=10) |
| 1618 | main.log.info("remove_block_cmd: %s" % response2) |
| 1619 | return main.TRUE |
| 1620 | except pexpect.EOF: |
| 1621 | main.log.error(self.name + ": EOF exception found") |
| 1622 | main.log.error(self.name + ": " + self.handle.before) |
| 1623 | main.cleanup() |
| 1624 | main.exit() |
| 1625 | except: |
| 1626 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1627 | main.log.error( traceback.print_exc() ) |
| 1628 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1629 | main.cleanup() |
| 1630 | main.exit() |
Ahmed El-Hassany | ab175ff | 2014-08-20 11:50:38 -0700 | [diff] [blame^] | 1631 | |
| 1632 | |
| 1633 | def unblock_all(self): |
| 1634 | ''' |
| 1635 | Remove all controller block rules |
| 1636 | ''' |
| 1637 | try: |
| 1638 | unblock_cmd = "sudo iptables --flush" |
| 1639 | response = self.execute(cmd=unblock_cmd,prompt="\$", timeout=10) |
| 1640 | return main.TRUE |
| 1641 | except pexpect.EOF: |
| 1642 | main.log.error(self.name + ": EOF exception found") |
| 1643 | main.log.error(self.name + ": " + self.handle.before) |
| 1644 | main.cleanup() |
| 1645 | main.exit() |
| 1646 | except: |
| 1647 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1648 | main.log.error( traceback.print_exc() ) |
| 1649 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 1650 | main.cleanup() |
| 1651 | main.exit() |
| 1652 | return main.ERROR |