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