cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 1 | |
| 2 | # Testing the basic functionality of ONOS Next |
| 3 | # For sanity and driver functionality excercises only. |
| 4 | |
| 5 | import time |
| 6 | import json |
| 7 | |
| 8 | time.sleep( 1 ) |
| 9 | |
| 10 | class FuncStartTemplate: |
| 11 | |
| 12 | def __init__( self ): |
| 13 | self.default = '' |
| 14 | |
| 15 | def CASE10( self, main ): |
| 16 | import time |
| 17 | import os |
kelvin-onlab | bf45682 | 2015-06-22 16:53:06 -0700 | [diff] [blame] | 18 | import imp |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 19 | """ |
| 20 | Startup sequence: |
kelvin-onlab | bf45682 | 2015-06-22 16:53:06 -0700 | [diff] [blame] | 21 | git pull |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 22 | cell <name> |
| 23 | onos-verify-cell |
| 24 | onos-remove-raft-log |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 25 | mvn clean install |
| 26 | onos-package |
| 27 | onos-install -f |
| 28 | onos-wait-for-start |
| 29 | """ |
| 30 | global init |
| 31 | global globalONOSip |
| 32 | try: |
| 33 | if type(init) is not bool: |
| 34 | init = False |
| 35 | except NameError: |
| 36 | init = False |
| 37 | |
| 38 | #Local variables |
| 39 | cellName = main.params[ 'ENV' ][ 'cellName' ] |
| 40 | apps = main.params[ 'ENV' ][ 'cellApps' ] |
| 41 | gitBranch = main.params[ 'GIT' ][ 'branch' ] |
| 42 | benchIp = os.environ[ 'OCN' ] |
| 43 | benchUser = main.params[ 'BENCH' ][ 'user' ] |
| 44 | topology = main.params[ 'MININET' ][ 'topo' ] |
| 45 | main.numSwitch = int( main.params[ 'MININET' ][ 'switch' ] ) |
| 46 | main.numLinks = int( main.params[ 'MININET' ][ 'links' ] ) |
| 47 | main.numCtrls = main.params[ 'CTRL' ][ 'num' ] |
kelvin-onlab | bf45682 | 2015-06-22 16:53:06 -0700 | [diff] [blame] | 48 | main.ONOSport = [] |
| 49 | main.hostsData = {} |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 50 | PULLCODE = False |
| 51 | if main.params[ 'GIT' ][ 'pull' ] == 'True': |
| 52 | PULLCODE = True |
| 53 | main.case( "Setting up test environment" ) |
| 54 | main.CLIs = [] |
| 55 | for i in range( 1, int( main.numCtrls ) + 1 ): |
| 56 | main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) ) |
kelvin-onlab | bf45682 | 2015-06-22 16:53:06 -0700 | [diff] [blame] | 57 | main.ONOSport.append( main.params[ 'CTRL' ][ 'port' + str( i ) ] ) |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 58 | |
| 59 | # -- INIT SECTION, ONLY RUNS ONCE -- # |
| 60 | if init == False: |
| 61 | init = True |
| 62 | |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 63 | main.scale = ( main.params[ 'SCALE' ] ).split( "," ) |
| 64 | main.numCtrls = int( main.scale[ 0 ] ) |
| 65 | |
| 66 | if PULLCODE: |
| 67 | main.step( "Git checkout and pull " + gitBranch ) |
| 68 | main.ONOSbench.gitCheckout( gitBranch ) |
| 69 | gitPullResult = main.ONOSbench.gitPull() |
| 70 | if gitPullResult == main.ERROR: |
| 71 | main.log.error( "Error pulling git branch" ) |
| 72 | main.step( "Using mvn clean & install" ) |
| 73 | cleanInstallResult = main.ONOSbench.cleanInstall() |
| 74 | stepResult = cleanInstallResult |
| 75 | utilities.assert_equals( expect=main.TRUE, |
| 76 | actual=stepResult, |
| 77 | onpass="Successfully compiled " + |
| 78 | "latest ONOS", |
| 79 | onfail="Failed to compile " + |
| 80 | "latest ONOS" ) |
| 81 | else: |
| 82 | main.log.warn( "Did not pull new code so skipping mvn " + |
| 83 | "clean install" ) |
| 84 | |
| 85 | globalONOSip = main.ONOSbench.getOnosIps() |
kelvin-onlab | bf45682 | 2015-06-22 16:53:06 -0700 | [diff] [blame] | 86 | |
kelvin-onlab | 6ff9cdb | 2015-06-23 15:00:36 -0700 | [diff] [blame] | 87 | maxNodes = ( len( globalONOSip ) - 2 ) |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 88 | |
| 89 | main.numCtrls = int( main.scale[ 0 ] ) |
| 90 | main.scale.remove( main.scale[ 0 ] ) |
| 91 | |
| 92 | main.ONOSip = [] |
kelvin-onlab | bf45682 | 2015-06-22 16:53:06 -0700 | [diff] [blame] | 93 | for i in range( maxNodes ): |
| 94 | main.ONOSip.append( globalONOSip[ i ] ) |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 95 | |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 96 | #kill off all onos processes |
| 97 | main.log.info( "Safety check, killing all ONOS processes" + |
| 98 | " before initiating enviornment setup" ) |
kelvin-onlab | 6ff9cdb | 2015-06-23 15:00:36 -0700 | [diff] [blame] | 99 | for i in range( maxNodes ): |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 100 | main.ONOSbench.onosDie( globalONOSip[ i ] ) |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 101 | |
| 102 | print "NODE COUNT = ", main.numCtrls |
| 103 | main.log.info( "Creating cell file" ) |
| 104 | cellIp = [] |
| 105 | for i in range( main.numCtrls ): |
| 106 | cellIp.append( str( main.ONOSip[ i ] ) ) |
| 107 | print cellIp |
| 108 | main.ONOSbench.createCellFile( benchIp, cellName, "", |
| 109 | str( apps ), *cellIp ) |
| 110 | |
| 111 | main.step( "Apply cell to environment" ) |
| 112 | cellResult = main.ONOSbench.setCell( cellName ) |
| 113 | verifyResult = main.ONOSbench.verifyCell() |
| 114 | stepResult = cellResult and verifyResult |
| 115 | utilities.assert_equals( expect=main.TRUE, |
| 116 | actual=stepResult, |
| 117 | onpass="Successfully applied cell to " + \ |
| 118 | "environment", |
| 119 | onfail="Failed to apply cell to environment " ) |
| 120 | |
| 121 | main.step( "Creating ONOS package" ) |
| 122 | packageResult = main.ONOSbench.onosPackage() |
| 123 | stepResult = packageResult |
| 124 | utilities.assert_equals( expect=main.TRUE, |
| 125 | actual=stepResult, |
| 126 | onpass="Successfully created ONOS package", |
| 127 | onfail="Failed to create ONOS package" ) |
| 128 | |
| 129 | main.step( "Uninstalling ONOS package" ) |
| 130 | onosUninstallResult = main.TRUE |
| 131 | for i in range( main.numCtrls ): |
| 132 | onosUninstallResult = onosUninstallResult and \ |
| 133 | main.ONOSbench.onosUninstall( nodeIp=main.ONOSip[ i ] ) |
| 134 | stepResult = onosUninstallResult |
| 135 | utilities.assert_equals( expect=main.TRUE, |
| 136 | actual=stepResult, |
| 137 | onpass="Successfully uninstalled ONOS package", |
| 138 | onfail="Failed to uninstall ONOS package" ) |
| 139 | time.sleep( 5 ) |
| 140 | main.step( "Installing ONOS package" ) |
| 141 | onosInstallResult = main.TRUE |
| 142 | for i in range( main.numCtrls ): |
| 143 | onosInstallResult = onosInstallResult and \ |
| 144 | main.ONOSbench.onosInstall( node=main.ONOSip[ i ] ) |
| 145 | stepResult = onosInstallResult |
| 146 | utilities.assert_equals( expect=main.TRUE, |
| 147 | actual=stepResult, |
| 148 | onpass="Successfully installed ONOS package", |
| 149 | onfail="Failed to install ONOS package" ) |
| 150 | |
| 151 | time.sleep( 20 ) |
| 152 | main.step( "Starting ONOS service" ) |
| 153 | stopResult = main.TRUE |
| 154 | startResult = main.TRUE |
| 155 | onosIsUp = main.TRUE |
| 156 | for i in range( main.numCtrls ): |
| 157 | onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] ) |
| 158 | if onosIsUp == main.TRUE: |
| 159 | main.log.report( "ONOS instance is up and ready" ) |
| 160 | else: |
| 161 | main.log.report( "ONOS instance may not be up, stop and " + |
| 162 | "start ONOS again " ) |
| 163 | for i in range( main.numCtrls ): |
| 164 | stopResult = stopResult and \ |
| 165 | main.ONOSbench.onosStop( main.ONOSip[ i ] ) |
| 166 | for i in range( main.numCtrls ): |
| 167 | startResult = startResult and \ |
| 168 | main.ONOSbench.onosStart( main.ONOSip[ i ] ) |
| 169 | stepResult = onosIsUp and stopResult and startResult |
| 170 | utilities.assert_equals( expect=main.TRUE, |
| 171 | actual=stepResult, |
| 172 | onpass="ONOS service is ready", |
| 173 | onfail="ONOS service did not start properly" ) |
kelvin-onlab | bf45682 | 2015-06-22 16:53:06 -0700 | [diff] [blame] | 174 | |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 175 | main.step( "Start ONOS cli" ) |
| 176 | cliResult = main.TRUE |
| 177 | for i in range( main.numCtrls ): |
| 178 | cliResult = cliResult and \ |
kelvin-onlab | bf45682 | 2015-06-22 16:53:06 -0700 | [diff] [blame] | 179 | main.CLIs[ i ].startOnosCli( main.ONOSip[ i ] ) |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 180 | stepResult = cliResult |
| 181 | utilities.assert_equals( expect=main.TRUE, |
| 182 | actual=stepResult, |
| 183 | onpass="Successfully start ONOS cli", |
| 184 | onfail="Failed to start ONOS cli" ) |
kelvin-onlab | bf45682 | 2015-06-22 16:53:06 -0700 | [diff] [blame] | 185 | |
| 186 | def CASE9( self, main ): |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 187 | ''' |
kelvin-onlab | bf45682 | 2015-06-22 16:53:06 -0700 | [diff] [blame] | 188 | Report errors/warnings/exceptions |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 189 | ''' |
kelvin-onlab | bf45682 | 2015-06-22 16:53:06 -0700 | [diff] [blame] | 190 | main.log.info("Error report: \n" ) |
| 191 | main.ONOSbench.logReport( globalONOSip[ 0 ], |
| 192 | [ "INFO", |
| 193 | "FOLLOWER", |
| 194 | "WARN", |
| 195 | "flow", |
| 196 | "ERROR", |
| 197 | "Except" ], |
| 198 | "s" ) |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 199 | #main.ONOSbench.logReport( globalONOSip[1], [ "INFO" ], "d" ) |
| 200 | |
| 201 | def CASE11( self, main ): |
| 202 | """ |
| 203 | Start mininet |
| 204 | """ |
| 205 | main.log.report( "Start Mininet topology" ) |
| 206 | main.log.case( "Start Mininet topology" ) |
| 207 | |
| 208 | main.step( "Starting Mininet Topology" ) |
| 209 | topoResult = main.Mininet1.startNet( topoFile=topology ) |
| 210 | stepResult = topoResult |
| 211 | utilities.assert_equals( expect=main.TRUE, |
| 212 | actual=stepResult, |
| 213 | onpass="Successfully loaded topology", |
| 214 | onfail="Failed to load topology" ) |
| 215 | # Exit if topology did not load properly |
| 216 | if not topoResult: |
| 217 | main.cleanup() |
| 218 | main.exit() |
| 219 | |