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