Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 1 | #!/usr/bin/env python |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 2 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3 | """ |
Jeremy Ronquillo | ec916a4 | 2018-02-02 13:05:57 -0800 | [diff] [blame] | 4 | Copyright 2014 Open Networking Foundation (ONF) |
| 5 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 6 | This driver interacts with ONOS bench, the OSGi platform |
| 7 | that configures the ONOS nodes. ( aka ONOS-next ) |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 8 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 9 | Please follow the coding style demonstrated by existing |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 10 | functions and document properly. |
| 11 | |
| 12 | If you are a contributor to the driver, please |
| 13 | list your email here for future contact: |
| 14 | |
| 15 | jhall@onlab.us |
| 16 | andrew@onlab.us |
| 17 | |
| 18 | OCT 9 2014 |
Jeremy Songster | ae01bba | 2016-07-11 15:39:17 -0700 | [diff] [blame] | 19 | Modified 2016 by ON.Lab |
| 20 | |
| 21 | Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 22 | the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 23 | or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg> |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 24 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 25 | """ |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 26 | import time |
Jon Hall | 6801cda | 2015-07-15 14:13:45 -0700 | [diff] [blame] | 27 | import types |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 28 | import pexpect |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 29 | import os |
Jon Hall | 6c44c0b | 2016-04-20 15:21:00 -0700 | [diff] [blame] | 30 | import re |
| 31 | import subprocess |
pingping-lin | 6d23d9e | 2015-02-02 16:54:24 -0800 | [diff] [blame] | 32 | from requests.models import Response |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 33 | from drivers.common.clidriver import CLI |
| 34 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 35 | class OnosDriver( CLI ): |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 36 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 37 | def __init__( self ): |
| 38 | """ |
| 39 | Initialize client |
| 40 | """ |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 41 | self.name = None |
| 42 | self.home = None |
| 43 | self.handle = None |
Jon Hall | 6c44c0b | 2016-04-20 15:21:00 -0700 | [diff] [blame] | 44 | self.nicAddr = None |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 45 | super( OnosDriver, self ).__init__() |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 46 | |
| 47 | def connect( self, **connectargs ): |
| 48 | """ |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 49 | Creates ssh handle for ONOS "bench". |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 50 | NOTE: |
| 51 | The ip_address would come from the topo file using the host tag, the |
| 52 | value can be an environment variable as well as a "localhost" to get |
| 53 | the ip address needed to ssh to the "bench" |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 54 | """ |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 55 | try: |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 56 | |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 57 | for key in connectargs: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 58 | vars( self )[ key ] = connectargs[ key ] |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 59 | self.home = "~/onos" |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 60 | for key in self.options: |
| 61 | if key == "home": |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 62 | self.home = self.options[ 'home' ] |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 63 | break |
Jon Hall | 274b664 | 2015-02-17 11:57:17 -0800 | [diff] [blame] | 64 | if self.home is None or self.home == "": |
Jon Hall | e94919c | 2015-03-23 11:42:57 -0700 | [diff] [blame] | 65 | self.home = "~/onos" |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 66 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 67 | self.name = self.options[ 'name' ] |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 68 | |
kelvin-onlab | c2b7910 | 2015-07-14 11:41:20 -0700 | [diff] [blame] | 69 | # The 'nodes' tag is optional and it is not required in .topo file |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 70 | for key in self.options: |
| 71 | if key == "nodes": |
kelvin-onlab | c2b7910 | 2015-07-14 11:41:20 -0700 | [diff] [blame] | 72 | # Maximum number of ONOS nodes to run, if there is any |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 73 | self.maxNodes = int( self.options[ 'nodes' ] ) |
| 74 | break |
| 75 | self.maxNodes = None |
| 76 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 77 | if self.maxNodes is None or self.maxNodes == "": |
kelvin-onlab | c2b7910 | 2015-07-14 11:41:20 -0700 | [diff] [blame] | 78 | self.maxNodes = 100 |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 79 | |
kelvin-onlab | c2b7910 | 2015-07-14 11:41:20 -0700 | [diff] [blame] | 80 | # Grabs all OC environment variables based on max number of nodes |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 81 | self.onosIps = {} # Dictionary of all possible ONOS ip |
| 82 | |
| 83 | try: |
| 84 | if self.maxNodes: |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 85 | for i in range( self.maxNodes ): |
| 86 | envString = "OC" + str( i + 1 ) |
kelvin-onlab | c2b7910 | 2015-07-14 11:41:20 -0700 | [diff] [blame] | 87 | # If there is no more OC# then break the loop |
| 88 | if os.getenv( envString ): |
| 89 | self.onosIps[ envString ] = os.getenv( envString ) |
| 90 | else: |
| 91 | self.maxNodes = len( self.onosIps ) |
| 92 | main.log.info( self.name + |
| 93 | ": Created cluster data with " + |
| 94 | str( self.maxNodes ) + |
| 95 | " maximum number" + |
| 96 | " of nodes" ) |
| 97 | break |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 98 | |
| 99 | if not self.onosIps: |
| 100 | main.log.info( "Could not read any environment variable" |
| 101 | + " please load a cell file with all" + |
| 102 | " onos IP" ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 103 | self.maxNodes = None |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 104 | else: |
| 105 | main.log.info( self.name + ": Found " + |
| 106 | str( self.onosIps.values() ) + |
| 107 | " ONOS IPs" ) |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 108 | except KeyError: |
| 109 | main.log.info( "Invalid environment variable" ) |
| 110 | except Exception as inst: |
| 111 | main.log.error( "Uncaught exception: " + str( inst ) ) |
| 112 | |
| 113 | try: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 114 | if os.getenv( str( self.ip_address ) ) is not None: |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 115 | self.ip_address = os.getenv( str( self.ip_address ) ) |
| 116 | else: |
| 117 | main.log.info( self.name + |
| 118 | ": Trying to connect to " + |
| 119 | self.ip_address ) |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 120 | except KeyError: |
| 121 | main.log.info( "Invalid host name," + |
| 122 | " connecting to local host instead" ) |
| 123 | self.ip_address = 'localhost' |
| 124 | except Exception as inst: |
| 125 | main.log.error( "Uncaught exception: " + str( inst ) ) |
| 126 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 127 | self.handle = super( OnosDriver, self ).connect( |
| 128 | user_name=self.user_name, |
kelvin-onlab | 08679eb | 2015-01-21 16:11:48 -0800 | [diff] [blame] | 129 | ip_address=self.ip_address, |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 130 | port=self.port, |
| 131 | pwd=self.pwd, |
| 132 | home=self.home ) |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 133 | |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 134 | if self.handle: |
Jon Hall | 0fc0d45 | 2015-07-14 09:49:58 -0700 | [diff] [blame] | 135 | self.handle.sendline( "cd " + self.home ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 136 | self.handle.expect( self.prompt ) |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 137 | return self.handle |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 138 | else: |
Jon Hall | 0fc0d45 | 2015-07-14 09:49:58 -0700 | [diff] [blame] | 139 | main.log.info( "Failed to create ONOS handle" ) |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 140 | return main.FALSE |
| 141 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 142 | main.log.error( self.name + ": EOF exception found" ) |
| 143 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 144 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 145 | except Exception: |
| 146 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 147 | main.cleanAndExit() |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 148 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 149 | def disconnect( self ): |
| 150 | """ |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 151 | Called when Test is complete to disconnect the ONOS handle. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 152 | """ |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 153 | response = main.TRUE |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 154 | try: |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 155 | if self.handle: |
| 156 | self.handle.sendline( "" ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 157 | self.handle.expect( self.prompt ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 158 | self.handle.sendline( "exit" ) |
| 159 | self.handle.expect( "closed" ) |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 160 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 161 | main.log.error( self.name + ": EOF exception found" ) |
| 162 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 163 | except ValueError: |
Jon Hall | 1a77a1e | 2015-04-06 10:41:13 -0700 | [diff] [blame] | 164 | main.log.exception( "Exception in disconnect of " + self.name ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 165 | response = main.TRUE |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 166 | except Exception: |
| 167 | main.log.exception( self.name + ": Connection failed to the host" ) |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 168 | response = main.FALSE |
| 169 | return response |
andrew@onlab.us | 9e2cd0f | 2014-10-08 20:32:32 -0400 | [diff] [blame] | 170 | |
andrew@onlab.us | aee415a | 2015-06-05 14:38:58 -0400 | [diff] [blame] | 171 | def getEpochMs( self ): |
| 172 | """ |
| 173 | Returns milliseconds since epoch |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 174 | |
| 175 | When checking multiple nodes in a for loop, |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 176 | around a hundred milliseconds of difference (ascending) is |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 177 | generally acceptable due to calltime of the function. |
| 178 | Few seconds, however, is not and it means clocks |
| 179 | are off sync. |
andrew@onlab.us | aee415a | 2015-06-05 14:38:58 -0400 | [diff] [blame] | 180 | """ |
| 181 | try: |
| 182 | self.handle.sendline( 'date +%s.%N' ) |
| 183 | self.handle.expect( 'date \+\%s\.\%N' ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 184 | self.handle.expect( self.prompt ) |
andrew@onlab.us | aee415a | 2015-06-05 14:38:58 -0400 | [diff] [blame] | 185 | epochMs = self.handle.before |
| 186 | return epochMs |
| 187 | except Exception: |
| 188 | main.log.exception( 'Uncaught exception getting epoch time' ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 189 | main.cleanAndExit() |
andrew@onlab.us | aee415a | 2015-06-05 14:38:58 -0400 | [diff] [blame] | 190 | |
Jon Hall | 6c44c0b | 2016-04-20 15:21:00 -0700 | [diff] [blame] | 191 | def onosPackage( self, opTimeout=180 ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 192 | """ |
andrew@onlab.us | 9e2cd0f | 2014-10-08 20:32:32 -0400 | [diff] [blame] | 193 | Produce a self-contained tar.gz file that can be deployed |
Jon Hall | 64af850 | 2015-12-15 10:09:33 -0800 | [diff] [blame] | 194 | and executed on any platform with Java 8 JRE. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 195 | """ |
andrew@onlab.us | 9e2cd0f | 2014-10-08 20:32:32 -0400 | [diff] [blame] | 196 | try: |
Jon Hall | 64af850 | 2015-12-15 10:09:33 -0800 | [diff] [blame] | 197 | ret = main.TRUE |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 198 | self.handle.sendline( "onos-package" ) |
| 199 | self.handle.expect( "onos-package" ) |
Jon Hall | 9645109 | 2016-05-04 09:42:30 -0700 | [diff] [blame] | 200 | while True: |
| 201 | i = self.handle.expect( [ "Downloading", |
| 202 | "Unknown options", |
| 203 | "No such file or directory", |
| 204 | "tar.gz", |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 205 | self.prompt ], |
Jon Hall | 9645109 | 2016-05-04 09:42:30 -0700 | [diff] [blame] | 206 | opTimeout ) |
| 207 | handle = str( self.handle.before + self.handle.after ) |
| 208 | if i == 0: |
| 209 | # Give more time to download the file |
| 210 | continue # expect again |
| 211 | elif i == 1: |
| 212 | # Incorrect usage |
| 213 | main.log.error( "onos-package does not recognize the given options" ) |
| 214 | ret = main.FALSE |
| 215 | continue # expect again |
| 216 | elif i == 2: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 217 | # File(s) not found |
Jon Hall | 9645109 | 2016-05-04 09:42:30 -0700 | [diff] [blame] | 218 | main.log.error( "onos-package could not find a file or directory" ) |
| 219 | ret = main.FALSE |
| 220 | continue # expect again |
| 221 | elif i == 3: |
| 222 | # tar.gz |
| 223 | continue # expect again |
| 224 | elif i == 4: |
| 225 | # Prompt returned |
| 226 | break |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 227 | main.log.info( "onos-package command returned: " + handle ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 228 | # As long as the sendline does not time out, |
| 229 | # return true. However, be careful to interpret |
| 230 | # the results of the onos-package command return |
Jon Hall | 64af850 | 2015-12-15 10:09:33 -0800 | [diff] [blame] | 231 | return ret |
| 232 | except pexpect.TIMEOUT: |
| 233 | main.log.exception( self.name + ": TIMEOUT exception found in onosPackage" ) |
| 234 | main.log.error( self.name + ": " + self.handle.before ) |
| 235 | return main.FALSE |
andrewonlab | 7735d85 | 2014-10-09 13:02:47 -0400 | [diff] [blame] | 236 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 237 | main.log.error( self.name + ": EOF exception found" ) |
| 238 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 239 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 240 | except Exception: |
| 241 | main.log.exception( "Failed to package ONOS" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 242 | main.cleanAndExit() |
andrew@onlab.us | 9e2cd0f | 2014-10-08 20:32:32 -0400 | [diff] [blame] | 243 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 244 | def onosBuild( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 245 | """ |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 246 | Use the pre defined script to build onos via mvn |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 247 | """ |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 248 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 249 | self.handle.sendline( "onos-build" ) |
| 250 | self.handle.expect( "onos-build" ) |
| 251 | i = self.handle.expect( [ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 252 | "BUILD SUCCESS", |
| 253 | "ERROR", |
| 254 | "BUILD FAILED" ], |
| 255 | timeout=120 ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 256 | handle = str( self.handle.before ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 257 | self.handle.expect( self.prompt ) |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 258 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 259 | main.log.info( "onos-build command returned: " + |
| 260 | handle ) |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 261 | |
| 262 | if i == 0: |
| 263 | return main.TRUE |
| 264 | else: |
| 265 | return handle |
| 266 | |
| 267 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 268 | main.log.error( self.name + ": EOF exception found" ) |
| 269 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 270 | except Exception: |
| 271 | main.log.exception( "Failed to build ONOS" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 272 | main.cleanAndExit() |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 273 | |
shahshreya | 9f531fe | 2015-06-10 12:03:51 -0700 | [diff] [blame] | 274 | def cleanInstall( self, skipTest=False, mciTimeout=600 ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 275 | """ |
| 276 | Runs mvn clean install in the root of the ONOS directory. |
| 277 | This will clean all ONOS artifacts then compile each module |
shahshreya | 9f531fe | 2015-06-10 12:03:51 -0700 | [diff] [blame] | 278 | Optional: |
| 279 | skipTest - Does "-DskipTests -Dcheckstyle.skip -U -T 1C" which |
| 280 | skip the test. This will make the building faster. |
| 281 | Disregarding the credibility of the build |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 282 | Returns: main.TRUE on success |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 283 | On Failure, exits the test |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 284 | """ |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 285 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 286 | main.log.info( "Running 'mvn clean install' on " + |
| 287 | str( self.name ) + |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 288 | ". This may take some time." ) |
| 289 | self.handle.sendline( "cd " + self.home ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 290 | self.handle.expect( self.prompt ) |
Jon Hall | ea7818b | 2014-10-09 14:30:59 -0400 | [diff] [blame] | 291 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 292 | self.handle.sendline( "" ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 293 | self.handle.expect( self.prompt ) |
shahshreya | 9f531fe | 2015-06-10 12:03:51 -0700 | [diff] [blame] | 294 | |
| 295 | if not skipTest: |
| 296 | self.handle.sendline( "mvn clean install" ) |
| 297 | self.handle.expect( "mvn clean install" ) |
| 298 | else: |
| 299 | self.handle.sendline( "mvn clean install -DskipTests" + |
| 300 | " -Dcheckstyle.skip -U -T 1C" ) |
| 301 | self.handle.expect( "mvn clean install -DskipTests" + |
| 302 | " -Dcheckstyle.skip -U -T 1C" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 303 | while True: |
| 304 | i = self.handle.expect( [ |
Jon Hall | 274b664 | 2015-02-17 11:57:17 -0800 | [diff] [blame] | 305 | 'There\sis\sinsufficient\smemory\sfor\sthe\sJava\s' + |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 306 | 'Runtime\sEnvironment\sto\scontinue', |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 307 | 'BUILD\sFAILURE', |
| 308 | 'BUILD\sSUCCESS', |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 309 | 'onos' + self.prompt, # TODO: fix this to be more generic? |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 310 | 'ONOS' + self.prompt, |
pingping-lin | 57a56ce | 2015-05-20 16:43:48 -0700 | [diff] [blame] | 311 | pexpect.TIMEOUT ], mciTimeout ) |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 312 | if i == 0: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 313 | main.log.error( self.name + ":There is insufficient memory \ |
| 314 | for the Java Runtime Environment to continue." ) |
| 315 | # return main.FALSE |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 316 | |
| 317 | main.cleanAndExit() |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 318 | if i == 1: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 319 | main.log.error( self.name + ": Build failure!" ) |
| 320 | # return main.FALSE |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 321 | |
| 322 | main.cleanAndExit() |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 323 | elif i == 2: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 324 | main.log.info( self.name + ": Build success!" ) |
Jon Hall | e94919c | 2015-03-23 11:42:57 -0700 | [diff] [blame] | 325 | elif i == 3 or i == 4: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 326 | main.log.info( self.name + ": Build complete" ) |
| 327 | # Print the build time |
Jon Hall | f8ef52c | 2014-10-09 19:37:33 -0400 | [diff] [blame] | 328 | for line in self.handle.before.splitlines(): |
| 329 | if "Total time:" in line: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 330 | main.log.info( line ) |
| 331 | self.handle.sendline( "" ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 332 | self.handle.expect( self.prompt, timeout=60 ) |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 333 | return main.TRUE |
Jon Hall | e94919c | 2015-03-23 11:42:57 -0700 | [diff] [blame] | 334 | elif i == 5: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 335 | main.log.error( |
| 336 | self.name + |
| 337 | ": mvn clean install TIMEOUT!" ) |
| 338 | # return main.FALSE |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 339 | |
| 340 | main.cleanAndExit() |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 341 | else: |
Jon Hall | 274b664 | 2015-02-17 11:57:17 -0800 | [diff] [blame] | 342 | main.log.error( self.name + ": unexpected response from " + |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 343 | "mvn clean install" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 344 | # return main.FALSE |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 345 | |
| 346 | main.cleanAndExit() |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 347 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 348 | main.log.error( self.name + ": EOF exception found" ) |
| 349 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 350 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 351 | except Exception: |
| 352 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 353 | main.cleanAndExit() |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 354 | |
Jon Hall | 3576f57 | 2016-08-23 10:01:07 -0700 | [diff] [blame] | 355 | def buckBuild( self, timeout=180 ): |
| 356 | """ |
| 357 | Build onos using buck. |
| 358 | """ |
| 359 | try: |
| 360 | ret = main.TRUE |
| 361 | self.handle.sendline( "buck build onos" ) |
| 362 | self.handle.expect( "buck build onos" ) |
| 363 | output = "" |
| 364 | while True: |
| 365 | i = self.handle.expect( [ "This does not appear to be the root of a Buck project.", |
| 366 | "\n", |
| 367 | "BUILD FAILED", |
Jon Hall | d906613 | 2018-03-01 14:52:53 -0800 | [diff] [blame] | 368 | "no buck in", |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 369 | self.prompt ], |
Jon Hall | 3576f57 | 2016-08-23 10:01:07 -0700 | [diff] [blame] | 370 | timeout=timeout ) |
| 371 | output += str( self.handle.before + self.handle.after ) |
| 372 | if i == 0: |
| 373 | main.log.error( "Wrong location" ) |
| 374 | ret = main.FALSE |
| 375 | elif i == 1: |
| 376 | # end of a line, buck is still printing output |
| 377 | pass |
| 378 | elif i == 2: |
| 379 | # Build failed |
| 380 | main.log.error( "Build failed" ) |
| 381 | ret = main.FALSE |
| 382 | elif i == 3: |
Jon Hall | d906613 | 2018-03-01 14:52:53 -0800 | [diff] [blame] | 383 | main.log.error( "Could not find buck in your PATH." ) |
| 384 | ret = main.FALSE |
| 385 | elif i == 4: |
Jon Hall | 3576f57 | 2016-08-23 10:01:07 -0700 | [diff] [blame] | 386 | # Prompt returned |
| 387 | break |
| 388 | main.log.debug( output ) |
| 389 | return ret |
| 390 | except pexpect.TIMEOUT: |
| 391 | main.log.exception( self.name + ": TIMEOUT exception found" ) |
| 392 | main.log.error( self.name + ": " + self.handle.before ) |
| 393 | return main.FALSE |
| 394 | except pexpect.EOF: |
| 395 | main.log.error( self.name + ": EOF exception found" ) |
| 396 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 397 | main.cleanAndExit() |
Jon Hall | 3576f57 | 2016-08-23 10:01:07 -0700 | [diff] [blame] | 398 | except Exception: |
| 399 | main.log.exception( "Failed to build and package ONOS" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 400 | main.cleanAndExit() |
Jon Hall | 3576f57 | 2016-08-23 10:01:07 -0700 | [diff] [blame] | 401 | |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 402 | def gitPull( self, comp1="", fastForward=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 403 | """ |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 404 | Assumes that "git pull" works without login |
Jon Hall | 47a93fb | 2015-01-06 16:46:06 -0800 | [diff] [blame] | 405 | |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 406 | If the fastForward boolean is set to true, only git pulls that can |
| 407 | be fast forwarded will be performed. IE if you have not local commits |
| 408 | in your branch. |
| 409 | |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 410 | This function will perform a git pull on the ONOS instance. |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 411 | If used as gitPull( "NODE" ) it will do git pull + NODE. This is |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 412 | for the purpose of pulling from other nodes if necessary. |
| 413 | |
Jon Hall | 47a93fb | 2015-01-06 16:46:06 -0800 | [diff] [blame] | 414 | Otherwise, this function will perform a git pull in the |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 415 | ONOS repository. If it has any problems, it will return main.ERROR |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 416 | If it successfully does a gitPull, it will return a 1 ( main.TRUE ) |
Shreya Shah | ee15f6c | 2014-10-28 18:12:30 -0400 | [diff] [blame] | 417 | If it has no updates, it will return 3. |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 418 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 419 | """ |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 420 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 421 | self.handle.sendline( "cd " + self.home ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 422 | self.handle.expect( self.prompt ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 423 | cmd = "git pull" |
| 424 | if comp1 != "": |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 425 | cmd += ' ' + comp1 |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 426 | if fastForward: |
| 427 | cmd += ' ' + " --ff-only" |
| 428 | self.handle.sendline( cmd ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 429 | i = self.handle.expect( |
| 430 | [ |
| 431 | 'fatal', |
| 432 | 'Username\sfor\s(.*):\s', |
| 433 | '\sfile(s*) changed,\s', |
| 434 | 'Already up-to-date', |
| 435 | 'Aborting', |
| 436 | 'You\sare\snot\scurrently\son\sa\sbranch', |
Jon Hall | 274b664 | 2015-02-17 11:57:17 -0800 | [diff] [blame] | 437 | 'You asked me to pull without telling me which branch you', |
| 438 | 'Pull is not possible because you have unmerged files', |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 439 | 'Please enter a commit message to explain why this merge', |
| 440 | 'Found a swap file by the name', |
| 441 | 'Please, commit your changes before you can merge.', |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 442 | pexpect.TIMEOUT ], |
| 443 | timeout=300 ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 444 | if i == 0: |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 445 | main.log.error( self.name + ": Git pull had some issue" ) |
| 446 | output = self.handle.after |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 447 | self.handle.expect( self.prompt ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 448 | output += self.handle.before |
| 449 | main.log.warn( output ) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 450 | return main.ERROR |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 451 | elif i == 1: |
| 452 | main.log.error( |
| 453 | self.name + |
| 454 | ": Git Pull Asking for username. " ) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 455 | return main.ERROR |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 456 | elif i == 2: |
| 457 | main.log.info( |
| 458 | self.name + |
| 459 | ": Git Pull - pulling repository now" ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 460 | self.handle.expect( self.prompt, 120 ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 461 | # So that only when git pull is done, we do mvn clean compile |
| 462 | return main.TRUE |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 463 | elif i == 3: |
| 464 | main.log.info( self.name + ": Git Pull - Already up to date" ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 465 | return main.TRUE |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 466 | elif i == 4: |
| 467 | main.log.info( |
| 468 | self.name + |
Jon Hall | 274b664 | 2015-02-17 11:57:17 -0800 | [diff] [blame] | 469 | ": Git Pull - Aborting..." + |
| 470 | "Are there conflicting git files?" ) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 471 | return main.ERROR |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 472 | elif i == 5: |
| 473 | main.log.info( |
| 474 | self.name + |
Jon Hall | 274b664 | 2015-02-17 11:57:17 -0800 | [diff] [blame] | 475 | ": Git Pull - You are not currently " + |
| 476 | "on a branch so git pull failed!" ) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 477 | return main.ERROR |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 478 | elif i == 6: |
| 479 | main.log.info( |
| 480 | self.name + |
Jon Hall | 274b664 | 2015-02-17 11:57:17 -0800 | [diff] [blame] | 481 | ": Git Pull - You have not configured an upstream " + |
| 482 | "branch to pull from. Git pull failed!" ) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 483 | return main.ERROR |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 484 | elif i == 7: |
| 485 | main.log.info( |
| 486 | self.name + |
Jon Hall | 274b664 | 2015-02-17 11:57:17 -0800 | [diff] [blame] | 487 | ": Git Pull - Pull is not possible because " + |
| 488 | "you have unmerged files." ) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 489 | return main.ERROR |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 490 | elif i == 8: |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 491 | # NOTE: abandoning test since we can't reliably handle this |
| 492 | # there could be different default text editors and we |
| 493 | # also don't know if we actually want to make the commit |
| 494 | main.log.error( "Git pull resulted in a merge commit message" + |
| 495 | ". Exiting test!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 496 | |
| 497 | main.cleanAndExit() |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 498 | elif i == 9: # Merge commit message but swap file exists |
| 499 | main.log.error( "Git pull resulted in a merge commit message" + |
| 500 | " but a swap file exists." ) |
| 501 | try: |
| 502 | self.handle.send( 'A' ) # Abort |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 503 | self.handle.expect( self.prompt ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 504 | return main.ERROR |
| 505 | except Exception: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 506 | main.log.exception( "Couldn't exit editor prompt!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 507 | |
| 508 | main.cleanAndExit() |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 509 | elif i == 10: # In the middle of a merge commit |
| 510 | main.log.error( "Git branch is in the middle of a merge. " ) |
| 511 | main.log.warn( self.handle.before + self.handle.after ) |
| 512 | return main.ERROR |
| 513 | elif i == 11: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 514 | main.log.error( self.name + ": Git Pull - TIMEOUT" ) |
| 515 | main.log.error( |
| 516 | self.name + " Response was: " + str( |
| 517 | self.handle.before ) ) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 518 | return main.ERROR |
| 519 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 520 | main.log.error( |
| 521 | self.name + |
| 522 | ": Git Pull - Unexpected response, check for pull errors" ) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 523 | return main.ERROR |
| 524 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 525 | main.log.error( self.name + ": EOF exception found" ) |
| 526 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 527 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 528 | except Exception: |
| 529 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 530 | main.cleanAndExit() |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 531 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 532 | def gitCheckout( self, branch="master" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 533 | """ |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 534 | Assumes that "git pull" works without login |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 535 | |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 536 | This function will perform a git git checkout on the ONOS instance. |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 537 | If used as gitCheckout( "branch" ) it will do git checkout |
| 538 | of the "branch". |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 539 | |
| 540 | Otherwise, this function will perform a git checkout of the master |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 541 | branch of the ONOS repository. If it has any problems, it will return |
| 542 | main.ERROR. |
| 543 | If the branch was already the specified branch, or the git checkout was |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 544 | successful then the function will return main.TRUE. |
| 545 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 546 | """ |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 547 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 548 | self.handle.sendline( "cd " + self.home ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 549 | self.handle.expect( self.prompt ) |
Jon Hall | 274b664 | 2015-02-17 11:57:17 -0800 | [diff] [blame] | 550 | main.log.info( self.name + |
| 551 | ": Checking out git branch/ref: " + branch + "..." ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 552 | cmd = "git checkout " + branch |
| 553 | self.handle.sendline( cmd ) |
| 554 | self.handle.expect( cmd ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 555 | i = self.handle.expect( |
Jon Hall | 274b664 | 2015-02-17 11:57:17 -0800 | [diff] [blame] | 556 | [ 'fatal', |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 557 | 'Username for (.*): ', |
| 558 | 'Already on \'', |
Jon Hall | 7a8354f | 2015-06-10 15:37:00 -0700 | [diff] [blame] | 559 | 'Switched to (a new )?branch \'' + str( branch ), |
Jon Hall | 274b664 | 2015-02-17 11:57:17 -0800 | [diff] [blame] | 560 | pexpect.TIMEOUT, |
| 561 | 'error: Your local changes to the following files' + |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 562 | 'would be overwritten by checkout:', |
Jon Hall | 274b664 | 2015-02-17 11:57:17 -0800 | [diff] [blame] | 563 | 'error: you need to resolve your current index first', |
| 564 | "You are in 'detached HEAD' state.", |
| 565 | "HEAD is now at " ], |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 566 | timeout=60 ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 567 | if i == 0: |
| 568 | main.log.error( |
| 569 | self.name + |
| 570 | ": Git checkout had some issue..." ) |
| 571 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 572 | return main.ERROR |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 573 | elif i == 1: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 574 | main.log.error( |
| 575 | self.name + |
| 576 | ": Git checkout asking for username." + |
| 577 | " Please configure your local git repository to be able " + |
| 578 | "to access your remote repository passwordlessly" ) |
Jon Hall | 274b664 | 2015-02-17 11:57:17 -0800 | [diff] [blame] | 579 | # TODO add support for authenticating |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 580 | return main.ERROR |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 581 | elif i == 2: |
| 582 | main.log.info( |
| 583 | self.name + |
Jon Hall | 274b664 | 2015-02-17 11:57:17 -0800 | [diff] [blame] | 584 | ": Git Checkout %s : Already on this branch" % branch ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 585 | self.handle.expect( self.prompt ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 586 | # main.log.info( "DEBUG: after checkout cmd = "+ |
| 587 | # self.handle.before ) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 588 | return main.TRUE |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 589 | elif i == 3: |
| 590 | main.log.info( |
| 591 | self.name + |
Jon Hall | 274b664 | 2015-02-17 11:57:17 -0800 | [diff] [blame] | 592 | ": Git checkout %s - Switched to this branch" % branch ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 593 | self.handle.expect( self.prompt ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 594 | # main.log.info( "DEBUG: after checkout cmd = "+ |
| 595 | # self.handle.before ) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 596 | return main.TRUE |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 597 | elif i == 4: |
| 598 | main.log.error( self.name + ": Git Checkout- TIMEOUT" ) |
| 599 | main.log.error( |
Jon Hall | 274b664 | 2015-02-17 11:57:17 -0800 | [diff] [blame] | 600 | self.name + " Response was: " + str( self.handle.before ) ) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 601 | return main.ERROR |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 602 | elif i == 5: |
| 603 | self.handle.expect( "Aborting" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 604 | main.log.error( |
| 605 | self.name + |
| 606 | ": Git checkout error: \n" + |
Jon Hall | 274b664 | 2015-02-17 11:57:17 -0800 | [diff] [blame] | 607 | "Your local changes to the following files would" + |
| 608 | " be overwritten by checkout:" + |
| 609 | str( self.handle.before ) ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 610 | self.handle.expect( self.prompt ) |
Jon Hall | 81e29af | 2014-11-04 20:41:23 -0500 | [diff] [blame] | 611 | return main.ERROR |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 612 | elif i == 6: |
Jon Hall | 274b664 | 2015-02-17 11:57:17 -0800 | [diff] [blame] | 613 | main.log.error( |
| 614 | self.name + |
| 615 | ": Git checkout error: \n" + |
| 616 | "You need to resolve your current index first:" + |
| 617 | str( self.handle.before ) ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 618 | self.handle.expect( self.prompt ) |
Jon Hall | 81e29af | 2014-11-04 20:41:23 -0500 | [diff] [blame] | 619 | return main.ERROR |
Jon Hall | 274b664 | 2015-02-17 11:57:17 -0800 | [diff] [blame] | 620 | elif i == 7: |
| 621 | main.log.info( |
| 622 | self.name + |
| 623 | ": Git checkout " + str( branch ) + |
| 624 | " - You are in 'detached HEAD' state. HEAD is now at " + |
| 625 | str( branch ) ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 626 | self.handle.expect( self.prompt ) |
Jon Hall | 274b664 | 2015-02-17 11:57:17 -0800 | [diff] [blame] | 627 | return main.TRUE |
| 628 | elif i == 8: # Already in detached HEAD on the specified commit |
| 629 | main.log.info( |
| 630 | self.name + |
| 631 | ": Git Checkout %s : Already on commit" % branch ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 632 | self.handle.expect( self.prompt ) |
Jon Hall | 274b664 | 2015-02-17 11:57:17 -0800 | [diff] [blame] | 633 | return main.TRUE |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 634 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 635 | main.log.error( |
| 636 | self.name + |
Jon Hall | 274b664 | 2015-02-17 11:57:17 -0800 | [diff] [blame] | 637 | ": Git Checkout - Unexpected response, " + |
| 638 | "check for pull errors" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 639 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 640 | return main.ERROR |
| 641 | |
| 642 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 643 | main.log.error( self.name + ": EOF exception found" ) |
| 644 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 645 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 646 | except Exception: |
| 647 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 648 | main.cleanAndExit() |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 649 | |
pingping-lin | 6d23d9e | 2015-02-02 16:54:24 -0800 | [diff] [blame] | 650 | def getBranchName( self ): |
You Wang | 9cdf9a2 | 2017-05-01 13:44:18 -0700 | [diff] [blame] | 651 | import re |
| 652 | try: |
| 653 | main.log.info( "self.home = " ) |
| 654 | main.log.info( self.home ) |
| 655 | self.handle.sendline( "cd " + self.home ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 656 | self.handle.expect( self.prompt ) |
You Wang | 9cdf9a2 | 2017-05-01 13:44:18 -0700 | [diff] [blame] | 657 | self.handle.sendline( "git name-rev --name-only HEAD" ) |
| 658 | self.handle.expect( "git name-rev --name-only HEAD" ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 659 | self.handle.expect( self.prompt ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 660 | lines = self.handle.before.splitlines() |
| 661 | if lines[ 1 ] == "master" or re.search( "^onos-\d+(\.\d+)+$", lines[ 1 ] ): |
| 662 | return lines[ 1 ] |
You Wang | 9cdf9a2 | 2017-05-01 13:44:18 -0700 | [diff] [blame] | 663 | else: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 664 | main.log.info( lines[ 1 ] ) |
You Wang | 9cdf9a2 | 2017-05-01 13:44:18 -0700 | [diff] [blame] | 665 | return "unexpected ONOS branch" |
| 666 | except pexpect.EOF: |
| 667 | main.log.error( self.name + ": EOF exception found" ) |
| 668 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 669 | main.cleanAndExit() |
You Wang | 9cdf9a2 | 2017-05-01 13:44:18 -0700 | [diff] [blame] | 670 | except pexpect.TIMEOUT: |
| 671 | main.log.error( self.name + ": TIMEOUT exception found" ) |
| 672 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 673 | main.cleanAndExit() |
You Wang | 9cdf9a2 | 2017-05-01 13:44:18 -0700 | [diff] [blame] | 674 | except Exception: |
| 675 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 676 | main.cleanAndExit() |
pingping-lin | 6d23d9e | 2015-02-02 16:54:24 -0800 | [diff] [blame] | 677 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 678 | def getVersion( self, report=False ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 679 | """ |
Jon Hall | 274b664 | 2015-02-17 11:57:17 -0800 | [diff] [blame] | 680 | Writes the COMMIT number to the report to be parsed |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 681 | by Jenkins data collector. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 682 | """ |
Jon Hall | 45ec092 | 2014-10-10 19:33:49 -0400 | [diff] [blame] | 683 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 684 | self.handle.sendline( "" ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 685 | self.handle.expect( self.prompt ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 686 | self.handle.sendline( |
| 687 | "cd " + |
| 688 | self.home + |
Jon Hall | 274b664 | 2015-02-17 11:57:17 -0800 | [diff] [blame] | 689 | "; git log -1 --pretty=fuller --decorate=short | grep -A 6 " + |
| 690 | " \"commit\" --color=never" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 691 | # NOTE: for some reason there are backspaces inserted in this |
| 692 | # phrase when run from Jenkins on some tests |
| 693 | self.handle.expect( "never" ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 694 | self.handle.expect( self.prompt ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 695 | response = ( self.name + ": \n" + str( |
| 696 | self.handle.before + self.handle.after ) ) |
| 697 | self.handle.sendline( "cd " + self.home ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 698 | self.handle.expect( self.prompt ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 699 | lines = response.splitlines() |
Jon Hall | 45ec092 | 2014-10-10 19:33:49 -0400 | [diff] [blame] | 700 | for line in lines: |
Jon Hall | fd19120 | 2014-11-07 18:36:09 -0500 | [diff] [blame] | 701 | print line |
| 702 | if report: |
pingping-lin | 763ee04 | 2015-05-20 17:45:30 -0700 | [diff] [blame] | 703 | main.log.wiki( "<blockquote>" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 704 | for line in lines[ 2:-1 ]: |
| 705 | # Bracket replacement is for Wiki-compliant |
| 706 | # formatting. '<' or '>' are interpreted |
| 707 | # as xml specific tags that cause errors |
| 708 | line = line.replace( "<", "[" ) |
| 709 | line = line.replace( ">", "]" ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 710 | # main.log.wiki( "\t" + line ) |
pingping-lin | 763ee04 | 2015-05-20 17:45:30 -0700 | [diff] [blame] | 711 | main.log.wiki( line + "<br /> " ) |
| 712 | main.log.summary( line ) |
| 713 | main.log.wiki( "</blockquote>" ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 714 | main.log.summary( "\n" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 715 | return lines[ 2 ] |
Jon Hall | 45ec092 | 2014-10-10 19:33:49 -0400 | [diff] [blame] | 716 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 717 | main.log.error( self.name + ": EOF exception found" ) |
| 718 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 719 | main.cleanAndExit() |
Jon Hall | 368769f | 2014-11-19 15:43:35 -0800 | [diff] [blame] | 720 | except pexpect.TIMEOUT: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 721 | main.log.error( self.name + ": TIMEOUT exception found" ) |
| 722 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 723 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 724 | except Exception: |
| 725 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 726 | main.cleanAndExit() |
Jon Hall | 45ec092 | 2014-10-10 19:33:49 -0400 | [diff] [blame] | 727 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 728 | def createCellFile( self, benchIp, fileName, mnIpAddrs, |
Jon Hall | 810b67d | 2016-12-05 10:19:01 -0800 | [diff] [blame] | 729 | appString, onosIpAddrs, onosUser="sdn", useSSH=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 730 | """ |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 731 | Creates a cell file based on arguments |
| 732 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 733 | * Bench IP address ( benchIp ) |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 734 | - Needed to copy the cell file over |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 735 | * File name of the cell file ( fileName ) |
| 736 | * Mininet IP address ( mnIpAddrs ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 737 | - Note that only 1 ip address is |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 738 | supported currently |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 739 | * ONOS IP addresses ( onosIpAddrs ) |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 740 | - Must be passed in as last arguments |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 741 | * ONOS USER (onosUser) |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 742 | - optional argument to set ONOS_USER environment variable |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 743 | |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 744 | NOTE: Assumes cells are located at: |
| 745 | ~/<self.home>/tools/test/cells/ |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 746 | """ |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 747 | try: |
Devin Lim | 461f087 | 2017-06-05 16:49:33 -0700 | [diff] [blame] | 748 | |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 749 | # Variable initialization |
| 750 | cellDirectory = self.home + "/tools/test/cells/" |
| 751 | # We want to create the cell file in the dependencies directory |
| 752 | # of TestON first, then copy over to ONOS bench |
| 753 | tempDirectory = "/tmp/" |
| 754 | # Create the cell file in the directory for writing ( w+ ) |
| 755 | cellFile = open( tempDirectory + fileName, 'w+' ) |
| 756 | if isinstance( onosIpAddrs, types.StringType ): |
| 757 | onosIpAddrs = [ onosIpAddrs ] |
| 758 | |
| 759 | # App string is hardcoded environment variables |
| 760 | # That you may wish to use by default on startup. |
| 761 | # Note that you may not want certain apps listed |
| 762 | # on here. |
| 763 | appString = "export ONOS_APPS=" + appString |
| 764 | onosGroup = "export ONOS_GROUP=" + onosUser |
| 765 | onosUser = "export ONOS_USER=" + onosUser |
| 766 | if useSSH: |
| 767 | onosUseSSH = "export ONOS_USE_SSH=true" |
| 768 | mnString = "export OCN=" |
| 769 | if mnIpAddrs == "": |
| 770 | mnString = "" |
| 771 | onosString = "export OC" |
| 772 | tempCount = 1 |
| 773 | |
| 774 | # Create ONOSNIC ip address prefix |
| 775 | tempOnosIp = str( onosIpAddrs[ 0 ] ) |
| 776 | tempList = [] |
| 777 | tempList = tempOnosIp.split( "." ) |
| 778 | # Omit last element of list to format for NIC |
| 779 | tempList = tempList[ :-1 ] |
| 780 | # Structure the nic string ip |
| 781 | nicAddr = ".".join( tempList ) + ".*" |
| 782 | self.nicAddr = nicAddr |
| 783 | onosNicString = "export ONOS_NIC=" + nicAddr |
| 784 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 785 | # Start writing to file |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 786 | cellFile.write( onosNicString + "\n" ) |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 787 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 788 | for arg in onosIpAddrs: |
| 789 | # For each argument in onosIpAddrs, write to file |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 790 | # Output should look like the following: |
andrewonlab | d494049 | 2014-10-24 12:21:27 -0400 | [diff] [blame] | 791 | # export OC1="10.128.20.11" |
| 792 | # export OC2="10.128.20.12" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 793 | cellFile.write( onosString + str( tempCount ) + |
Jon Hall | 6f66565 | 2015-09-18 10:08:07 -0700 | [diff] [blame] | 794 | "=\"" + arg + "\"\n" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 795 | tempCount = tempCount + 1 |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 796 | |
Jon Hall | 6f66565 | 2015-09-18 10:08:07 -0700 | [diff] [blame] | 797 | cellFile.write( "export OCI=$OC1\n" ) |
Jon Hall | ab61137 | 2018-02-21 15:26:05 -0800 | [diff] [blame] | 798 | if mnString: |
| 799 | cellFile.write( mnString + "\"" + str( mnIpAddrs ) + "\"\n" ) |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 800 | cellFile.write( appString + "\n" ) |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 801 | cellFile.write( onosGroup + "\n" ) |
| 802 | cellFile.write( onosUser + "\n" ) |
Pier | 88189b6 | 2016-09-07 17:01:53 -0700 | [diff] [blame] | 803 | if useSSH: |
| 804 | cellFile.write( onosUseSSH + "\n" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 805 | cellFile.close() |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 806 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 807 | # We use os.system to send the command to TestON cluster |
| 808 | # to account for the case in which TestON is not located |
| 809 | # on the same cluster as the ONOS bench |
| 810 | # Note that even if TestON is located on the same cluster |
| 811 | # as ONOS bench, you must setup passwordless ssh |
| 812 | # between TestON and ONOS bench in order to automate the test. |
kelvin-onlab | c2b7910 | 2015-07-14 11:41:20 -0700 | [diff] [blame] | 813 | os.system( "scp " + tempDirectory + fileName + " " + |
| 814 | self.user_name + "@" + self.ip_address + ":" + cellDirectory ) |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 815 | |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 816 | return main.TRUE |
| 817 | |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 818 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 819 | main.log.error( self.name + ": EOF exception found" ) |
| 820 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 821 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 822 | except Exception: |
| 823 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 824 | main.cleanAndExit() |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 825 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 826 | def setCell( self, cellname ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 827 | """ |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 828 | Calls 'cell <name>' to set the environment variables on ONOSbench |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 829 | """ |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 830 | try: |
| 831 | if not cellname: |
You Wang | 1cdc5f5 | 2017-12-19 16:47:51 -0800 | [diff] [blame] | 832 | main.log.error( self.name + ": Must define cellname" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 833 | main.cleanAndExit() |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 834 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 835 | self.handle.sendline( "cell " + str( cellname ) ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 836 | # Expect the cellname in the ONOSCELL variable. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 837 | # Note that this variable name is subject to change |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 838 | # and that this driver will have to change accordingly |
Jon Hall | 3b489db | 2015-10-05 14:38:37 -0700 | [diff] [blame] | 839 | self.handle.expect( str( cellname ) ) |
Jon Hall | ab61137 | 2018-02-21 15:26:05 -0800 | [diff] [blame] | 840 | response = self.handle.before + self.handle.after |
You Wang | 1cdc5f5 | 2017-12-19 16:47:51 -0800 | [diff] [blame] | 841 | i = self.handle.expect( [ "No such cell", |
Jon Hall | ab61137 | 2018-02-21 15:26:05 -0800 | [diff] [blame] | 842 | "command not found", |
| 843 | self.prompt ], timeout=10 ) |
| 844 | response += self.handle.before + self.handle.after |
You Wang | 1cdc5f5 | 2017-12-19 16:47:51 -0800 | [diff] [blame] | 845 | if i == 0: |
Jon Hall | ab61137 | 2018-02-21 15:26:05 -0800 | [diff] [blame] | 846 | main.log.error( self.name + ": No such cell. Response: " + str( response ) ) |
You Wang | 1cdc5f5 | 2017-12-19 16:47:51 -0800 | [diff] [blame] | 847 | main.cleanAndExit() |
| 848 | elif i == 1: |
Jon Hall | ab61137 | 2018-02-21 15:26:05 -0800 | [diff] [blame] | 849 | main.log.error( self.name + ": Error setting cell. Response: " + str( response ) ) |
| 850 | main.cleanAndExit() |
You Wang | 1cdc5f5 | 2017-12-19 16:47:51 -0800 | [diff] [blame] | 851 | elif i == 2: |
Jon Hall | ab61137 | 2018-02-21 15:26:05 -0800 | [diff] [blame] | 852 | main.log.info( self.name + ": Successfully set cell: " + str( response ) ) |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 853 | return main.TRUE |
You Wang | 1cdc5f5 | 2017-12-19 16:47:51 -0800 | [diff] [blame] | 854 | except pexpect.TIMEOUT: |
| 855 | main.log.error( self.name + ": TIMEOUT exception found" ) |
| 856 | main.log.error( self.name + ": " + self.handle.before ) |
| 857 | main.cleanAndExit() |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 858 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 859 | main.log.error( self.name + ": EOF exception found" ) |
| 860 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 861 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 862 | except Exception: |
| 863 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 864 | main.cleanAndExit() |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 865 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 866 | def verifyCell( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 867 | """ |
andrewonlab | c03bf6c | 2014-10-09 14:56:18 -0400 | [diff] [blame] | 868 | Calls 'onos-verify-cell' to check for cell installation |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 869 | """ |
| 870 | # TODO: Add meaningful expect value |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 871 | |
andrewonlab | c03bf6c | 2014-10-09 14:56:18 -0400 | [diff] [blame] | 872 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 873 | # Clean handle by sending empty and expecting $ |
| 874 | self.handle.sendline( "" ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 875 | self.handle.expect( self.prompt ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 876 | self.handle.sendline( "onos-verify-cell" ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 877 | self.handle.expect( self.prompt ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 878 | handleBefore = self.handle.before |
| 879 | handleAfter = self.handle.after |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 880 | main.log.info( "Verify cell returned: " + handleBefore + |
Jon Hall | 3b489db | 2015-10-05 14:38:37 -0700 | [diff] [blame] | 881 | handleAfter ) |
andrewonlab | c03bf6c | 2014-10-09 14:56:18 -0400 | [diff] [blame] | 882 | return main.TRUE |
Jon Hall | a5cb617 | 2015-02-23 09:28:28 -0800 | [diff] [blame] | 883 | except pexpect.ExceptionPexpect as e: |
Jon Hall | 3b489db | 2015-10-05 14:38:37 -0700 | [diff] [blame] | 884 | main.log.exception( self.name + ": Pexpect exception found: " ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 885 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 886 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 887 | except Exception: |
| 888 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 889 | main.cleanAndExit() |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 890 | |
jenkins | 1e99e7b | 2015-04-02 18:15:39 -0700 | [diff] [blame] | 891 | def onosCfgSet( self, ONOSIp, configName, configParam ): |
| 892 | """ |
| 893 | Uses 'onos <node-ip> cfg set' to change a parameter value of an |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 894 | application. |
| 895 | |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 896 | ex) |
jenkins | 1e99e7b | 2015-04-02 18:15:39 -0700 | [diff] [blame] | 897 | onos 10.0.0.1 cfg set org.onosproject.myapp appSetting 1 |
jenkins | 1e99e7b | 2015-04-02 18:15:39 -0700 | [diff] [blame] | 898 | ONOSIp = '10.0.0.1' |
| 899 | configName = 'org.onosproject.myapp' |
| 900 | configParam = 'appSetting 1' |
jenkins | 1e99e7b | 2015-04-02 18:15:39 -0700 | [diff] [blame] | 901 | """ |
Jon Hall | 72280bc | 2016-01-25 14:29:05 -0800 | [diff] [blame] | 902 | try: |
| 903 | cfgStr = "onos {} cfg set {} {}".format( ONOSIp, |
| 904 | configName, |
| 905 | configParam ) |
| 906 | self.handle.sendline( "" ) |
| 907 | self.handle.expect( ":~" ) |
| 908 | self.handle.sendline( cfgStr ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 909 | self.handle.expect( "cfg set" ) |
Jon Hall | 72280bc | 2016-01-25 14:29:05 -0800 | [diff] [blame] | 910 | self.handle.expect( ":~" ) |
jenkins | 1e99e7b | 2015-04-02 18:15:39 -0700 | [diff] [blame] | 911 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 912 | paramValue = configParam.split( " " )[ 1 ] |
| 913 | paramName = configParam.split( " " )[ 0 ] |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 914 | |
Jon Hall | 72280bc | 2016-01-25 14:29:05 -0800 | [diff] [blame] | 915 | checkStr = 'onos {} cfg get " {} {} " '.format( ONOSIp, configName, paramName ) |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 916 | |
Jon Hall | 72280bc | 2016-01-25 14:29:05 -0800 | [diff] [blame] | 917 | self.handle.sendline( checkStr ) |
| 918 | self.handle.expect( ":~" ) |
jenkins | 1e99e7b | 2015-04-02 18:15:39 -0700 | [diff] [blame] | 919 | |
Jon Hall | 72280bc | 2016-01-25 14:29:05 -0800 | [diff] [blame] | 920 | if "value=" + paramValue + "," in self.handle.before: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 921 | main.log.info( "cfg " + configName + " successfully set to " + configParam ) |
Jon Hall | 72280bc | 2016-01-25 14:29:05 -0800 | [diff] [blame] | 922 | return main.TRUE |
| 923 | except pexpect.ExceptionPexpect as e: |
| 924 | main.log.exception( self.name + ": Pexpect exception found: " ) |
| 925 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 926 | main.cleanAndExit() |
Jon Hall | 72280bc | 2016-01-25 14:29:05 -0800 | [diff] [blame] | 927 | except Exception: |
| 928 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 929 | main.cleanAndExit() |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 930 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 931 | def onosCli( self, ONOSIp, cmdstr ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 932 | """ |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 933 | Uses 'onos' command to send various ONOS CLI arguments. |
| 934 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 935 | * ONOSIp: specify the ip of the cell machine |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 936 | * cmdstr: specify the command string to send |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 937 | |
| 938 | This function is intended to expose the entire karaf |
andrewonlab | 6e20c34 | 2014-10-10 18:08:48 -0400 | [diff] [blame] | 939 | CLI commands for ONOS. Try to use this function first |
| 940 | before attempting to write a ONOS CLI specific driver |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 941 | function. |
| 942 | You can see a list of available 'cmdstr' arguments |
andrewonlab | 6e20c34 | 2014-10-10 18:08:48 -0400 | [diff] [blame] | 943 | by starting onos, and typing in 'onos' to enter the |
| 944 | onos> CLI. Then, type 'help' to see the list of |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 945 | available commands. |
| 946 | """ |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 947 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 948 | if not ONOSIp: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 949 | main.log.error( "You must specify the IP address" ) |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 950 | return main.FALSE |
| 951 | if not cmdstr: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 952 | main.log.error( "You must specify the command string" ) |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 953 | return main.FALSE |
| 954 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 955 | cmdstr = str( cmdstr ) |
| 956 | self.handle.sendline( "" ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 957 | self.handle.expect( self.prompt ) |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 958 | |
You Wang | dd3dae5 | 2018-02-15 13:31:25 -0800 | [diff] [blame] | 959 | self.handle.sendline( "onos-wait-for-start " + ONOSIp ) |
| 960 | self.handle.expect( self.prompt ) |
| 961 | |
| 962 | self.handle.sendline( "onos " + ONOSIp + " " + cmdstr ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 963 | self.handle.expect( self.prompt ) |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 964 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 965 | handleBefore = self.handle.before |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 966 | main.log.info( "Command sent successfully" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 967 | # Obtain return handle that consists of result from |
| 968 | # the onos command. The string may need to be |
| 969 | # configured further. |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 970 | returnString = handleBefore |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 971 | return returnString |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 972 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 973 | main.log.error( self.name + ": EOF exception found" ) |
| 974 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 975 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 976 | except Exception: |
| 977 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 978 | main.cleanAndExit() |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 979 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 980 | def onosSecureSSH( self, userName="onos", userPWD="rocks", node="" ): |
Pier | 88189b6 | 2016-09-07 17:01:53 -0700 | [diff] [blame] | 981 | """ |
| 982 | Enables secure access to ONOS console |
| 983 | by removing default users & keys. |
| 984 | |
| 985 | onos-secure-ssh -u onos -p rocks node |
| 986 | |
| 987 | Returns: main.TRUE on success and main.FALSE on failure |
| 988 | """ |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 989 | |
Pier | 88189b6 | 2016-09-07 17:01:53 -0700 | [diff] [blame] | 990 | try: |
Chiyu Cheng | ef10950 | 2016-11-21 15:51:38 -0800 | [diff] [blame] | 991 | self.handle.sendline( "" ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 992 | self.handle.expect( self.prompt ) |
Pier | 88189b6 | 2016-09-07 17:01:53 -0700 | [diff] [blame] | 993 | self.handle.sendline( " onos-secure-ssh -u " + userName + " -p " + userPWD + " " + node ) |
| 994 | |
| 995 | # NOTE: this timeout may need to change depending on the network |
| 996 | # and size of ONOS |
| 997 | # TODO: Handle the other possible error |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 998 | i = self.handle.expect( [ "Network\sis\sunreachable", |
| 999 | self.prompt, |
| 1000 | pexpect.TIMEOUT ], timeout=180 ) |
Pier | 88189b6 | 2016-09-07 17:01:53 -0700 | [diff] [blame] | 1001 | if i == 0: |
| 1002 | # can't reach ONOS node |
| 1003 | main.log.warn( "Network is unreachable" ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 1004 | self.handle.expect( self.prompt ) |
Pier | 88189b6 | 2016-09-07 17:01:53 -0700 | [diff] [blame] | 1005 | return main.FALSE |
| 1006 | elif i == 1: |
| 1007 | # Process started |
| 1008 | main.log.info( |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1009 | "Secure SSH performed on " + |
| 1010 | node ) |
Pier | 88189b6 | 2016-09-07 17:01:53 -0700 | [diff] [blame] | 1011 | return main.TRUE |
| 1012 | except pexpect.EOF: |
| 1013 | main.log.error( self.name + ": EOF exception found" ) |
| 1014 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1015 | main.cleanAndExit() |
Pier | 88189b6 | 2016-09-07 17:01:53 -0700 | [diff] [blame] | 1016 | except Exception: |
| 1017 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1018 | main.cleanAndExit() |
Pier | 88189b6 | 2016-09-07 17:01:53 -0700 | [diff] [blame] | 1019 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1020 | def onosInstall( self, options="-f", node="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1021 | """ |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 1022 | Installs ONOS bits on the designated cell machine. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1023 | If -f option is provided, it also forces an uninstall. |
| 1024 | Presently, install also includes onos-push-bits and |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 1025 | onos-config within. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1026 | The node option allows you to selectively only push the jar |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 1027 | files to certain onos nodes |
| 1028 | |
| 1029 | Returns: main.TRUE on success and main.FALSE on failure |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1030 | """ |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 1031 | try: |
andrewonlab | 114768a | 2014-11-14 12:44:44 -0500 | [diff] [blame] | 1032 | if options: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1033 | self.handle.sendline( "onos-install " + options + " " + node ) |
andrewonlab | 114768a | 2014-11-14 12:44:44 -0500 | [diff] [blame] | 1034 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1035 | self.handle.sendline( "onos-install " + node ) |
| 1036 | self.handle.expect( "onos-install " ) |
| 1037 | # NOTE: this timeout may need to change depending on the network |
| 1038 | # and size of ONOS |
| 1039 | i = self.handle.expect( [ "Network\sis\sunreachable", |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1040 | "onos\sstart/running,\sprocess", |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1041 | "ONOS\sis\salready\sinstalled", |
Jeremy | c72b258 | 2016-02-26 18:27:38 -0800 | [diff] [blame] | 1042 | "already\sup-to-date", |
Jon Hall | 3576f57 | 2016-08-23 10:01:07 -0700 | [diff] [blame] | 1043 | "does not exist", |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 1044 | self.prompt, |
Jon Hall | 6c44c0b | 2016-04-20 15:21:00 -0700 | [diff] [blame] | 1045 | pexpect.TIMEOUT ], timeout=180 ) |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 1046 | if i == 0: |
Jon Hall | 3576f57 | 2016-08-23 10:01:07 -0700 | [diff] [blame] | 1047 | # can't reach ONOS node |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1048 | main.log.warn( "Network is unreachable" ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 1049 | self.handle.expect( self.prompt ) |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 1050 | return main.FALSE |
| 1051 | elif i == 1: |
Jon Hall | 3576f57 | 2016-08-23 10:01:07 -0700 | [diff] [blame] | 1052 | # Process started |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1053 | main.log.info( |
| 1054 | "ONOS was installed on " + |
| 1055 | node + |
| 1056 | " and started" ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 1057 | self.handle.expect( self.prompt ) |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 1058 | return main.TRUE |
Jon Hall | 3576f57 | 2016-08-23 10:01:07 -0700 | [diff] [blame] | 1059 | elif i == 2 or i == 3: |
| 1060 | # same bits are already on ONOS node |
Jeremy | c72b258 | 2016-02-26 18:27:38 -0800 | [diff] [blame] | 1061 | main.log.info( "ONOS is already installed on " + node ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 1062 | self.handle.expect( self.prompt ) |
Jeremy | c72b258 | 2016-02-26 18:27:38 -0800 | [diff] [blame] | 1063 | return main.TRUE |
| 1064 | elif i == 4: |
Jon Hall | 3576f57 | 2016-08-23 10:01:07 -0700 | [diff] [blame] | 1065 | # onos not packaged |
| 1066 | main.log.error( "ONOS package not found." ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 1067 | self.handle.expect( self.prompt ) |
Jon Hall | 3576f57 | 2016-08-23 10:01:07 -0700 | [diff] [blame] | 1068 | return main.FALSE |
| 1069 | elif i == 5: |
| 1070 | # prompt |
Jeremy | c72b258 | 2016-02-26 18:27:38 -0800 | [diff] [blame] | 1071 | main.log.info( "ONOS was installed on " + node ) |
| 1072 | return main.TRUE |
Jon Hall | 3576f57 | 2016-08-23 10:01:07 -0700 | [diff] [blame] | 1073 | elif i == 6: |
| 1074 | # timeout |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1075 | main.log.info( |
| 1076 | "Installation of ONOS on " + |
| 1077 | node + |
| 1078 | " timed out" ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 1079 | self.handle.expect( self.prompt ) |
Jon Hall | 53c5e66 | 2016-04-13 16:06:56 -0700 | [diff] [blame] | 1080 | main.log.warn( self.handle.before ) |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 1081 | return main.FALSE |
andrewonlab | c03bf6c | 2014-10-09 14:56:18 -0400 | [diff] [blame] | 1082 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1083 | main.log.error( self.name + ": EOF exception found" ) |
| 1084 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1085 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1086 | except Exception: |
| 1087 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1088 | main.cleanAndExit() |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 1089 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1090 | def onosStart( self, nodeIp ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1091 | """ |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 1092 | Calls onos command: 'onos-service [<node-ip>] start' |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 1093 | This command is a remote management of the ONOS upstart daemon |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1094 | """ |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 1095 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1096 | self.handle.sendline( "" ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 1097 | self.handle.expect( self.prompt ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1098 | self.handle.sendline( "onos-service " + str( nodeIp ) + |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1099 | " start" ) |
| 1100 | i = self.handle.expect( [ |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 1101 | "Job\sis\salready\srunning", |
| 1102 | "start/running", |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 1103 | self.prompt, |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 1104 | "Unknown\sinstance", |
Jeremy Songster | 14c1357 | 2016-04-21 17:34:03 -0700 | [diff] [blame] | 1105 | pexpect.TIMEOUT ], timeout=180 ) |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 1106 | if i == 0: |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 1107 | self.handle.expect( self.prompt ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1108 | main.log.info( "Service is already running" ) |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 1109 | return main.TRUE |
| 1110 | elif i == 1: |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 1111 | self.handle.expect( self.prompt ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1112 | main.log.info( "ONOS service started" ) |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 1113 | return main.TRUE |
Jeremy | d0e9a6d | 2016-03-02 11:28:52 -0800 | [diff] [blame] | 1114 | elif i == 2: |
| 1115 | main.log.info( "ONOS service started" ) |
| 1116 | return main.TRUE |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 1117 | else: |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 1118 | self.handle.expect( self.prompt ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1119 | main.log.error( "ONOS service failed to start" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1120 | |
| 1121 | main.cleanAndExit() |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 1122 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1123 | main.log.error( self.name + ": EOF exception found" ) |
| 1124 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1125 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1126 | except Exception: |
| 1127 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1128 | main.cleanAndExit() |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 1129 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1130 | def onosStop( self, nodeIp ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1131 | """ |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 1132 | Calls onos command: 'onos-service [<node-ip>] stop' |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 1133 | This command is a remote management of the ONOS upstart daemon |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1134 | """ |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 1135 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1136 | self.handle.sendline( "" ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 1137 | self.handle.expect( self.prompt ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1138 | self.handle.sendline( "onos-service " + str( nodeIp ) + |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1139 | " stop" ) |
| 1140 | i = self.handle.expect( [ |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 1141 | "stop/waiting", |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 1142 | "Could not resolve hostname", |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 1143 | "Unknown\sinstance", |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 1144 | self.prompt, |
Jeremy Songster | 14c1357 | 2016-04-21 17:34:03 -0700 | [diff] [blame] | 1145 | pexpect.TIMEOUT ], timeout=180 ) |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 1146 | if i == 0: |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 1147 | self.handle.expect( self.prompt ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1148 | main.log.info( "ONOS service stopped" ) |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 1149 | return main.TRUE |
| 1150 | elif i == 1: |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 1151 | self.handle.expect( self.prompt ) |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1152 | main.log.info( "onosStop() Unknown ONOS instance specified: " + |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1153 | str( nodeIp ) ) |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 1154 | return main.FALSE |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 1155 | elif i == 2: |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 1156 | self.handle.expect( self.prompt ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 1157 | main.log.warn( "ONOS wasn't running" ) |
| 1158 | return main.TRUE |
YPZhang | 77badfc | 2016-03-09 10:28:59 -0800 | [diff] [blame] | 1159 | elif i == 3: |
| 1160 | main.log.info( "ONOS service stopped" ) |
| 1161 | return main.TRUE |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 1162 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1163 | main.log.error( "ONOS service failed to stop" ) |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 1164 | return main.FALSE |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 1165 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1166 | main.log.error( self.name + ": EOF exception found" ) |
| 1167 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1168 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1169 | except Exception: |
| 1170 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1171 | main.cleanAndExit() |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1172 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1173 | def onosUninstall( self, nodeIp="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1174 | """ |
andrewonlab | c8d4797 | 2014-10-09 16:52:36 -0400 | [diff] [blame] | 1175 | Calls the command: 'onos-uninstall' |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1176 | Uninstalls ONOS from the designated cell machine, stopping |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 1177 | if needed |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1178 | """ |
andrewonlab | c8d4797 | 2014-10-09 16:52:36 -0400 | [diff] [blame] | 1179 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1180 | self.handle.sendline( "" ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 1181 | self.handle.expect( self.prompt, timeout=180 ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1182 | self.handle.sendline( "onos-uninstall " + str( nodeIp ) ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 1183 | self.handle.expect( self.prompt, timeout=180 ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1184 | main.log.info( "ONOS " + nodeIp + " was uninstalled" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1185 | # onos-uninstall command does not return any text |
andrewonlab | c8d4797 | 2014-10-09 16:52:36 -0400 | [diff] [blame] | 1186 | return main.TRUE |
pingping-lin | 763ee04 | 2015-05-20 17:45:30 -0700 | [diff] [blame] | 1187 | except pexpect.TIMEOUT: |
| 1188 | main.log.exception( self.name + ": Timeout in onosUninstall" ) |
| 1189 | return main.FALSE |
andrewonlab | c8d4797 | 2014-10-09 16:52:36 -0400 | [diff] [blame] | 1190 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1191 | main.log.error( self.name + ": EOF exception found" ) |
| 1192 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1193 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1194 | except Exception: |
| 1195 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1196 | main.cleanAndExit() |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 1197 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1198 | def onosDie( self, nodeIp ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1199 | """ |
andrewonlab | aedc833 | 2014-12-04 12:43:03 -0500 | [diff] [blame] | 1200 | Issues the command 'onos-die <node-ip>' |
| 1201 | This command calls onos-kill and also stops the node |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1202 | """ |
andrewonlab | aedc833 | 2014-12-04 12:43:03 -0500 | [diff] [blame] | 1203 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1204 | self.handle.sendline( "" ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 1205 | self.handle.expect( self.prompt ) |
Jeremy | f0aecdb | 2016-03-30 13:19:57 -0700 | [diff] [blame] | 1206 | cmdStr = "onos-die " + str( nodeIp ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1207 | self.handle.sendline( cmdStr ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1208 | i = self.handle.expect( [ |
andrewonlab | aedc833 | 2014-12-04 12:43:03 -0500 | [diff] [blame] | 1209 | "Killing\sONOS", |
| 1210 | "ONOS\sprocess\sis\snot\srunning", |
Jeremy Songster | 14c1357 | 2016-04-21 17:34:03 -0700 | [diff] [blame] | 1211 | pexpect.TIMEOUT ], timeout=60 ) |
andrewonlab | aedc833 | 2014-12-04 12:43:03 -0500 | [diff] [blame] | 1212 | if i == 0: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1213 | main.log.info( "ONOS instance " + str( nodeIp ) + |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1214 | " was killed and stopped" ) |
Jon Hall | 53c5e66 | 2016-04-13 16:06:56 -0700 | [diff] [blame] | 1215 | self.handle.sendline( "" ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 1216 | self.handle.expect( self.prompt ) |
andrewonlab | aedc833 | 2014-12-04 12:43:03 -0500 | [diff] [blame] | 1217 | return main.TRUE |
| 1218 | elif i == 1: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1219 | main.log.info( "ONOS process was not running" ) |
Jon Hall | 53c5e66 | 2016-04-13 16:06:56 -0700 | [diff] [blame] | 1220 | self.handle.sendline( "" ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 1221 | self.handle.expect( self.prompt ) |
andrewonlab | aedc833 | 2014-12-04 12:43:03 -0500 | [diff] [blame] | 1222 | return main.FALSE |
| 1223 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1224 | main.log.error( self.name + ": EOF exception found" ) |
| 1225 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1226 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1227 | except Exception: |
| 1228 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1229 | main.cleanAndExit() |
andrewonlab | aedc833 | 2014-12-04 12:43:03 -0500 | [diff] [blame] | 1230 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1231 | def onosKill( self, nodeIp ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1232 | """ |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 1233 | Calls the command: 'onos-kill [<node-ip>]' |
| 1234 | "Remotely, and unceremoniously kills the ONOS instance running on |
| 1235 | the specified cell machine" - Tom V |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1236 | """ |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 1237 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1238 | self.handle.sendline( "" ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 1239 | self.handle.expect( self.prompt ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1240 | self.handle.sendline( "onos-kill " + str( nodeIp ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1241 | i = self.handle.expect( [ |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 1242 | self.prompt, |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 1243 | "No\sroute\sto\shost", |
| 1244 | "password:", |
Jeremy Songster | 14c1357 | 2016-04-21 17:34:03 -0700 | [diff] [blame] | 1245 | pexpect.TIMEOUT ], timeout=60 ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1246 | |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 1247 | if i == 0: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1248 | main.log.info( |
| 1249 | "ONOS instance " + str( |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1250 | nodeIp ) + " was killed" ) |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 1251 | return main.TRUE |
| 1252 | elif i == 1: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1253 | main.log.info( "No route to host" ) |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 1254 | return main.FALSE |
| 1255 | elif i == 2: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1256 | main.log.info( |
| 1257 | "Passwordless login for host: " + |
| 1258 | str( nodeIp ) + |
| 1259 | " not configured" ) |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 1260 | return main.FALSE |
| 1261 | else: |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1262 | main.log.info( "ONOS instance was not killed" ) |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 1263 | return main.FALSE |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1264 | |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 1265 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1266 | main.log.error( self.name + ": EOF exception found" ) |
| 1267 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1268 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1269 | except Exception: |
| 1270 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1271 | main.cleanAndExit() |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 1272 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1273 | def onosRemoveRaftLogs( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1274 | """ |
andrewonlab | 19fbdca | 2014-11-14 12:55:59 -0500 | [diff] [blame] | 1275 | Removes Raft / Copy cat files from ONOS to ensure |
Jon Hall | fcc8862 | 2014-11-25 13:09:54 -0500 | [diff] [blame] | 1276 | a cleaner environment. |
| 1277 | |
andrewonlab | 19fbdca | 2014-11-14 12:55:59 -0500 | [diff] [blame] | 1278 | Description: |
Jon Hall | fcc8862 | 2014-11-25 13:09:54 -0500 | [diff] [blame] | 1279 | Stops all ONOS defined in the cell, |
andrewonlab | 19fbdca | 2014-11-14 12:55:59 -0500 | [diff] [blame] | 1280 | wipes the raft / copycat log files |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1281 | """ |
andrewonlab | 19fbdca | 2014-11-14 12:55:59 -0500 | [diff] [blame] | 1282 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1283 | self.handle.sendline( "" ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 1284 | self.handle.expect( self.prompt ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1285 | self.handle.sendline( "onos-remove-raft-logs" ) |
| 1286 | # Sometimes this command hangs |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 1287 | i = self.handle.expect( [ self.prompt, pexpect.TIMEOUT ], |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1288 | timeout=120 ) |
Jon Hall | fcc8862 | 2014-11-25 13:09:54 -0500 | [diff] [blame] | 1289 | if i == 1: |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 1290 | i = self.handle.expect( [ self.prompt, pexpect.TIMEOUT ], |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1291 | timeout=120 ) |
Jon Hall | fcc8862 | 2014-11-25 13:09:54 -0500 | [diff] [blame] | 1292 | if i == 1: |
| 1293 | return main.FALSE |
andrewonlab | 19fbdca | 2014-11-14 12:55:59 -0500 | [diff] [blame] | 1294 | return main.TRUE |
andrewonlab | 19fbdca | 2014-11-14 12:55:59 -0500 | [diff] [blame] | 1295 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1296 | main.log.error( self.name + ": EOF exception found" ) |
| 1297 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1298 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1299 | except Exception: |
| 1300 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1301 | main.cleanAndExit() |
Jon Hall | fcc8862 | 2014-11-25 13:09:54 -0500 | [diff] [blame] | 1302 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1303 | def onosStartNetwork( self, mntopo ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1304 | """ |
| 1305 | Calls the command 'onos-start-network [ <mininet-topo> ] |
| 1306 | "remotely starts the specified topology on the cell's |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 1307 | mininet machine against all controllers configured in the |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1308 | cell." |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 1309 | * Specify mininet topology file name for mntopo |
| 1310 | * Topo files should be placed at: |
| 1311 | ~/<your-onos-directory>/tools/test/topos |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1312 | |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 1313 | NOTE: This function will take you to the mininet prompt |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1314 | """ |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 1315 | try: |
| 1316 | if not mntopo: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1317 | main.log.error( "You must specify a topo file to execute" ) |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 1318 | return main.FALSE |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 1319 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1320 | mntopo = str( mntopo ) |
| 1321 | self.handle.sendline( "" ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 1322 | self.handle.expect( self.prompt ) |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 1323 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1324 | self.handle.sendline( "onos-start-network " + mntopo ) |
| 1325 | self.handle.expect( "mininet>" ) |
| 1326 | main.log.info( "Network started, entered mininet prompt" ) |
| 1327 | |
| 1328 | # TODO: Think about whether return is necessary or not |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 1329 | |
| 1330 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1331 | main.log.error( self.name + ": EOF exception found" ) |
| 1332 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1333 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1334 | except Exception: |
| 1335 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1336 | main.cleanAndExit() |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 1337 | |
Jeremy Songster | 14c1357 | 2016-04-21 17:34:03 -0700 | [diff] [blame] | 1338 | def isup( self, node="", timeout=240 ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1339 | """ |
| 1340 | Run's onos-wait-for-start which only returns once ONOS is at run |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 1341 | level 100(ready for use) |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 1342 | |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 1343 | Returns: main.TRUE if ONOS is running and main.FALSE on timeout |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1344 | """ |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 1345 | try: |
Jon Hall | 3b489db | 2015-10-05 14:38:37 -0700 | [diff] [blame] | 1346 | self.handle.sendline( "onos-wait-for-start " + node ) |
| 1347 | self.handle.expect( "onos-wait-for-start" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1348 | # NOTE: this timeout is arbitrary" |
Jon Hall | cababf7 | 2018-02-05 12:05:19 -0800 | [diff] [blame] | 1349 | i = self.handle.expect( [ self.prompt, pexpect.TIMEOUT, "Password:" ], timeout ) |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 1350 | if i == 0: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1351 | main.log.info( self.name + ": " + node + " is up" ) |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 1352 | return main.TRUE |
Jon Hall | cababf7 | 2018-02-05 12:05:19 -0800 | [diff] [blame] | 1353 | elif i == 1 or i == 2: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1354 | # NOTE: since this function won't return until ONOS is ready, |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 1355 | # we will kill it on timeout |
Jon Hall | cababf7 | 2018-02-05 12:05:19 -0800 | [diff] [blame] | 1356 | if i == 1: |
| 1357 | main.log.error( "ONOS has not started yet" ) |
| 1358 | elif i == 2: |
| 1359 | main.log.error( "Cannot login to ONOS CLI, try using onos-secure-ssh" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1360 | self.handle.send( "\x03" ) # Control-C |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 1361 | self.handle.expect( self.prompt ) |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 1362 | return main.FALSE |
| 1363 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1364 | main.log.error( self.name + ": EOF exception found" ) |
| 1365 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1366 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1367 | except Exception: |
| 1368 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1369 | main.cleanAndExit() |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 1370 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 1371 | def preventAutoRespawn( self ): |
| 1372 | """ |
| 1373 | Description: |
| 1374 | This will prevent ONOSservice to automatically |
| 1375 | respawn. |
| 1376 | """ |
| 1377 | try: |
| 1378 | self.handle.sendline( "sed -i -e 's/^respawn$/#respawn/g' tools/package/init/onos.conf" ) |
| 1379 | self.handle.expect( "\$" ) # $ from the command |
| 1380 | self.handle.sendline( "sed -i -e 's/^Restart=always/Restart=no/g' tools/package/init/onos.service" ) |
| 1381 | self.handle.expect( "\$" ) # $ from the command |
| 1382 | self.handle.expect( "\$" ) # $ from the prompt |
| 1383 | except pexpect.EOF: |
| 1384 | main.log.error( self.name + ": EOF exception found" ) |
| 1385 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1386 | main.cleanAndExit() |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 1387 | except Exception: |
| 1388 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1389 | main.cleanAndExit() |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 1390 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1391 | def pushTestIntentsShell( |
| 1392 | self, |
| 1393 | dpidSrc, |
| 1394 | dpidDst, |
| 1395 | numIntents, |
| 1396 | dirFile, |
| 1397 | onosIp, |
| 1398 | numMult="", |
| 1399 | appId="", |
| 1400 | report=True, |
| 1401 | options="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1402 | """ |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1403 | Description: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1404 | Use the linux prompt to push test intents to |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1405 | better parallelize the results than the CLI |
| 1406 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1407 | * dpidSrc: specify source dpid |
| 1408 | * dpidDst: specify destination dpid |
| 1409 | * numIntents: specify number of intents to push |
| 1410 | * dirFile: specify directory and file name to save |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1411 | results |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1412 | * onosIp: specify the IP of ONOS to install on |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1413 | NOTE: |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1414 | You must invoke this command at linux shell prompt |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1415 | """ |
| 1416 | try: |
| 1417 | # Create the string to sendline |
andrewonlab | aedc833 | 2014-12-04 12:43:03 -0500 | [diff] [blame] | 1418 | if options: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1419 | baseCmd = "onos " + str( onosIp ) + " push-test-intents " +\ |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1420 | options + " " |
andrewonlab | aedc833 | 2014-12-04 12:43:03 -0500 | [diff] [blame] | 1421 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1422 | baseCmd = "onos " + str( onosIp ) + " push-test-intents " |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1423 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1424 | addDpid = baseCmd + str( dpidSrc ) + " " + str( dpidDst ) |
| 1425 | if not numMult: |
| 1426 | addIntents = addDpid + " " + str( numIntents ) |
| 1427 | elif numMult: |
| 1428 | addIntents = addDpid + " " + str( numIntents ) + " " +\ |
| 1429 | str( numMult ) |
| 1430 | if appId: |
| 1431 | addApp = addIntents + " " + str( appId ) |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1432 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1433 | addApp = addIntents |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1434 | |
andrewonlab | aedc833 | 2014-12-04 12:43:03 -0500 | [diff] [blame] | 1435 | if report: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1436 | sendCmd = addApp + " > " + str( dirFile ) + " &" |
andrewonlab | aedc833 | 2014-12-04 12:43:03 -0500 | [diff] [blame] | 1437 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1438 | sendCmd = addApp + " &" |
| 1439 | main.log.info( "Send cmd: " + sendCmd ) |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1440 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1441 | self.handle.sendline( sendCmd ) |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1442 | |
| 1443 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1444 | main.log.error( self.name + ": EOF exception found" ) |
| 1445 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1446 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1447 | except Exception: |
| 1448 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1449 | main.cleanAndExit() |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 1450 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1451 | def tsharkPcap( self, interface, dirFile ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1452 | """ |
andrewonlab | 970399c | 2014-11-07 13:09:32 -0500 | [diff] [blame] | 1453 | Capture all packet activity and store in specified |
| 1454 | directory/file |
| 1455 | |
| 1456 | Required: |
| 1457 | * interface: interface to capture |
| 1458 | * dir: directory/filename to store pcap |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1459 | """ |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1460 | try: |
| 1461 | self.handle.sendline( "" ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 1462 | self.handle.expect( self.prompt ) |
andrewonlab | 970399c | 2014-11-07 13:09:32 -0500 | [diff] [blame] | 1463 | |
cameron@onlab.us | 21106ea | 2015-07-23 15:32:51 -0700 | [diff] [blame] | 1464 | self.handle.sendline( "tshark -i " + str( interface ) + " -t e -w " + str( dirFile ) + " &" ) |
Jon Hall | 5ec6b1b | 2015-09-17 18:20:14 -0700 | [diff] [blame] | 1465 | self.handle.sendline( "\n" ) |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1466 | self.handle.expect( "Capturing on" ) |
Jon Hall | 5ec6b1b | 2015-09-17 18:20:14 -0700 | [diff] [blame] | 1467 | self.handle.sendline( "\n" ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 1468 | self.handle.expect( self.prompt ) |
andrewonlab | 970399c | 2014-11-07 13:09:32 -0500 | [diff] [blame] | 1469 | |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1470 | main.log.info( "Tshark started capturing files on " + |
| 1471 | str( interface ) + " and saving to directory: " + |
| 1472 | str( dirFile ) ) |
| 1473 | except pexpect.EOF: |
| 1474 | main.log.error( self.name + ": EOF exception found" ) |
| 1475 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1476 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1477 | except Exception: |
| 1478 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1479 | main.cleanAndExit() |
Shreya Shah | a73aaad | 2014-10-27 18:03:09 -0400 | [diff] [blame] | 1480 | |
kelvin-onlab | d9e23de | 2015-08-06 10:34:44 -0700 | [diff] [blame] | 1481 | def onosTopoCfg( self, onosIp, jsonFile ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1482 | """ |
kelvin-onlab | d9e23de | 2015-08-06 10:34:44 -0700 | [diff] [blame] | 1483 | Description: |
| 1484 | Execute onos-topo-cfg command |
| 1485 | Required: |
| 1486 | onosIp - IP of the onos node you want to send the json to |
| 1487 | jsonFile - File path of the json file |
| 1488 | Return: |
| 1489 | Returns main.TRUE if the command is successfull; Returns |
| 1490 | main.FALSE if there was an error |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1491 | """ |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 1492 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1493 | self.handle.sendline( "" ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 1494 | self.handle.expect( self.prompt ) |
kelvin-onlab | d9e23de | 2015-08-06 10:34:44 -0700 | [diff] [blame] | 1495 | cmd = "onos-topo-cfg " |
| 1496 | self.handle.sendline( cmd + str( onosIp ) + " " + jsonFile ) |
| 1497 | handle = self.handle.before |
| 1498 | print handle |
| 1499 | if "Error" in handle: |
| 1500 | main.log.error( self.name + ": " + self.handle.before ) |
| 1501 | return main.FALSE |
| 1502 | else: |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 1503 | self.handle.expect( self.prompt ) |
kelvin-onlab | d9e23de | 2015-08-06 10:34:44 -0700 | [diff] [blame] | 1504 | return main.TRUE |
| 1505 | |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1506 | except pexpect.EOF: |
| 1507 | main.log.error( self.name + ": EOF exception found" ) |
| 1508 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1509 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1510 | except Exception: |
| 1511 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1512 | main.cleanAndExit() |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1513 | |
jenkins | 1e99e7b | 2015-04-02 18:15:39 -0700 | [diff] [blame] | 1514 | def tsharkGrep( self, grep, directory, interface='eth0', grepOptions='' ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1515 | """ |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 1516 | Required: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1517 | * grep string |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 1518 | * directory to store results |
| 1519 | Optional: |
| 1520 | * interface - default: eth0 |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 1521 | * grepOptions - options for grep |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 1522 | Description: |
| 1523 | Uses tshark command to grep specific group of packets |
| 1524 | and stores the results to specified directory. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1525 | The timestamp is hardcoded to be in epoch |
| 1526 | """ |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1527 | try: |
| 1528 | self.handle.sendline( "" ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 1529 | self.handle.expect( self.prompt ) |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1530 | self.handle.sendline( "" ) |
jenkins | 1e99e7b | 2015-04-02 18:15:39 -0700 | [diff] [blame] | 1531 | if grepOptions: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1532 | grepStr = "grep " + str( grepOptions ) |
jenkins | 1e99e7b | 2015-04-02 18:15:39 -0700 | [diff] [blame] | 1533 | else: |
| 1534 | grepStr = "grep" |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 1535 | |
cameron@onlab.us | 21106ea | 2015-07-23 15:32:51 -0700 | [diff] [blame] | 1536 | cmd = ( |
| 1537 | "sudo tshark -i " + |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1538 | str( interface ) + |
jenkins | 1e99e7b | 2015-04-02 18:15:39 -0700 | [diff] [blame] | 1539 | " -t e | " + |
| 1540 | grepStr + " --line-buffered \"" + |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1541 | str( grep ) + |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1542 | "\" >" + |
| 1543 | directory + |
| 1544 | " &" ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1545 | self.handle.sendline( cmd ) |
| 1546 | main.log.info( cmd ) |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1547 | self.handle.expect( "Capturing on" ) |
cameron@onlab.us | 21106ea | 2015-07-23 15:32:51 -0700 | [diff] [blame] | 1548 | self.handle.sendline( "\n" ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 1549 | self.handle.expect( self.prompt ) |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1550 | except pexpect.EOF: |
| 1551 | main.log.error( self.name + ": EOF exception found" ) |
| 1552 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1553 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1554 | except Exception: |
| 1555 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1556 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1557 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1558 | def tsharkStop( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1559 | """ |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 1560 | Removes wireshark files from /tmp and kills all tshark processes |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1561 | """ |
| 1562 | # Remove all pcap from previous captures |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1563 | try: |
| 1564 | self.execute( cmd="sudo rm /tmp/wireshark*" ) |
| 1565 | self.handle.sendline( "" ) |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1566 | self.handle.sendline( "sudo kill -9 `ps -ef | grep \"tshark -i\"" + |
| 1567 | " | grep -v grep | awk '{print $2}'`" ) |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1568 | self.handle.sendline( "" ) |
| 1569 | main.log.info( "Tshark stopped" ) |
| 1570 | except pexpect.EOF: |
| 1571 | main.log.error( self.name + ": EOF exception found" ) |
| 1572 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1573 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1574 | except Exception: |
| 1575 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1576 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1577 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1578 | def ptpd( self, args ): |
| 1579 | """ |
andrewonlab | 0c38a4a | 2014-10-28 18:35:35 -0400 | [diff] [blame] | 1580 | Initiate ptp with user-specified args. |
| 1581 | Required: |
| 1582 | * args: specify string of args after command |
| 1583 | 'sudo ptpd' |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1584 | """ |
andrewonlab | 0c38a4a | 2014-10-28 18:35:35 -0400 | [diff] [blame] | 1585 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1586 | self.handle.sendline( "sudo ptpd " + str( args ) ) |
| 1587 | i = self.handle.expect( [ |
andrewonlab | 0c38a4a | 2014-10-28 18:35:35 -0400 | [diff] [blame] | 1588 | "Multiple", |
| 1589 | "Error", |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 1590 | self.prompt ] ) |
| 1591 | self.handle.expect( self.prompt ) |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 1592 | |
andrewonlab | 0c38a4a | 2014-10-28 18:35:35 -0400 | [diff] [blame] | 1593 | if i == 0: |
| 1594 | handle = self.handle.before |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1595 | main.log.info( "ptpd returned an error: " + |
| 1596 | str( handle ) ) |
andrewonlab | 0c38a4a | 2014-10-28 18:35:35 -0400 | [diff] [blame] | 1597 | return handle |
| 1598 | elif i == 1: |
| 1599 | handle = self.handle.before |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1600 | main.log.error( "ptpd returned an error: " + |
| 1601 | str( handle ) ) |
andrewonlab | 0c38a4a | 2014-10-28 18:35:35 -0400 | [diff] [blame] | 1602 | return handle |
| 1603 | else: |
| 1604 | return main.TRUE |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1605 | |
andrewonlab | 0c38a4a | 2014-10-28 18:35:35 -0400 | [diff] [blame] | 1606 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1607 | main.log.error( self.name + ": EOF exception found" ) |
| 1608 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1609 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1610 | except Exception: |
| 1611 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1612 | main.cleanAndExit() |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 1613 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1614 | def dumpONOSCmd( self, ONOSIp, CMD, destDir, filename, options="" ): |
Flavio Castro | d2ffffa | 2016-04-26 15:56:56 -0700 | [diff] [blame] | 1615 | """ |
Pier | 50f0bc6 | 2016-09-07 17:53:40 -0700 | [diff] [blame] | 1616 | Dump Cmd to a desired directory. |
Flavio Castro | d2ffffa | 2016-04-26 15:56:56 -0700 | [diff] [blame] | 1617 | For debugging purposes, you may want to use |
Pier | 50f0bc6 | 2016-09-07 17:53:40 -0700 | [diff] [blame] | 1618 | this function to capture Cmd at a given point in time. |
Flavio Castro | d2ffffa | 2016-04-26 15:56:56 -0700 | [diff] [blame] | 1619 | Localtime will be attached to the filename |
| 1620 | |
| 1621 | Required: |
| 1622 | * ONOSIp: the IP of the target ONOS instance |
Pier | 50f0bc6 | 2016-09-07 17:53:40 -0700 | [diff] [blame] | 1623 | * CMD: the command to dump; |
Flavio Castro | d2ffffa | 2016-04-26 15:56:56 -0700 | [diff] [blame] | 1624 | * destDir: specify directory to copy to. |
| 1625 | ex ) /tmp/ |
Flavio Castro | d2ffffa | 2016-04-26 15:56:56 -0700 | [diff] [blame] | 1626 | * fileName: Name of the file |
Pier | 50f0bc6 | 2016-09-07 17:53:40 -0700 | [diff] [blame] | 1627 | * options: Options for ONOS command |
Flavio Castro | d2ffffa | 2016-04-26 15:56:56 -0700 | [diff] [blame] | 1628 | """ |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 1629 | |
Flavio Castro | d2ffffa | 2016-04-26 15:56:56 -0700 | [diff] [blame] | 1630 | localtime = time.strftime( '%x %X' ) |
| 1631 | localtime = localtime.replace( "/", "" ) |
| 1632 | localtime = localtime.replace( " ", "_" ) |
| 1633 | localtime = localtime.replace( ":", "" ) |
| 1634 | if destDir[ -1: ] != "/": |
| 1635 | destDir += "/" |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1636 | cmd = CMD + " " + options + " > " + str( destDir ) + str( filename ) + localtime |
| 1637 | return self.onosCli( ONOSIp, cmd ) |
Flavio Castro | b771895 | 2016-05-18 08:53:41 -0700 | [diff] [blame] | 1638 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1639 | def cpLogsToDir( self, logToCopy, |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1640 | destDir, copyFileName="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1641 | """ |
| 1642 | Copies logs to a desired directory. |
andrewonlab | 5d7a8f3 | 2014-11-10 13:07:56 -0500 | [diff] [blame] | 1643 | Current implementation of ONOS deletes its karaf |
| 1644 | logs on every iteration. For debugging purposes, |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1645 | you may want to use this function to capture |
| 1646 | certain karaf logs. ( or any other logs if needed ) |
andrewonlab | 5d7a8f3 | 2014-11-10 13:07:56 -0500 | [diff] [blame] | 1647 | Localtime will be attached to the filename |
| 1648 | |
| 1649 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1650 | * logToCopy: specify directory and log name to |
andrewonlab | 5d7a8f3 | 2014-11-10 13:07:56 -0500 | [diff] [blame] | 1651 | copy. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1652 | ex ) /opt/onos/log/karaf.log.1 |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1653 | For copying multiple files, leave copyFileName |
| 1654 | empty and only specify destDir - |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1655 | ex ) /opt/onos/log/karaf* |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1656 | * destDir: specify directory to copy to. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1657 | ex ) /tmp/ |
| 1658 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1659 | * copyFileName: If you want to rename the log |
| 1660 | file, specify copyFileName. This will not work |
andrewonlab | 5d7a8f3 | 2014-11-10 13:07:56 -0500 | [diff] [blame] | 1661 | with multiple file copying |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1662 | """ |
andrewonlab | 5d7a8f3 | 2014-11-10 13:07:56 -0500 | [diff] [blame] | 1663 | try: |
Flavio Castro | 09ab59d | 2016-05-25 17:01:35 -0700 | [diff] [blame] | 1664 | localtime = time.strftime( '%H %M' ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1665 | localtime = localtime.replace( "/", "" ) |
| 1666 | localtime = localtime.replace( " ", "_" ) |
| 1667 | localtime = localtime.replace( ":", "" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1668 | if destDir[ -1: ] != "/": |
| 1669 | destDir += "/" |
andrewonlab | 5d7a8f3 | 2014-11-10 13:07:56 -0500 | [diff] [blame] | 1670 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1671 | if copyFileName: |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1672 | self.handle.sendline( "cp " + str( logToCopy ) + " " + |
| 1673 | str( destDir ) + str( copyFileName ) + |
| 1674 | localtime ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1675 | self.handle.expect( "cp" ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 1676 | self.handle.expect( self.prompt ) |
andrewonlab | 5d7a8f3 | 2014-11-10 13:07:56 -0500 | [diff] [blame] | 1677 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1678 | self.handle.sendline( "cp " + str( logToCopy ) + |
| 1679 | " " + str( destDir ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1680 | self.handle.expect( "cp" ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 1681 | self.handle.expect( self.prompt ) |
andrewonlab | 5d7a8f3 | 2014-11-10 13:07:56 -0500 | [diff] [blame] | 1682 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1683 | return self.handle.before |
| 1684 | |
| 1685 | except pexpect.EOF: |
| 1686 | main.log.error( "Copying files failed" ) |
| 1687 | main.log.error( self.name + ": EOF exception found" ) |
| 1688 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1689 | except Exception: |
| 1690 | main.log.exception( "Copying files failed" ) |
| 1691 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1692 | def checkLogs( self, onosIp, restart=False ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1693 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1694 | runs onos-check-logs on the given onos node |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 1695 | If restart is True, use the old version of onos-check-logs which |
| 1696 | does not print the full stacktrace, but shows the entire log file, |
| 1697 | including across restarts |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1698 | returns the response |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1699 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1700 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1701 | cmd = "onos-check-logs " + str( onosIp ) |
Jon Hall | 16b72c4 | 2015-05-20 10:23:36 -0700 | [diff] [blame] | 1702 | if restart: |
| 1703 | cmd += " old" |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1704 | self.handle.sendline( cmd ) |
| 1705 | self.handle.expect( cmd ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 1706 | self.handle.expect( self.prompt + " " ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1707 | response = self.handle.before |
| 1708 | return response |
| 1709 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1710 | main.log.error( "Lost ssh connection" ) |
| 1711 | main.log.error( self.name + ": EOF exception found" ) |
| 1712 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1713 | except Exception: |
| 1714 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1715 | main.cleanAndExit() |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1716 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1717 | def onosStatus( self, node="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1718 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1719 | Calls onos command: 'onos-service [<node-ip>] status' |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1720 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1721 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1722 | self.handle.sendline( "" ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 1723 | self.handle.expect( self.prompt ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1724 | self.handle.sendline( "onos-service " + str( node ) + |
| 1725 | " status" ) |
| 1726 | i = self.handle.expect( [ |
You Wang | ef1e657 | 2016-03-08 12:53:18 -0800 | [diff] [blame] | 1727 | "start/running", |
You Wang | 7bd8306 | 2016-03-01 11:50:00 -0800 | [diff] [blame] | 1728 | "Running ...", |
You Wang | ef1e657 | 2016-03-08 12:53:18 -0800 | [diff] [blame] | 1729 | "stop/waiting", |
You Wang | 7bd8306 | 2016-03-01 11:50:00 -0800 | [diff] [blame] | 1730 | "Not Running ...", |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1731 | pexpect.TIMEOUT ], timeout=120 ) |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 1732 | self.handle.sendline( "" ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 1733 | self.handle.expect( self.prompt ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1734 | |
You Wang | ef1e657 | 2016-03-08 12:53:18 -0800 | [diff] [blame] | 1735 | if i == 0 or i == 1: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1736 | main.log.info( "ONOS is running" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1737 | return main.TRUE |
You Wang | ef1e657 | 2016-03-08 12:53:18 -0800 | [diff] [blame] | 1738 | elif i == 2 or i == 3: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1739 | main.log.info( "ONOS is stopped" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1740 | main.log.error( "ONOS service failed to check the status" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1741 | |
| 1742 | main.cleanAndExit() |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1743 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1744 | main.log.error( self.name + ": EOF exception found" ) |
| 1745 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1746 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1747 | except Exception: |
| 1748 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1749 | main.cleanAndExit() |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1750 | |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 1751 | def setIpTables( self, ip, port='', action='add', packet_type='', |
| 1752 | direction='INPUT', rule='DROP', states=True ): |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1753 | """ |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1754 | Description: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 1755 | add or remove iptables rule to DROP (default) packets from |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1756 | specific IP and PORT |
| 1757 | Usage: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 1758 | * specify action ('add' or 'remove') |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1759 | when removing, pass in the same argument as you would add. It will |
| 1760 | delete that specific rule. |
| 1761 | * specify the ip to block |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 1762 | * specify the destination port to block (defaults to all ports) |
| 1763 | * optional packet type to block (default tcp) |
| 1764 | * optional iptables rule (default DROP) |
| 1765 | * optional direction to block (default 'INPUT') |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 1766 | * States boolean toggles adding all supported tcp states to the |
| 1767 | firewall rule |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1768 | Returns: |
| 1769 | main.TRUE on success or |
| 1770 | main.FALSE if given invalid input or |
| 1771 | main.ERROR if there is an error in response from iptables |
| 1772 | WARNING: |
| 1773 | * This function uses root privilege iptables command which may result |
| 1774 | in unwanted network errors. USE WITH CAUTION |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1775 | """ |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 1776 | |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1777 | # NOTE********* |
| 1778 | # The strict checking methods of this driver function is intentional |
| 1779 | # to discourage any misuse or error of iptables, which can cause |
| 1780 | # severe network errors |
| 1781 | # ************* |
| 1782 | |
| 1783 | # NOTE: Sleep needed to give some time for rule to be added and |
| 1784 | # registered to the instance. If you are calling this function |
| 1785 | # multiple times this sleep will prevent any errors. |
| 1786 | # DO NOT REMOVE |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 1787 | # time.sleep( 5 ) |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1788 | try: |
| 1789 | # input validation |
| 1790 | action_type = action.lower() |
| 1791 | rule = rule.upper() |
| 1792 | direction = direction.upper() |
| 1793 | if action_type != 'add' and action_type != 'remove': |
| 1794 | main.log.error( "Invalid action type. Use 'add' or " |
| 1795 | "'remove' table rule" ) |
| 1796 | if rule != 'DROP' and rule != 'ACCEPT' and rule != 'LOG': |
| 1797 | # NOTE Currently only supports rules DROP, ACCEPT, and LOG |
| 1798 | main.log.error( "Invalid rule. Valid rules are 'DROP' or " |
| 1799 | "'ACCEPT' or 'LOG' only." ) |
| 1800 | if direction != 'INPUT' and direction != 'OUTPUT': |
| 1801 | # NOTE currently only supports rules INPUT and OUPTUT |
| 1802 | main.log.error( "Invalid rule. Valid directions are" |
| 1803 | " 'OUTPUT' or 'INPUT'" ) |
| 1804 | return main.FALSE |
| 1805 | return main.FALSE |
| 1806 | return main.FALSE |
| 1807 | if action_type == 'add': |
| 1808 | # -A is the 'append' action of iptables |
| 1809 | actionFlag = '-A' |
| 1810 | elif action_type == 'remove': |
| 1811 | # -D is the 'delete' rule of iptables |
| 1812 | actionFlag = '-D' |
| 1813 | self.handle.sendline( "" ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 1814 | self.handle.expect( self.prompt ) |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1815 | cmd = "sudo iptables " + actionFlag + " " +\ |
| 1816 | direction +\ |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1817 | " -s " + str( ip ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1818 | # " -p " + str( packet_type ) +\ |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 1819 | if packet_type: |
| 1820 | cmd += " -p " + str( packet_type ) |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1821 | if port: |
| 1822 | cmd += " --dport " + str( port ) |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 1823 | if states: |
| 1824 | cmd += " -m state --state=" |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1825 | # FIXME- Allow user to configure which states to block |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 1826 | cmd += "INVALID,ESTABLISHED,NEW,RELATED,UNTRACKED" |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1827 | cmd += " -j " + str( rule ) |
| 1828 | |
| 1829 | self.handle.sendline( cmd ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 1830 | self.handle.expect( self.prompt ) |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1831 | main.log.warn( self.handle.before ) |
| 1832 | |
| 1833 | info_string = "On " + str( self.name ) |
| 1834 | info_string += " " + str( action_type ) |
| 1835 | info_string += " iptable rule [ " |
| 1836 | info_string += " IP: " + str( ip ) |
| 1837 | info_string += " Port: " + str( port ) |
| 1838 | info_string += " Rule: " + str( rule ) |
| 1839 | info_string += " Direction: " + str( direction ) + " ]" |
| 1840 | main.log.info( info_string ) |
| 1841 | return main.TRUE |
| 1842 | except pexpect.TIMEOUT: |
| 1843 | main.log.exception( self.name + ": Timeout exception in " |
| 1844 | "setIpTables function" ) |
| 1845 | return main.ERROR |
| 1846 | except pexpect.EOF: |
| 1847 | main.log.error( self.name + ": EOF exception found" ) |
| 1848 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1849 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1850 | except Exception: |
| 1851 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1852 | main.cleanAndExit() |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1853 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1854 | def detailed_status( self, log_filename ): |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1855 | """ |
Jon Hall | 0468b04 | 2015-02-19 19:08:21 -0800 | [diff] [blame] | 1856 | This method is used by STS to check the status of the controller |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 1857 | Reports RUNNING, STARTING, STOPPED, FROZEN, ERROR (and reason) |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1858 | """ |
Jon Hall | 0468b04 | 2015-02-19 19:08:21 -0800 | [diff] [blame] | 1859 | import re |
| 1860 | try: |
| 1861 | self.handle.sendline( "" ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 1862 | self.handle.expect( self.prompt ) |
Jon Hall | 0468b04 | 2015-02-19 19:08:21 -0800 | [diff] [blame] | 1863 | self.handle.sendline( "cd " + self.home ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 1864 | self.handle.expect( self.prompt ) |
Jon Hall | 0468b04 | 2015-02-19 19:08:21 -0800 | [diff] [blame] | 1865 | self.handle.sendline( "service onos status" ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 1866 | self.handle.expect( self.prompt ) |
Jon Hall | 0468b04 | 2015-02-19 19:08:21 -0800 | [diff] [blame] | 1867 | response = self.handle.before |
| 1868 | if re.search( "onos start/running", response ): |
| 1869 | # onos start/running, process 10457 |
| 1870 | return 'RUNNING' |
| 1871 | # FIXME: Implement this case |
| 1872 | # elif re.search( pattern, response ): |
| 1873 | # return 'STARTING' |
| 1874 | elif re.search( "onos stop/", response ): |
| 1875 | # onos stop/waiting |
| 1876 | # FIXME handle this differently?: onos stop/pre-stop |
| 1877 | return 'STOPPED' |
| 1878 | # FIXME: Implement this case |
| 1879 | # elif re.search( pattern, response ): |
| 1880 | # return 'FROZEN' |
| 1881 | else: |
| 1882 | main.log.warn( self.name + |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1883 | " WARNING: status received unknown response" ) |
Jon Hall | 0468b04 | 2015-02-19 19:08:21 -0800 | [diff] [blame] | 1884 | main.log.warn( response ) |
| 1885 | return 'ERROR', "Unknown response: %s" % response |
| 1886 | except pexpect.TIMEOUT: |
| 1887 | main.log.exception( self.name + ": Timeout exception in " |
| 1888 | "setIpTables function" ) |
| 1889 | return 'ERROR', "Pexpect Timeout" |
| 1890 | except pexpect.EOF: |
| 1891 | main.log.error( self.name + ": EOF exception found" ) |
| 1892 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1893 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1894 | except Exception: |
| 1895 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1896 | main.cleanAndExit() |
Jon Hall | 0468b04 | 2015-02-19 19:08:21 -0800 | [diff] [blame] | 1897 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1898 | def createLinkGraphFile( self, benchIp, ONOSIpList, deviceCount ): |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 1899 | ''' |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 1900 | Create/formats the LinkGraph.cfg file based on arguments |
| 1901 | -only creates a linear topology and connects islands |
| 1902 | -evenly distributes devices |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 1903 | -must be called by ONOSbench |
| 1904 | |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 1905 | ONOSIpList - list of all of the node IPs to be used |
| 1906 | |
| 1907 | deviceCount - number of switches to be assigned |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 1908 | ''' |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1909 | main.log.info( "Creating link graph configuration file." ) |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 1910 | linkGraphPath = self.home + "/tools/package/etc/linkGraph.cfg" |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 1911 | tempFile = "/tmp/linkGraph.cfg" |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 1912 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1913 | linkGraph = open( tempFile, 'w+' ) |
| 1914 | linkGraph.write( "# NullLinkProvider topology description (config file).\n" ) |
| 1915 | linkGraph.write( "# The NodeId is only added if the destination is another node's device.\n" ) |
| 1916 | linkGraph.write( "# Bugs: Comments cannot be appended to a line to be read.\n" ) |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 1917 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1918 | clusterCount = len( ONOSIpList ) |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 1919 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1920 | if isinstance( deviceCount, int ) or isinstance( deviceCount, str ): |
| 1921 | deviceCount = int( deviceCount ) |
| 1922 | switchList = [ 0 ]*( clusterCount+1 ) |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 1923 | baselineSwitchCount = deviceCount/clusterCount |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 1924 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1925 | for node in range( 1, clusterCount + 1 ): |
| 1926 | switchList[ node ] = baselineSwitchCount |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 1927 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1928 | for node in range( 1, ( deviceCount % clusterCount )+1 ): |
| 1929 | switchList[ node ] += 1 |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 1930 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1931 | if isinstance( deviceCount, list ): |
| 1932 | main.log.info( "Using provided device distribution" ) |
| 1933 | switchList = [ 0 ] |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 1934 | for i in deviceCount: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1935 | switchList.append( int( i ) ) |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 1936 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1937 | tempList = [ '0' ] |
| 1938 | tempList.extend( ONOSIpList ) |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 1939 | ONOSIpList = tempList |
| 1940 | |
| 1941 | myPort = 6 |
| 1942 | lastSwitch = 0 |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1943 | for node in range( 1, clusterCount+1 ): |
| 1944 | if switchList[ node ] == 0: |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 1945 | continue |
| 1946 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1947 | linkGraph.write( "graph " + ONOSIpList[ node ] + " {\n" ) |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 1948 | |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 1949 | if node > 1: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1950 | # connect to last device on previous node |
| 1951 | line = ( "\t0:5 -> " + str( lastSwitch ) + ":6:" + lastIp + "\n" ) # ONOSIpList[node-1] |
| 1952 | linkGraph.write( line ) |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 1953 | |
| 1954 | lastSwitch = 0 |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1955 | for switch in range( 0, switchList[ node ]-1 ): |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 1956 | line = "" |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1957 | line = ( "\t" + str( switch ) + ":" + str( myPort ) ) |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 1958 | line += " -- " |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1959 | line += ( str( switch+1 ) + ":" + str( myPort-1 ) + "\n" ) |
| 1960 | linkGraph.write( line ) |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 1961 | lastSwitch = switch+1 |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1962 | lastIp = ONOSIpList[ node ] |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 1963 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1964 | # lastSwitch += 1 |
| 1965 | if node < ( clusterCount ): |
| 1966 | # connect to first device on the next node |
| 1967 | line = ( "\t" + str( lastSwitch ) + ":6 -> 0:5:" + ONOSIpList[ node+1 ] + "\n" ) |
| 1968 | linkGraph.write( line ) |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 1969 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1970 | linkGraph.write( "}\n" ) |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 1971 | linkGraph.close() |
| 1972 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1973 | # SCP |
| 1974 | os.system( "scp " + tempFile + " " + self.user_name + "@" + benchIp + ":" + linkGraphPath ) |
| 1975 | main.log.info( "linkGraph.cfg creation complete" ) |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 1976 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1977 | def configNullDev( self, ONOSIpList, deviceCount, numPorts=10 ): |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 1978 | ''' |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 1979 | ONOSIpList = list of Ip addresses of nodes switches will be devided amongst |
| 1980 | deviceCount = number of switches to distribute, or list of values to use as custom distribution |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 1981 | numPorts = number of ports per device. Defaults to 10 both in this function and in ONOS. Optional arg |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 1982 | ''' |
| 1983 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1984 | main.log.info( "Configuring Null Device Provider" ) |
| 1985 | clusterCount = len( ONOSIpList ) |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 1986 | |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 1987 | try: |
| 1988 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1989 | if isinstance( deviceCount, int ) or isinstance( deviceCount, str ): |
| 1990 | main.log.info( "Creating device distribution" ) |
| 1991 | deviceCount = int( deviceCount ) |
| 1992 | switchList = [ 0 ]*( clusterCount+1 ) |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 1993 | baselineSwitchCount = deviceCount/clusterCount |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 1994 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1995 | for node in range( 1, clusterCount + 1 ): |
| 1996 | switchList[ node ] = baselineSwitchCount |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 1997 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1998 | for node in range( 1, ( deviceCount % clusterCount )+1 ): |
| 1999 | switchList[ node ] += 1 |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 2000 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2001 | if isinstance( deviceCount, list ): |
| 2002 | main.log.info( "Using provided device distribution" ) |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 2003 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2004 | if len( deviceCount ) == clusterCount: |
| 2005 | switchList = [ '0' ] |
| 2006 | switchList.extend( deviceCount ) |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 2007 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2008 | if len( deviceCount ) == ( clusterCount + 1 ): |
| 2009 | if deviceCount[ 0 ] == '0' or deviceCount[ 0 ] == 0: |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 2010 | switchList = deviceCount |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 2011 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2012 | assert len( switchList ) == ( clusterCount + 1 ) |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 2013 | |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 2014 | except AssertionError: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2015 | main.log.error( "Bad device/Ip list match" ) |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 2016 | except TypeError: |
| 2017 | main.log.exception( self.name + ": Object not as expected" ) |
| 2018 | return None |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 2019 | except Exception: |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 2020 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2021 | main.cleanAndExit() |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 2022 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2023 | ONOSIp = [ 0 ] |
| 2024 | ONOSIp.extend( ONOSIpList ) |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 2025 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2026 | devicesString = "devConfigs = " |
| 2027 | for node in range( 1, len( ONOSIp ) ): |
| 2028 | devicesString += ( ONOSIp[ node ] + ":" + str( switchList[ node ] ) ) |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 2029 | if node < clusterCount: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2030 | devicesString += ( "," ) |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 2031 | |
| 2032 | try: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2033 | self.handle.sendline( "onos $OC1 cfg set org.onosproject.provider.nil.device.impl.NullDeviceProvider devConfigs " + devicesString ) |
| 2034 | self.handle.expect( ":~" ) |
| 2035 | self.handle.sendline( "onos $OC1 cfg set org.onosproject.provider.nil.device.impl.NullDeviceProvider numPorts " + str( numPorts ) ) |
| 2036 | self.handle.expect( ":~" ) |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 2037 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2038 | for i in range( 10 ): |
| 2039 | self.handle.sendline( "onos $OC1 cfg get org.onosproject.provider.nil.device.impl.NullDeviceProvider" ) |
| 2040 | self.handle.expect( ":~" ) |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 2041 | verification = self.handle.before |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2042 | if ( " value=" + str( numPorts ) ) in verification and ( " value=" + devicesString ) in verification: |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 2043 | break |
| 2044 | else: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2045 | time.sleep( 1 ) |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 2046 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2047 | assert ( "value=" + str( numPorts ) ) in verification and ( " value=" + devicesString ) in verification |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 2048 | |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 2049 | except AssertionError: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2050 | main.log.error( "Incorrect Config settings: " + verification ) |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 2051 | except Exception: |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 2052 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2053 | main.cleanAndExit() |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 2054 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2055 | def configNullLink( self, fileName="/opt/onos/apache-karaf-3.0.3/etc/linkGraph.cfg", eventRate=0 ): |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2056 | ''' |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 2057 | fileName default is currently the same as the default on ONOS, specify alternate file if |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 2058 | you want to use a different topology file than linkGraph.cfg |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2059 | ''' |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 2060 | |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2061 | try: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2062 | self.handle.sendline( "onos $OC1 cfg set org.onosproject.provider.nil.link.impl.NullLinkProvider eventRate " + str( eventRate ) ) |
| 2063 | self.handle.expect( ":~" ) |
| 2064 | self.handle.sendline( "onos $OC1 cfg set org.onosproject.provider.nil.link.impl.NullLinkProvider cfgFile " + fileName ) |
| 2065 | self.handle.expect( ":~" ) |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2066 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2067 | for i in range( 10 ): |
| 2068 | self.handle.sendline( "onos $OC1 cfg get org.onosproject.provider.nil.link.impl.NullLinkProvider" ) |
| 2069 | self.handle.expect( ":~" ) |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 2070 | verification = self.handle.before |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2071 | if ( " value=" + str( eventRate ) ) in verification and ( " value=" + fileName ) in verification: |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 2072 | break |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 2073 | else: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2074 | time.sleep( 1 ) |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 2075 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2076 | assert ( "value=" + str( eventRate ) ) in verification and ( " value=" + fileName ) in verification |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 2077 | |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 2078 | except pexpect.EOF: |
| 2079 | main.log.error( self.name + ": EOF exception found" ) |
| 2080 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2081 | main.cleanAndExit() |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 2082 | except AssertionError: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2083 | main.log.info( "Settings did not post to ONOS" ) |
| 2084 | main.log.error( varification ) |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 2085 | except Exception: |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 2086 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2087 | main.log.error( varification ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2088 | main.cleanAndExit() |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 2089 | |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 2090 | def getOnosIps( self ): |
| 2091 | """ |
| 2092 | Get all onos IPs stored in |
| 2093 | """ |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2094 | |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 2095 | return sorted( self.onosIps.values() ) |
cameron@onlab.us | 59d29d9 | 2015-05-11 14:31:54 -0700 | [diff] [blame] | 2096 | |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 2097 | def listLog( self, nodeIp ): |
| 2098 | """ |
| 2099 | Get a list of all the karaf log names |
| 2100 | """ |
| 2101 | try: |
| 2102 | cmd = "onos-ssh " + nodeIp + " ls -tr /opt/onos/log" |
| 2103 | self.handle.sendline( cmd ) |
| 2104 | self.handle.expect( ":~" ) |
| 2105 | before = self.handle.before.splitlines() |
| 2106 | logNames = [] |
| 2107 | for word in before: |
| 2108 | if 'karaf.log' in word: |
| 2109 | logNames.append( word ) |
| 2110 | return logNames |
| 2111 | except pexpect.EOF: |
| 2112 | main.log.error( self.name + ": EOF exception found" ) |
| 2113 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2114 | main.cleanAndExit() |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 2115 | except pexpect.TIMEOUT: |
| 2116 | main.log.error( self.name + ": TIMEOUT exception found" ) |
| 2117 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2118 | main.cleanAndExit() |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 2119 | except Exception: |
| 2120 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2121 | main.cleanAndExit() |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 2122 | |
Pratik Parab | 3b2ab5a | 2017-02-14 13:15:14 -0800 | [diff] [blame] | 2123 | def logReport( self, nodeIp, searchTerms, outputMode="s", startStr=None, endStr=None ): |
Jon Hall | b424222 | 2016-01-25 17:07:04 -0800 | [diff] [blame] | 2124 | """ |
| 2125 | Searches the latest ONOS log file for the given search terms and |
| 2126 | prints the total occurances of each term. Returns to combined total of |
| 2127 | all occurances. |
cameron@onlab.us | 70dd8c6 | 2015-05-14 11:19:39 -0700 | [diff] [blame] | 2128 | |
Jon Hall | b424222 | 2016-01-25 17:07:04 -0800 | [diff] [blame] | 2129 | Arguments: |
| 2130 | * nodeIp - The ip of the ONOS node where the log is located |
| 2131 | * searchTerms - A string to grep for or a list of strings to grep |
| 2132 | for in the ONOS log. Will print out the number of |
| 2133 | occurances for each term. |
| 2134 | Optional Arguments: |
| 2135 | * outputMode - 's' or 'd'. If 'd' will print the last 5 lines |
| 2136 | containing each search term as well as the total |
| 2137 | number of occurances of each term. Defaults to 's', |
| 2138 | which prints the simple output of just the number |
| 2139 | of occurances for each term. |
Pratik Parab | 3b2ab5a | 2017-02-14 13:15:14 -0800 | [diff] [blame] | 2140 | * startStr - the start string to be given to stream editor command |
| 2141 | as the start point for extraction of data |
| 2142 | * endStr - the end string to be given to stream editor command as |
| 2143 | the end point for extraction of data |
Jon Hall | b424222 | 2016-01-25 17:07:04 -0800 | [diff] [blame] | 2144 | """ |
| 2145 | try: |
| 2146 | main.log.info( " Log Report for {} ".format( nodeIp ).center( 70, '=' ) ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2147 | if isinstance( searchTerms, str ): |
| 2148 | searchTerms = [ searchTerms ] |
Jon Hall | b424222 | 2016-01-25 17:07:04 -0800 | [diff] [blame] | 2149 | numTerms = len( searchTerms ) |
| 2150 | outputMode = outputMode.lower() |
cameron@onlab.us | 70dd8c6 | 2015-05-14 11:19:39 -0700 | [diff] [blame] | 2151 | |
Jon Hall | b424222 | 2016-01-25 17:07:04 -0800 | [diff] [blame] | 2152 | totalHits = 0 |
| 2153 | logLines = [] |
| 2154 | for termIndex in range( numTerms ): |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2155 | term = searchTerms[ termIndex ] |
| 2156 | logLines.append( [ term ] ) |
Pratik Parab | 3b2ab5a | 2017-02-14 13:15:14 -0800 | [diff] [blame] | 2157 | if startStr and endStr: |
| 2158 | cmd = "onos-ssh {} \"sed -n '/{}/,/{}/p' /opt/onos/log/karaf.log | grep {}\"".format( nodeIp, |
| 2159 | startStr, |
| 2160 | endStr, |
| 2161 | term ) |
| 2162 | else: |
| 2163 | cmd = "onos-ssh {} cat /opt/onos/log/karaf.log | grep {}".format( nodeIp, |
| 2164 | term ) |
Jon Hall | b424222 | 2016-01-25 17:07:04 -0800 | [diff] [blame] | 2165 | self.handle.sendline( cmd ) |
| 2166 | self.handle.expect( ":~" ) |
| 2167 | before = self.handle.before.splitlines() |
| 2168 | count = 0 |
| 2169 | for line in before: |
| 2170 | if term in line and "grep" not in line: |
| 2171 | count += 1 |
| 2172 | if before.index( line ) > ( len( before ) - 7 ): |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2173 | logLines[ termIndex ].append( line ) |
Jon Hall | b424222 | 2016-01-25 17:07:04 -0800 | [diff] [blame] | 2174 | main.log.info( "{}: {}".format( term, count ) ) |
| 2175 | totalHits += count |
| 2176 | if termIndex == numTerms - 1: |
| 2177 | print "\n" |
| 2178 | if outputMode != "s": |
| 2179 | outputString = "" |
| 2180 | for term in logLines: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2181 | outputString = term[ 0 ] + ": \n" |
Jon Hall | b424222 | 2016-01-25 17:07:04 -0800 | [diff] [blame] | 2182 | for line in range( 1, len( term ) ): |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2183 | outputString += ( "\t" + term[ line ] + "\n" ) |
| 2184 | if outputString != ( term[ 0 ] + ": \n" ): |
Jon Hall | b424222 | 2016-01-25 17:07:04 -0800 | [diff] [blame] | 2185 | main.log.info( outputString ) |
| 2186 | main.log.info( "=" * 70 ) |
| 2187 | return totalHits |
| 2188 | except pexpect.EOF: |
| 2189 | main.log.error( self.name + ": EOF exception found" ) |
| 2190 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2191 | main.cleanAndExit() |
Jon Hall | b424222 | 2016-01-25 17:07:04 -0800 | [diff] [blame] | 2192 | except pexpect.TIMEOUT: |
| 2193 | main.log.error( self.name + ": TIMEOUT exception found" ) |
| 2194 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2195 | main.cleanAndExit() |
Jon Hall | b424222 | 2016-01-25 17:07:04 -0800 | [diff] [blame] | 2196 | except Exception: |
| 2197 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2198 | main.cleanAndExit() |
kelvin-onlab | 7a719bb | 2015-07-08 11:09:51 -0700 | [diff] [blame] | 2199 | |
| 2200 | def copyMininetFile( self, fileName, localPath, userName, ip, |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2201 | mnPath='~/mininet/custom/', timeout = 60 ): |
kelvin-onlab | 7a719bb | 2015-07-08 11:09:51 -0700 | [diff] [blame] | 2202 | """ |
| 2203 | Description: |
| 2204 | Copy mininet topology file from dependency folder in the test folder |
| 2205 | and paste it to the mininet machine's mininet/custom folder |
| 2206 | Required: |
| 2207 | fileName - Name of the topology file to copy |
| 2208 | localPath - File path of the mininet topology file |
| 2209 | userName - User name of the mininet machine to send the file to |
| 2210 | ip - Ip address of the mininet machine |
| 2211 | Optional: |
| 2212 | mnPath - of the mininet directory to send the file to |
| 2213 | Return: |
| 2214 | Return main.TRUE if successfully copied the file otherwise |
| 2215 | return main.FALSE |
| 2216 | """ |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2217 | |
kelvin-onlab | 7a719bb | 2015-07-08 11:09:51 -0700 | [diff] [blame] | 2218 | try: |
| 2219 | cmd = "scp " + localPath + fileName + " " + userName + "@" + \ |
| 2220 | str( ip ) + ":" + mnPath + fileName |
| 2221 | |
| 2222 | self.handle.sendline( "" ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 2223 | self.handle.expect( self.prompt ) |
kelvin-onlab | 7a719bb | 2015-07-08 11:09:51 -0700 | [diff] [blame] | 2224 | |
| 2225 | main.log.info( self.name + ": Execute: " + cmd ) |
| 2226 | |
| 2227 | self.handle.sendline( cmd ) |
| 2228 | |
| 2229 | i = self.handle.expect( [ 'No such file', |
| 2230 | "100%", |
| 2231 | pexpect.TIMEOUT ] ) |
| 2232 | |
| 2233 | if i == 0: |
| 2234 | main.log.error( self.name + ": File " + fileName + |
| 2235 | " does not exist!" ) |
| 2236 | return main.FALSE |
| 2237 | |
| 2238 | if i == 1: |
| 2239 | main.log.info( self.name + ": File " + fileName + |
| 2240 | " has been copied!" ) |
| 2241 | self.handle.sendline( "" ) |
Devin Lim | c20e79a | 2017-06-07 10:29:57 -0700 | [diff] [blame] | 2242 | self.handle.expect( self.prompt ) |
kelvin-onlab | 7a719bb | 2015-07-08 11:09:51 -0700 | [diff] [blame] | 2243 | return main.TRUE |
| 2244 | |
| 2245 | except pexpect.EOF: |
| 2246 | main.log.error( self.name + ": EOF exception found" ) |
| 2247 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2248 | main.cleanAndExit() |
kelvin-onlab | 7a719bb | 2015-07-08 11:09:51 -0700 | [diff] [blame] | 2249 | except pexpect.TIMEOUT: |
| 2250 | main.log.error( self.name + ": TIMEOUT exception found" ) |
| 2251 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2252 | main.cleanAndExit() |
cameron@onlab.us | 78b8965 | 2015-07-08 15:21:03 -0700 | [diff] [blame] | 2253 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2254 | def jvmSet( self, memory=8 ): |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 2255 | |
cameron@onlab.us | 78b8965 | 2015-07-08 15:21:03 -0700 | [diff] [blame] | 2256 | import os |
| 2257 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2258 | homeDir = os.path.expanduser( '~' ) |
cameron@onlab.us | 78b8965 | 2015-07-08 15:21:03 -0700 | [diff] [blame] | 2259 | filename = "/onos/tools/package/bin/onos-service" |
| 2260 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2261 | serviceConfig = open( homeDir + filename, 'w+' ) |
| 2262 | serviceConfig.write( "#!/bin/bash\n " ) |
| 2263 | serviceConfig.write( "#------------------------------------- \n " ) |
| 2264 | serviceConfig.write( "# Starts ONOS Apache Karaf container\n " ) |
| 2265 | serviceConfig.write( "#------------------------------------- \n " ) |
| 2266 | serviceConfig.write( "#export JAVA_HOME=${JAVA_HOME:-/usr/lib/jvm/java-7-openjdk-amd64/}\n " ) |
| 2267 | serviceConfig.write( """export JAVA_OPTS="${JAVA_OPTS:--Xms""" + str( memory ) + "G -Xmx" + str( memory ) + """G}" \n """ ) |
| 2268 | serviceConfig.write( "[ -d $ONOS_HOME ] && cd $ONOS_HOME || ONOS_HOME=$(dirname $0)/..\n" ) |
| 2269 | serviceConfig.write( """${ONOS_HOME}/apache-karaf-$KARAF_VERSION/bin/karaf "$@" \n """ ) |
cameron@onlab.us | 78b8965 | 2015-07-08 15:21:03 -0700 | [diff] [blame] | 2270 | serviceConfig.close() |
| 2271 | |
Jon Hall | 6c44c0b | 2016-04-20 15:21:00 -0700 | [diff] [blame] | 2272 | def createDBFile( self, testData ): |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 2273 | |
cameron@onlab.us | 78b8965 | 2015-07-08 15:21:03 -0700 | [diff] [blame] | 2274 | filename = main.TEST + "DB" |
| 2275 | DBString = "" |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 2276 | |
cameron@onlab.us | 78b8965 | 2015-07-08 15:21:03 -0700 | [diff] [blame] | 2277 | for item in testData: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2278 | if isinstance( item, string ): |
cameron@onlab.us | 78b8965 | 2015-07-08 15:21:03 -0700 | [diff] [blame] | 2279 | item = "'" + item + "'" |
Jon Hall | 6c44c0b | 2016-04-20 15:21:00 -0700 | [diff] [blame] | 2280 | if testData.index( item ) < len( testData - 1 ): |
cameron@onlab.us | 78b8965 | 2015-07-08 15:21:03 -0700 | [diff] [blame] | 2281 | item += "," |
Jon Hall | 6c44c0b | 2016-04-20 15:21:00 -0700 | [diff] [blame] | 2282 | DBString += str( item ) |
cameron@onlab.us | 78b8965 | 2015-07-08 15:21:03 -0700 | [diff] [blame] | 2283 | |
Jon Hall | 6c44c0b | 2016-04-20 15:21:00 -0700 | [diff] [blame] | 2284 | DBFile = open( filename, "a" ) |
| 2285 | DBFile.write( DBString ) |
cameron@onlab.us | 78b8965 | 2015-07-08 15:21:03 -0700 | [diff] [blame] | 2286 | DBFile.close() |
| 2287 | |
Jon Hall | 6c44c0b | 2016-04-20 15:21:00 -0700 | [diff] [blame] | 2288 | def verifySummary( self, ONOSIp, *deviceCount ): |
cameron@onlab.us | 78b8965 | 2015-07-08 15:21:03 -0700 | [diff] [blame] | 2289 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2290 | self.handle.sendline( "onos " + ONOSIp + " summary" ) |
Jon Hall | 6c44c0b | 2016-04-20 15:21:00 -0700 | [diff] [blame] | 2291 | self.handle.expect( ":~" ) |
cameron@onlab.us | 78b8965 | 2015-07-08 15:21:03 -0700 | [diff] [blame] | 2292 | |
| 2293 | summaryStr = self.handle.before |
| 2294 | print "\nSummary\n==============\n" + summaryStr + "\n\n" |
| 2295 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2296 | # passed = "SCC(s)=1" in summaryStr |
| 2297 | # if deviceCount: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2298 | # passed = "devices=" + str(deviceCount) + "," not in summaryStr |
cameron@onlab.us | 78b8965 | 2015-07-08 15:21:03 -0700 | [diff] [blame] | 2299 | |
GlennRC | 772363b | 2015-08-25 13:05:57 -0700 | [diff] [blame] | 2300 | passed = False |
cameron@onlab.us | 78b8965 | 2015-07-08 15:21:03 -0700 | [diff] [blame] | 2301 | if "SCC(s)=1," in summaryStr: |
| 2302 | passed = True |
Jon Hall | 6c44c0b | 2016-04-20 15:21:00 -0700 | [diff] [blame] | 2303 | print "Summary is verifed" |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 2304 | else: |
Jon Hall | 6c44c0b | 2016-04-20 15:21:00 -0700 | [diff] [blame] | 2305 | print "Summary failed" |
cameron@onlab.us | 78b8965 | 2015-07-08 15:21:03 -0700 | [diff] [blame] | 2306 | |
| 2307 | if deviceCount: |
| 2308 | print" =============================" |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2309 | checkStr = "devices=" + str( deviceCount[ 0 ] ) + "," |
cameron@onlab.us | 78b8965 | 2015-07-08 15:21:03 -0700 | [diff] [blame] | 2310 | print "Checkstr: " + checkStr |
| 2311 | if checkStr not in summaryStr: |
| 2312 | passed = False |
Jon Hall | 6c44c0b | 2016-04-20 15:21:00 -0700 | [diff] [blame] | 2313 | print "Device count failed" |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 2314 | else: |
| 2315 | print "device count verified" |
cameron@onlab.us | 78b8965 | 2015-07-08 15:21:03 -0700 | [diff] [blame] | 2316 | |
| 2317 | return passed |
Jon Hall | 6c44c0b | 2016-04-20 15:21:00 -0700 | [diff] [blame] | 2318 | |
Jon Hall | 8f6d462 | 2016-05-23 15:27:18 -0700 | [diff] [blame] | 2319 | def getIpAddr( self, iface=None ): |
Jon Hall | 6c44c0b | 2016-04-20 15:21:00 -0700 | [diff] [blame] | 2320 | """ |
| 2321 | Update self.ip_address with numerical ip address. If multiple IP's are |
| 2322 | located on the device, will attempt to use self.nicAddr to choose the |
| 2323 | right one. Defaults to 127.0.0.1 if no other address is found or cannot |
| 2324 | determine the correct address. |
| 2325 | |
| 2326 | ONLY WORKS WITH IPV4 ADDRESSES |
| 2327 | """ |
| 2328 | try: |
Jon Hall | 8f6d462 | 2016-05-23 15:27:18 -0700 | [diff] [blame] | 2329 | LOCALHOST = "127.0.0.1" |
Jon Hall | 6c44c0b | 2016-04-20 15:21:00 -0700 | [diff] [blame] | 2330 | ipPat = "\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}" |
| 2331 | pattern = re.compile( ipPat ) |
| 2332 | match = re.search( pattern, self.ip_address ) |
| 2333 | if self.nicAddr: |
| 2334 | nicPat = self.nicAddr.replace( ".", "\." ).replace( "\*", r"\d{1,3}" ) |
| 2335 | nicPat = re.compile( nicPat ) |
| 2336 | else: |
| 2337 | nicPat = None |
| 2338 | # IF self.ip_address is an ip address and matches |
| 2339 | # self.nicAddr: return self.ip_address |
| 2340 | if match: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2341 | curIp = match.group( 0 ) |
Jon Hall | 6c44c0b | 2016-04-20 15:21:00 -0700 | [diff] [blame] | 2342 | if nicPat: |
| 2343 | nicMatch = re.search( nicPat, curIp ) |
| 2344 | if nicMatch: |
| 2345 | return self.ip_address |
Jon Hall | 8f6d462 | 2016-05-23 15:27:18 -0700 | [diff] [blame] | 2346 | # ELSE: IF iface, return ip of interface |
| 2347 | cmd = "ifconfig" |
| 2348 | ifPat = re.compile( "inet addr:({})".format( ipPat ) ) |
| 2349 | if iface: |
| 2350 | cmd += " " + str( iface ) |
| 2351 | raw = subprocess.check_output( cmd.split() ) |
Jon Hall | 6c44c0b | 2016-04-20 15:21:00 -0700 | [diff] [blame] | 2352 | ifPat = re.compile( "inet addr:({})".format( ipPat ) ) |
| 2353 | ips = re.findall( ifPat, raw ) |
Jon Hall | 8f6d462 | 2016-05-23 15:27:18 -0700 | [diff] [blame] | 2354 | if iface: |
| 2355 | if ips: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2356 | ip = ips[ 0 ] |
Jon Hall | 8f6d462 | 2016-05-23 15:27:18 -0700 | [diff] [blame] | 2357 | self.ip_address = ip |
| 2358 | return ip |
| 2359 | else: |
| 2360 | main.log.error( "Error finding ip, ifconfig output:".format( raw ) ) |
| 2361 | # ELSE: attempt to get address matching nicPat. |
Jon Hall | 6c44c0b | 2016-04-20 15:21:00 -0700 | [diff] [blame] | 2362 | if nicPat: |
| 2363 | for ip in ips: |
| 2364 | curMatch = re.search( nicPat, ip ) |
| 2365 | if curMatch: |
| 2366 | self.ip_address = ip |
| 2367 | return ip |
Jon Hall | 8f6d462 | 2016-05-23 15:27:18 -0700 | [diff] [blame] | 2368 | else: # If only one non-localhost ip, return that |
| 2369 | tmpList = [ ip for ip in ips if ip is not LOCALHOST ] |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2370 | if len( tmpList ) == 1: |
| 2371 | curIp = tmpList[ 0 ] |
Jon Hall | 6c44c0b | 2016-04-20 15:21:00 -0700 | [diff] [blame] | 2372 | self.ip_address = curIp |
| 2373 | return curIp |
Jon Hall | 8f6d462 | 2016-05-23 15:27:18 -0700 | [diff] [blame] | 2374 | # Either no non-localhost IPs, or more than 1 |
Jon Hall | ebccd35 | 2016-05-20 15:17:17 -0700 | [diff] [blame] | 2375 | main.log.warn( "getIpAddr failed to find a public IP address" ) |
Jon Hall | 8f6d462 | 2016-05-23 15:27:18 -0700 | [diff] [blame] | 2376 | return LOCALHOST |
Jon Hall | e179095 | 2016-05-23 15:51:46 -0700 | [diff] [blame] | 2377 | except subprocess.CalledProcessError: |
Jon Hall | 8f6d462 | 2016-05-23 15:27:18 -0700 | [diff] [blame] | 2378 | main.log.exception( "Error executing ifconfig" ) |
| 2379 | except IndexError: |
| 2380 | main.log.exception( "Error getting IP Address" ) |
Jon Hall | 6c44c0b | 2016-04-20 15:21:00 -0700 | [diff] [blame] | 2381 | except Exception: |
| 2382 | main.log.exception( "Uncaught exception" ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 2383 | |
Devin Lim | 461f087 | 2017-06-05 16:49:33 -0700 | [diff] [blame] | 2384 | def startBasicONOS( self, nodeList, opSleep=60, onosStartupSleep=30, onosUser="sdn" ): |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2385 | ''' |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 2386 | Start onos cluster with defined nodes, but only with drivers app |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2387 | ''' |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 2388 | import time |
| 2389 | |
| 2390 | self.createCellFile( self.ip_address, |
| 2391 | "temp", |
| 2392 | self.ip_address, |
| 2393 | "drivers", |
Devin Lim | 461f087 | 2017-06-05 16:49:33 -0700 | [diff] [blame] | 2394 | nodeList, onosUser ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 2395 | |
| 2396 | main.log.info( self.name + ": Apply cell to environment" ) |
| 2397 | cellResult = self.setCell( "temp" ) |
| 2398 | verifyResult = self.verifyCell() |
| 2399 | |
| 2400 | main.log.info( self.name + ": Creating ONOS package" ) |
You Wang | d1bcaca | 2016-10-24 15:23:26 -0700 | [diff] [blame] | 2401 | packageResult = self.buckBuild( timeout=opSleep ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 2402 | |
You Wang | c669d21 | 2017-01-25 11:09:48 -0800 | [diff] [blame] | 2403 | main.log.info( self.name + ": Uninstalling ONOS" ) |
| 2404 | for nd in nodeList: |
| 2405 | self.onosUninstall( nodeIp=nd ) |
| 2406 | |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 2407 | main.log.info( self.name + ": Installing ONOS package" ) |
| 2408 | for nd in nodeList: |
You Wang | c669d21 | 2017-01-25 11:09:48 -0800 | [diff] [blame] | 2409 | self.onosInstall( node=nd ) |
| 2410 | |
| 2411 | main.log.info( self.name + ": Set up ONOS secure SSH" ) |
| 2412 | for nd in nodeList: |
| 2413 | self.onosSecureSSH( node=nd ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 2414 | |
| 2415 | main.log.info( self.name + ": Starting ONOS service" ) |
| 2416 | time.sleep( onosStartupSleep ) |
| 2417 | |
| 2418 | onosStatus = True |
| 2419 | for nd in nodeList: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2420 | onosStatus = onosStatus & self.isup( node = nd ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2421 | # print "onosStatus is: " + str( onosStatus ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 2422 | |
| 2423 | return main.TRUE if onosStatus else main.FALSE |
| 2424 | |
Devin Lim | 0207527 | 2017-07-10 15:33:21 -0700 | [diff] [blame] | 2425 | def onosNetCfg( self, controllerIp, path, fileName ): |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 2426 | """ |
| 2427 | Push a specified json file to ONOS through the onos-netcfg service |
| 2428 | |
| 2429 | Required: |
Devin Lim | 0207527 | 2017-07-10 15:33:21 -0700 | [diff] [blame] | 2430 | controllerIp - the Ip of the ONOS node in the cluster |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 2431 | path - the location of the file to be sent |
| 2432 | fileName - name of the json file to be sent |
| 2433 | |
| 2434 | Returns main.TRUE on successfully sending json file, and main.FALSE if |
| 2435 | there is an error. |
| 2436 | """ |
| 2437 | try: |
Devin Lim | 0207527 | 2017-07-10 15:33:21 -0700 | [diff] [blame] | 2438 | cmd = "onos-netcfg {0} {1}{2}".format( controllerIp, path, fileName ) |
| 2439 | main.log.info( "Sending: " + cmd ) |
| 2440 | main.ONOSbench.handle.sendline( cmd ) |
Jeremy Ronquillo | 3008aa3 | 2017-07-07 15:38:57 -0700 | [diff] [blame] | 2441 | main.ONOSbench.handle.expect( self.prompt ) |
Devin Lim | 0207527 | 2017-07-10 15:33:21 -0700 | [diff] [blame] | 2442 | handle = self.handle.before |
Jeremy Ronquillo | 3008aa3 | 2017-07-07 15:38:57 -0700 | [diff] [blame] | 2443 | if "Error" in handle or "No such file or directory" in handle or "curl: " in handle: |
| 2444 | main.log.error( self.name + ": " + handle + self.handle.after ) |
Devin Lim | 0207527 | 2017-07-10 15:33:21 -0700 | [diff] [blame] | 2445 | return main.FALSE |
Devin Lim | 752dd7b | 2017-06-27 14:40:03 -0700 | [diff] [blame] | 2446 | return main.TRUE |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 2447 | except pexpect.EOF: |
| 2448 | main.log.error( self.name + ": EOF exception found" ) |
| 2449 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2450 | main.cleanAndExit() |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 2451 | except Exception: |
| 2452 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2453 | main.cleanAndExit() |
Devin Lim | 3ebd5e7 | 2017-11-14 10:38:00 -0800 | [diff] [blame] | 2454 | |
| 2455 | def formCluster( self, onosIPs ): |
| 2456 | """ |
| 2457 | From ONOS cluster for IP addresses in onosIPs list |
| 2458 | """ |
| 2459 | try: |
| 2460 | onosIPs = " ".join( onosIPs ) |
| 2461 | command = "onos-form-cluster {}".format( onosIPs ) |
| 2462 | main.log.info( "Sending: " + command ) |
| 2463 | self.handle.sendline( "" ) |
| 2464 | self.handle.expect( self.prompt ) |
| 2465 | self.handle.sendline( command ) |
| 2466 | self.handle.expect( self.prompt ) |
| 2467 | handle = self.handle.before |
| 2468 | main.log.debug( handle ) |
| 2469 | assert handle is not None, "Error in sendline" |
| 2470 | assert "Command not found:" not in handle, handle |
| 2471 | assert "Error" not in handle, handle |
| 2472 | assert "Exception:" not in handle, handle |
| 2473 | assert "curl:" not in handle, handle |
| 2474 | return main.TRUE |
| 2475 | except AssertionError: |
| 2476 | main.log.exception( "{} Error in onos-form-cluster output:".format( self.name ) ) |
| 2477 | return main.FALSE |
| 2478 | except TypeError: |
| 2479 | main.log.exception( self.name + ": Object not as expected" ) |
| 2480 | return main.FALSE |
| 2481 | except pexpect.EOF: |
| 2482 | main.log.error( self.name + ": EOF exception found" ) |
| 2483 | main.log.error( self.name + ": " + self.handle.before ) |
| 2484 | main.cleanAndExit() |
| 2485 | except Exception: |
| 2486 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2487 | main.cleanAndExit() |
Jon Hall | 7ce46ea | 2018-02-05 12:20:59 -0800 | [diff] [blame] | 2488 | |
| 2489 | def backupData( self, location ): |
| 2490 | """ |
| 2491 | Backs up ONOS data and logs to a given location. Returns main.FALSE |
| 2492 | if there is an error executing the command, and main.TRUE otherwise. |
| 2493 | required arguments: |
| 2494 | loaction - The file path to save the backup to |
| 2495 | """ |
| 2496 | try: |
| 2497 | cmd = "/opt/onos/bin/onos-backup " + str( location ) |
| 2498 | self.handle.sendline( cmd ) |
| 2499 | self.handle.expect( self.prompt ) |
| 2500 | handle = self.handle.before |
| 2501 | main.log.debug( handle ) |
| 2502 | assert handle is not None, "Error in sendline" |
| 2503 | assert "Command not found:" not in handle, handle |
| 2504 | assert "Error" not in handle, handle |
| 2505 | assert "Exception:" not in handle, handle |
| 2506 | return main.TRUE |
| 2507 | except AssertionError: |
| 2508 | main.log.exception( "{} Error in onos-backup output:".format( self.name ) ) |
| 2509 | return main.FALSE |
| 2510 | except TypeError: |
| 2511 | main.log.exception( self.name + ": Object not as expected" ) |
| 2512 | return main.FALSE |
| 2513 | except pexpect.EOF: |
| 2514 | main.log.error( self.name + ": EOF exception found" ) |
| 2515 | main.log.error( self.name + ": " + self.handle.before ) |
| 2516 | main.cleanAndExit() |
| 2517 | except Exception: |
| 2518 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2519 | main.cleanAndExit() |
| 2520 | |
| 2521 | def restoreData( self, location ): |
| 2522 | """ |
| 2523 | Restores ONOS data and logs from a given location. Returns main.FALSE |
| 2524 | if there is an error executing the command, and main.TRUE otherwise. |
| 2525 | required arguments: |
| 2526 | loaction - The file path of a backup file |
| 2527 | """ |
| 2528 | try: |
| 2529 | cmd = "/opt/onos/bin/onos-restore " + str( location ) |
| 2530 | self.handle.sendline( cmd ) |
| 2531 | self.handle.expect( self.prompt ) |
| 2532 | handle = self.handle.before |
| 2533 | main.log.debug( handle ) |
| 2534 | assert handle is not None, "Error in sendline" |
| 2535 | assert "Command not found:" not in handle, handle |
| 2536 | assert "Error" not in handle, handle |
| 2537 | assert "Exception:" not in handle, handle |
| 2538 | return main.TRUE |
| 2539 | except AssertionError: |
| 2540 | main.log.exception( "{} Error in onos-restore output:".format( self.name ) ) |
| 2541 | return main.FALSE |
| 2542 | except TypeError: |
| 2543 | main.log.exception( self.name + ": Object not as expected" ) |
| 2544 | return main.FALSE |
| 2545 | except pexpect.EOF: |
| 2546 | main.log.error( self.name + ": EOF exception found" ) |
| 2547 | main.log.error( self.name + ": " + self.handle.before ) |
| 2548 | main.cleanAndExit() |
| 2549 | except Exception: |
| 2550 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2551 | main.cleanAndExit() |
You Wang | 5df1c6d | 2018-04-06 18:02:02 -0700 | [diff] [blame] | 2552 | |
| 2553 | def onosDiagnostics( self, onosIPs, dstDir, suffix ): |
| 2554 | """ |
| 2555 | Run onos-diagnostics with given ONOS instance IPs and save output to dstDir |
| 2556 | with suffix specified E.g. onos-diags-suffix.tar.gz |
| 2557 | required argDuments: |
| 2558 | onosIPs - list of ONOS IPs for collecting diags |
| 2559 | dstDir - diags file will be saved under the directory specified |
| 2560 | suffix - diags file will be named with the suffix specified |
| 2561 | returns: |
| 2562 | main.FALSE if there's an error executing the command, and main.TRUE otherwise |
| 2563 | """ |
| 2564 | try: |
| 2565 | cmd = "onos-diagnostics" |
| 2566 | assert isinstance( onosIPs, list ) |
| 2567 | for ip in onosIPs: |
| 2568 | cmd += " " + str( ip ) |
| 2569 | self.handle.sendline( cmd ) |
| 2570 | self.handle.expect( self.prompt ) |
| 2571 | handle = self.handle.before |
| 2572 | main.log.debug( handle ) |
| 2573 | assert handle is not None, "Error in sendline" |
| 2574 | assert "Command not found:" not in handle, handle |
| 2575 | assert "Exception:" not in handle, handle |
| 2576 | # Rename and move diags file to dstDir from /tmp |
| 2577 | if dstDir[ -1: ] != "/": |
| 2578 | dstDir += "/" |
| 2579 | self.handle.sendline( "mv /tmp/onos-diags.tar.gz " + str( dstDir ) + "onos-diags" + str( suffix ) + ".tar.gz" ) |
| 2580 | self.handle.expect( self.prompt ) |
| 2581 | handle = self.handle.before |
| 2582 | main.log.debug( handle ) |
| 2583 | assert handle is not None, "Error in sendline" |
| 2584 | assert "No such file or directory" not in handle, handle |
| 2585 | return main.TRUE |
| 2586 | except AssertionError: |
| 2587 | main.log.exception( "{} Error in onos-diagnostics output:".format( self.name ) ) |
| 2588 | return main.FALSE |
| 2589 | except TypeError: |
| 2590 | main.log.exception( self.name + ": Object not as expected" ) |
| 2591 | return main.FALSE |
| 2592 | except pexpect.EOF: |
| 2593 | main.log.error( self.name + ": EOF exception found" ) |
| 2594 | main.log.error( self.name + ": " + self.handle.before ) |
| 2595 | main.cleanAndExit() |
| 2596 | except Exception: |
| 2597 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2598 | main.cleanAndExit() |