Jon Hall | f1f285d | 2015-01-12 10:58:08 -0800 | [diff] [blame] | 1 | """ |
| 2 | Description: This test is an example of a simple single node ONOS test |
| 3 | |
| 4 | List of test cases: |
| 5 | CASE1: Compile ONOS and push it to the test machine |
| 6 | CASE2: Assign mastership to controller |
| 7 | CASE3: Pingall |
| 8 | """ |
| 9 | class PingallExample: |
| 10 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 11 | def __init__( self ): |
Jon Hall | f1f285d | 2015-01-12 10:58:08 -0800 | [diff] [blame] | 12 | self.default = '' |
| 13 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 14 | def CASE1( self, main ): |
Jon Hall | f1f285d | 2015-01-12 10:58:08 -0800 | [diff] [blame] | 15 | """ |
| 16 | CASE1 is to compile ONOS and push it to the test machines |
| 17 | |
| 18 | Startup sequence: |
| 19 | git pull |
| 20 | mvn clean install |
| 21 | onos-package |
| 22 | cell <name> |
| 23 | onos-verify-cell |
| 24 | onos-install -f |
| 25 | onos-wait-for-start |
| 26 | """ |
| 27 | desc = "ONOS Single node cluster restart HA test - initialization" |
| 28 | main.log.report( desc ) |
| 29 | main.case( "Setting up test environment" ) |
| 30 | |
| 31 | # load some vairables from the params file |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 32 | PULLCODE = False |
Jon Hall | f1f285d | 2015-01-12 10:58:08 -0800 | [diff] [blame] | 33 | if main.params[ 'Git' ] == 'True': |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 34 | PULLCODE = True |
| 35 | cellName = main.params[ 'ENV' ][ 'cellName' ] |
Jon Hall | f1f285d | 2015-01-12 10:58:08 -0800 | [diff] [blame] | 36 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 37 | ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ] |
Jon Hall | f1f285d | 2015-01-12 10:58:08 -0800 | [diff] [blame] | 38 | |
| 39 | main.step( "Applying cell variable to environment" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 40 | cellResult = main.ONOSbench.setCell( cellName ) |
| 41 | verifyResult = main.ONOSbench.verifyCell() |
Jon Hall | f1f285d | 2015-01-12 10:58:08 -0800 | [diff] [blame] | 42 | |
| 43 | main.log.report( "Uninstalling ONOS" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 44 | main.ONOSbench.onosUninstall( ONOS1Ip ) |
Jon Hall | f1f285d | 2015-01-12 10:58:08 -0800 | [diff] [blame] | 45 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 46 | cleanInstallResult = main.TRUE |
| 47 | gitPullResult = main.TRUE |
Jon Hall | f1f285d | 2015-01-12 10:58:08 -0800 | [diff] [blame] | 48 | |
| 49 | main.step( "Compiling the latest version of ONOS" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 50 | if PULLCODE: |
Jon Hall | f1f285d | 2015-01-12 10:58:08 -0800 | [diff] [blame] | 51 | main.step( "Git checkout and pull master" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 52 | main.ONOSbench.gitCheckout( "master" ) |
| 53 | gitPullResult = main.ONOSbench.gitPull() |
Jon Hall | f1f285d | 2015-01-12 10:58:08 -0800 | [diff] [blame] | 54 | |
| 55 | main.step( "Using mvn clean & install" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 56 | cleanInstallResult = main.TRUE |
| 57 | if gitPullResult == main.TRUE: |
| 58 | cleanInstallResult = main.ONOSbench.cleanInstall() |
Jon Hall | f1f285d | 2015-01-12 10:58:08 -0800 | [diff] [blame] | 59 | else: |
| 60 | main.log.warn( "Did not pull new code so skipping mvn " + |
| 61 | "clean install" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 62 | main.ONOSbench.getVersion( report=True ) |
Jon Hall | f1f285d | 2015-01-12 10:58:08 -0800 | [diff] [blame] | 63 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 64 | cellResult = main.ONOSbench.setCell( cellName ) |
| 65 | verifyResult = main.ONOSbench.verifyCell() |
Jon Hall | f1f285d | 2015-01-12 10:58:08 -0800 | [diff] [blame] | 66 | main.step( "Creating ONOS package" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 67 | packageResult = main.ONOSbench.onosPackage() |
Jon Hall | f1f285d | 2015-01-12 10:58:08 -0800 | [diff] [blame] | 68 | |
| 69 | main.step( "Installing ONOS package" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 70 | onos1InstallResult = main.ONOSbench.onosInstall( options="-f", |
| 71 | node=ONOS1Ip ) |
Jon Hall | f1f285d | 2015-01-12 10:58:08 -0800 | [diff] [blame] | 72 | |
| 73 | main.step( "Checking if ONOS is up yet" ) |
| 74 | for i in range( 2 ): |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 75 | onos1Isup = main.ONOSbench.isup( ONOS1Ip ) |
| 76 | if onos1Isup: |
Jon Hall | f1f285d | 2015-01-12 10:58:08 -0800 | [diff] [blame] | 77 | break |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 78 | if not onos1Isup: |
Jon Hall | f1f285d | 2015-01-12 10:58:08 -0800 | [diff] [blame] | 79 | main.log.report( "ONOS1 didn't start!" ) |
| 80 | |
| 81 | # TODO: if it becomes an issue, we can retry this step a few times |
| 82 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 83 | cliResult = main.ONOScli1.startOnosCli( ONOS1Ip ) |
Jon Hall | f1f285d | 2015-01-12 10:58:08 -0800 | [diff] [blame] | 84 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 85 | case1Result = ( cleanInstallResult and packageResult and |
| 86 | cellResult and verifyResult and |
| 87 | onos1InstallResult and |
| 88 | onos1Isup and cliResult ) |
Jon Hall | f1f285d | 2015-01-12 10:58:08 -0800 | [diff] [blame] | 89 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 90 | utilities.assert_equals( expect=main.TRUE, actual=case1Result, |
kelvin-onlab | a72405f | 2015-01-20 15:59:41 -0800 | [diff] [blame] | 91 | onpass="Test startup successful", |
| 92 | onfail="Test startup NOT successful" ) |
Jon Hall | f1f285d | 2015-01-12 10:58:08 -0800 | [diff] [blame] | 93 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 94 | if case1Result == main.FALSE: |
Jon Hall | f1f285d | 2015-01-12 10:58:08 -0800 | [diff] [blame] | 95 | main.cleanup() |
| 96 | main.exit() |
kelvin-onlab | 52730b5 | 2015-02-04 16:59:18 -0800 | [diff] [blame] | 97 | |
| 98 | # Starting the mininet using the old way |
| 99 | main.step( "Starting Mininet ..." ) |
| 100 | netIsUp = main.Mininet1.startNet() |
| 101 | if netIsUp: |
| 102 | main.log.info("Mininet CLI is up") |
| 103 | else: |
| 104 | main.log.info("Mininet CLI is down") |
Jon Hall | f1f285d | 2015-01-12 10:58:08 -0800 | [diff] [blame] | 105 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 106 | def CASE2( self, main ): |
Jon Hall | f1f285d | 2015-01-12 10:58:08 -0800 | [diff] [blame] | 107 | """ |
| 108 | Assign mastership to controller |
| 109 | """ |
| 110 | import re |
| 111 | |
| 112 | main.log.report( "Assigning switches to controller" ) |
| 113 | main.case( "Assigning Controller" ) |
| 114 | main.step( "Assign switches to controller" ) |
| 115 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 116 | ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ] |
| 117 | ONOS1Port = main.params[ 'CTRL' ][ 'port1' ] |
Jon Hall | f1f285d | 2015-01-12 10:58:08 -0800 | [diff] [blame] | 118 | |
| 119 | for i in range( 1, 14 ): |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 120 | main.Mininet1.assignSwController( |
Jon Hall | f1f285d | 2015-01-12 10:58:08 -0800 | [diff] [blame] | 121 | sw=str( i ), |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 122 | ip1=ONOS1Ip, |
| 123 | port1=ONOS1Port ) |
Jon Hall | f1f285d | 2015-01-12 10:58:08 -0800 | [diff] [blame] | 124 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 125 | mastershipCheck = main.TRUE |
Jon Hall | f1f285d | 2015-01-12 10:58:08 -0800 | [diff] [blame] | 126 | for i in range( 1, 14 ): |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 127 | response = main.Mininet1.getSwController( "s" + str( i ) ) |
Jon Hall | f1f285d | 2015-01-12 10:58:08 -0800 | [diff] [blame] | 128 | try: |
| 129 | main.log.info( str( response ) ) |
| 130 | except: |
| 131 | main.log.info( repr( response ) ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 132 | if re.search( "tcp:" + ONOS1Ip, response ): |
| 133 | mastershipCheck = mastershipCheck and main.TRUE |
Jon Hall | f1f285d | 2015-01-12 10:58:08 -0800 | [diff] [blame] | 134 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 135 | mastershipCheck = main.FALSE |
| 136 | if mastershipCheck == main.TRUE: |
Jon Hall | f1f285d | 2015-01-12 10:58:08 -0800 | [diff] [blame] | 137 | main.log.report( "Switch mastership assigned correctly" ) |
| 138 | utilities.assert_equals( |
| 139 | expect=main.TRUE, |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 140 | actual=mastershipCheck, |
Jon Hall | f1f285d | 2015-01-12 10:58:08 -0800 | [diff] [blame] | 141 | onpass="Switch mastership assigned correctly", |
| 142 | onfail="Switches not assigned correctly to controllers" ) |
| 143 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 144 | def CASE3( self, main ): |
Jon Hall | f1f285d | 2015-01-12 10:58:08 -0800 | [diff] [blame] | 145 | """ |
| 146 | Assign intents |
| 147 | """ |
| 148 | import time |
| 149 | |
| 150 | main.log.report( "Run Pingall" ) |
| 151 | main.case( "Run Pingall" ) |
| 152 | |
| 153 | # install onos-app-fwd |
| 154 | main.log.info( "Install reactive forwarding app" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 155 | main.ONOScli1.featureInstall( "onos-app-fwd" ) |
Jon Hall | f1f285d | 2015-01-12 10:58:08 -0800 | [diff] [blame] | 156 | |
| 157 | # REACTIVE FWD test |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 158 | pingResult = main.FALSE |
Jon Hall | f1f285d | 2015-01-12 10:58:08 -0800 | [diff] [blame] | 159 | time1 = time.time() |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 160 | pingResult = main.Mininet1.pingall() |
Jon Hall | f1f285d | 2015-01-12 10:58:08 -0800 | [diff] [blame] | 161 | time2 = time.time() |
| 162 | main.log.info( "Time for pingall: %2f seconds" % ( time2 - time1 ) ) |
| 163 | |
| 164 | # uninstall onos-app-fwd |
| 165 | main.log.info( "Uninstall reactive forwarding app" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 166 | main.ONOScli1.featureUninstall( "onos-app-fwd" ) |
Jon Hall | f1f285d | 2015-01-12 10:58:08 -0800 | [diff] [blame] | 167 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 168 | utilities.assert_equals( expect=main.TRUE, actual=pingResult, |
kelvin-onlab | a72405f | 2015-01-20 15:59:41 -0800 | [diff] [blame] | 169 | onpass="All hosts are reachable", |
| 170 | onfail="Some pings failed" ) |