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