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