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