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