cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 1 | |
kelvin-onlab | c2b7910 | 2015-07-14 11:41:20 -0700 | [diff] [blame] | 2 | # This is a sample template that starts up ONOS cluster, this template |
| 3 | # is used as a starting script for creating functionality and performance test |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 4 | |
Jon Hall | f57a5ef | 2015-07-07 17:56:16 -0700 | [diff] [blame] | 5 | class SAMPstartTemplate: |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 6 | |
| 7 | def __init__( self ): |
| 8 | self.default = '' |
| 9 | |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 10 | def CASE1( self, main ): |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 11 | import time |
| 12 | import os |
kelvin-onlab | bf45682 | 2015-06-22 16:53:06 -0700 | [diff] [blame] | 13 | import imp |
Jon Hall | f632d20 | 2015-07-30 15:45:11 -0700 | [diff] [blame] | 14 | import re |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 15 | |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 16 | """ |
| 17 | - Construct tests variables |
| 18 | - GIT ( optional ) |
| 19 | - Checkout ONOS master branch |
| 20 | - Pull latest ONOS code |
| 21 | - Building ONOS ( optional ) |
| 22 | - Install ONOS package |
| 23 | - Build ONOS package |
| 24 | """ |
| 25 | |
| 26 | main.case( "Constructing test variables and building ONOS package" ) |
| 27 | main.step( "Constructing test variables" ) |
| 28 | stepResult = main.FALSE |
| 29 | |
| 30 | # Test variables |
Jon Hall | f632d20 | 2015-07-30 15:45:11 -0700 | [diff] [blame] | 31 | main.testOnDirectory = re.sub( "(/tests)$", "", main.testDir ) |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 32 | main.cellName = main.params[ 'ENV' ][ 'cellName' ] |
| 33 | main.apps = main.params[ 'ENV' ][ 'cellApps' ] |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 34 | gitBranch = main.params[ 'GIT' ][ 'branch' ] |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 35 | main.dependencyPath = main.testOnDirectory + \ |
| 36 | main.params[ 'DEPENDENCY' ][ 'path' ] |
| 37 | main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ] |
| 38 | main.scale = ( main.params[ 'SCALE' ][ 'size' ] ).split( "," ) |
| 39 | main.maxNodes = int( main.params[ 'SCALE' ][ 'max' ] ) |
| 40 | main.ONOSport = main.params[ 'CTRL' ][ 'port' ] |
| 41 | wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ] |
| 42 | main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] ) |
| 43 | gitPull = main.params[ 'GIT' ][ 'pull' ] |
| 44 | main.cellData = {} # for creating cell file |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 45 | main.CLIs = [] |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 46 | main.ONOSip = [] |
| 47 | |
| 48 | main.ONOSip = main.ONOSbench.getOnosIps() |
| 49 | print main.ONOSip |
| 50 | |
| 51 | # Assigning ONOS cli handles to a list |
| 52 | for i in range( 1, main.maxNodes + 1 ): |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 53 | main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) ) |
| 54 | |
| 55 | # -- INIT SECTION, ONLY RUNS ONCE -- # |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 56 | main.startUp = imp.load_source( wrapperFile1, |
| 57 | main.dependencyPath + |
| 58 | wrapperFile1 + |
| 59 | ".py" ) |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 60 | |
kelvin-onlab | d9e23de | 2015-08-06 10:34:44 -0700 | [diff] [blame] | 61 | copyResult1 = main.ONOSbench.scp( main.Mininet1, |
| 62 | main.dependencyPath + |
| 63 | main.topology, |
| 64 | main.Mininet1.home, |
| 65 | direction="to" ) |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 66 | if main.CLIs: |
| 67 | stepResult = main.TRUE |
| 68 | else: |
| 69 | main.log.error( "Did not properly created list of ONOS CLI handle" ) |
| 70 | stepResult = main.FALSE |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 71 | |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 72 | utilities.assert_equals( expect=main.TRUE, |
| 73 | actual=stepResult, |
| 74 | onpass="Successfully construct " + |
| 75 | "test variables ", |
| 76 | onfail="Failed to construct test variables" ) |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 77 | |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 78 | if gitPull == 'True': |
| 79 | main.step( "Building ONOS in " + gitBranch + " branch" ) |
| 80 | onosBuildResult = main.startUp.onosBuild( main, gitBranch ) |
| 81 | stepResult = onosBuildResult |
| 82 | utilities.assert_equals( expect=main.TRUE, |
| 83 | actual=stepResult, |
| 84 | onpass="Successfully compiled " + |
| 85 | "latest ONOS", |
| 86 | onfail="Failed to compile " + |
| 87 | "latest ONOS" ) |
| 88 | else: |
| 89 | main.log.warn( "Did not pull new code so skipping mvn " + |
| 90 | "clean install" ) |
kelvin-onlab | bf45682 | 2015-06-22 16:53:06 -0700 | [diff] [blame] | 91 | |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 92 | def CASE2( self, main ): |
| 93 | """ |
| 94 | - Set up cell |
| 95 | - Create cell file |
| 96 | - Set cell file |
| 97 | - Verify cell file |
| 98 | - Kill ONOS process |
| 99 | - Uninstall ONOS cluster |
| 100 | - Verify ONOS start up |
| 101 | - Install ONOS cluster |
| 102 | - Connect to cli |
| 103 | """ |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 104 | |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 105 | # main.scale[ 0 ] determines the current number of ONOS controller |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 106 | main.numCtrls = int( main.scale[ 0 ] ) |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 107 | |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 108 | main.case( "Starting up " + str( main.numCtrls ) + |
| 109 | " node(s) ONOS cluster" ) |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 110 | |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 111 | #kill off all onos processes |
| 112 | main.log.info( "Safety check, killing all ONOS processes" + |
Jon Hall | 70b2ff4 | 2015-11-17 15:49:44 -0800 | [diff] [blame^] | 113 | " before initiating environment setup" ) |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 114 | |
| 115 | for i in range( main.maxNodes ): |
| 116 | main.ONOSbench.onosDie( main.ONOSip[ i ] ) |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 117 | |
| 118 | print "NODE COUNT = ", main.numCtrls |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 119 | |
| 120 | tempOnosIp = [] |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 121 | for i in range( main.numCtrls ): |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 122 | tempOnosIp.append( main.ONOSip[i] ) |
| 123 | |
kelvin-onlab | d9e23de | 2015-08-06 10:34:44 -0700 | [diff] [blame] | 124 | main.ONOSbench.createCellFile( main.ONOSbench.ip_address, |
| 125 | "temp", |
| 126 | main.Mininet1.ip_address, |
| 127 | main.apps, |
| 128 | tempOnosIp ) |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 129 | |
| 130 | main.step( "Apply cell to environment" ) |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 131 | cellResult = main.ONOSbench.setCell( "temp" ) |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 132 | verifyResult = main.ONOSbench.verifyCell() |
| 133 | stepResult = cellResult and verifyResult |
| 134 | utilities.assert_equals( expect=main.TRUE, |
| 135 | actual=stepResult, |
| 136 | onpass="Successfully applied cell to " + \ |
| 137 | "environment", |
| 138 | onfail="Failed to apply cell to environment " ) |
| 139 | |
| 140 | main.step( "Creating ONOS package" ) |
| 141 | packageResult = main.ONOSbench.onosPackage() |
| 142 | stepResult = packageResult |
| 143 | utilities.assert_equals( expect=main.TRUE, |
| 144 | actual=stepResult, |
| 145 | onpass="Successfully created ONOS package", |
| 146 | onfail="Failed to create ONOS package" ) |
| 147 | |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 148 | time.sleep( main.startUpSleep ) |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 149 | main.step( "Uninstalling ONOS package" ) |
| 150 | onosUninstallResult = main.TRUE |
| 151 | for i in range( main.numCtrls ): |
| 152 | onosUninstallResult = onosUninstallResult and \ |
| 153 | main.ONOSbench.onosUninstall( nodeIp=main.ONOSip[ i ] ) |
| 154 | stepResult = onosUninstallResult |
| 155 | utilities.assert_equals( expect=main.TRUE, |
| 156 | actual=stepResult, |
| 157 | onpass="Successfully uninstalled ONOS package", |
| 158 | onfail="Failed to uninstall ONOS package" ) |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 159 | |
| 160 | time.sleep( main.startUpSleep ) |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 161 | main.step( "Installing ONOS package" ) |
| 162 | onosInstallResult = main.TRUE |
| 163 | for i in range( main.numCtrls ): |
| 164 | onosInstallResult = onosInstallResult and \ |
| 165 | main.ONOSbench.onosInstall( node=main.ONOSip[ i ] ) |
| 166 | stepResult = onosInstallResult |
| 167 | utilities.assert_equals( expect=main.TRUE, |
| 168 | actual=stepResult, |
| 169 | onpass="Successfully installed ONOS package", |
| 170 | onfail="Failed to install ONOS package" ) |
| 171 | |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 172 | time.sleep( main.startUpSleep ) |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 173 | main.step( "Starting ONOS service" ) |
| 174 | stopResult = main.TRUE |
| 175 | startResult = main.TRUE |
| 176 | onosIsUp = main.TRUE |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 177 | |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 178 | for i in range( main.numCtrls ): |
| 179 | onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] ) |
| 180 | if onosIsUp == main.TRUE: |
| 181 | main.log.report( "ONOS instance is up and ready" ) |
| 182 | else: |
| 183 | main.log.report( "ONOS instance may not be up, stop and " + |
| 184 | "start ONOS again " ) |
| 185 | for i in range( main.numCtrls ): |
| 186 | stopResult = stopResult and \ |
| 187 | main.ONOSbench.onosStop( main.ONOSip[ i ] ) |
| 188 | for i in range( main.numCtrls ): |
| 189 | startResult = startResult and \ |
| 190 | main.ONOSbench.onosStart( main.ONOSip[ i ] ) |
| 191 | stepResult = onosIsUp and stopResult and startResult |
| 192 | utilities.assert_equals( expect=main.TRUE, |
| 193 | actual=stepResult, |
| 194 | onpass="ONOS service is ready", |
| 195 | onfail="ONOS service did not start properly" ) |
kelvin-onlab | bf45682 | 2015-06-22 16:53:06 -0700 | [diff] [blame] | 196 | |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 197 | main.step( "Start ONOS cli" ) |
| 198 | cliResult = main.TRUE |
| 199 | for i in range( main.numCtrls ): |
| 200 | cliResult = cliResult and \ |
kelvin-onlab | bf45682 | 2015-06-22 16:53:06 -0700 | [diff] [blame] | 201 | main.CLIs[ i ].startOnosCli( main.ONOSip[ i ] ) |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 202 | stepResult = cliResult |
| 203 | utilities.assert_equals( expect=main.TRUE, |
| 204 | actual=stepResult, |
| 205 | onpass="Successfully start ONOS cli", |
| 206 | onfail="Failed to start ONOS cli" ) |
kelvin-onlab | bf45682 | 2015-06-22 16:53:06 -0700 | [diff] [blame] | 207 | |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 208 | # Remove the first element in main.scale list |
| 209 | main.scale.remove( main.scale[ 0 ] ) |
| 210 | |
kelvin-onlab | bf45682 | 2015-06-22 16:53:06 -0700 | [diff] [blame] | 211 | def CASE9( self, main ): |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 212 | ''' |
kelvin-onlab | bf45682 | 2015-06-22 16:53:06 -0700 | [diff] [blame] | 213 | Report errors/warnings/exceptions |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 214 | ''' |
kelvin-onlab | bf45682 | 2015-06-22 16:53:06 -0700 | [diff] [blame] | 215 | main.log.info("Error report: \n" ) |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 216 | main.ONOSbench.logReport( main.ONOSip[ 0 ], |
kelvin-onlab | bf45682 | 2015-06-22 16:53:06 -0700 | [diff] [blame] | 217 | [ "INFO", |
| 218 | "FOLLOWER", |
| 219 | "WARN", |
| 220 | "flow", |
| 221 | "ERROR", |
| 222 | "Except" ], |
| 223 | "s" ) |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 224 | |
| 225 | def CASE11( self, main ): |
| 226 | """ |
| 227 | Start mininet |
| 228 | """ |
| 229 | main.log.report( "Start Mininet topology" ) |
| 230 | main.log.case( "Start Mininet topology" ) |
| 231 | |
| 232 | main.step( "Starting Mininet Topology" ) |
| 233 | topoResult = main.Mininet1.startNet( topoFile=topology ) |
| 234 | stepResult = topoResult |
| 235 | utilities.assert_equals( expect=main.TRUE, |
| 236 | actual=stepResult, |
| 237 | onpass="Successfully loaded topology", |
| 238 | onfail="Failed to load topology" ) |
| 239 | # Exit if topology did not load properly |
| 240 | if not topoResult: |
| 241 | main.cleanup() |
| 242 | main.exit() |
| 243 | |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 244 | def CASE12( self, main ): |
| 245 | """ |
| 246 | Test random ONOS command |
| 247 | """ |
| 248 | |
| 249 | main.CLIs[ 0 ].startOnosCli( main.ONOSip[ 0 ] ) |
| 250 | print main.CLIs[ 0 ].leaders() |
| 251 | |