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