Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2 | Description: This test is to determine if a single |
| 3 | instance ONOS 'cluster' can handle a restart |
| 4 | |
| 5 | List of test cases: |
| 6 | CASE1: Compile ONOS and push it to the test machines |
| 7 | CASE2: Assign mastership to controllers |
| 8 | CASE3: Assign intents |
| 9 | CASE4: Ping across added host intents |
| 10 | CASE5: Reading state of ONOS |
| 11 | CASE6: The Failure case. Since this is the Sanity test, we do nothing. |
| 12 | CASE7: Check state after control plane failure |
| 13 | CASE8: Compare topo |
| 14 | CASE9: Link s3-s28 down |
| 15 | CASE10: Link s3-s28 up |
| 16 | CASE11: Switch down |
| 17 | CASE12: Switch up |
| 18 | CASE13: Clean up |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 19 | CASE14: start election app on all onos nodes |
| 20 | CASE15: Check that Leadership Election is still functional |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 21 | """ |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 22 | |
| 23 | |
Jon Hall | 48cf3ce | 2015-01-12 15:43:18 -0800 | [diff] [blame] | 24 | class HATestSingleInstanceRestart: |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 25 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 26 | def __init__( self ): |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 27 | self.default = '' |
| 28 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 29 | def CASE1( self, main ): |
| 30 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 31 | CASE1 is to compile ONOS and push it to the test machines |
| 32 | |
| 33 | Startup sequence: |
| 34 | git pull |
| 35 | mvn clean install |
| 36 | onos-package |
| 37 | cell <name> |
| 38 | onos-verify-cell |
| 39 | NOTE: temporary - onos-remove-raft-logs |
| 40 | onos-install -f |
| 41 | onos-wait-for-start |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 42 | """ |
| 43 | main.log.report( "ONOS Single node cluster restart " + |
| 44 | "HA test - initialization" ) |
| 45 | main.case( "Setting up test environment" ) |
| 46 | # TODO: save all the timers and output them for plotting |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 47 | |
| 48 | # load some vairables from the params file |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 49 | PULLCODE = False |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 50 | if main.params[ 'Git' ] == 'True': |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 51 | PULLCODE = True |
Jon Hall | 529a37f | 2015-01-28 10:02:00 -0800 | [diff] [blame] | 52 | gitBranch = main.params[ 'branch' ] |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 53 | cellName = main.params[ 'ENV' ][ 'cellName' ] |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 54 | |
| 55 | # set global variables |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 56 | global ONOS1Ip |
| 57 | global ONOS1Port |
| 58 | global ONOS2Ip |
| 59 | global ONOS2Port |
| 60 | global ONOS3Ip |
| 61 | global ONOS3Port |
| 62 | global ONOS4Ip |
| 63 | global ONOS4Port |
| 64 | global ONOS5Ip |
| 65 | global ONOS5Port |
| 66 | global ONOS6Ip |
| 67 | global ONOS6Port |
| 68 | global ONOS7Ip |
| 69 | global ONOS7Port |
| 70 | global numControllers |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 71 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 72 | ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ] |
| 73 | ONOS1Port = main.params[ 'CTRL' ][ 'port1' ] |
| 74 | ONOS2Ip = main.params[ 'CTRL' ][ 'ip2' ] |
| 75 | ONOS2Port = main.params[ 'CTRL' ][ 'port2' ] |
| 76 | ONOS3Ip = main.params[ 'CTRL' ][ 'ip3' ] |
| 77 | ONOS3Port = main.params[ 'CTRL' ][ 'port3' ] |
| 78 | ONOS4Ip = main.params[ 'CTRL' ][ 'ip4' ] |
| 79 | ONOS4Port = main.params[ 'CTRL' ][ 'port4' ] |
| 80 | ONOS5Ip = main.params[ 'CTRL' ][ 'ip5' ] |
| 81 | ONOS5Port = main.params[ 'CTRL' ][ 'port5' ] |
| 82 | ONOS6Ip = main.params[ 'CTRL' ][ 'ip6' ] |
| 83 | ONOS6Port = main.params[ 'CTRL' ][ 'port6' ] |
| 84 | ONOS7Ip = main.params[ 'CTRL' ][ 'ip7' ] |
| 85 | ONOS7Port = main.params[ 'CTRL' ][ 'port7' ] |
| 86 | numControllers = int( main.params[ 'num_controllers' ] ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 87 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 88 | main.step( "Applying cell variable to environment" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 89 | cellResult = main.ONOSbench.setCell( cellName ) |
| 90 | verifyResult = main.ONOSbench.verifyCell() |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 91 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 92 | # FIXME:this is short term fix |
| 93 | main.log.report( "Removing raft logs" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 94 | main.ONOSbench.onosRemoveRaftLogs() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 95 | main.log.report( "Uninstalling ONOS" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 96 | main.ONOSbench.onosUninstall( ONOS1Ip ) |
| 97 | main.ONOSbench.onosUninstall( ONOS2Ip ) |
| 98 | main.ONOSbench.onosUninstall( ONOS3Ip ) |
| 99 | main.ONOSbench.onosUninstall( ONOS4Ip ) |
| 100 | main.ONOSbench.onosUninstall( ONOS5Ip ) |
| 101 | main.ONOSbench.onosUninstall( ONOS6Ip ) |
| 102 | main.ONOSbench.onosUninstall( ONOS7Ip ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 103 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 104 | cleanInstallResult = main.TRUE |
| 105 | gitPullResult = main.TRUE |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 106 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 107 | main.step( "Compiling the latest version of ONOS" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 108 | if PULLCODE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 109 | # TODO Configure branch in params |
| 110 | main.step( "Git checkout and pull master" ) |
Jon Hall | 529a37f | 2015-01-28 10:02:00 -0800 | [diff] [blame] | 111 | main.ONOSbench.gitCheckout( gitBranch ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 112 | gitPullResult = main.ONOSbench.gitPull() |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 113 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 114 | main.step( "Using mvn clean & install" ) |
Jon Hall | 529a37f | 2015-01-28 10:02:00 -0800 | [diff] [blame] | 115 | cleanInstallResult = main.ONOSbench.cleanInstall() |
| 116 | else: |
| 117 | main.log.warn( "Did not pull new code so skipping mvn " + |
| 118 | "clean install" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 119 | main.ONOSbench.getVersion( report=True ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 120 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 121 | cellResult = main.ONOSbench.setCell( "SingleHA" ) |
| 122 | verifyResult = main.ONOSbench.verifyCell() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 123 | main.step( "Creating ONOS package" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 124 | packageResult = main.ONOSbench.onosPackage() |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 125 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 126 | main.step( "Installing ONOS package" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 127 | onos1InstallResult = main.ONOSbench.onosInstall( options="-f", |
| 128 | node=ONOS1Ip ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 129 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 130 | main.step( "Checking if ONOS is up yet" ) |
| 131 | # TODO check bundle:list? |
| 132 | for i in range( 2 ): |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 133 | onos1Isup = main.ONOSbench.isup( ONOS1Ip ) |
| 134 | if onos1Isup: |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 135 | break |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 136 | if not onos1Isup: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 137 | main.log.report( "ONOS1 didn't start!" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 138 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 139 | cliResult = main.ONOScli1.startOnosCli( ONOS1Ip ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 140 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 141 | main.step( "Start Packet Capture MN" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 142 | main.Mininet2.startTcpdump( |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 143 | str( main.params[ 'MNtcpdump' ][ 'folder' ] ) + str( main.TEST ) |
| 144 | + "-MN.pcap", |
| 145 | intf=main.params[ 'MNtcpdump' ][ 'intf' ], |
| 146 | port=main.params[ 'MNtcpdump' ][ 'port' ] ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 147 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 148 | case1Result = ( cleanInstallResult and packageResult and |
| 149 | cellResult and verifyResult and onos1InstallResult |
| 150 | and onos1Isup and cliResult ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 151 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 152 | utilities.assert_equals( expect=main.TRUE, actual=case1Result, |
| 153 | onpass="Test startup successful", |
| 154 | onfail="Test startup NOT successful" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 155 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 156 | if case1Result == main.FALSE: |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 157 | main.cleanup() |
| 158 | main.exit() |
| 159 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 160 | def CASE2( self, main ): |
| 161 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 162 | Assign mastership to controllers |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 163 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 164 | import re |
| 165 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 166 | main.log.report( "Assigning switches to controllers" ) |
| 167 | main.case( "Assigning Controllers" ) |
| 168 | main.step( "Assign switches to controllers" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 169 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 170 | for i in range( 1, 29 ): |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 171 | main.Mininet1.assignSwController( |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 172 | sw=str( i ), |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 173 | ip1=ONOS1Ip, port1=ONOS1Port ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 174 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 175 | mastershipCheck = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 176 | for i in range( 1, 29 ): |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 177 | response = main.Mininet1.getSwController( "s" + str( i ) ) |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 178 | try: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 179 | main.log.info( str( response ) ) |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 180 | except: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 181 | main.log.info( repr( response ) ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 182 | if re.search( "tcp:" + ONOS1Ip, response ): |
| 183 | mastershipCheck = mastershipCheck and main.TRUE |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 184 | else: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 185 | mastershipCheck = main.FALSE |
| 186 | if mastershipCheck == main.TRUE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 187 | main.log.report( "Switch mastership assigned correctly" ) |
| 188 | utilities.assert_equals( |
| 189 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 190 | actual=mastershipCheck, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 191 | onpass="Switch mastership assigned correctly", |
| 192 | onfail="Switches not assigned correctly to controllers" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 193 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 194 | def CASE3( self, main ): |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 195 | """ |
| 196 | Assign intents |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 197 | """ |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 198 | # FIXME: we must reinstall intents until we have a persistant |
| 199 | # datastore! |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 200 | import time |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 201 | main.log.report( "Adding host intents" ) |
| 202 | main.case( "Adding host Intents" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 203 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 204 | main.step( "Discovering Hosts( Via pingall for now )" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 205 | # FIXME: Once we have a host discovery mechanism, use that instead |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 206 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 207 | # install onos-app-fwd |
| 208 | main.log.info( "Install reactive forwarding app" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 209 | main.ONOScli1.featureInstall( "onos-app-fwd" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 210 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 211 | # REACTIVE FWD test |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 212 | pingResult = main.FALSE |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 213 | time1 = time.time() |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 214 | pingResult = main.Mininet1.pingall() |
Jon Hall | 529a37f | 2015-01-28 10:02:00 -0800 | [diff] [blame] | 215 | utilities.assert_equals( |
| 216 | expect=main.TRUE, |
| 217 | actual=pingResult, |
| 218 | onpass="Reactive Pingall test passed", |
| 219 | onfail="Reactive Pingall failed, one or more ping pairs failed" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 220 | time2 = time.time() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 221 | main.log.info( "Time for pingall: %2f seconds" % ( time2 - time1 ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 222 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 223 | # uninstall onos-app-fwd |
| 224 | main.log.info( "Uninstall reactive forwarding app" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 225 | main.ONOScli1.featureUninstall( "onos-app-fwd" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 226 | # timeout for fwd flows |
| 227 | time.sleep( 10 ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 228 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 229 | main.step( "Add host intents" ) |
| 230 | # TODO: move the host numbers to params |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 231 | intentAddResult = True |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 232 | for i in range( 8, 18 ): |
| 233 | main.log.info( "Adding host intent between h" + str( i ) + |
| 234 | " and h" + str( i + 10 ) ) |
| 235 | host1 = "00:00:00:00:00:" + \ |
| 236 | str( hex( i )[ 2: ] ).zfill( 2 ).upper() |
| 237 | host2 = "00:00:00:00:00:" + \ |
| 238 | str( hex( i + 10 )[ 2: ] ).zfill( 2 ).upper() |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 239 | host1Id = main.ONOScli1.getHost( host1 )[ 'id' ] |
| 240 | host2Id = main.ONOScli1.getHost( host2 )[ 'id' ] |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 241 | # NOTE: get host can return None |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 242 | if host1Id and host2Id: |
| 243 | tmpResult = main.ONOScli1.addHostIntent( |
| 244 | host1Id, |
| 245 | host2Id ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 246 | else: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 247 | main.log.error( "Error, getHost() failed" ) |
| 248 | tmpResult = main.FALSE |
| 249 | intentAddResult = bool( pingResult and intentAddResult |
| 250 | and tmpResult ) |
Jon Hall | 529a37f | 2015-01-28 10:02:00 -0800 | [diff] [blame] | 251 | # TODO Check that intents were added? |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 252 | utilities.assert_equals( |
| 253 | expect=True, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 254 | actual=intentAddResult, |
Jon Hall | 529a37f | 2015-01-28 10:02:00 -0800 | [diff] [blame] | 255 | onpass="Pushed host intents to ONOS", |
| 256 | onfail="Error in pushing host intents to ONOS" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 257 | # TODO Check if intents all exist in datastore |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 258 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 259 | def CASE4( self, main ): |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 260 | """ |
| 261 | Ping across added host intents |
| 262 | """ |
| 263 | description = " Ping across added host intents" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 264 | main.log.report( description ) |
| 265 | main.case( description ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 266 | PingResult = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 267 | for i in range( 8, 18 ): |
| 268 | ping = main.Mininet1.pingHost( |
| 269 | src="h" + str( i ), target="h" + str( i + 10 ) ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 270 | PingResult = PingResult and ping |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 271 | if ping == main.FALSE: |
| 272 | main.log.warn( "Ping failed between h" + str( i ) + |
| 273 | " and h" + str( i + 10 ) ) |
| 274 | elif ping == main.TRUE: |
| 275 | main.log.info( "Ping test passed!" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 276 | PingResult = main.TRUE |
| 277 | if PingResult == main.FALSE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 278 | main.log.report( |
| 279 | "Intents have not been installed correctly, pings failed." ) |
Jon Hall | 529a37f | 2015-01-28 10:02:00 -0800 | [diff] [blame] | 280 | #TODO: pretty print |
| 281 | main.log.warn( "ONSO1 intents: " ) |
| 282 | main.log.warn( json.dumps( json.loads( main.ONOScli1.intents() ), |
| 283 | sort_keys=True, |
| 284 | indent=4, |
| 285 | separators=( ',', ': ' ) ) ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 286 | if PingResult == main.TRUE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 287 | main.log.report( |
| 288 | "Intents have been installed correctly and verified by pings" ) |
| 289 | utilities.assert_equals( |
| 290 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 291 | actual=PingResult, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 292 | onpass="Intents have been installed correctly and pings work", |
| 293 | onfail="Intents have not been installed correctly, pings failed." ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 294 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 295 | def CASE5( self, main ): |
| 296 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 297 | Reading state of ONOS |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 298 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 299 | import json |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 300 | # assumes that sts is already in you PYTHONPATH |
| 301 | from sts.topology.teston_topology import TestONTopology |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 302 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 303 | main.log.report( "Setting up and gathering data for current state" ) |
| 304 | main.case( "Setting up and gathering data for current state" ) |
| 305 | # The general idea for this test case is to pull the state of |
| 306 | # ( intents,flows, topology,... ) from each ONOS node |
| 307 | # We can then compare them with eachother and also with past states |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 308 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 309 | main.step( "Get the Mastership of each switch from each controller" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 310 | global mastershipState |
| 311 | mastershipState = [] |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 312 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 313 | # Assert that each device has a master |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 314 | rolesNotNull = main.ONOScli1.rolesNotNull() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 315 | utilities.assert_equals( |
| 316 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 317 | actual=rolesNotNull, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 318 | onpass="Each device has a master", |
| 319 | onfail="Some devices don't have a master assigned" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 320 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 321 | ONOS1Mastership = main.ONOScli1.roles() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 322 | # TODO: Make this a meaningful check |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 323 | if "Error" in ONOS1Mastership or not ONOS1Mastership: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 324 | main.log.report( "Error in getting ONOS roles" ) |
| 325 | main.log.warn( |
| 326 | "ONOS1 mastership response: " + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 327 | repr( ONOS1Mastership ) ) |
| 328 | consistentMastership = main.FALSE |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 329 | else: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 330 | mastershipState = ONOS1Mastership |
| 331 | consistentMastership = main.TRUE |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 332 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 333 | main.step( "Get the intents from each controller" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 334 | global intentState |
| 335 | intentState = [] |
| 336 | ONOS1Intents = main.ONOScli1.intents( jsonFormat=True ) |
| 337 | intentCheck = main.FALSE |
| 338 | if "Error" in ONOS1Intents or not ONOS1Intents: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 339 | main.log.report( "Error in getting ONOS intents" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 340 | main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 341 | else: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 342 | intentCheck = main.TRUE |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 343 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 344 | main.step( "Get the flows from each controller" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 345 | global flowState |
| 346 | flowState = [] |
| 347 | ONOS1Flows = main.ONOScli1.flows( jsonFormat=True ) |
| 348 | flowCheck = main.FALSE |
| 349 | if "Error" in ONOS1Flows or not ONOS1Flows: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 350 | main.log.report( "Error in getting ONOS intents" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 351 | main.log.warn( "ONOS1 flows repsponse: " + ONOS1Flows ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 352 | else: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 353 | # TODO: Do a better check, maybe compare flows on switches? |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 354 | flowState = ONOS1Flows |
| 355 | flowCheck = main.TRUE |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 356 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 357 | main.step( "Get the OF Table entries" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 358 | global flows |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 359 | flows = [] |
| 360 | for i in range( 1, 29 ): |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 361 | flows.append( main.Mininet2.getFlowTable( 1.3, "s" + str( i ) ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 362 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 363 | # TODO: Compare switch flow tables with ONOS flow tables |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 364 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 365 | main.step( "Create TestONTopology object" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 366 | ctrls = [] |
| 367 | count = 1 |
| 368 | temp = () |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 369 | temp = temp + ( getattr( main, ( 'ONOS' + str( count ) ) ), ) |
| 370 | temp = temp + ( "ONOS" + str( count ), ) |
| 371 | temp = temp + ( main.params[ 'CTRL' ][ 'ip' + str( count ) ], ) |
| 372 | temp = temp + \ |
| 373 | ( eval( main.params[ 'CTRL' ][ 'port' + str( count ) ] ), ) |
| 374 | ctrls.append( temp ) |
| 375 | MNTopo = TestONTopology( |
| 376 | main.Mininet1, |
| 377 | ctrls ) # can also add Intent API info for intent operations |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 378 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 379 | main.step( "Collecting topology information from ONOS" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 380 | devices = [] |
| 381 | devices.append( main.ONOScli1.devices() ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 382 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 383 | hosts = [] |
| 384 | hosts.append( main.ONOScli1.hosts() ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 385 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 386 | ports = [] |
| 387 | ports.append( main.ONOScli1.ports() ) |
| 388 | links = [] |
| 389 | links.append( main.ONOScli1.links() ) |
| 390 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 391 | main.step( "Comparing ONOS topology to MN" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 392 | devicesResults = main.TRUE |
| 393 | portsResults = main.TRUE |
| 394 | linksResults = main.TRUE |
| 395 | for controller in range( numControllers ): |
| 396 | controllerStr = str( controller + 1 ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 397 | if devices[ controller ] or "Error" not in devices[ controller ]: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 398 | currentDevicesResult = main.Mininet1.compareSwitches( |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 399 | MNTopo, |
| 400 | json.loads( |
| 401 | devices[ controller ] ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 402 | else: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 403 | currentDevicesResult = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 404 | utilities.assert_equals( expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 405 | actual=currentDevicesResult, |
| 406 | onpass="ONOS" + controllerStr + |
| 407 | " Switches view is correct", |
| 408 | onfail="ONOS" + controllerStr + |
| 409 | " Switches view is incorrect" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 410 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 411 | if ports[ controller ] or "Error" not in ports[ controller ]: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 412 | currentPortsResult = main.Mininet1.comparePorts( |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 413 | MNTopo, |
| 414 | json.loads( |
| 415 | ports[ controller ] ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 416 | else: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 417 | currentPortsResult = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 418 | utilities.assert_equals( expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 419 | actual=currentPortsResult, |
| 420 | onpass="ONOS" + controllerStr + |
| 421 | " ports view is correct", |
| 422 | onfail="ONOS" + controllerStr + |
| 423 | " ports view is incorrect" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 424 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 425 | if links[ controller ] or "Error" not in links[ controller ]: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 426 | currentLinksResult = main.Mininet1.compareLinks( |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 427 | MNTopo, |
| 428 | json.loads( |
| 429 | links[ controller ] ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 430 | else: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 431 | currentLinksResult = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 432 | utilities.assert_equals( expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 433 | actual=currentLinksResult, |
| 434 | onpass="ONOS" + controllerStr + |
| 435 | " links view is correct", |
| 436 | onfail="ONOS" + controllerStr + |
| 437 | " links view is incorrect" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 438 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 439 | devicesResults = devicesResults and currentDevicesResult |
| 440 | portsResults = portsResults and currentPortsResult |
| 441 | linksResults = linksResults and currentLinksResult |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 442 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 443 | topoResult = devicesResults and portsResults and linksResults |
| 444 | utilities.assert_equals( expect=main.TRUE, actual=topoResult, |
| 445 | onpass="Topology Check Test successful", |
| 446 | onfail="Topology Check Test NOT successful" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 447 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 448 | finalAssert = main.TRUE |
| 449 | finalAssert = finalAssert and topoResult and flowCheck \ |
| 450 | and intentCheck and consistentMastership and rolesNotNull |
| 451 | utilities.assert_equals( expect=main.TRUE, actual=finalAssert, |
| 452 | onpass="State check successful", |
| 453 | onfail="State check NOT successful" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 454 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 455 | def CASE6( self, main ): |
| 456 | """ |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 457 | The Failure case. |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 458 | """ |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 459 | import time |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 460 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 461 | main.log.report( "Restart ONOS node" ) |
| 462 | main.log.case( "Restart ONOS node" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 463 | main.ONOSbench.onosKill( ONOS1Ip ) |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 464 | start = time.time() |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 465 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 466 | main.step( "Checking if ONOS is up yet" ) |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 467 | count = 0 |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 468 | while count < 10: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 469 | onos1Isup = main.ONOSbench.isup( ONOS1Ip ) |
| 470 | if onos1Isup == main.TRUE: |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 471 | elapsed = time.time() - start |
| 472 | break |
| 473 | else: |
| 474 | count = count + 1 |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 475 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 476 | cliResult = main.ONOScli1.startOnosCli( ONOS1Ip ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 477 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 478 | caseResults = main.TRUE and onos1Isup and cliResult |
| 479 | utilities.assert_equals( expect=main.TRUE, actual=caseResults, |
| 480 | onpass="ONOS restart successful", |
| 481 | onfail="ONOS restart NOT successful" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 482 | main.log.info( |
| 483 | "ESTIMATE: ONOS took %s seconds to restart" % |
| 484 | str( elapsed ) ) |
| 485 | time.sleep( 5 ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 486 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 487 | def CASE7( self, main ): |
| 488 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 489 | Check state after ONOS failure |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 490 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 491 | import json |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 492 | main.case( "Running ONOS Constant State Tests" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 493 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 494 | # Assert that each device has a master |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 495 | rolesNotNull = main.ONOScli1.rolesNotNull() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 496 | utilities.assert_equals( |
| 497 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 498 | actual=rolesNotNull, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 499 | onpass="Each device has a master", |
| 500 | onfail="Some devices don't have a master assigned" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 501 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 502 | main.step( "Check if switch roles are consistent across all nodes" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 503 | ONOS1Mastership = main.ONOScli1.roles() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 504 | # FIXME: Refactor this whole case for single instance |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 505 | if "Error" in ONOS1Mastership or not ONOS1Mastership: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 506 | main.log.report( "Error in getting ONOS mastership" ) |
| 507 | main.log.warn( |
| 508 | "ONOS1 mastership response: " + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 509 | repr( ONOS1Mastership ) ) |
| 510 | consistentMastership = main.FALSE |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 511 | else: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 512 | consistentMastership = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 513 | main.log.report( |
| 514 | "Switch roles are consistent across all ONOS nodes" ) |
| 515 | utilities.assert_equals( |
| 516 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 517 | actual=consistentMastership, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 518 | onpass="Switch roles are consistent across all ONOS nodes", |
| 519 | onfail="ONOS nodes have different views of switch roles" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 520 | |
| 521 | description2 = "Compare switch roles from before failure" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 522 | main.step( description2 ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 523 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 524 | currentJson = json.loads( ONOS1Mastership ) |
| 525 | oldJson = json.loads( mastershipState ) |
| 526 | mastershipCheck = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 527 | for i in range( 1, 29 ): |
| 528 | switchDPID = str( |
| 529 | main.Mininet1.getSwitchDPID( |
| 530 | switch="s" + |
| 531 | str( i ) ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 532 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 533 | current = [ switch[ 'master' ] for switch in currentJson |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 534 | if switchDPID in switch[ 'id' ] ] |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 535 | old = [ switch[ 'master' ] for switch in oldJson |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 536 | if switchDPID in switch[ 'id' ] ] |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 537 | if current == old: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 538 | mastershipCheck = mastershipCheck and main.TRUE |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 539 | else: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 540 | main.log.warn( "Mastership of switch %s changed" % switchDPID ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 541 | mastershipCheck = main.FALSE |
| 542 | if mastershipCheck == main.TRUE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 543 | main.log.report( "Mastership of Switches was not changed" ) |
| 544 | utilities.assert_equals( |
| 545 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 546 | actual=mastershipCheck, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 547 | onpass="Mastership of Switches was not changed", |
| 548 | onfail="Mastership of some switches changed" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 549 | mastershipCheck = mastershipCheck and consistentMastership |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 550 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 551 | main.step( "Get the intents and compare across all nodes" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 552 | ONOS1Intents = main.ONOScli1.intents( jsonFormat=True ) |
| 553 | intentCheck = main.FALSE |
| 554 | if "Error" in ONOS1Intents or not ONOS1Intents: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 555 | main.log.report( "Error in getting ONOS intents" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 556 | main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 557 | else: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 558 | intentCheck = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 559 | main.log.report( "Intents are consistent across all ONOS nodes" ) |
| 560 | utilities.assert_equals( |
| 561 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 562 | actual=intentCheck, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 563 | onpass="Intents are consistent across all ONOS nodes", |
| 564 | onfail="ONOS nodes have different views of intents" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 565 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 566 | # NOTE: Hazelcast has no durability, so intents are lost across system |
| 567 | # restarts |
| 568 | """ |
| 569 | main.step( "Compare current intents with intents before the failure" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 570 | # NOTE: this requires case 5 to pass for intentState to be set. |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 571 | # maybe we should stop the test if that fails? |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 572 | if intentState == ONOS1Intents: |
| 573 | sameIntents = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 574 | main.log.report( "Intents are consistent with before failure" ) |
| 575 | # TODO: possibly the states have changed? we may need to figure out |
| 576 | # what the aceptable states are |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 577 | else: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 578 | try: |
| 579 | main.log.warn( "ONOS1 intents: " ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 580 | print json.dumps( json.loads( ONOS1Intents ), |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 581 | sort_keys=True, indent=4, |
| 582 | separators=( ',', ': ' ) ) |
| 583 | except: |
| 584 | pass |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 585 | sameIntents = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 586 | utilities.assert_equals( |
| 587 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 588 | actual=sameIntents, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 589 | onpass="Intents are consistent with before failure", |
| 590 | onfail="The Intents changed during failure" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 591 | intentCheck = intentCheck and sameIntents |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 592 | """ |
| 593 | main.step( "Get the OF Table entries and compare to before " + |
| 594 | "component failure" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 595 | FlowTables = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 596 | flows2 = [] |
| 597 | for i in range( 28 ): |
| 598 | main.log.info( "Checking flow table on s" + str( i + 1 ) ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 599 | tmpFlows = main.Mininet2.getFlowTable( 1.3, "s" + str( i + 1 ) ) |
| 600 | flows2.append( tmpFlows ) |
| 601 | tempResult = main.Mininet2.flowComp( |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 602 | flow1=flows[ i ], |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 603 | flow2=tmpFlows ) |
| 604 | FlowTables = FlowTables and tempResult |
| 605 | if FlowTables == main.FALSE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 606 | main.log.info( "Differences in flow table for switch: s" + |
| 607 | str( i + 1 ) ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 608 | if FlowTables == main.TRUE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 609 | main.log.report( "No changes were found in the flow tables" ) |
| 610 | utilities.assert_equals( |
| 611 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 612 | actual=FlowTables, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 613 | onpass="No changes were found in the flow tables", |
| 614 | onfail="Changes were found in the flow tables" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 615 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 616 | # Test of LeadershipElection |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 617 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 618 | leader = ONOS1Ip |
| 619 | leaderResult = main.TRUE |
| 620 | for controller in range( 1, numControllers + 1 ): |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 621 | # loop through ONOScli handlers |
| 622 | node = getattr( main, ( 'ONOScli' + str( controller ) ) ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 623 | leaderN = node.electionTestLeader() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 624 | # verify leader is ONOS1 |
| 625 | # NOTE even though we restarted ONOS, it is the only one so onos 1 |
| 626 | # must be leader |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 627 | if leaderN == leader: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 628 | # all is well |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 629 | pass |
| 630 | elif leaderN == main.FALSE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 631 | # error in response |
| 632 | main.log.report( "Something is wrong with " + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 633 | "electionTestLeader function, check the" + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 634 | " error logs" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 635 | leaderResult = main.FALSE |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 636 | elif leader != leaderN: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 637 | leaderResult = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 638 | main.log.report( "ONOS" + str( controller ) + |
| 639 | " sees " + str( leaderN ) + |
| 640 | " as the leader of the election app." + |
| 641 | " Leader should be " + str( leader ) ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 642 | if leaderResult: |
| 643 | main.log.report( "Leadership election tests passed( consistent " + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 644 | "view of leader across listeners and a new " + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 645 | "leader was re-elected if applicable )" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 646 | utilities.assert_equals( |
| 647 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 648 | actual=leaderResult, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 649 | onpass="Leadership election passed", |
| 650 | onfail="Something went wrong with Leadership election" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 651 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 652 | result = ( mastershipCheck and intentCheck and FlowTables and |
| 653 | rolesNotNull and leaderResult ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 654 | result = int( result ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 655 | if result == main.TRUE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 656 | main.log.report( "Constant State Tests Passed" ) |
| 657 | utilities.assert_equals( expect=main.TRUE, actual=result, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 658 | onpass="Constant State Tests Passed", |
| 659 | onfail="Constant state tests failed" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 660 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 661 | def CASE8( self, main ): |
| 662 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 663 | Compare topo |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 664 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 665 | import sys |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 666 | # FIXME add this path to params |
| 667 | sys.path.append( "/home/admin/sts" ) |
| 668 | # assumes that sts is already in you PYTHONPATH |
| 669 | from sts.topology.teston_topology import TestONTopology |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 670 | import json |
| 671 | import time |
| 672 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 673 | description = "Compare ONOS Topology view to Mininet topology" |
| 674 | main.case( description ) |
| 675 | main.log.report( description ) |
| 676 | main.step( "Create TestONTopology object" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 677 | ctrls = [] |
| 678 | count = 1 |
| 679 | temp = () |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 680 | temp = temp + ( getattr( main, ( 'ONOS' + str( count ) ) ), ) |
| 681 | temp = temp + ( "ONOS" + str( count ), ) |
| 682 | temp = temp + ( main.params[ 'CTRL' ][ 'ip' + str( count ) ], ) |
| 683 | temp = temp + \ |
| 684 | ( eval( main.params[ 'CTRL' ][ 'port' + str( count ) ] ), ) |
| 685 | ctrls.append( temp ) |
| 686 | MNTopo = TestONTopology( |
| 687 | main.Mininet1, |
| 688 | ctrls ) # can also add Intent API info for intent operations |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 689 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 690 | main.step( "Comparing ONOS topology to MN" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 691 | devicesResults = main.TRUE |
| 692 | portsResults = main.TRUE |
| 693 | linksResults = main.TRUE |
| 694 | topoResult = main.FALSE |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 695 | elapsed = 0 |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 696 | count = 0 |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 697 | main.step( "Collecting topology information from ONOS" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 698 | startTime = time.time() |
| 699 | while topoResult == main.FALSE and elapsed < 60: |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 700 | count = count + 1 |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 701 | if count > 1: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 702 | MNTopo = TestONTopology( |
| 703 | main.Mininet1, |
| 704 | ctrls ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 705 | cliStart = time.time() |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 706 | devices = [] |
| 707 | devices.append( main.ONOScli1.devices() ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 708 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 709 | hosts = [] |
| 710 | hosts.append( main.ONOScli1.hosts() ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 711 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 712 | ports = [] |
| 713 | ports.append( main.ONOScli1.ports() ) |
| 714 | links = [] |
| 715 | links.append( main.ONOScli1.links() ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 716 | elapsed = time.time() - startTime |
| 717 | cliTime = time.time() - cliStart |
| 718 | print "CLI time: " + str( cliTime ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 719 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 720 | for controller in range( numControllers ): |
| 721 | controllerStr = str( controller + 1 ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 722 | if devices[ controller ] or "Error" not in devices[ |
| 723 | controller ]: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 724 | currentDevicesResult = main.Mininet1.compareSwitches( |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 725 | MNTopo, |
| 726 | json.loads( |
| 727 | devices[ controller ] ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 728 | else: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 729 | currentDevicesResult = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 730 | utilities.assert_equals( expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 731 | actual=currentDevicesResult, |
| 732 | onpass="ONOS" + controllerStr + |
| 733 | " Switches view is correct", |
| 734 | onfail="ONOS" + controllerStr + |
| 735 | " Switches view is incorrect" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 736 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 737 | if ports[ controller ] or "Error" not in ports[ controller ]: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 738 | currentPortsResult = main.Mininet1.comparePorts( |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 739 | MNTopo, |
| 740 | json.loads( |
| 741 | ports[ controller ] ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 742 | else: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 743 | currentPortsResult = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 744 | utilities.assert_equals( expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 745 | actual=currentPortsResult, |
| 746 | onpass="ONOS" + controllerStr + |
| 747 | " ports view is correct", |
| 748 | onfail="ONOS" + controllerStr + |
| 749 | " ports view is incorrect" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 750 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 751 | if links[ controller ] or "Error" not in links[ controller ]: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 752 | currentLinksResult = main.Mininet1.compareLinks( |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 753 | MNTopo, |
| 754 | json.loads( |
| 755 | links[ controller ] ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 756 | else: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 757 | currentLinksResult = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 758 | utilities.assert_equals( expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 759 | actual=currentLinksResult, |
| 760 | onpass="ONOS" + controllerStr + |
| 761 | " links view is correct", |
| 762 | onfail="ONOS" + controllerStr + |
| 763 | " links view is incorrect" ) |
| 764 | devicesResults = devicesResults and currentDevicesResult |
| 765 | portsResults = portsResults and currentPortsResult |
| 766 | linksResults = linksResults and currentLinksResult |
| 767 | topoResult = devicesResults and portsResults and linksResults |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 768 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 769 | topoResult = topoResult and int( count <= 2 ) |
| 770 | note = "note it takes about " + str( int( cliTime ) ) + \ |
| 771 | " seconds for the test to make all the cli calls to fetch " +\ |
| 772 | "the topology from each ONOS instance" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 773 | main.log.report( |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 774 | "Very crass estimate for topology discovery/convergence( " + |
| 775 | str( note ) + " ): " + str( elapsed ) + " seconds, " + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 776 | str( count ) + " tries" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 777 | if elapsed > 60: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 778 | main.log.report( "Giving up on topology convergence" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 779 | utilities.assert_equals( expect=main.TRUE, actual=topoResult, |
| 780 | onpass="Topology Check Test successful", |
| 781 | onfail="Topology Check Test NOT successful" ) |
| 782 | if topoResult == main.TRUE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 783 | main.log.report( "ONOS topology view matches Mininet topology" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 784 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 785 | def CASE9( self, main ): |
| 786 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 787 | Link s3-s28 down |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 788 | """ |
| 789 | import time |
| 790 | # NOTE: You should probably run a topology check after this |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 791 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 792 | linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 793 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 794 | description = "Turn off a link to ensure that Link Discovery " +\ |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 795 | "is working properly" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 796 | main.log.report( description ) |
| 797 | main.case( description ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 798 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 799 | main.step( "Kill Link between s3 and s28" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 800 | LinkDown = main.Mininet1.link( END1="s3", END2="s28", OPTION="down" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 801 | main.log.info( |
| 802 | "Waiting " + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 803 | str( linkSleep ) + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 804 | " seconds for link down to be discovered" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 805 | time.sleep( linkSleep ) |
| 806 | utilities.assert_equals( expect=main.TRUE, actual=LinkDown, |
| 807 | onpass="Link down succesful", |
| 808 | onfail="Failed to bring link down" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 809 | # TODO do some sort of check here |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 810 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 811 | def CASE10( self, main ): |
| 812 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 813 | Link s3-s28 up |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 814 | """ |
| 815 | import time |
| 816 | # NOTE: You should probably run a topology check after this |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 817 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 818 | linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 819 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 820 | description = "Restore a link to ensure that Link Discovery is " + \ |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 821 | "working properly" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 822 | main.log.report( description ) |
| 823 | main.case( description ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 824 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 825 | main.step( "Bring link between s3 and s28 back up" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 826 | LinkUp = main.Mininet1.link( END1="s3", END2="s28", OPTION="up" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 827 | main.log.info( |
| 828 | "Waiting " + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 829 | str( linkSleep ) + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 830 | " seconds for link up to be discovered" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 831 | time.sleep( linkSleep ) |
| 832 | utilities.assert_equals( expect=main.TRUE, actual=LinkUp, |
| 833 | onpass="Link up succesful", |
| 834 | onfail="Failed to bring link up" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 835 | # TODO do some sort of check here |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 836 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 837 | def CASE11( self, main ): |
| 838 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 839 | Switch Down |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 840 | """ |
| 841 | # NOTE: You should probably run a topology check after this |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 842 | import time |
| 843 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 844 | switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 845 | |
| 846 | description = "Killing a switch to ensure it is discovered correctly" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 847 | main.log.report( description ) |
| 848 | main.case( description ) |
| 849 | switch = main.params[ 'kill' ][ 'switch' ] |
| 850 | switchDPID = main.params[ 'kill' ][ 'dpid' ] |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 851 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 852 | # TODO: Make this switch parameterizable |
| 853 | main.step( "Kill " + switch ) |
| 854 | main.log.report( "Deleting " + switch ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 855 | main.Mininet1.delSwitch( switch ) |
| 856 | main.log.info( "Waiting " + str( switchSleep ) + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 857 | " seconds for switch down to be discovered" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 858 | time.sleep( switchSleep ) |
| 859 | device = main.ONOScli1.getDevice( dpid=switchDPID ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 860 | # Peek at the deleted switch |
| 861 | main.log.warn( str( device ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 862 | result = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 863 | if device and device[ 'available' ] is False: |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 864 | result = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 865 | utilities.assert_equals( expect=main.TRUE, actual=result, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 866 | onpass="Kill switch succesful", |
| 867 | onfail="Failed to kill switch?" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 868 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 869 | def CASE12( self, main ): |
| 870 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 871 | Switch Up |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 872 | """ |
| 873 | # NOTE: You should probably run a topology check after this |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 874 | import time |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 875 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 876 | switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 877 | switch = main.params[ 'kill' ][ 'switch' ] |
| 878 | switchDPID = main.params[ 'kill' ][ 'dpid' ] |
| 879 | links = main.params[ 'kill' ][ 'links' ].split() |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 880 | description = "Adding a switch to ensure it is discovered correctly" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 881 | main.log.report( description ) |
| 882 | main.case( description ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 883 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 884 | main.step( "Add back " + switch ) |
| 885 | main.log.report( "Adding back " + switch ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 886 | main.Mininet1.addSwitch( switch, dpid=switchDPID ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 887 | # TODO: New dpid or same? Ask Thomas? |
| 888 | for peer in links: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 889 | main.Mininet1.addLink( switch, peer ) |
| 890 | main.Mininet1.assignSwController( sw=switch.split( 's' )[ 1 ], |
| 891 | ip1=ONOS1Ip, port1=ONOS1Port ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 892 | main.log.info( |
| 893 | "Waiting " + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 894 | str( switchSleep ) + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 895 | " seconds for switch up to be discovered" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 896 | time.sleep( switchSleep ) |
| 897 | device = main.ONOScli1.getDevice( dpid=switchDPID ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 898 | # Peek at the deleted switch |
| 899 | main.log.warn( str( device ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 900 | result = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 901 | if device and device[ 'available' ]: |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 902 | result = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 903 | utilities.assert_equals( expect=main.TRUE, actual=result, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 904 | onpass="add switch succesful", |
| 905 | onfail="Failed to add switch?" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 906 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 907 | def CASE13( self, main ): |
| 908 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 909 | Clean up |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 910 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 911 | import os |
| 912 | import time |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 913 | # printing colors to terminal |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 914 | colors = {} |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 915 | colors[ 'cyan' ] = '\033[96m' |
| 916 | colors[ 'purple' ] = '\033[95m' |
| 917 | colors[ 'blue' ] = '\033[94m' |
| 918 | colors[ 'green' ] = '\033[92m' |
| 919 | colors[ 'yellow' ] = '\033[93m' |
| 920 | colors[ 'red' ] = '\033[91m' |
| 921 | colors[ 'end' ] = '\033[0m' |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 922 | description = "Test Cleanup" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 923 | main.log.report( description ) |
| 924 | main.case( description ) |
| 925 | main.step( "Killing tcpdumps" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 926 | main.Mininet2.stopTcpdump() |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 927 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 928 | main.step( "Checking ONOS Logs for errors" ) |
| 929 | print colors[ 'purple' ] + "Checking logs for errors on ONOS1:" + \ |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 930 | colors[ 'end' ] |
| 931 | print main.ONOSbench.checkLogs( ONOS1Ip ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 932 | main.step( "Copying MN pcap and ONOS log files to test station" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 933 | testname = main.TEST |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 934 | teststationUser = main.params[ 'TESTONUSER' ] |
| 935 | teststationIP = main.params[ 'TESTONIP' ] |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 936 | # NOTE: MN Pcap file is being saved to ~/packet_captures |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 937 | # scp this file as MN and TestON aren't necessarily the same vm |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 938 | # FIXME: scp |
| 939 | # mn files |
| 940 | # TODO: Load these from params |
| 941 | # NOTE: must end in / |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 942 | logFolder = "/opt/onos/log/" |
| 943 | logFiles = [ "karaf.log", "karaf.log.1" ] |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 944 | # NOTE: must end in / |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 945 | dstDir = "~/packet_captures/" |
| 946 | for f in logFiles: |
| 947 | main.ONOSbench.handle.sendline( "scp sdn@" + ONOS1Ip + ":" + |
| 948 | logFolder + f + " " + |
| 949 | teststationUser + "@" + |
| 950 | teststationIP + ":" + dstDir + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 951 | str( testname ) + "-ONOS1-" + f ) |
| 952 | main.ONOSbench.handle.expect( "\$" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 953 | print main.ONOSbench.handle.before |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 954 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 955 | # std*.log's |
| 956 | # NOTE: must end in / |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 957 | logFolder = "/opt/onos/var/" |
| 958 | logFiles = [ "stderr.log", "stdout.log" ] |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 959 | # NOTE: must end in / |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 960 | dstDir = "~/packet_captures/" |
| 961 | for f in logFiles: |
| 962 | main.ONOSbench.handle.sendline( "scp sdn@" + ONOS1Ip + ":" + |
| 963 | logFolder + f + " " + |
| 964 | teststationUser + "@" + |
| 965 | teststationIP + ":" + dstDir + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 966 | str( testname ) + "-ONOS1-" + f ) |
| 967 | # sleep so scp can finish |
| 968 | time.sleep( 10 ) |
| 969 | main.step( "Packing and rotating pcap archives" ) |
| 970 | os.system( "~/TestON/dependencies/rotate.sh " + str( testname ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 971 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 972 | # TODO: actually check something here |
| 973 | utilities.assert_equals( expect=main.TRUE, actual=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 974 | onpass="Test cleanup successful", |
| 975 | onfail="Test cleanup NOT successful" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 976 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 977 | def CASE14( self, main ): |
| 978 | """ |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 979 | start election app on all onos nodes |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 980 | """ |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 981 | leaderResult = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 982 | # install app on onos 1 |
| 983 | main.log.info( "Install leadership election app" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 984 | main.ONOScli1.featureInstall( "onos-app-election" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 985 | # wait for election |
| 986 | # check for leader |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 987 | leader = main.ONOScli1.electionTestLeader() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 988 | # verify leader is ONOS1 |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 989 | if leader == ONOS1Ip: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 990 | # all is well |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 991 | pass |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 992 | elif leader is None: |
| 993 | # No leader elected |
| 994 | main.log.report( "No leader was elected" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 995 | leaderResult = main.FALSE |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 996 | elif leader == main.FALSE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 997 | # error in response |
| 998 | # TODO: add check for "Command not found:" in the driver, this |
| 999 | # means the app isn't loaded |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1000 | main.log.report( "Something is wrong with electionTestLeader" + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1001 | " function, check the error logs" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1002 | leaderResult = main.FALSE |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1003 | else: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1004 | # error in response |
| 1005 | main.log.report( |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1006 | "Unexpected response from electionTestLeader function:'" + |
| 1007 | str( leader ) + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1008 | "'" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1009 | leaderResult = main.FALSE |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1010 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1011 | # install on other nodes and check for leader. |
| 1012 | # Should be onos1 and each app should show the same leader |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1013 | for controller in range( 2, numControllers + 1 ): |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1014 | # loop through ONOScli handlers |
| 1015 | node = getattr( main, ( 'ONOScli' + str( controller ) ) ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1016 | node.featureInstall( "onos-app-election" ) |
| 1017 | leaderN = node.electionTestLeader() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1018 | # verify leader is ONOS1 |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1019 | if leaderN == ONOS1Ip: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1020 | # all is well |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1021 | pass |
| 1022 | elif leaderN == main.FALSE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1023 | # error in response |
| 1024 | # TODO: add check for "Command not found:" in the driver, this |
| 1025 | # means the app isn't loaded |
| 1026 | main.log.report( "Something is wrong with " + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1027 | "electionTestLeader function, check the" + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1028 | " error logs" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1029 | leaderResult = main.FALSE |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1030 | elif leader != leaderN: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1031 | leaderResult = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1032 | main.log.report( "ONOS" + str( controller ) + " sees " + |
| 1033 | str( leaderN ) + |
| 1034 | " as the leader of the election app. Leader" + |
| 1035 | " should be " + |
| 1036 | str( leader ) ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1037 | if leaderResult: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1038 | main.log.report( "Leadership election tests passed( consistent " + |
| 1039 | "view of leader across listeners and a leader " + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1040 | "was elected )" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1041 | utilities.assert_equals( |
| 1042 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1043 | actual=leaderResult, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1044 | onpass="Leadership election passed", |
| 1045 | onfail="Something went wrong with Leadership election" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1046 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1047 | def CASE15( self, main ): |
| 1048 | """ |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1049 | Check that Leadership Election is still functional |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1050 | """ |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1051 | leaderResult = main.TRUE |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1052 | description = "Check that Leadership Election is still functional" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1053 | main.log.report( description ) |
| 1054 | main.case( description ) |
| 1055 | main.step( "Find current leader and withdraw" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1056 | leader = main.ONOScli1.electionTestLeader() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1057 | # TODO: do some sanity checking on leader before using it |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1058 | withdrawResult = main.FALSE |
| 1059 | if leader == ONOS1Ip: |
| 1060 | oldLeader = getattr( main, "ONOScli1" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1061 | elif leader is None or leader == main.FALSE: |
| 1062 | main.log.report( |
| 1063 | "Leader for the election app should be an ONOS node," + |
| 1064 | "instead got '" + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1065 | str( leader ) + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1066 | "'" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1067 | leaderResult = main.FALSE |
| 1068 | withdrawResult = oldLeader.electionTestWithdraw() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1069 | utilities.assert_equals( |
| 1070 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1071 | actual=withdrawResult, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1072 | onpass="App was withdrawn from election", |
| 1073 | onfail="App was not withdrawn from election" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1074 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1075 | main.step( "Make sure new leader is elected" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1076 | leaderList = [] |
| 1077 | leaderN = main.ONOScli1.electionTestLeader() |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1078 | if leaderN == leader: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1079 | main.log.report( "ONOS still sees " + str( leaderN ) + |
| 1080 | " as leader after they withdrew" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1081 | leaderResult = main.FALSE |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1082 | elif leaderN == main.FALSE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1083 | # error in response |
| 1084 | # TODO: add check for "Command not found:" in the driver, this |
| 1085 | # means the app isn't loaded |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1086 | main.log.report( "Something is wrong with electionTestLeader " + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1087 | "function, check the error logs" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1088 | leaderResult = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1089 | elif leaderN is None: |
| 1090 | main.log.info( |
| 1091 | "There is no leader after the app withdrew from election" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1092 | if leaderResult: |
| 1093 | main.log.report( "Leadership election tests passed( There is no " + |
| 1094 | "leader after the old leader resigned )" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1095 | utilities.assert_equals( |
| 1096 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1097 | actual=leaderResult, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1098 | onpass="Leadership election passed", |
| 1099 | onfail="Something went wrong with Leadership election" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1100 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1101 | main.step( |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1102 | "Run for election on old leader( just so everyone is in the hat )" ) |
| 1103 | runResult = oldLeader.electionTestRun() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1104 | utilities.assert_equals( |
| 1105 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1106 | actual=runResult, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1107 | onpass="App re-ran for election", |
| 1108 | onfail="App failed to run for election" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1109 | leader = main.ONOScli1.electionTestLeader() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1110 | # verify leader is ONOS1 |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1111 | if leader == ONOS1Ip: |
| 1112 | leaderResult = main.TRUE |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1113 | else: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1114 | leaderResult = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1115 | # TODO: assert on run and withdraw results? |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1116 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1117 | utilities.assert_equals( |
| 1118 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1119 | actual=leaderResult, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1120 | onpass="Leadership election passed", |
| 1121 | onfail="ONOS1's election app was not leader after it re-ran " + |
| 1122 | "for election" ) |