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: |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 34 | cell <name> |
| 35 | onos-verify-cell |
| 36 | NOTE: temporary - onos-remove-raft-logs |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 37 | onos-uninstall |
| 38 | start mininet |
| 39 | git pull |
| 40 | mvn clean install |
| 41 | onos-package |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 42 | onos-install -f |
| 43 | onos-wait-for-start |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 44 | start cli sessions |
| 45 | start tcpdump |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 46 | """ |
| 47 | main.log.report( "ONOS Single node cluster restart " + |
| 48 | "HA test - initialization" ) |
| 49 | main.case( "Setting up test environment" ) |
| 50 | # TODO: save all the timers and output them for plotting |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 51 | |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 52 | # load some variables from the params file |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 53 | PULLCODE = False |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 54 | if main.params[ 'Git' ] == 'True': |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 55 | PULLCODE = True |
Jon Hall | 529a37f | 2015-01-28 10:02:00 -0800 | [diff] [blame] | 56 | gitBranch = main.params[ 'branch' ] |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 57 | cellName = main.params[ 'ENV' ][ 'cellName' ] |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 58 | |
| 59 | # set global variables |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 60 | global ONOS1Ip |
| 61 | global ONOS1Port |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 62 | global ONOS2Port |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 63 | global ONOS3Port |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 64 | global ONOS4Port |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 65 | global ONOS5Port |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 66 | global ONOS6Port |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 67 | global ONOS7Port |
| 68 | global numControllers |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 69 | numControllers = int( main.params[ 'num_controllers' ] ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 70 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 71 | ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ] |
| 72 | ONOS1Port = main.params[ 'CTRL' ][ 'port1' ] |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 73 | ONOS2Port = main.params[ 'CTRL' ][ 'port2' ] |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 74 | ONOS3Port = main.params[ 'CTRL' ][ 'port3' ] |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 75 | ONOS4Port = main.params[ 'CTRL' ][ 'port4' ] |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 76 | ONOS5Port = main.params[ 'CTRL' ][ 'port5' ] |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 77 | ONOS6Port = main.params[ 'CTRL' ][ 'port6' ] |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 78 | ONOS7Port = main.params[ 'CTRL' ][ 'port7' ] |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 79 | |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 80 | global CLIs |
| 81 | CLIs = [] |
| 82 | global nodes |
| 83 | nodes = [] |
| 84 | for i in range( 1, numControllers + 1 ): |
| 85 | CLIs.append( getattr( main, 'ONOScli' + str( i ) ) ) |
| 86 | nodes.append( getattr( main, 'ONOS' + str( i ) ) ) |
| 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 | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 95 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 96 | main.log.report( "Uninstalling ONOS" ) |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 97 | for node in nodes: |
| 98 | main.ONOSbench.onosUninstall( node.ip_address ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 99 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 100 | cleanInstallResult = main.TRUE |
| 101 | gitPullResult = main.TRUE |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 102 | |
Jon Hall | 97f3175 | 2015-02-04 12:01:04 -0800 | [diff] [blame] | 103 | main.step( "Starting Mininet" ) |
| 104 | main.Mininet1.startNet( ) |
| 105 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 106 | main.step( "Compiling the latest version of ONOS" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 107 | if PULLCODE: |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 108 | main.step( "Git checkout and pull " + gitBranch ) |
Jon Hall | 529a37f | 2015-01-28 10:02:00 -0800 | [diff] [blame] | 109 | main.ONOSbench.gitCheckout( gitBranch ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 110 | gitPullResult = main.ONOSbench.gitPull() |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 111 | if gitPullResult == main.ERROR: |
| 112 | main.log.error( "Error pulling git branch" ) |
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" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 131 | for i in range( 2 ): |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 132 | onos1Isup = main.ONOSbench.isup( ONOS1Ip ) |
| 133 | if onos1Isup: |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 134 | break |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 135 | if not onos1Isup: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 136 | main.log.report( "ONOS1 didn't start!" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 137 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 138 | cliResult = main.ONOScli1.startOnosCli( ONOS1Ip ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 139 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 140 | main.step( "Start Packet Capture MN" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 141 | main.Mininet2.startTcpdump( |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 142 | str( main.params[ 'MNtcpdump' ][ 'folder' ] ) + str( main.TEST ) |
| 143 | + "-MN.pcap", |
| 144 | intf=main.params[ 'MNtcpdump' ][ 'intf' ], |
| 145 | port=main.params[ 'MNtcpdump' ][ 'port' ] ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 146 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 147 | case1Result = ( cleanInstallResult and packageResult and |
| 148 | cellResult and verifyResult and onos1InstallResult |
| 149 | and onos1Isup and cliResult ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 150 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 151 | utilities.assert_equals( expect=main.TRUE, actual=case1Result, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 152 | onpass="Test startup successful", |
| 153 | onfail="Test startup NOT successful" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 154 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 155 | if case1Result == main.FALSE: |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 156 | main.cleanup() |
| 157 | main.exit() |
| 158 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 159 | def CASE2( self, main ): |
| 160 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 161 | Assign mastership to controllers |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 162 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 163 | import re |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 164 | assert numControllers, "numControllers not defined" |
| 165 | assert main, "main not defined" |
| 166 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
| 167 | assert ONOS1Port, "ONOS1Port not defined" |
| 168 | assert ONOS2Port, "ONOS2Port not defined" |
| 169 | assert ONOS3Port, "ONOS3Port not defined" |
| 170 | assert ONOS4Port, "ONOS4Port not defined" |
| 171 | assert ONOS5Port, "ONOS5Port not defined" |
| 172 | assert ONOS6Port, "ONOS6Port not defined" |
| 173 | assert ONOS7Port, "ONOS7Port not defined" |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 174 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 175 | main.log.report( "Assigning switches to controllers" ) |
| 176 | main.case( "Assigning Controllers" ) |
| 177 | main.step( "Assign switches to controllers" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 178 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 179 | for i in range( 1, 29 ): |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 180 | main.Mininet1.assignSwController( |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 181 | sw=str( i ), |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 182 | ip1=ONOS1Ip, port1=ONOS1Port ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 183 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 184 | mastershipCheck = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 185 | for i in range( 1, 29 ): |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 186 | response = main.Mininet1.getSwController( "s" + str( i ) ) |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 187 | try: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 188 | main.log.info( str( response ) ) |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 189 | except Exception: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 190 | main.log.info( repr( response ) ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 191 | if re.search( "tcp:" + ONOS1Ip, response ): |
| 192 | mastershipCheck = mastershipCheck and main.TRUE |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 193 | else: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 194 | mastershipCheck = main.FALSE |
| 195 | if mastershipCheck == main.TRUE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 196 | main.log.report( "Switch mastership assigned correctly" ) |
| 197 | utilities.assert_equals( |
| 198 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 199 | actual=mastershipCheck, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 200 | onpass="Switch mastership assigned correctly", |
| 201 | onfail="Switches not assigned correctly to controllers" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 202 | |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 203 | roleCall = main.TRUE |
| 204 | roleCheck = main.TRUE |
| 205 | try: |
| 206 | for i in range( 1, 29 ): # switches 1 through 28 |
| 207 | ip = nodes[ 0 ].ip_address # ONOS1 |
| 208 | # set up correct variables: |
| 209 | if i == 1: |
| 210 | deviceId = main.ONOScli1.getDevice( "1000" ).get( 'id' ) |
| 211 | elif i == 2: |
| 212 | deviceId = main.ONOScli1.getDevice( "2000" ).get( 'id' ) |
| 213 | elif i == 3: |
| 214 | deviceId = main.ONOScli1.getDevice( "3000" ).get( 'id' ) |
| 215 | elif i == 4: |
| 216 | deviceId = main.ONOScli1.getDevice( "3004" ).get( 'id' ) |
| 217 | elif i == 5: |
| 218 | deviceId = main.ONOScli1.getDevice( "5000" ).get( 'id' ) |
| 219 | elif i == 6: |
| 220 | deviceId = main.ONOScli1.getDevice( "6000" ).get( 'id' ) |
| 221 | elif i == 7: |
| 222 | deviceId = main.ONOScli1.getDevice( "6007" ).get( 'id' ) |
| 223 | elif i >= 8 and i <= 17: |
| 224 | dpid = '3' + str( i ).zfill( 3 ) |
| 225 | deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' ) |
| 226 | elif i >= 18 and i <= 27: |
| 227 | dpid = '6' + str( i ).zfill( 3 ) |
| 228 | deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' ) |
| 229 | elif i == 28: |
| 230 | deviceId = main.ONOScli1.getDevice( "2800" ).get( 'id' ) |
| 231 | else: |
| 232 | main.log.error( "You didn't write an else statement for " + |
| 233 | "switch s" + str( i ) ) |
| 234 | # Assign switch |
| 235 | assert deviceId, "No device id for s" + str( i ) + " in ONOS" |
| 236 | # TODO: make this controller dynamic |
| 237 | roleCall = roleCall and main.ONOScli1.deviceRole( deviceId, |
| 238 | ip ) |
| 239 | # Check assignment |
| 240 | if ip in main.ONOScli1.getRole( deviceId ).get( 'master' ): |
| 241 | roleCheck = roleCheck and main.TRUE |
| 242 | else: |
| 243 | roleCheck = roleCheck and main.FALSE |
| 244 | main.log.error( "Error, controller " + ip + " is not" + |
| 245 | " master " + "of device " + |
| 246 | str( deviceId ) ) |
| 247 | except ( AttributeError, AssertionError ): |
| 248 | main.log.exception( "Something is wrong with ONOS device view" ) |
| 249 | main.log.info( main.ONOScli1.devices() ) |
| 250 | utilities.assert_equals( |
| 251 | expect=main.TRUE, |
| 252 | actual=roleCall, |
| 253 | onpass="Re-assigned switch mastership to designated controller", |
| 254 | onfail="Something wrong with deviceRole calls" ) |
| 255 | |
| 256 | utilities.assert_equals( |
| 257 | expect=main.TRUE, |
| 258 | actual=roleCheck, |
| 259 | onpass="Switches were successfully reassigned to designated " + |
| 260 | "controller", |
| 261 | onfail="Switches were not successfully reassigned" ) |
| 262 | mastershipCheck = mastershipCheck and roleCall and roleCheck |
| 263 | utilities.assert_equals( expect=main.TRUE, actual=mastershipCheck, |
| 264 | onpass="Switch mastership correctly assigned", |
| 265 | onfail="Error in (re)assigning switch" + |
| 266 | " mastership" ) |
| 267 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 268 | def CASE3( self, main ): |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 269 | """ |
| 270 | Assign intents |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 271 | """ |
| 272 | import time |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 273 | import json |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 274 | assert numControllers, "numControllers not defined" |
| 275 | assert main, "main not defined" |
| 276 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 277 | # FIXME: we must reinstall intents until we have a persistant |
| 278 | # datastore! |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 279 | main.log.report( "Adding host intents" ) |
| 280 | main.case( "Adding host Intents" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 281 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 282 | main.step( "Discovering Hosts( Via pingall for now )" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 283 | # FIXME: Once we have a host discovery mechanism, use that instead |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 284 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 285 | # install onos-app-fwd |
| 286 | main.log.info( "Install reactive forwarding app" ) |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 287 | appResults = main.ONOScli1.activateApp( "org.onosproject.fwd" ) |
| 288 | |
| 289 | # FIXME: add this to asserts |
| 290 | appCheck = main.ONOScli1.appToIDCheck() |
| 291 | if appCheck != main.TRUE: |
| 292 | main.log.warn( CLIs[0].apps() ) |
| 293 | main.log.warn( CLIs[0].appIDs() ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 294 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 295 | # REACTIVE FWD test |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 296 | pingResult = main.FALSE |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 297 | for i in range(2): # Retry if pingall fails first time |
| 298 | time1 = time.time() |
| 299 | pingResult = main.Mininet1.pingall() |
| 300 | utilities.assert_equals( |
| 301 | expect=main.TRUE, |
| 302 | actual=pingResult, |
| 303 | onpass="Reactive Pingall test passed", |
| 304 | onfail="Reactive Pingall failed, one or more ping pairs failed" ) |
| 305 | time2 = time.time() |
| 306 | main.log.info( "Time for pingall: %2f seconds" % ( time2 - time1 ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 307 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 308 | # uninstall onos-app-fwd |
| 309 | main.log.info( "Uninstall reactive forwarding app" ) |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 310 | appResults = appResults and main.ONOScli1.deactivateApp( "org.onosproject.fwd" ) |
| 311 | appCheck2 = main.ONOScli1.appToIDCheck() |
| 312 | if appCheck2 != main.TRUE: |
| 313 | main.log.warn( CLIs[0].apps() ) |
| 314 | main.log.warn( CLIs[0].appIDs() ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 315 | |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 316 | # timeout for fwd flows |
| 317 | time.sleep( 11 ) |
| 318 | |
| 319 | main.step( "Add host intents" ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 320 | intentIds = [] |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 321 | # TODO: move the host numbers to params |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 322 | # Maybe look at all the paths we ping? |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 323 | intentAddResult = True |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 324 | hostResult = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 325 | for i in range( 8, 18 ): |
| 326 | main.log.info( "Adding host intent between h" + str( i ) + |
| 327 | " and h" + str( i + 10 ) ) |
| 328 | host1 = "00:00:00:00:00:" + \ |
| 329 | str( hex( i )[ 2: ] ).zfill( 2 ).upper() |
| 330 | host2 = "00:00:00:00:00:" + \ |
| 331 | str( hex( i + 10 )[ 2: ] ).zfill( 2 ).upper() |
Jon Hall | 1b8f54a | 2015-02-04 13:24:20 -0800 | [diff] [blame] | 332 | # NOTE: getHost can return None |
| 333 | host1Dict = main.ONOScli1.getHost( host1 ) |
| 334 | host2Dict = main.ONOScli1.getHost( host2 ) |
| 335 | host1Id = None |
| 336 | host2Id = None |
| 337 | if host1Dict and host2Dict: |
| 338 | host1Id = host1Dict.get( 'id', None ) |
| 339 | host2Id = host2Dict.get( 'id', None ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 340 | if host1Id and host2Id: |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 341 | tmpId = main.ONOScli1.addHostIntent( host1Id, host2Id ) |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 342 | if tmpId: |
| 343 | main.log.info( "Added intent with id: " + tmpId ) |
| 344 | intentIds.append( tmpId ) |
| 345 | else: |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 346 | main.log.error( "addHostIntent returned: " + |
| 347 | repr( tmpId ) ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 348 | else: |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 349 | main.log.error( "Error, getHost() failed for h" + str( i ) + |
| 350 | " and/or h" + str( i + 10 ) ) |
| 351 | hosts = main.ONOScli1.hosts() |
| 352 | main.log.warn( "Hosts output: " ) |
| 353 | try: |
| 354 | main.log.warn( json.dumps( json.loads( hosts ), |
| 355 | sort_keys=True, |
| 356 | indent=4, |
| 357 | separators=( ',', ': ' ) ) ) |
| 358 | except ( ValueError, TypeError ): |
| 359 | main.log.warn( repr( hosts ) ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 360 | hostResult = main.FALSE |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 361 | # FIXME: DEBUG |
| 362 | intentStart = time.time() |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 363 | onosIds = main.ONOScli1.getAllIntentsId() |
| 364 | main.log.info( "Submitted intents: " + str( intentIds ) ) |
| 365 | main.log.info( "Intents in ONOS: " + str( onosIds ) ) |
| 366 | for intent in intentIds: |
| 367 | if intent in onosIds: |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 368 | pass # intent submitted is in onos |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 369 | else: |
| 370 | intentAddResult = False |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 371 | # FIXME: DEBUG |
| 372 | if intentAddResult: |
| 373 | intentStop = time.time() |
| 374 | else: |
| 375 | intentStop = None |
Jon Hall | 1b8f54a | 2015-02-04 13:24:20 -0800 | [diff] [blame] | 376 | # Print the intent states |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 377 | intents = main.ONOScli1.intents() |
Jon Hall | 1b8f54a | 2015-02-04 13:24:20 -0800 | [diff] [blame] | 378 | intentStates = [] |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 379 | installedCheck = True |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 380 | main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) ) |
| 381 | count = 0 |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 382 | try: |
| 383 | for intent in json.loads( intents ): |
| 384 | state = intent.get( 'state', None ) |
| 385 | if "INSTALLED" not in state: |
| 386 | installedCheck = False |
| 387 | intentId = intent.get( 'id', None ) |
| 388 | intentStates.append( ( intentId, state ) ) |
| 389 | except ( ValueError, TypeError ): |
| 390 | main.log.exception( "Error parsing intents" ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 391 | # add submitted intents not in the store |
| 392 | tmplist = [ i for i, s in intentStates ] |
| 393 | missingIntents = False |
| 394 | for i in intentIds: |
| 395 | if i not in tmplist: |
| 396 | intentStates.append( ( i, " - " ) ) |
| 397 | missingIntents = True |
| 398 | intentStates.sort() |
| 399 | for i, s in intentStates: |
| 400 | count += 1 |
| 401 | main.log.info( "%-6s%-15s%-15s" % |
| 402 | ( str( count ), str( i ), str( s ) ) ) |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 403 | leaders = main.ONOScli1.leaders() |
| 404 | try: |
| 405 | if leaders: |
| 406 | parsedLeaders = json.loads( leaders ) |
| 407 | main.log.warn( json.dumps( parsedLeaders, |
| 408 | sort_keys=True, |
| 409 | indent=4, |
| 410 | separators=( ',', ': ' ) ) ) |
| 411 | # check for all intent partitions |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 412 | topics = [] |
| 413 | for i in range( 14 ): |
| 414 | topics.append( "intent-partition-" + str( i ) ) |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 415 | main.log.debug( topics ) |
| 416 | ONOStopics = [ j['topic'] for j in parsedLeaders ] |
| 417 | for topic in topics: |
| 418 | if topic not in ONOStopics: |
| 419 | main.log.error( "Error: " + topic + |
| 420 | " not in leaders" ) |
| 421 | else: |
| 422 | main.log.error( "leaders() returned None" ) |
| 423 | except ( ValueError, TypeError ): |
| 424 | main.log.exception( "Error parsing leaders" ) |
| 425 | main.log.error( repr( leaders ) ) |
| 426 | partitions = main.ONOScli1.partitions() |
| 427 | try: |
| 428 | if partitions : |
| 429 | parsedPartitions = json.loads( partitions ) |
| 430 | main.log.warn( json.dumps( parsedPartitions, |
| 431 | sort_keys=True, |
| 432 | indent=4, |
| 433 | separators=( ',', ': ' ) ) ) |
| 434 | # TODO check for a leader in all paritions |
| 435 | # TODO check for consistency among nodes |
| 436 | else: |
| 437 | main.log.error( "partitions() returned None" ) |
| 438 | except ( ValueError, TypeError ): |
| 439 | main.log.exception( "Error parsing partitions" ) |
| 440 | main.log.error( repr( partitions ) ) |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 441 | pendingMap = main.ONOScli1.pendingMap() |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 442 | try: |
| 443 | if pendingMap : |
| 444 | parsedPending = json.loads( pendingMap ) |
| 445 | main.log.warn( json.dumps( parsedPending, |
| 446 | sort_keys=True, |
| 447 | indent=4, |
| 448 | separators=( ',', ': ' ) ) ) |
| 449 | # TODO check something here? |
| 450 | else: |
| 451 | main.log.error( "pendingMap() returned None" ) |
| 452 | except ( ValueError, TypeError ): |
| 453 | main.log.exception( "Error parsing pending map" ) |
| 454 | main.log.error( repr( pendingMap ) ) |
| 455 | |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 456 | intentAddResult = bool( pingResult and hostResult and intentAddResult |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 457 | and not missingIntents and installedCheck ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 458 | utilities.assert_equals( |
| 459 | expect=True, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 460 | actual=intentAddResult, |
Jon Hall | 529a37f | 2015-01-28 10:02:00 -0800 | [diff] [blame] | 461 | onpass="Pushed host intents to ONOS", |
| 462 | onfail="Error in pushing host intents to ONOS" ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 463 | |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 464 | if not intentAddResult or "key" in pendingMap: |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 465 | import time |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 466 | installedCheck = True |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 467 | main.log.info( "Sleeping 60 seconds to see if intents are found" ) |
| 468 | time.sleep( 60 ) |
| 469 | onosIds = main.ONOScli1.getAllIntentsId() |
| 470 | main.log.info( "Submitted intents: " + str( intentIds ) ) |
| 471 | main.log.info( "Intents in ONOS: " + str( onosIds ) ) |
| 472 | # Print the intent states |
| 473 | intents = main.ONOScli1.intents() |
| 474 | intentStates = [] |
| 475 | main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) ) |
| 476 | count = 0 |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 477 | try: |
| 478 | for intent in json.loads( intents ): |
| 479 | # Iter through intents of a node |
| 480 | state = intent.get( 'state', None ) |
| 481 | if "INSTALLED" not in state: |
| 482 | installedCheck = False |
| 483 | intentId = intent.get( 'id', None ) |
| 484 | intentStates.append( ( intentId, state ) ) |
| 485 | except ( ValueError, TypeError ): |
| 486 | main.log.exception( "Error parsing intents" ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 487 | # add submitted intents not in the store |
| 488 | tmplist = [ i for i, s in intentStates ] |
| 489 | for i in intentIds: |
| 490 | if i not in tmplist: |
| 491 | intentStates.append( ( i, " - " ) ) |
| 492 | intentStates.sort() |
| 493 | for i, s in intentStates: |
| 494 | count += 1 |
| 495 | main.log.info( "%-6s%-15s%-15s" % |
| 496 | ( str( count ), str( i ), str( s ) ) ) |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 497 | leaders = main.ONOScli1.leaders() |
| 498 | try: |
| 499 | if leaders: |
| 500 | parsedLeaders = json.loads( leaders ) |
| 501 | main.log.warn( json.dumps( parsedLeaders, |
| 502 | sort_keys=True, |
| 503 | indent=4, |
| 504 | separators=( ',', ': ' ) ) ) |
| 505 | # check for all intent partitions |
| 506 | # check for election |
| 507 | topics = [] |
| 508 | for i in range( 14 ): |
| 509 | topics.append( "intent-partition-" + str( i ) ) |
| 510 | # FIXME: this should only be after we start the app |
| 511 | topics.append( "org.onosproject.election" ) |
| 512 | main.log.debug( topics ) |
| 513 | ONOStopics = [ j['topic'] for j in parsedLeaders ] |
| 514 | for topic in topics: |
| 515 | if topic not in ONOStopics: |
| 516 | main.log.error( "Error: " + topic + |
| 517 | " not in leaders" ) |
| 518 | else: |
| 519 | main.log.error( "leaders() returned None" ) |
| 520 | except ( ValueError, TypeError ): |
| 521 | main.log.exception( "Error parsing leaders" ) |
| 522 | main.log.error( repr( leaders ) ) |
| 523 | partitions = main.ONOScli1.partitions() |
| 524 | try: |
| 525 | if partitions : |
| 526 | parsedPartitions = json.loads( partitions ) |
| 527 | main.log.warn( json.dumps( parsedPartitions, |
| 528 | sort_keys=True, |
| 529 | indent=4, |
| 530 | separators=( ',', ': ' ) ) ) |
| 531 | # TODO check for a leader in all paritions |
| 532 | # TODO check for consistency among nodes |
| 533 | else: |
| 534 | main.log.error( "partitions() returned None" ) |
| 535 | except ( ValueError, TypeError ): |
| 536 | main.log.exception( "Error parsing partitions" ) |
| 537 | main.log.error( repr( partitions ) ) |
| 538 | pendingMap = main.ONOScli1.pendingMap() |
| 539 | try: |
| 540 | if pendingMap : |
| 541 | parsedPending = json.loads( pendingMap ) |
| 542 | main.log.warn( json.dumps( parsedPending, |
| 543 | sort_keys=True, |
| 544 | indent=4, |
| 545 | separators=( ',', ': ' ) ) ) |
| 546 | # TODO check something here? |
| 547 | else: |
| 548 | main.log.error( "pendingMap() returned None" ) |
| 549 | except ( ValueError, TypeError ): |
| 550 | main.log.exception( "Error parsing pending map" ) |
| 551 | main.log.error( repr( pendingMap ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 552 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 553 | def CASE4( self, main ): |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 554 | """ |
| 555 | Ping across added host intents |
| 556 | """ |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 557 | import json |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 558 | import time |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 559 | assert numControllers, "numControllers not defined" |
| 560 | assert main, "main not defined" |
| 561 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 562 | description = " Ping across added host intents" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 563 | main.log.report( description ) |
| 564 | main.case( description ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 565 | PingResult = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 566 | for i in range( 8, 18 ): |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 567 | ping = main.Mininet1.pingHost( src="h" + str( i ), |
| 568 | target="h" + str( i + 10 ) ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 569 | PingResult = PingResult and ping |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 570 | if ping == main.FALSE: |
| 571 | main.log.warn( "Ping failed between h" + str( i ) + |
| 572 | " and h" + str( i + 10 ) ) |
| 573 | elif ping == main.TRUE: |
| 574 | main.log.info( "Ping test passed!" ) |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 575 | # Don't set PingResult or you'd override failures |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 576 | if PingResult == main.FALSE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 577 | main.log.report( |
| 578 | "Intents have not been installed correctly, pings failed." ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 579 | # TODO: pretty print |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 580 | main.log.warn( "ONOS1 intents: " ) |
| 581 | try: |
| 582 | tmpIntents = main.ONOScli1.intents() |
| 583 | main.log.warn( json.dumps( json.loads( tmpIntents ), |
| 584 | sort_keys=True, |
| 585 | indent=4, |
| 586 | separators=( ',', ': ' ) ) ) |
| 587 | except ( ValueError, TypeError ): |
| 588 | main.log.warn( repr( tmpIntents ) ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 589 | if PingResult == main.TRUE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 590 | main.log.report( |
| 591 | "Intents have been installed correctly and verified by pings" ) |
| 592 | utilities.assert_equals( |
| 593 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 594 | actual=PingResult, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 595 | onpass="Intents have been installed correctly and pings work", |
| 596 | onfail="Intents have not been installed correctly, pings failed." ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 597 | |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 598 | installedCheck = True |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 599 | if PingResult is not main.TRUE: |
| 600 | # Print the intent states |
| 601 | intents = main.ONOScli1.intents() |
| 602 | intentStates = [] |
| 603 | main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) ) |
| 604 | count = 0 |
| 605 | # Iter through intents of a node |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 606 | try: |
| 607 | for intent in json.loads( intents ): |
| 608 | state = intent.get( 'state', None ) |
| 609 | if "INSTALLED" not in state: |
| 610 | installedCheck = False |
| 611 | intentId = intent.get( 'id', None ) |
| 612 | intentStates.append( ( intentId, state ) ) |
| 613 | except ( ValueError, TypeError ): |
| 614 | main.log.exception( "Error parsing intents." ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 615 | intentStates.sort() |
| 616 | for i, s in intentStates: |
| 617 | count += 1 |
| 618 | main.log.info( "%-6s%-15s%-15s" % |
| 619 | ( str( count ), str( i ), str( s ) ) ) |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 620 | leaders = main.ONOScli1.leaders() |
| 621 | try: |
| 622 | if leaders: |
| 623 | parsedLeaders = json.loads( leaders ) |
| 624 | main.log.warn( json.dumps( parsedLeaders, |
| 625 | sort_keys=True, |
| 626 | indent=4, |
| 627 | separators=( ',', ': ' ) ) ) |
| 628 | # check for all intent partitions |
| 629 | # check for election |
| 630 | topics = [] |
| 631 | for i in range( 14 ): |
| 632 | topics.append( "intent-partition-" + str( i ) ) |
| 633 | # FIXME: this should only be after we start the app |
| 634 | topics.append( "org.onosproject.election" ) |
| 635 | main.log.debug( topics ) |
| 636 | ONOStopics = [ j['topic'] for j in parsedLeaders ] |
| 637 | for topic in topics: |
| 638 | if topic not in ONOStopics: |
| 639 | main.log.error( "Error: " + topic + |
| 640 | " not in leaders" ) |
| 641 | else: |
| 642 | main.log.error( "leaders() returned None" ) |
| 643 | except ( ValueError, TypeError ): |
| 644 | main.log.exception( "Error parsing leaders" ) |
| 645 | main.log.error( repr( leaders ) ) |
| 646 | partitions = main.ONOScli1.partitions() |
| 647 | try: |
| 648 | if partitions : |
| 649 | parsedPartitions = json.loads( partitions ) |
| 650 | main.log.warn( json.dumps( parsedPartitions, |
| 651 | sort_keys=True, |
| 652 | indent=4, |
| 653 | separators=( ',', ': ' ) ) ) |
| 654 | # TODO check for a leader in all paritions |
| 655 | # TODO check for consistency among nodes |
| 656 | else: |
| 657 | main.log.error( "partitions() returned None" ) |
| 658 | except ( ValueError, TypeError ): |
| 659 | main.log.exception( "Error parsing partitions" ) |
| 660 | main.log.error( repr( partitions ) ) |
| 661 | pendingMap = main.ONOScli1.pendingMap() |
| 662 | try: |
| 663 | if pendingMap : |
| 664 | parsedPending = json.loads( pendingMap ) |
| 665 | main.log.warn( json.dumps( parsedPending, |
| 666 | sort_keys=True, |
| 667 | indent=4, |
| 668 | separators=( ',', ': ' ) ) ) |
| 669 | # TODO check something here? |
| 670 | else: |
| 671 | main.log.error( "pendingMap() returned None" ) |
| 672 | except ( ValueError, TypeError ): |
| 673 | main.log.exception( "Error parsing pending map" ) |
| 674 | main.log.error( repr( pendingMap ) ) |
| 675 | |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 676 | if not installedCheck: |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 677 | main.log.info( "Waiting 60 seconds to see if the state of " + |
| 678 | "intents change" ) |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 679 | time.sleep( 60 ) |
| 680 | # Print the intent states |
| 681 | intents = main.ONOScli1.intents() |
| 682 | intentStates = [] |
| 683 | main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) ) |
| 684 | count = 0 |
| 685 | # Iter through intents of a node |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 686 | try: |
| 687 | for intent in json.loads( intents ): |
| 688 | state = intent.get( 'state', None ) |
| 689 | if "INSTALLED" not in state: |
| 690 | installedCheck = False |
| 691 | intentId = intent.get( 'id', None ) |
| 692 | intentStates.append( ( intentId, state ) ) |
| 693 | except ( ValueError, TypeError ): |
| 694 | main.log.exception( "Error parsing intents." ) |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 695 | intentStates.sort() |
| 696 | for i, s in intentStates: |
| 697 | count += 1 |
| 698 | main.log.info( "%-6s%-15s%-15s" % |
| 699 | ( str( count ), str( i ), str( s ) ) ) |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 700 | leaders = main.ONOScli1.leaders() |
| 701 | try: |
| 702 | if leaders: |
| 703 | parsedLeaders = json.loads( leaders ) |
| 704 | main.log.warn( json.dumps( parsedLeaders, |
| 705 | sort_keys=True, |
| 706 | indent=4, |
| 707 | separators=( ',', ': ' ) ) ) |
| 708 | # check for all intent partitions |
| 709 | # check for election |
| 710 | topics = [] |
| 711 | for i in range( 14 ): |
| 712 | topics.append( "intent-partition-" + str( i ) ) |
| 713 | # FIXME: this should only be after we start the app |
| 714 | topics.append( "org.onosproject.election" ) |
| 715 | main.log.debug( topics ) |
| 716 | ONOStopics = [ j['topic'] for j in parsedLeaders ] |
| 717 | for topic in topics: |
| 718 | if topic not in ONOStopics: |
| 719 | main.log.error( "Error: " + topic + |
| 720 | " not in leaders" ) |
| 721 | else: |
| 722 | main.log.error( "leaders() returned None" ) |
| 723 | except ( ValueError, TypeError ): |
| 724 | main.log.exception( "Error parsing leaders" ) |
| 725 | main.log.error( repr( leaders ) ) |
| 726 | partitions = main.ONOScli1.partitions() |
| 727 | try: |
| 728 | if partitions : |
| 729 | parsedPartitions = json.loads( partitions ) |
| 730 | main.log.warn( json.dumps( parsedPartitions, |
| 731 | sort_keys=True, |
| 732 | indent=4, |
| 733 | separators=( ',', ': ' ) ) ) |
| 734 | # TODO check for a leader in all paritions |
| 735 | # TODO check for consistency among nodes |
| 736 | else: |
| 737 | main.log.error( "partitions() returned None" ) |
| 738 | except ( ValueError, TypeError ): |
| 739 | main.log.exception( "Error parsing partitions" ) |
| 740 | main.log.error( repr( partitions ) ) |
| 741 | pendingMap = main.ONOScli1.pendingMap() |
| 742 | try: |
| 743 | if pendingMap : |
| 744 | parsedPending = json.loads( pendingMap ) |
| 745 | main.log.warn( json.dumps( parsedPending, |
| 746 | sort_keys=True, |
| 747 | indent=4, |
| 748 | separators=( ',', ': ' ) ) ) |
| 749 | # TODO check something here? |
| 750 | else: |
| 751 | main.log.error( "pendingMap() returned None" ) |
| 752 | except ( ValueError, TypeError ): |
| 753 | main.log.exception( "Error parsing pending map" ) |
| 754 | main.log.error( repr( pendingMap ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 755 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 756 | def CASE5( self, main ): |
| 757 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 758 | Reading state of ONOS |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 759 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 760 | import json |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 761 | assert numControllers, "numControllers not defined" |
| 762 | assert main, "main not defined" |
| 763 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 764 | # assumes that sts is already in you PYTHONPATH |
| 765 | from sts.topology.teston_topology import TestONTopology |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 766 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 767 | main.log.report( "Setting up and gathering data for current state" ) |
| 768 | main.case( "Setting up and gathering data for current state" ) |
| 769 | # The general idea for this test case is to pull the state of |
| 770 | # ( intents,flows, topology,... ) from each ONOS node |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 771 | # We can then compare them with each other and also with past states |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 772 | |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 773 | main.step( "Check that each switch has a master" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 774 | global mastershipState |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 775 | mastershipState = '[]' |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 776 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 777 | # Assert that each device has a master |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 778 | rolesNotNull = main.ONOScli1.rolesNotNull() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 779 | utilities.assert_equals( |
| 780 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 781 | actual=rolesNotNull, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 782 | onpass="Each device has a master", |
| 783 | onfail="Some devices don't have a master assigned" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 784 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 785 | ONOS1Mastership = main.ONOScli1.roles() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 786 | # TODO: Make this a meaningful check |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 787 | if "Error" in ONOS1Mastership or not ONOS1Mastership: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 788 | main.log.report( "Error in getting ONOS roles" ) |
| 789 | main.log.warn( |
| 790 | "ONOS1 mastership response: " + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 791 | repr( ONOS1Mastership ) ) |
| 792 | consistentMastership = main.FALSE |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 793 | else: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 794 | mastershipState = ONOS1Mastership |
| 795 | consistentMastership = main.TRUE |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 796 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 797 | main.step( "Get the intents from each controller" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 798 | global intentState |
| 799 | intentState = [] |
| 800 | ONOS1Intents = main.ONOScli1.intents( jsonFormat=True ) |
| 801 | intentCheck = main.FALSE |
| 802 | if "Error" in ONOS1Intents or not ONOS1Intents: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 803 | main.log.report( "Error in getting ONOS intents" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 804 | main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 805 | else: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 806 | intentCheck = main.TRUE |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 807 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 808 | main.step( "Get the flows from each controller" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 809 | global flowState |
| 810 | flowState = [] |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 811 | flowCheck = main.FALSE |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 812 | ONOS1Flows = main.ONOScli1.flows( jsonFormat=True ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 813 | if "Error" in ONOS1Flows or not ONOS1Flows: |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 814 | main.log.report( "Error in getting ONOS flows" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 815 | main.log.warn( "ONOS1 flows repsponse: " + ONOS1Flows ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 816 | else: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 817 | # TODO: Do a better check, maybe compare flows on switches? |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 818 | flowState = ONOS1Flows |
| 819 | flowCheck = main.TRUE |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 820 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 821 | main.step( "Get the OF Table entries" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 822 | global flows |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 823 | flows = [] |
| 824 | for i in range( 1, 29 ): |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 825 | flows.append( main.Mininet2.getFlowTable( 1.3, "s" + str( i ) ) ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 826 | if flowCheck == main.FALSE: |
| 827 | for table in flows: |
| 828 | main.log.warn( table ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 829 | # TODO: Compare switch flow tables with ONOS flow tables |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 830 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 831 | main.step( "Create TestONTopology object" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 832 | ctrls = [] |
| 833 | count = 1 |
| 834 | temp = () |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 835 | temp = temp + ( getattr( main, ( 'ONOS' + str( count ) ) ), ) |
| 836 | temp = temp + ( "ONOS" + str( count ), ) |
| 837 | temp = temp + ( main.params[ 'CTRL' ][ 'ip' + str( count ) ], ) |
| 838 | temp = temp + \ |
| 839 | ( eval( main.params[ 'CTRL' ][ 'port' + str( count ) ] ), ) |
| 840 | ctrls.append( temp ) |
| 841 | MNTopo = TestONTopology( |
| 842 | main.Mininet1, |
| 843 | ctrls ) # can also add Intent API info for intent operations |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 844 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 845 | main.step( "Collecting topology information from ONOS" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 846 | devices = [] |
| 847 | devices.append( main.ONOScli1.devices() ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 848 | hosts = [] |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 849 | hosts.append( json.loads( main.ONOScli1.hosts() ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 850 | ports = [] |
| 851 | ports.append( main.ONOScli1.ports() ) |
| 852 | links = [] |
| 853 | links.append( main.ONOScli1.links() ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 854 | clusters = [] |
| 855 | clusters.append( main.ONOScli1.clusters() ) |
| 856 | ipResult = main.TRUE |
| 857 | for controller in range( 0, len( hosts ) ): |
| 858 | controllerStr = str( controller + 1 ) |
| 859 | for host in hosts[ controller ]: |
| 860 | if host is None or host.get( 'ips', [] ) == []: |
| 861 | main.log.error( |
| 862 | "DEBUG:Error with host ips on controller" + |
| 863 | controllerStr + ": " + str( host ) ) |
| 864 | ipResult = main.FALSE |
| 865 | |
| 866 | # there should always only be one cluster |
| 867 | numClusters = len( json.loads( clusters[ 0 ] ) ) |
| 868 | clusterResults = main.FALSE |
| 869 | if numClusters == 1: |
| 870 | clusterResults = main.TRUE |
| 871 | utilities.assert_equals( |
| 872 | expect=1, |
| 873 | actual=numClusters, |
| 874 | onpass="ONOS shows 1 SCC", |
| 875 | onfail="ONOS shows " + str( numClusters ) + " SCCs" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 876 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 877 | main.step( "Comparing ONOS topology to MN" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 878 | devicesResults = main.TRUE |
| 879 | portsResults = main.TRUE |
| 880 | linksResults = main.TRUE |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 881 | hostsResults = main.TRUE |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 882 | for controller in range( numControllers ): |
| 883 | controllerStr = str( controller + 1 ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 884 | if devices[ controller ] or "Error" not in devices[ controller ]: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 885 | currentDevicesResult = main.Mininet1.compareSwitches( |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 886 | MNTopo, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 887 | json.loads( devices[ controller ] ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 888 | else: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 889 | currentDevicesResult = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 890 | utilities.assert_equals( expect=main.TRUE, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 891 | actual=currentDevicesResult, |
| 892 | onpass="ONOS" + controllerStr + |
| 893 | " Switches view is correct", |
| 894 | onfail="ONOS" + controllerStr + |
| 895 | " Switches view is incorrect" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 896 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 897 | if ports[ controller ] or "Error" not in ports[ controller ]: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 898 | currentPortsResult = main.Mininet1.comparePorts( |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 899 | MNTopo, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 900 | json.loads( ports[ controller ] ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 901 | else: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 902 | currentPortsResult = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 903 | utilities.assert_equals( expect=main.TRUE, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 904 | actual=currentPortsResult, |
| 905 | onpass="ONOS" + controllerStr + |
| 906 | " ports view is correct", |
| 907 | onfail="ONOS" + controllerStr + |
| 908 | " ports view is incorrect" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 909 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 910 | if links[ controller ] or "Error" not in links[ controller ]: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 911 | currentLinksResult = main.Mininet1.compareLinks( |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 912 | MNTopo, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 913 | json.loads( links[ controller ] ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 914 | else: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 915 | currentLinksResult = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 916 | utilities.assert_equals( expect=main.TRUE, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 917 | actual=currentLinksResult, |
| 918 | onpass="ONOS" + controllerStr + |
| 919 | " links view is correct", |
| 920 | onfail="ONOS" + controllerStr + |
| 921 | " links view is incorrect" ) |
| 922 | |
| 923 | if hosts[ controller ] or "Error" not in hosts[ controller ]: |
| 924 | currentHostsResult = main.Mininet1.compareHosts( |
| 925 | MNTopo, hosts[ controller ] ) |
| 926 | else: |
| 927 | currentHostsResult = main.FALSE |
| 928 | utilities.assert_equals( expect=main.TRUE, |
| 929 | actual=currentHostsResult, |
| 930 | onpass="ONOS" + controllerStr + |
| 931 | " hosts exist in Mininet", |
| 932 | onfail="ONOS" + controllerStr + |
| 933 | " hosts don't match Mininet" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 934 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 935 | devicesResults = devicesResults and currentDevicesResult |
| 936 | portsResults = portsResults and currentPortsResult |
| 937 | linksResults = linksResults and currentLinksResult |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 938 | hostsResults = hostsResults and currentHostsResult |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 939 | |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 940 | topoResult = devicesResults and portsResults and linksResults\ |
| 941 | and clusterResults and ipResult and hostsResults |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 942 | utilities.assert_equals( expect=main.TRUE, actual=topoResult, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 943 | onpass="Topology Check Test successful", |
| 944 | onfail="Topology Check Test NOT successful" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 945 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 946 | finalAssert = main.TRUE |
| 947 | finalAssert = finalAssert and topoResult and flowCheck \ |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 948 | and intentCheck and consistentMastership and rolesNotNull |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 949 | utilities.assert_equals( expect=main.TRUE, actual=finalAssert, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 950 | onpass="State check successful", |
| 951 | onfail="State check NOT successful" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 952 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 953 | def CASE6( self, main ): |
| 954 | """ |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 955 | The Failure case. |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 956 | """ |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 957 | import time |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 958 | assert numControllers, "numControllers not defined" |
| 959 | assert main, "main not defined" |
| 960 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 961 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 962 | main.log.report( "Restart ONOS node" ) |
| 963 | main.log.case( "Restart ONOS node" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 964 | main.ONOSbench.onosKill( ONOS1Ip ) |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 965 | start = time.time() |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 966 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 967 | main.step( "Checking if ONOS is up yet" ) |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 968 | count = 0 |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 969 | while count < 10: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 970 | onos1Isup = main.ONOSbench.isup( ONOS1Ip ) |
| 971 | if onos1Isup == main.TRUE: |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 972 | elapsed = time.time() - start |
| 973 | break |
| 974 | else: |
| 975 | count = count + 1 |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 976 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 977 | cliResult = main.ONOScli1.startOnosCli( ONOS1Ip ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 978 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 979 | caseResults = main.TRUE and onos1Isup and cliResult |
| 980 | utilities.assert_equals( expect=main.TRUE, actual=caseResults, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 981 | onpass="ONOS restart successful", |
| 982 | onfail="ONOS restart NOT successful" ) |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 983 | if elapsed: |
| 984 | main.log.info( "ESTIMATE: ONOS took %s seconds to restart" % |
| 985 | str( elapsed ) ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 986 | time.sleep( 5 ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 987 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 988 | def CASE7( self, main ): |
| 989 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 990 | Check state after ONOS failure |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 991 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 992 | import json |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 993 | assert numControllers, "numControllers not defined" |
| 994 | assert main, "main not defined" |
| 995 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 996 | main.case( "Running ONOS Constant State Tests" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 997 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 998 | # Assert that each device has a master |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 999 | rolesNotNull = main.ONOScli1.rolesNotNull() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1000 | utilities.assert_equals( |
| 1001 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1002 | actual=rolesNotNull, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1003 | onpass="Each device has a master", |
| 1004 | onfail="Some devices don't have a master assigned" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1005 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1006 | main.step( "Check if switch roles are consistent across all nodes" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1007 | ONOS1Mastership = main.ONOScli1.roles() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1008 | # FIXME: Refactor this whole case for single instance |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1009 | if "Error" in ONOS1Mastership or not ONOS1Mastership: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1010 | main.log.report( "Error in getting ONOS mastership" ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1011 | main.log.warn( "ONOS1 mastership response: " + |
| 1012 | repr( ONOS1Mastership ) ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1013 | consistentMastership = main.FALSE |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1014 | else: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1015 | consistentMastership = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1016 | main.log.report( |
| 1017 | "Switch roles are consistent across all ONOS nodes" ) |
| 1018 | utilities.assert_equals( |
| 1019 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1020 | actual=consistentMastership, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1021 | onpass="Switch roles are consistent across all ONOS nodes", |
| 1022 | onfail="ONOS nodes have different views of switch roles" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1023 | |
| 1024 | description2 = "Compare switch roles from before failure" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1025 | main.step( description2 ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1026 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1027 | currentJson = json.loads( ONOS1Mastership ) |
| 1028 | oldJson = json.loads( mastershipState ) |
| 1029 | mastershipCheck = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1030 | for i in range( 1, 29 ): |
| 1031 | switchDPID = str( |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1032 | main.Mininet1.getSwitchDPID( switch="s" + str( i ) ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1033 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1034 | current = [ switch[ 'master' ] for switch in currentJson |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1035 | if switchDPID in switch[ 'id' ] ] |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1036 | old = [ switch[ 'master' ] for switch in oldJson |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1037 | if switchDPID in switch[ 'id' ] ] |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1038 | if current == old: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1039 | mastershipCheck = mastershipCheck and main.TRUE |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1040 | else: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1041 | main.log.warn( "Mastership of switch %s changed" % switchDPID ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1042 | mastershipCheck = main.FALSE |
| 1043 | if mastershipCheck == main.TRUE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1044 | main.log.report( "Mastership of Switches was not changed" ) |
| 1045 | utilities.assert_equals( |
| 1046 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1047 | actual=mastershipCheck, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1048 | onpass="Mastership of Switches was not changed", |
| 1049 | onfail="Mastership of some switches changed" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1050 | mastershipCheck = mastershipCheck and consistentMastership |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1051 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1052 | main.step( "Get the intents and compare across all nodes" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1053 | ONOS1Intents = main.ONOScli1.intents( jsonFormat=True ) |
| 1054 | intentCheck = main.FALSE |
| 1055 | if "Error" in ONOS1Intents or not ONOS1Intents: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1056 | main.log.report( "Error in getting ONOS intents" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1057 | main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1058 | else: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1059 | intentCheck = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1060 | main.log.report( "Intents are consistent across all ONOS nodes" ) |
| 1061 | utilities.assert_equals( |
| 1062 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1063 | actual=intentCheck, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1064 | onpass="Intents are consistent across all ONOS nodes", |
| 1065 | onfail="ONOS nodes have different views of intents" ) |
Jon Hall | 1b8f54a | 2015-02-04 13:24:20 -0800 | [diff] [blame] | 1066 | # Print the intent states |
| 1067 | intents = [] |
| 1068 | intents.append( ONOS1Intents ) |
| 1069 | intentStates = [] |
| 1070 | for node in intents: # Iter through ONOS nodes |
| 1071 | nodeStates = [] |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1072 | # Iter through intents of a node |
| 1073 | for intent in json.loads( node ): |
Jon Hall | 1b8f54a | 2015-02-04 13:24:20 -0800 | [diff] [blame] | 1074 | nodeStates.append( intent[ 'state' ] ) |
| 1075 | intentStates.append( nodeStates ) |
| 1076 | out = [ (i, nodeStates.count( i ) ) for i in set( nodeStates ) ] |
| 1077 | main.log.info( dict( out ) ) |
| 1078 | |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1079 | # NOTE: Store has no durability, so intents are lost across system |
| 1080 | # restarts |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1081 | """ |
| 1082 | main.step( "Compare current intents with intents before the failure" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1083 | # NOTE: this requires case 5 to pass for intentState to be set. |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1084 | # maybe we should stop the test if that fails? |
Jon Hall | 1b8f54a | 2015-02-04 13:24:20 -0800 | [diff] [blame] | 1085 | sameIntents = main.TRUE |
| 1086 | if intentState and intentState == ONOS1Intents: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1087 | sameIntents = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1088 | main.log.report( "Intents are consistent with before failure" ) |
| 1089 | # TODO: possibly the states have changed? we may need to figure out |
| 1090 | # what the aceptable states are |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1091 | else: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1092 | try: |
| 1093 | main.log.warn( "ONOS1 intents: " ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1094 | print json.dumps( json.loads( ONOS1Intents ), |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1095 | sort_keys=True, indent=4, |
| 1096 | separators=( ',', ': ' ) ) |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1097 | except Exception: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1098 | pass |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1099 | sameIntents = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1100 | utilities.assert_equals( |
| 1101 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1102 | actual=sameIntents, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1103 | onpass="Intents are consistent with before failure", |
| 1104 | onfail="The Intents changed during failure" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1105 | intentCheck = intentCheck and sameIntents |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1106 | """ |
| 1107 | main.step( "Get the OF Table entries and compare to before " + |
| 1108 | "component failure" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1109 | FlowTables = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1110 | flows2 = [] |
| 1111 | for i in range( 28 ): |
| 1112 | main.log.info( "Checking flow table on s" + str( i + 1 ) ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1113 | tmpFlows = main.Mininet2.getFlowTable( 1.3, "s" + str( i + 1 ) ) |
| 1114 | flows2.append( tmpFlows ) |
| 1115 | tempResult = main.Mininet2.flowComp( |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1116 | flow1=flows[ i ], |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1117 | flow2=tmpFlows ) |
| 1118 | FlowTables = FlowTables and tempResult |
| 1119 | if FlowTables == main.FALSE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1120 | main.log.info( "Differences in flow table for switch: s" + |
| 1121 | str( i + 1 ) ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1122 | if FlowTables == main.TRUE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1123 | main.log.report( "No changes were found in the flow tables" ) |
| 1124 | utilities.assert_equals( |
| 1125 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1126 | actual=FlowTables, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1127 | onpass="No changes were found in the flow tables", |
| 1128 | onfail="Changes were found in the flow tables" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1129 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1130 | # Test of LeadershipElection |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1131 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1132 | leader = ONOS1Ip |
| 1133 | leaderResult = main.TRUE |
| 1134 | for controller in range( 1, numControllers + 1 ): |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1135 | # loop through ONOScli handlers |
| 1136 | node = getattr( main, ( 'ONOScli' + str( controller ) ) ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1137 | leaderN = node.electionTestLeader() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1138 | # verify leader is ONOS1 |
| 1139 | # NOTE even though we restarted ONOS, it is the only one so onos 1 |
| 1140 | # must be leader |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1141 | if leaderN == leader: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1142 | # all is well |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1143 | pass |
| 1144 | elif leaderN == main.FALSE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1145 | # error in response |
| 1146 | main.log.report( "Something is wrong with " + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1147 | "electionTestLeader function, check the" + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1148 | " error logs" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1149 | leaderResult = main.FALSE |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1150 | elif leader != leaderN: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1151 | leaderResult = main.FALSE |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1152 | main.log.report( "ONOS" + str( controller ) + " sees " + |
| 1153 | str( leaderN ) + |
| 1154 | " as the leader of the election app. " + |
| 1155 | "Leader should be " + str( leader ) ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1156 | if leaderResult: |
| 1157 | main.log.report( "Leadership election tests passed( consistent " + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1158 | "view of leader across listeners and a new " + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1159 | "leader was re-elected if applicable )" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1160 | utilities.assert_equals( |
| 1161 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1162 | actual=leaderResult, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1163 | onpass="Leadership election passed", |
| 1164 | onfail="Something went wrong with Leadership election" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1165 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1166 | result = ( mastershipCheck and intentCheck and FlowTables and |
| 1167 | rolesNotNull and leaderResult ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1168 | result = int( result ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1169 | if result == main.TRUE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1170 | main.log.report( "Constant State Tests Passed" ) |
| 1171 | utilities.assert_equals( expect=main.TRUE, actual=result, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1172 | onpass="Constant State Tests Passed", |
| 1173 | onfail="Constant state tests failed" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1174 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1175 | def CASE8( self, main ): |
| 1176 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1177 | Compare topo |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1178 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1179 | import sys |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1180 | # FIXME add this path to params |
| 1181 | sys.path.append( "/home/admin/sts" ) |
| 1182 | # assumes that sts is already in you PYTHONPATH |
| 1183 | from sts.topology.teston_topology import TestONTopology |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1184 | import json |
| 1185 | import time |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1186 | assert numControllers, "numControllers not defined" |
| 1187 | assert main, "main not defined" |
| 1188 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1189 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1190 | description = "Compare ONOS Topology view to Mininet topology" |
| 1191 | main.case( description ) |
| 1192 | main.log.report( description ) |
| 1193 | main.step( "Create TestONTopology object" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1194 | ctrls = [] |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 1195 | node = main.ONOS1 |
| 1196 | temp = ( node, node.name, node.ip_address, 6633 ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1197 | ctrls.append( temp ) |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 1198 | MNTopo = TestONTopology( main.Mininet1, ctrls ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1199 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1200 | main.step( "Comparing ONOS topology to MN" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1201 | devicesResults = main.TRUE |
| 1202 | portsResults = main.TRUE |
| 1203 | linksResults = main.TRUE |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1204 | hostsResults = main.TRUE |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1205 | topoResult = main.FALSE |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1206 | elapsed = 0 |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 1207 | count = 0 |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1208 | main.step( "Collecting topology information from ONOS" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1209 | startTime = time.time() |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1210 | # Give time for Gossip to work |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1211 | while topoResult == main.FALSE and elapsed < 60: |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 1212 | count += 1 |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1213 | if count > 1: |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 1214 | # TODO: Deprecate STS usage |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1215 | MNTopo = TestONTopology( main.Mininet1, ctrls ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1216 | cliStart = time.time() |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1217 | devices = [] |
| 1218 | devices.append( main.ONOScli1.devices() ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1219 | hosts = [] |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1220 | hosts.append( json.loads( main.ONOScli1.hosts() ) ) |
| 1221 | ipResult = main.TRUE |
| 1222 | for controller in range( 0, len( hosts ) ): |
| 1223 | controllerStr = str( controller + 1 ) |
| 1224 | for host in hosts[ controller ]: |
| 1225 | if host is None or host.get( 'ips', [] ) == []: |
| 1226 | main.log.error( |
| 1227 | "DEBUG:Error with host ips on controller" + |
| 1228 | controllerStr + ": " + str( host ) ) |
| 1229 | ipResult = main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1230 | ports = [] |
| 1231 | ports.append( main.ONOScli1.ports() ) |
| 1232 | links = [] |
| 1233 | links.append( main.ONOScli1.links() ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1234 | clusters = [] |
| 1235 | clusters.append( main.ONOScli1.clusters() ) |
| 1236 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1237 | elapsed = time.time() - startTime |
| 1238 | cliTime = time.time() - cliStart |
| 1239 | print "CLI time: " + str( cliTime ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1240 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1241 | for controller in range( numControllers ): |
| 1242 | controllerStr = str( controller + 1 ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1243 | if devices[ controller ] or "Error" not in devices[ |
| 1244 | controller ]: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1245 | currentDevicesResult = main.Mininet1.compareSwitches( |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1246 | MNTopo, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1247 | json.loads( devices[ controller ] ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1248 | else: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1249 | currentDevicesResult = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1250 | utilities.assert_equals( expect=main.TRUE, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1251 | actual=currentDevicesResult, |
| 1252 | onpass="ONOS" + controllerStr + |
| 1253 | " Switches view is correct", |
| 1254 | onfail="ONOS" + controllerStr + |
| 1255 | " Switches view is incorrect" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1256 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1257 | if ports[ controller ] or "Error" not in ports[ controller ]: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1258 | currentPortsResult = main.Mininet1.comparePorts( |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1259 | MNTopo, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1260 | json.loads( ports[ controller ] ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1261 | else: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1262 | currentPortsResult = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1263 | utilities.assert_equals( expect=main.TRUE, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1264 | actual=currentPortsResult, |
| 1265 | onpass="ONOS" + controllerStr + |
| 1266 | " ports view is correct", |
| 1267 | onfail="ONOS" + controllerStr + |
| 1268 | " ports view is incorrect" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1269 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1270 | if links[ controller ] or "Error" not in links[ controller ]: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1271 | currentLinksResult = main.Mininet1.compareLinks( |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1272 | MNTopo, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1273 | json.loads( links[ controller ] ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1274 | else: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1275 | currentLinksResult = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1276 | utilities.assert_equals( expect=main.TRUE, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1277 | actual=currentLinksResult, |
| 1278 | onpass="ONOS" + controllerStr + |
| 1279 | " links view is correct", |
| 1280 | onfail="ONOS" + controllerStr + |
| 1281 | " links view is incorrect" ) |
| 1282 | |
| 1283 | if hosts[ controller ] or "Error" not in hosts[ controller ]: |
| 1284 | currentHostsResult = main.Mininet1.compareHosts( |
| 1285 | MNTopo, hosts[ controller ] ) |
| 1286 | else: |
| 1287 | currentHostsResult = main.FALSE |
| 1288 | utilities.assert_equals( expect=main.TRUE, |
| 1289 | actual=currentHostsResult, |
| 1290 | onpass="ONOS" + controllerStr + |
| 1291 | " hosts exist in Mininet", |
| 1292 | onfail="ONOS" + controllerStr + |
| 1293 | " hosts don't match Mininet" ) |
| 1294 | |
| 1295 | devicesResults = devicesResults and currentDevicesResult |
| 1296 | portsResults = portsResults and currentPortsResult |
| 1297 | linksResults = linksResults and currentLinksResult |
| 1298 | hostsResults = hostsResults and currentHostsResult |
| 1299 | |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 1300 | # "consistent" results don't make sense for single instance |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1301 | # there should always only be one cluster |
| 1302 | numClusters = len( json.loads( clusters[ 0 ] ) ) |
| 1303 | clusterResults = main.FALSE |
| 1304 | if numClusters == 1: |
| 1305 | clusterResults = main.TRUE |
| 1306 | utilities.assert_equals( |
| 1307 | expect=1, |
| 1308 | actual=numClusters, |
| 1309 | onpass="ONOS shows 1 SCC", |
| 1310 | onfail="ONOS shows " + str( numClusters ) + " SCCs" ) |
| 1311 | |
| 1312 | topoResult = ( devicesResults and portsResults and linksResults |
| 1313 | and hostsResults and ipResult and clusterResults ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1314 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1315 | topoResult = topoResult and int( count <= 2 ) |
| 1316 | note = "note it takes about " + str( int( cliTime ) ) + \ |
| 1317 | " seconds for the test to make all the cli calls to fetch " +\ |
| 1318 | "the topology from each ONOS instance" |
Jon Hall | 1b8f54a | 2015-02-04 13:24:20 -0800 | [diff] [blame] | 1319 | main.log.info( |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1320 | "Very crass estimate for topology discovery/convergence( " + |
| 1321 | str( note ) + " ): " + str( elapsed ) + " seconds, " + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1322 | str( count ) + " tries" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1323 | utilities.assert_equals( expect=main.TRUE, actual=topoResult, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1324 | onpass="Topology Check Test successful", |
| 1325 | onfail="Topology Check Test NOT successful" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1326 | if topoResult == main.TRUE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1327 | main.log.report( "ONOS topology view matches Mininet topology" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1328 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1329 | def CASE9( self, main ): |
| 1330 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1331 | Link s3-s28 down |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1332 | """ |
| 1333 | import time |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1334 | assert numControllers, "numControllers not defined" |
| 1335 | assert main, "main not defined" |
| 1336 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1337 | # NOTE: You should probably run a topology check after this |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1338 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1339 | linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1340 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1341 | description = "Turn off a link to ensure that Link Discovery " +\ |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1342 | "is working properly" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1343 | main.log.report( description ) |
| 1344 | main.case( description ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1345 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1346 | main.step( "Kill Link between s3 and s28" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1347 | LinkDown = main.Mininet1.link( END1="s3", END2="s28", OPTION="down" ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1348 | main.log.info( "Waiting " + str( linkSleep ) + |
| 1349 | " seconds for link down to be discovered" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1350 | time.sleep( linkSleep ) |
| 1351 | utilities.assert_equals( expect=main.TRUE, actual=LinkDown, |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 1352 | onpass="Link down successful", |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1353 | onfail="Failed to bring link down" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1354 | # TODO do some sort of check here |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1355 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1356 | def CASE10( self, main ): |
| 1357 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1358 | Link s3-s28 up |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1359 | """ |
| 1360 | import time |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1361 | assert numControllers, "numControllers not defined" |
| 1362 | assert main, "main not defined" |
| 1363 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1364 | # NOTE: You should probably run a topology check after this |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1365 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1366 | linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1367 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1368 | description = "Restore a link to ensure that Link Discovery is " + \ |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1369 | "working properly" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1370 | main.log.report( description ) |
| 1371 | main.case( description ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1372 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1373 | main.step( "Bring link between s3 and s28 back up" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1374 | LinkUp = main.Mininet1.link( END1="s3", END2="s28", OPTION="up" ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1375 | main.log.info( "Waiting " + str( linkSleep ) + |
| 1376 | " seconds for link up to be discovered" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1377 | time.sleep( linkSleep ) |
| 1378 | utilities.assert_equals( expect=main.TRUE, actual=LinkUp, |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 1379 | onpass="Link up successful", |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1380 | onfail="Failed to bring link up" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1381 | # TODO do some sort of check here |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1382 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1383 | def CASE11( self, main ): |
| 1384 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1385 | Switch Down |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1386 | """ |
| 1387 | # NOTE: You should probably run a topology check after this |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1388 | import time |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1389 | assert numControllers, "numControllers not defined" |
| 1390 | assert main, "main not defined" |
| 1391 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1392 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1393 | switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1394 | |
| 1395 | description = "Killing a switch to ensure it is discovered correctly" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1396 | main.log.report( description ) |
| 1397 | main.case( description ) |
| 1398 | switch = main.params[ 'kill' ][ 'switch' ] |
| 1399 | switchDPID = main.params[ 'kill' ][ 'dpid' ] |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1400 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1401 | # TODO: Make this switch parameterizable |
| 1402 | main.step( "Kill " + switch ) |
| 1403 | main.log.report( "Deleting " + switch ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1404 | main.Mininet1.delSwitch( switch ) |
| 1405 | main.log.info( "Waiting " + str( switchSleep ) + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1406 | " seconds for switch down to be discovered" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1407 | time.sleep( switchSleep ) |
| 1408 | device = main.ONOScli1.getDevice( dpid=switchDPID ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1409 | # Peek at the deleted switch |
| 1410 | main.log.warn( str( device ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1411 | result = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1412 | if device and device[ 'available' ] is False: |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1413 | result = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1414 | utilities.assert_equals( expect=main.TRUE, actual=result, |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 1415 | onpass="Kill switch successful", |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1416 | onfail="Failed to kill switch?" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1417 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1418 | def CASE12( self, main ): |
| 1419 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1420 | Switch Up |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1421 | """ |
| 1422 | # NOTE: You should probably run a topology check after this |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1423 | import time |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1424 | assert numControllers, "numControllers not defined" |
| 1425 | assert main, "main not defined" |
| 1426 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
| 1427 | assert ONOS1Port, "ONOS1Port not defined" |
| 1428 | assert ONOS2Port, "ONOS2Port not defined" |
| 1429 | assert ONOS3Port, "ONOS3Port not defined" |
| 1430 | assert ONOS4Port, "ONOS4Port not defined" |
| 1431 | assert ONOS5Port, "ONOS5Port not defined" |
| 1432 | assert ONOS6Port, "ONOS6Port not defined" |
| 1433 | assert ONOS7Port, "ONOS7Port not defined" |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1434 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1435 | switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1436 | switch = main.params[ 'kill' ][ 'switch' ] |
| 1437 | switchDPID = main.params[ 'kill' ][ 'dpid' ] |
| 1438 | links = main.params[ 'kill' ][ 'links' ].split() |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1439 | description = "Adding a switch to ensure it is discovered correctly" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1440 | main.log.report( description ) |
| 1441 | main.case( description ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1442 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1443 | main.step( "Add back " + switch ) |
| 1444 | main.log.report( "Adding back " + switch ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1445 | main.Mininet1.addSwitch( switch, dpid=switchDPID ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1446 | for peer in links: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1447 | main.Mininet1.addLink( switch, peer ) |
| 1448 | main.Mininet1.assignSwController( sw=switch.split( 's' )[ 1 ], |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1449 | ip1=ONOS1Ip, |
| 1450 | port1=ONOS1Port ) |
| 1451 | main.log.info( "Waiting " + str( switchSleep ) + |
| 1452 | " seconds for switch up to be discovered" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1453 | time.sleep( switchSleep ) |
| 1454 | device = main.ONOScli1.getDevice( dpid=switchDPID ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1455 | # Peek at the deleted switch |
| 1456 | main.log.warn( str( device ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1457 | result = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1458 | if device and device[ 'available' ]: |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1459 | result = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1460 | utilities.assert_equals( expect=main.TRUE, actual=result, |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 1461 | onpass="add switch successful", |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1462 | onfail="Failed to add switch?" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1463 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1464 | def CASE13( self, main ): |
| 1465 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1466 | Clean up |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1467 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1468 | import os |
| 1469 | import time |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1470 | assert numControllers, "numControllers not defined" |
| 1471 | assert main, "main not defined" |
| 1472 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1473 | # printing colors to terminal |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 1474 | colors = { 'cyan': '\033[96m', 'purple': '\033[95m', |
| 1475 | 'blue': '\033[94m', 'green': '\033[92m', |
| 1476 | 'yellow': '\033[93m', 'red': '\033[91m', 'end': '\033[0m' } |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1477 | description = "Test Cleanup" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1478 | main.log.report( description ) |
| 1479 | main.case( description ) |
| 1480 | main.step( "Killing tcpdumps" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1481 | main.Mininet2.stopTcpdump() |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1482 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1483 | main.step( "Copying MN pcap and ONOS log files to test station" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1484 | testname = main.TEST |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1485 | teststationUser = main.params[ 'TESTONUSER' ] |
| 1486 | teststationIP = main.params[ 'TESTONIP' ] |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1487 | # NOTE: MN Pcap file is being saved to ~/packet_captures |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1488 | # 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] | 1489 | # FIXME: scp |
| 1490 | # mn files |
| 1491 | # TODO: Load these from params |
| 1492 | # NOTE: must end in / |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1493 | logFolder = "/opt/onos/log/" |
| 1494 | logFiles = [ "karaf.log", "karaf.log.1" ] |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1495 | # NOTE: must end in / |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1496 | dstDir = "~/packet_captures/" |
| 1497 | for f in logFiles: |
| 1498 | main.ONOSbench.handle.sendline( "scp sdn@" + ONOS1Ip + ":" + |
| 1499 | logFolder + f + " " + |
| 1500 | teststationUser + "@" + |
| 1501 | teststationIP + ":" + dstDir + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1502 | str( testname ) + "-ONOS1-" + f ) |
| 1503 | main.ONOSbench.handle.expect( "\$" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1504 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1505 | # std*.log's |
| 1506 | # NOTE: must end in / |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1507 | logFolder = "/opt/onos/var/" |
| 1508 | logFiles = [ "stderr.log", "stdout.log" ] |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1509 | # NOTE: must end in / |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1510 | dstDir = "~/packet_captures/" |
| 1511 | for f in logFiles: |
| 1512 | main.ONOSbench.handle.sendline( "scp sdn@" + ONOS1Ip + ":" + |
| 1513 | logFolder + f + " " + |
| 1514 | teststationUser + "@" + |
| 1515 | teststationIP + ":" + dstDir + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1516 | str( testname ) + "-ONOS1-" + f ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1517 | main.ONOSbench.handle.expect( "\$" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1518 | # sleep so scp can finish |
| 1519 | time.sleep( 10 ) |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 1520 | |
| 1521 | main.step( "Stopping Mininet" ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1522 | main.Mininet1.stopNet() |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 1523 | |
| 1524 | main.step( "Checking ONOS Logs for errors" ) |
| 1525 | print colors[ 'purple' ] + "Checking logs for errors on ONOS1:" + \ |
| 1526 | colors[ 'end' ] |
| 1527 | print main.ONOSbench.checkLogs( ONOS1Ip ) |
| 1528 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1529 | main.step( "Packing and rotating pcap archives" ) |
| 1530 | os.system( "~/TestON/dependencies/rotate.sh " + str( testname ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1531 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1532 | # TODO: actually check something here |
| 1533 | utilities.assert_equals( expect=main.TRUE, actual=main.TRUE, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1534 | onpass="Test cleanup successful", |
| 1535 | onfail="Test cleanup NOT successful" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1536 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1537 | def CASE14( self, main ): |
| 1538 | """ |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1539 | start election app on all onos nodes |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1540 | """ |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1541 | assert numControllers, "numControllers not defined" |
| 1542 | assert main, "main not defined" |
| 1543 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 1544 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1545 | leaderResult = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1546 | main.log.info( "Install leadership election app" ) |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 1547 | main.ONOScli1.activateApp( "org.onosproject.election" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1548 | # check for leader |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1549 | leader = main.ONOScli1.electionTestLeader() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1550 | # verify leader is ONOS1 |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1551 | if leader == ONOS1Ip: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1552 | # all is well |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1553 | pass |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1554 | elif leader is None: |
| 1555 | # No leader elected |
| 1556 | main.log.report( "No leader was elected" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1557 | leaderResult = main.FALSE |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1558 | elif leader == main.FALSE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1559 | # error in response |
| 1560 | # TODO: add check for "Command not found:" in the driver, this |
| 1561 | # means the app isn't loaded |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1562 | main.log.report( "Something is wrong with electionTestLeader" + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1563 | " function, check the error logs" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1564 | leaderResult = main.FALSE |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1565 | else: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1566 | # error in response |
| 1567 | main.log.report( |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1568 | "Unexpected response from electionTestLeader function:'" + |
| 1569 | str( leader ) + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1570 | "'" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1571 | leaderResult = main.FALSE |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1572 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1573 | if leaderResult: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1574 | main.log.report( "Leadership election tests passed( consistent " + |
| 1575 | "view of leader across listeners and a leader " + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1576 | "was elected )" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1577 | utilities.assert_equals( |
| 1578 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1579 | actual=leaderResult, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1580 | onpass="Leadership election passed", |
| 1581 | onfail="Something went wrong with Leadership election" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1582 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1583 | def CASE15( self, main ): |
| 1584 | """ |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1585 | Check that Leadership Election is still functional |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1586 | """ |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1587 | assert numControllers, "numControllers not defined" |
| 1588 | assert main, "main not defined" |
| 1589 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1590 | leaderResult = main.TRUE |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1591 | description = "Check that Leadership Election is still functional" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1592 | main.log.report( description ) |
| 1593 | main.case( description ) |
| 1594 | main.step( "Find current leader and withdraw" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1595 | leader = main.ONOScli1.electionTestLeader() |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 1596 | # do some sanity checking on leader before using it |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1597 | withdrawResult = main.FALSE |
| 1598 | if leader == ONOS1Ip: |
| 1599 | oldLeader = getattr( main, "ONOScli1" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1600 | elif leader is None or leader == main.FALSE: |
| 1601 | main.log.report( |
| 1602 | "Leader for the election app should be an ONOS node," + |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1603 | "instead got '" + str( leader ) + "'" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1604 | leaderResult = main.FALSE |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 1605 | oldLeader = None |
| 1606 | else: |
| 1607 | main.log.error( "Leader election --- why am I HERE?!?") |
| 1608 | if oldLeader: |
| 1609 | withdrawResult = oldLeader.electionTestWithdraw() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1610 | utilities.assert_equals( |
| 1611 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1612 | actual=withdrawResult, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1613 | onpass="App was withdrawn from election", |
| 1614 | onfail="App was not withdrawn from election" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1615 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1616 | main.step( "Make sure new leader is elected" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1617 | leaderN = main.ONOScli1.electionTestLeader() |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1618 | if leaderN == leader: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1619 | main.log.report( "ONOS still sees " + str( leaderN ) + |
| 1620 | " as leader after they withdrew" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1621 | leaderResult = main.FALSE |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1622 | elif leaderN == main.FALSE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1623 | # error in response |
| 1624 | # TODO: add check for "Command not found:" in the driver, this |
| 1625 | # means the app isn't loaded |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1626 | main.log.report( "Something is wrong with electionTestLeader " + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1627 | "function, check the error logs" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1628 | leaderResult = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1629 | elif leaderN is None: |
| 1630 | main.log.info( |
| 1631 | "There is no leader after the app withdrew from election" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1632 | if leaderResult: |
| 1633 | main.log.report( "Leadership election tests passed( There is no " + |
| 1634 | "leader after the old leader resigned )" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1635 | utilities.assert_equals( |
| 1636 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1637 | actual=leaderResult, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1638 | onpass="Leadership election passed", |
| 1639 | onfail="Something went wrong with Leadership election" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1640 | |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1641 | main.step( "Run for election on old leader( just so everyone " + |
| 1642 | "is in the hat )" ) |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 1643 | if oldLeader: |
| 1644 | runResult = oldLeader.electionTestRun() |
| 1645 | else: |
| 1646 | runResult = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1647 | utilities.assert_equals( |
| 1648 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1649 | actual=runResult, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1650 | onpass="App re-ran for election", |
| 1651 | onfail="App failed to run for election" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1652 | leader = main.ONOScli1.electionTestLeader() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1653 | # verify leader is ONOS1 |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1654 | if leader == ONOS1Ip: |
| 1655 | leaderResult = main.TRUE |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1656 | else: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1657 | leaderResult = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1658 | # TODO: assert on run and withdraw results? |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1659 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1660 | utilities.assert_equals( |
| 1661 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1662 | actual=leaderResult, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1663 | onpass="Leadership election passed", |
| 1664 | onfail="ONOS1's election app was not leader after it re-ran " + |
| 1665 | "for election" ) |