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