Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1 | """ |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 2 | Description: This test is to determine if the HA test setup is |
| 3 | working correctly. There are no failures so this test should |
| 4 | have a 100% pass rate |
| 5 | |
| 6 | List of test cases: |
| 7 | CASE1: Compile ONOS and push it to the test machines |
| 8 | CASE2: Assign mastership to controllers |
| 9 | CASE3: Assign intents |
| 10 | CASE4: Ping across added host intents |
| 11 | CASE5: Reading state of ONOS |
| 12 | CASE6: The Failure case. Since this is the Sanity test, we do nothing. |
Jon Hall | 368769f | 2014-11-19 15:43:35 -0800 | [diff] [blame] | 13 | CASE7: Check state after control plane failure |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 14 | CASE8: Compare topo |
| 15 | CASE9: Link s3-s28 down |
| 16 | CASE10: Link s3-s28 up |
| 17 | CASE11: Switch down |
| 18 | CASE12: Switch up |
| 19 | CASE13: Clean up |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 20 | CASE14: start election app on all onos nodes |
| 21 | CASE15: Check that Leadership Election is still functional |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 22 | """ |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 23 | |
| 24 | |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 25 | class HATestSanity: |
| 26 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 27 | def __init__( self ): |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 28 | self.default = '' |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 29 | self.threadID = 0 |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 30 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 31 | def CASE1( self, main ): |
| 32 | """ |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 33 | CASE1 is to compile ONOS and push it to the test machines |
| 34 | |
| 35 | Startup sequence: |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 36 | cell <name> |
| 37 | onos-verify-cell |
| 38 | NOTE: temporary - onos-remove-raft-logs |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 39 | onos-uninstall |
| 40 | start mininet |
| 41 | git pull |
| 42 | mvn clean install |
| 43 | onos-package |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 44 | onos-install -f |
| 45 | onos-wait-for-start |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 46 | start cli sessions |
| 47 | start tcpdump |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 48 | """ |
| 49 | main.log.report( "ONOS HA Sanity test - initialization" ) |
| 50 | main.case( "Setting up test environment" ) |
| 51 | # TODO: save all the timers and output them for plotting |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 52 | |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 53 | # load some variables from the params file |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 54 | PULLCODE = False |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 55 | if main.params[ 'Git' ] == 'True': |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 56 | PULLCODE = True |
Jon Hall | 529a37f | 2015-01-28 10:02:00 -0800 | [diff] [blame] | 57 | gitBranch = main.params[ 'branch' ] |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 58 | cellName = main.params[ 'ENV' ][ 'cellName' ] |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 59 | |
| 60 | # set global variables |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 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 | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 69 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 70 | numControllers = int( main.params[ 'num_controllers' ] ) |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 71 | # FIXME: just get controller port from params? |
| 72 | # TODO: do we really need all these? |
| 73 | ONOS1Port = main.params[ 'CTRL' ][ 'port1' ] |
| 74 | ONOS2Port = main.params[ 'CTRL' ][ 'port2' ] |
| 75 | ONOS3Port = main.params[ 'CTRL' ][ 'port3' ] |
| 76 | ONOS4Port = main.params[ 'CTRL' ][ 'port4' ] |
| 77 | ONOS5Port = main.params[ 'CTRL' ][ 'port5' ] |
| 78 | ONOS6Port = main.params[ 'CTRL' ][ 'port6' ] |
| 79 | ONOS7Port = main.params[ 'CTRL' ][ 'port7' ] |
| 80 | |
| 81 | global CLIs |
| 82 | CLIs = [] |
| 83 | global nodes |
| 84 | nodes = [] |
| 85 | for i in range( 1, numControllers + 1 ): |
| 86 | CLIs.append( getattr( main, 'ONOScli' + str( i ) ) ) |
| 87 | nodes.append( getattr( main, 'ONOS' + str( i ) ) ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 88 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 89 | main.step( "Applying cell variable to environment" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 90 | cellResult = main.ONOSbench.setCell( cellName ) |
| 91 | verifyResult = main.ONOSbench.verifyCell() |
Jon Hall | 368769f | 2014-11-19 15:43:35 -0800 | [diff] [blame] | 92 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 93 | # FIXME:this is short term fix |
| 94 | main.log.report( "Removing raft logs" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 95 | main.ONOSbench.onosRemoveRaftLogs() |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 96 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 97 | main.log.report( "Uninstalling ONOS" ) |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 98 | for node in nodes: |
| 99 | main.ONOSbench.onosUninstall( node.ip_address ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 100 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 101 | cleanInstallResult = main.TRUE |
| 102 | gitPullResult = main.TRUE |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 103 | |
Jon Hall | 97f3175 | 2015-02-04 12:01:04 -0800 | [diff] [blame] | 104 | main.step( "Starting Mininet" ) |
| 105 | main.Mininet1.startNet( ) |
| 106 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 107 | main.step( "Compiling the latest version of ONOS" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 108 | if PULLCODE: |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 109 | main.step( "Git checkout and pull " + gitBranch ) |
Jon Hall | 529a37f | 2015-01-28 10:02:00 -0800 | [diff] [blame] | 110 | main.ONOSbench.gitCheckout( gitBranch ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 111 | gitPullResult = main.ONOSbench.gitPull() |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 112 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 113 | main.step( "Using mvn clean & install" ) |
Jon Hall | 529a37f | 2015-01-28 10:02:00 -0800 | [diff] [blame] | 114 | cleanInstallResult = main.ONOSbench.cleanInstall() |
| 115 | else: |
| 116 | main.log.warn( "Did not pull new code so skipping mvn " + |
| 117 | "clean install" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 118 | main.ONOSbench.getVersion( report=True ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 119 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 120 | main.step( "Creating ONOS package" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 121 | packageResult = main.ONOSbench.onosPackage() |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 122 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 123 | main.step( "Installing ONOS package" ) |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 124 | onosInstallResult = main.TRUE |
| 125 | for node in nodes: |
| 126 | tmpResult = main.ONOSbench.onosInstall( options="-f", |
| 127 | node=node.ip_address ) |
| 128 | onosInstallResult = onosInstallResult and tmpResult |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [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 | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 132 | onosIsupResult = main.TRUE |
| 133 | for node in nodes: |
| 134 | started = main.ONOSbench.isup( node.ip_address ) |
| 135 | if not started: |
| 136 | main.log.report( node.name + " didn't start!" ) |
| 137 | main.ONOSbench.onosStop( node.ip_address ) |
| 138 | main.ONOSbench.onosStart( node.ip_address ) |
| 139 | onosIsupResult = onosIsupResult and started |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 140 | if onosIsupResult == main.TRUE: |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 141 | break |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 142 | |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 143 | main.log.step( "Starting ONOS CLI sessions" ) |
| 144 | cliResults = main.TRUE |
| 145 | threads = [] |
| 146 | for i in range( numControllers ): |
| 147 | t = main.Thread( target=CLIs[i].startOnosCli, |
| 148 | threadID=self.threadID, |
| 149 | name="startOnosCli-" + str( i ), |
| 150 | args=[nodes[i].ip_address] ) |
| 151 | threads.append( t ) |
| 152 | t.start() |
| 153 | self.threadID += 1 |
| 154 | |
| 155 | for t in threads: |
| 156 | t.join() |
| 157 | cliResults = cliResults and t.result |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 158 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 159 | main.step( "Start Packet Capture MN" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 160 | main.Mininet2.startTcpdump( |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 161 | str( main.params[ 'MNtcpdump' ][ 'folder' ] ) + str( main.TEST ) |
| 162 | + "-MN.pcap", |
| 163 | intf=main.params[ 'MNtcpdump' ][ 'intf' ], |
| 164 | port=main.params[ 'MNtcpdump' ][ 'port' ] ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 165 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 166 | case1Result = ( cleanInstallResult and packageResult and |
| 167 | cellResult and verifyResult and onosInstallResult |
| 168 | and onosIsupResult and cliResults ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 169 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 170 | utilities.assert_equals( expect=main.TRUE, actual=case1Result, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 171 | onpass="Test startup successful", |
| 172 | onfail="Test startup NOT successful" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 173 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 174 | if case1Result == main.FALSE: |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 175 | main.cleanup() |
| 176 | main.exit() |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 177 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 178 | def CASE2( self, main ): |
| 179 | """ |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 180 | Assign mastership to controllers |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 181 | """ |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 182 | import re |
| 183 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 184 | main.log.report( "Assigning switches to controllers" ) |
| 185 | main.case( "Assigning Controllers" ) |
| 186 | main.step( "Assign switches to controllers" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 187 | |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 188 | # TODO: rewrite this function to take lists of ips and ports? |
| 189 | # or list of tuples? |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 190 | for i in range( 1, 29 ): |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 191 | main.Mininet1.assignSwController( |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 192 | sw=str( i ), |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 193 | count=numControllers, |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 194 | ip1=nodes[ 0 ].ip_address, port1=ONOS1Port, |
| 195 | ip2=nodes[ 1 ].ip_address, port2=ONOS2Port, |
| 196 | ip3=nodes[ 2 ].ip_address, port3=ONOS3Port, |
| 197 | ip4=nodes[ 3 ].ip_address, port4=ONOS4Port, |
| 198 | ip5=nodes[ 4 ].ip_address, port5=ONOS5Port, |
| 199 | ip6=nodes[ 5 ].ip_address, port6=ONOS6Port, |
| 200 | ip7=nodes[ 6 ].ip_address, port7=ONOS7Port ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 201 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 202 | mastershipCheck = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 203 | for i in range( 1, 29 ): |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 204 | response = main.Mininet1.getSwController( "s" + str( i ) ) |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 205 | try: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 206 | main.log.info( str( response ) ) |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 207 | except Exception: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 208 | main.log.info( repr( response ) ) |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 209 | for node in nodes: |
| 210 | if re.search( "tcp:" + node.ip_address, response ): |
| 211 | mastershipCheck = mastershipCheck and main.TRUE |
| 212 | else: |
| 213 | mastershipCheck = main.FALSE |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 214 | if mastershipCheck == main.TRUE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 215 | main.log.report( "Switch mastership assigned correctly" ) |
| 216 | utilities.assert_equals( |
| 217 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 218 | actual=mastershipCheck, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 219 | onpass="Switch mastership assigned correctly", |
| 220 | onfail="Switches not assigned correctly to controllers" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 221 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 222 | # Manually assign mastership to the controller we want |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 223 | roleCall = main.TRUE |
| 224 | roleCheck = main.TRUE |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 225 | try: |
| 226 | # Assign switch |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 227 | ip = nodes[ 0 ].ip_address # ONOS1 |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 228 | deviceId = main.ONOScli1.getDevice( "1000" ).get( 'id' ) |
| 229 | assert deviceId, "No device id for s1 in ONOS" |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 230 | roleCall = roleCall and main.ONOScli1.deviceRole( |
| 231 | deviceId, |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 232 | ip ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 233 | # Check assignment |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 234 | if ip in main.ONOScli1.getRole( deviceId ).get( 'master' ): |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 235 | roleCheck = roleCheck and main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 236 | else: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 237 | roleCheck = roleCheck and main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 238 | |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 239 | # Assign switch |
| 240 | deviceId = main.ONOScli1.getDevice( "2800" ).get( 'id' ) |
| 241 | assert deviceId, "No device id for s28 in ONOS" |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 242 | roleCall = roleCall and main.ONOScli1.deviceRole( |
| 243 | deviceId, |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 244 | ip ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 245 | # Check assignment |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 246 | if ip in main.ONOScli1.getRole( deviceId ).get( 'master' ): |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 247 | roleCheck = roleCheck and main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 248 | else: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 249 | roleCheck = roleCheck and main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 250 | |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 251 | ip = nodes[ 1 ].ip_address # ONOS2 |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 252 | # Assign switch |
| 253 | deviceId = main.ONOScli1.getDevice( "2000" ).get( 'id' ) |
| 254 | assert deviceId, "No device id for s2 in ONOS" |
| 255 | roleCall = roleCall and main.ONOScli1.deviceRole( |
| 256 | deviceId, |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 257 | ip ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 258 | # Check assignment |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 259 | if ip in main.ONOScli1.getRole( deviceId ).get( 'master' ): |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 260 | roleCheck = roleCheck and main.TRUE |
| 261 | else: |
| 262 | roleCheck = roleCheck and main.FALSE |
| 263 | |
| 264 | # Assign switch |
| 265 | deviceId = main.ONOScli1.getDevice( "3000" ).get( 'id' ) |
| 266 | assert deviceId, "No device id for s3 in ONOS" |
| 267 | roleCall = roleCall and main.ONOScli1.deviceRole( |
| 268 | deviceId, |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 269 | ip ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 270 | # Check assignment |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 271 | if ip in main.ONOScli1.getRole( deviceId ).get( 'master' ): |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 272 | roleCheck = roleCheck and main.TRUE |
| 273 | else: |
| 274 | roleCheck = roleCheck and main.FALSE |
| 275 | |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 276 | ip = nodes[ 2 ].ip_address # ONOS3 |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 277 | # Assign switch |
| 278 | deviceId = main.ONOScli1.getDevice( "5000" ).get( 'id' ) |
| 279 | assert deviceId, "No device id for s5 in ONOS" |
| 280 | roleCall = roleCall and main.ONOScli1.deviceRole( |
| 281 | deviceId, |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 282 | ip ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 283 | # Check assignment |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 284 | if ip in main.ONOScli1.getRole( deviceId ).get( 'master' ): |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 285 | roleCheck = roleCheck and main.TRUE |
| 286 | else: |
| 287 | roleCheck = roleCheck and main.FALSE |
| 288 | |
| 289 | # Assign switch |
| 290 | deviceId = main.ONOScli1.getDevice( "6000" ).get( 'id' ) |
| 291 | assert deviceId, "No device id for s6 in ONOS" |
| 292 | roleCall = roleCall and main.ONOScli1.deviceRole( |
| 293 | deviceId, |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 294 | ip ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 295 | # Check assignment |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 296 | if ip in main.ONOScli1.getRole( deviceId ).get( 'master' ): |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 297 | roleCheck = roleCheck and main.TRUE |
| 298 | else: |
| 299 | roleCheck = roleCheck and main.FALSE |
| 300 | |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 301 | ip = nodes[ 3 ].ip_address # ONOS4 |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 302 | # Assign switch |
| 303 | deviceId = main.ONOScli1.getDevice( "3004" ).get( 'id' ) |
| 304 | assert deviceId, "No device id for s4 in ONOS" |
| 305 | roleCall = roleCall and main.ONOScli1.deviceRole( |
| 306 | deviceId, |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 307 | ip ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 308 | # Check assignment |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 309 | if ip in main.ONOScli1.getRole( deviceId ).get( 'master' ): |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 310 | roleCheck = roleCheck and main.TRUE |
| 311 | else: |
| 312 | roleCheck = roleCheck and main.FALSE |
| 313 | |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 314 | ip = nodes[ 4 ].ip_address # ONOS5 |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 315 | for i in range( 8, 18 ): |
| 316 | dpid = '3' + str( i ).zfill( 3 ) |
| 317 | deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' ) |
| 318 | assert deviceId, "No device id for s%i in ONOS" % i |
| 319 | roleCall = roleCall and main.ONOScli1.deviceRole( |
| 320 | deviceId, |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 321 | ip ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 322 | # Check assignment |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 323 | if ip in main.ONOScli1.getRole( deviceId ).get( 'master' ): |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 324 | roleCheck = roleCheck and main.TRUE |
| 325 | else: |
| 326 | roleCheck = roleCheck and main.FALSE |
| 327 | |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 328 | ip = nodes[ 5 ].ip_address # ONOS6 |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 329 | deviceId = main.ONOScli1.getDevice( "6007" ).get( 'id' ) |
| 330 | assert deviceId, "No device id for s7 in ONOS" |
| 331 | roleCall = roleCall and main.ONOScli1.deviceRole( |
| 332 | deviceId, |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 333 | ip ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 334 | # Check assignment |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 335 | if ip in main.ONOScli1.getRole( deviceId ).get( 'master' ): |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 336 | roleCheck = roleCheck and main.TRUE |
| 337 | else: |
| 338 | roleCheck = roleCheck and main.FALSE |
| 339 | |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 340 | ip = nodes[ 6 ].ip_address # ONOS7 |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 341 | for i in range( 18, 28 ): |
| 342 | dpid = '6' + str( i ).zfill( 3 ) |
| 343 | deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' ) |
| 344 | assert deviceId, "No device id for s%i in ONOS" % i |
| 345 | roleCall = roleCall and main.ONOScli1.deviceRole( |
| 346 | deviceId, |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 347 | ip ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 348 | # Check assignment |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 349 | if ip in main.ONOScli1.getRole( deviceId ).get( 'master' ): |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 350 | roleCheck = roleCheck and main.TRUE |
| 351 | else: |
| 352 | roleCheck = roleCheck and main.FALSE |
| 353 | except ( AttributeError, AssertionError ): |
| 354 | main.log.exception( "Something is wrong with ONOS device view" ) |
| 355 | main.log.info( main.ONOScli1.devices() ) |
| 356 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 357 | utilities.assert_equals( |
| 358 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 359 | actual=roleCall, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 360 | onpass="Re-assigned switch mastership to designated controller", |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 361 | onfail="Something wrong with deviceRole calls" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 362 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 363 | utilities.assert_equals( |
| 364 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 365 | actual=roleCheck, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 366 | onpass="Switches were successfully reassigned to designated " + |
| 367 | "controller", |
| 368 | onfail="Switches were not successfully reassigned" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 369 | mastershipCheck = mastershipCheck and roleCall and roleCheck |
| 370 | utilities.assert_equals( expect=main.TRUE, actual=mastershipCheck, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 371 | onpass="Switch mastership correctly assigned", |
| 372 | onfail="Error in (re)assigning switch" + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 373 | " mastership" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 374 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 375 | def CASE3( self, main ): |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 376 | """ |
| 377 | Assign intents |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 378 | """ |
| 379 | import time |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 380 | import json |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 381 | main.log.report( "Adding host intents" ) |
| 382 | main.case( "Adding host Intents" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 383 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 384 | main.step( "Discovering Hosts( Via pingall for now )" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 385 | # FIXME: Once we have a host discovery mechanism, use that instead |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 386 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 387 | # install onos-app-fwd |
| 388 | main.log.info( "Install reactive forwarding app" ) |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 389 | appResults = main.TRUE |
| 390 | threads = [] |
| 391 | for i in range( numControllers ): |
| 392 | t = main.Thread( target=CLIs[i].featureInstall, |
| 393 | threadID=self.threadID, |
| 394 | name="featureInstall-" + str( i ), |
| 395 | args=["onos-app-fwd"] ) |
| 396 | threads.append( t ) |
| 397 | t.start() |
| 398 | self.threadID += 1 |
| 399 | |
| 400 | for t in threads: |
| 401 | t.join() |
| 402 | appResults = appResults and t.result |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 403 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 404 | # REACTIVE FWD test |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 405 | pingResult = main.FALSE |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 406 | time1 = time.time() |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 407 | pingResult = main.Mininet1.pingall() |
Jon Hall | 529a37f | 2015-01-28 10:02:00 -0800 | [diff] [blame] | 408 | utilities.assert_equals( |
| 409 | expect=main.TRUE, |
| 410 | actual=pingResult, |
| 411 | onpass="Reactive Pingall test passed", |
| 412 | onfail="Reactive Pingall failed, one or more ping pairs failed" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 413 | time2 = time.time() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 414 | main.log.info( "Time for pingall: %2f seconds" % ( time2 - time1 ) ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 415 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 416 | # uninstall onos-app-fwd |
| 417 | main.log.info( "Uninstall reactive forwarding app" ) |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 418 | threads = [] |
| 419 | for i in range( numControllers ): |
| 420 | t = main.Thread( target=CLIs[i].featureUninstall, |
| 421 | threadID=self.threadID, |
| 422 | name="featureUninstall-" + str( i ), |
| 423 | args=["onos-app-fwd"] ) |
| 424 | threads.append( t ) |
| 425 | t.start() |
| 426 | self.threadID += 1 |
| 427 | |
| 428 | for t in threads: |
| 429 | t.join() |
| 430 | appResults = appResults and t.result |
| 431 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 432 | # timeout for fwd flows |
| 433 | time.sleep( 10 ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 434 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 435 | main.step( "Add host intents" ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 436 | intentIds = [] |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 437 | # TODO: move the host numbers to params |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 438 | # Maybe look at all the paths we ping? |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 439 | intentAddResult = True |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 440 | hostResult = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 441 | for i in range( 8, 18 ): |
| 442 | main.log.info( "Adding host intent between h" + str( i ) + |
| 443 | " and h" + str( i + 10 ) ) |
| 444 | host1 = "00:00:00:00:00:" + \ |
| 445 | str( hex( i )[ 2: ] ).zfill( 2 ).upper() |
| 446 | host2 = "00:00:00:00:00:" + \ |
| 447 | str( hex( i + 10 )[ 2: ] ).zfill( 2 ).upper() |
Jon Hall | 1b8f54a | 2015-02-04 13:24:20 -0800 | [diff] [blame] | 448 | # NOTE: getHost can return None |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 449 | host1Dict = CLIs[ 0 ].getHost( host1 ) |
| 450 | host2Dict = CLIs[ 0 ].getHost( host2 ) |
Jon Hall | 1b8f54a | 2015-02-04 13:24:20 -0800 | [diff] [blame] | 451 | host1Id = None |
| 452 | host2Id = None |
| 453 | if host1Dict and host2Dict: |
| 454 | host1Id = host1Dict.get( 'id', None ) |
| 455 | host2Id = host2Dict.get( 'id', None ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 456 | if host1Id and host2Id: |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 457 | nodeNum = ( i % 7 ) + 1 |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 458 | tmpId = nodes[ nodeNum ].addHostIntent( host1Id, host2Id ) |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 459 | if tmpId: |
| 460 | main.log.info( "Added intent with id: " + tmpId ) |
| 461 | intentIds.append( tmpId ) |
| 462 | else: |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 463 | main.log.error( "addHostIntent returned None" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 464 | else: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 465 | main.log.error( "Error, getHost() failed" ) |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 466 | main.log.warn( json.dumps( json.loads( CLIs[ 0 ].hosts() ), |
Jon Hall | 1b8f54a | 2015-02-04 13:24:20 -0800 | [diff] [blame] | 467 | sort_keys=True, |
| 468 | indent=4, |
| 469 | separators=( ',', ': ' ) ) ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 470 | hostResult = main.FALSE |
| 471 | onosIds = main.ONOScli1.getAllIntentsId() |
| 472 | main.log.info( "Submitted intents: " + str( intentIds ) ) |
| 473 | main.log.info( "Intents in ONOS: " + str( onosIds ) ) |
| 474 | for intent in intentIds: |
| 475 | if intent in onosIds: |
| 476 | pass # intent submitted is still in onos |
| 477 | else: |
| 478 | intentAddResult = False |
Jon Hall | 1b8f54a | 2015-02-04 13:24:20 -0800 | [diff] [blame] | 479 | # Print the intent states |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 480 | intents = main.ONOScli1.intents() |
Jon Hall | 1b8f54a | 2015-02-04 13:24:20 -0800 | [diff] [blame] | 481 | intentStates = [] |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 482 | installedCheck = True |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 483 | main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) ) |
| 484 | count = 0 |
Jon Hall | 1b8f54a | 2015-02-04 13:24:20 -0800 | [diff] [blame] | 485 | for intent in json.loads( intents ): # Iter through intents of a node |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 486 | state = intent.get( 'state', None ) |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 487 | if "INSTALLED" not in state: |
| 488 | installedCheck = False |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 489 | intentId = intent.get( 'id', None ) |
| 490 | intentStates.append( ( intentId, state ) ) |
| 491 | # add submitted intents not in the store |
| 492 | tmplist = [ i for i, s in intentStates ] |
| 493 | missingIntents = False |
| 494 | for i in intentIds: |
| 495 | if i not in tmplist: |
| 496 | intentStates.append( ( i, " - " ) ) |
| 497 | missingIntents = True |
| 498 | intentStates.sort() |
| 499 | for i, s in intentStates: |
| 500 | count += 1 |
| 501 | main.log.info( "%-6s%-15s%-15s" % |
| 502 | ( str( count ), str( i ), str( s ) ) ) |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 503 | main.ONOScli1.leaders() |
| 504 | main.ONOScli1.partitions() |
| 505 | # for node in nodes: |
| 506 | # node.pendingMap() |
| 507 | pendingMap = main.ONOScli1.pendingMap() |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 508 | intentAddResult = bool( pingResult and hostResult and intentAddResult |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 509 | and not missingIntents and installedCheck ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 510 | utilities.assert_equals( |
| 511 | expect=True, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 512 | actual=intentAddResult, |
| 513 | onpass="Pushed host intents to ONOS", |
| 514 | onfail="Error in pushing host intents to ONOS" ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 515 | |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 516 | if not intentAddResult or "key" in pendingMap: |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 517 | import time |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 518 | installedCheck = True |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 519 | main.log.info( "Sleeping 60 seconds to see if intents are found" ) |
| 520 | time.sleep( 60 ) |
| 521 | onosIds = main.ONOScli1.getAllIntentsId() |
| 522 | main.log.info( "Submitted intents: " + str( intentIds ) ) |
| 523 | main.log.info( "Intents in ONOS: " + str( onosIds ) ) |
| 524 | # Print the intent states |
| 525 | intents = main.ONOScli1.intents() |
| 526 | intentStates = [] |
| 527 | main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) ) |
| 528 | count = 0 |
| 529 | for intent in json.loads( intents ): |
| 530 | # Iter through intents of a node |
| 531 | state = intent.get( 'state', None ) |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 532 | if "INSTALLED" not in state: |
| 533 | installedCheck = False |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 534 | intentId = intent.get( 'id', None ) |
| 535 | intentStates.append( ( intentId, state ) ) |
| 536 | # add submitted intents not in the store |
| 537 | tmplist = [ i for i, s in intentStates ] |
| 538 | for i in intentIds: |
| 539 | if i not in tmplist: |
| 540 | intentStates.append( ( i, " - " ) ) |
| 541 | intentStates.sort() |
| 542 | for i, s in intentStates: |
| 543 | count += 1 |
| 544 | main.log.info( "%-6s%-15s%-15s" % |
| 545 | ( str( count ), str( i ), str( s ) ) ) |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 546 | main.ONOScli1.leaders() |
| 547 | main.ONOScli1.pendingMap() |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 548 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 549 | def CASE4( self, main ): |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 550 | """ |
| 551 | Ping across added host intents |
| 552 | """ |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 553 | import json |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 554 | import time |
Jon Hall | 368769f | 2014-11-19 15:43:35 -0800 | [diff] [blame] | 555 | description = " Ping across added host intents" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 556 | main.log.report( description ) |
| 557 | main.case( description ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 558 | PingResult = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 559 | for i in range( 8, 18 ): |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 560 | ping = main.Mininet1.pingHost( src="h" + str( i ), |
| 561 | target="h" + str( i + 10 ) ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 562 | PingResult = PingResult and ping |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 563 | if ping == main.FALSE: |
| 564 | main.log.warn( "Ping failed between h" + str( i ) + |
| 565 | " and h" + str( i + 10 ) ) |
| 566 | elif ping == main.TRUE: |
| 567 | main.log.info( "Ping test passed!" ) |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 568 | # Don't set PingResult or you'd override failures |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 569 | if PingResult == main.FALSE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 570 | main.log.report( |
| 571 | "Intents have not been installed correctly, pings failed." ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 572 | # TODO: pretty print |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 573 | main.log.warn( "ONOS1 intents: " ) |
Jon Hall | 529a37f | 2015-01-28 10:02:00 -0800 | [diff] [blame] | 574 | main.log.warn( json.dumps( json.loads( main.ONOScli1.intents() ), |
| 575 | sort_keys=True, |
| 576 | indent=4, |
| 577 | separators=( ',', ': ' ) ) ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 578 | if PingResult == main.TRUE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 579 | main.log.report( |
| 580 | "Intents have been installed correctly and verified by pings" ) |
| 581 | utilities.assert_equals( |
| 582 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 583 | actual=PingResult, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 584 | onpass="Intents have been installed correctly and pings work", |
| 585 | onfail="Intents have not been installed correctly, pings failed." ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 586 | |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 587 | installedCheck = True |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 588 | if PingResult is not main.TRUE: |
| 589 | # Print the intent states |
| 590 | intents = main.ONOScli1.intents() |
| 591 | intentStates = [] |
| 592 | main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) ) |
| 593 | count = 0 |
| 594 | # Iter through intents of a node |
| 595 | for intent in json.loads( intents ): |
| 596 | state = intent.get( 'state', None ) |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 597 | if "INSTALLED" not in state: |
| 598 | installedCheck = False |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 599 | intentId = intent.get( 'id', None ) |
| 600 | intentStates.append( ( intentId, state ) ) |
| 601 | intentStates.sort() |
| 602 | for i, s in intentStates: |
| 603 | count += 1 |
| 604 | main.log.info( "%-6s%-15s%-15s" % |
| 605 | ( str( count ), str( i ), str( s ) ) ) |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 606 | main.ONOScli1.leaders() |
| 607 | main.ONOScli1.partitions() |
| 608 | main.ONOScli1.pendingMap() |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 609 | if not installedCheck: |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 610 | main.log.info( "Waiting 60 seconds to see if the state of " + |
| 611 | "intents change" ) |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 612 | time.sleep( 60 ) |
| 613 | # Print the intent states |
| 614 | intents = main.ONOScli1.intents() |
| 615 | intentStates = [] |
| 616 | main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) ) |
| 617 | count = 0 |
| 618 | # Iter through intents of a node |
| 619 | for intent in json.loads( intents ): |
| 620 | state = intent.get( 'state', None ) |
| 621 | if "INSTALLED" not in state: |
| 622 | installedCheck = False |
| 623 | intentId = intent.get( 'id', None ) |
| 624 | intentStates.append( ( intentId, state ) ) |
| 625 | intentStates.sort() |
| 626 | for i, s in intentStates: |
| 627 | count += 1 |
| 628 | main.log.info( "%-6s%-15s%-15s" % |
| 629 | ( str( count ), str( i ), str( s ) ) ) |
| 630 | main.ONOScli1.leaders() |
| 631 | main.ONOScli1.partitions() |
| 632 | main.ONOScli1.pendingMap() |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 633 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 634 | def CASE5( self, main ): |
| 635 | """ |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 636 | Reading state of ONOS |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 637 | """ |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 638 | import json |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 639 | # assumes that sts is already in you PYTHONPATH |
| 640 | from sts.topology.teston_topology import TestONTopology |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 641 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 642 | main.log.report( "Setting up and gathering data for current state" ) |
| 643 | main.case( "Setting up and gathering data for current state" ) |
| 644 | # The general idea for this test case is to pull the state of |
| 645 | # ( intents,flows, topology,... ) from each ONOS node |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 646 | # We can then compare them with each other and also with past states |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 647 | |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 648 | main.step( "Check that each switch has a master" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 649 | global mastershipState |
| 650 | mastershipState = [] |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 651 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 652 | # Assert that each device has a master |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 653 | rolesNotNull = main.TRUE |
| 654 | threads = [] |
| 655 | for i in range( numControllers ): |
| 656 | t = main.Thread( target=CLIs[i].rolesNotNull, |
| 657 | threadID=self.threadID, |
| 658 | name="rolesNotNull-" + str( i ), |
| 659 | args=[] ) |
| 660 | threads.append( t ) |
| 661 | t.start() |
| 662 | self.threadID += 1 |
| 663 | |
| 664 | for t in threads: |
| 665 | t.join() |
| 666 | rolesNotNull = rolesNotNull and t.result |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 667 | utilities.assert_equals( |
| 668 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 669 | actual=rolesNotNull, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 670 | onpass="Each device has a master", |
| 671 | onfail="Some devices don't have a master assigned" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 672 | |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 673 | main.step( "Get the Mastership of each switch from each controller" ) |
| 674 | ONOSMastership = [] |
| 675 | mastershipCheck = main.FALSE |
| 676 | consistentMastership = True |
| 677 | rolesResults = True |
| 678 | threads = [] |
| 679 | for i in range( numControllers ): |
| 680 | t = main.Thread( target=CLIs[i].roles, |
| 681 | threadID=self.threadID, |
| 682 | name="roles-" + str( i ), |
| 683 | args=[] ) |
| 684 | threads.append( t ) |
| 685 | t.start() |
| 686 | self.threadID += 1 |
| 687 | |
| 688 | for t in threads: |
| 689 | t.join() |
| 690 | ONOSMastership.append( t.result ) |
| 691 | |
| 692 | for i in range( numControllers ): |
| 693 | if not ONOSMastership[i] or "Error" in ONOSMastership[i]: |
| 694 | main.log.report( "Error in getting ONOS" + str( i + 1 ) + |
| 695 | " roles" ) |
| 696 | main.log.warn( |
| 697 | "ONOS" + str( i + 1 ) + " mastership response: " + |
| 698 | repr( ONOSMastership[i] ) ) |
| 699 | rolesResults = False |
| 700 | utilities.assert_equals( |
| 701 | expect=True, |
| 702 | actual=rolesResults, |
| 703 | onpass="No error in reading roles output", |
| 704 | onfail="Error in reading roles from ONOS" ) |
| 705 | |
| 706 | main.step( "Check for consistency in roles from each controller" ) |
| 707 | if all([ i == ONOSMastership[ 0 ] for i in ONOSMastership ] ): |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 708 | main.log.report( |
| 709 | "Switch roles are consistent across all ONOS nodes" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 710 | else: |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 711 | consistentMastership = False |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 712 | utilities.assert_equals( |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 713 | expect=True, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 714 | actual=consistentMastership, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 715 | onpass="Switch roles are consistent across all ONOS nodes", |
| 716 | onfail="ONOS nodes have different views of switch roles" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 717 | |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 718 | if rolesResults and not consistentMastership: |
| 719 | for i in range( numControllers ): |
| 720 | main.log.warn( |
| 721 | "ONOS" + str( i + 1 ) + " roles: ", |
| 722 | json.dumps( |
| 723 | json.loads( ONOSMastership[ i ] ), |
| 724 | sort_keys=True, |
| 725 | indent=4, |
| 726 | separators=( ',', ': ' ) ) ) |
| 727 | elif rolesResults and not consistentMastership: |
| 728 | mastershipCheck = main.TRUE |
| 729 | mastershipState = ONOSMastership[ 0 ] |
| 730 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 731 | main.step( "Get the intents from each controller" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 732 | global intentState |
| 733 | intentState = [] |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 734 | ONOSIntents = [] |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 735 | intentCheck = main.FALSE |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 736 | consistentIntents = True |
| 737 | intentsResults = True |
| 738 | threads = [] |
| 739 | for i in range( numControllers ): |
| 740 | t = main.Thread( target=CLIs[i].intents, |
| 741 | threadID=self.threadID, |
| 742 | name="intents-" + str( i ), |
| 743 | args=[], |
| 744 | kwargs={ 'jsonFormat': True } ) |
| 745 | threads.append( t ) |
| 746 | t.start() |
| 747 | self.threadID += 1 |
| 748 | |
| 749 | for t in threads: |
| 750 | t.join() |
| 751 | ONOSIntents.append( t.result ) |
| 752 | |
| 753 | for i in range( numControllers ): |
| 754 | if not ONOSIntents[ i ] or "Error" in ONOSIntents[ i ]: |
| 755 | main.log.report( "Error in getting ONOS" + str( i + 1 ) + |
| 756 | " intents" ) |
| 757 | main.log.warn( "ONOS" + str( i + 1 ) + " intents response: " + |
| 758 | repr( ONOSIntents[ i ] ) ) |
| 759 | intentsResults = False |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 760 | utilities.assert_equals( |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 761 | expect=True, |
| 762 | actual=intentsResults, |
| 763 | onpass="No error in reading intents output", |
| 764 | onfail="Error in reading intents from ONOS" ) |
| 765 | |
| 766 | main.step( "Check for consistency in Intents from each controller" ) |
| 767 | if all([ i == ONOSIntents[ 0 ] for i in ONOSIntents ] ): |
| 768 | main.log.report( "Intents are consistent across all ONOS " + |
| 769 | "nodes" ) |
| 770 | else: |
| 771 | consistentIntents = False |
| 772 | utilities.assert_equals( |
| 773 | expect=True, |
| 774 | actual=consistentIntents, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 775 | onpass="Intents are consistent across all ONOS nodes", |
| 776 | onfail="ONOS nodes have different views of intents" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 777 | |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 778 | if intentsResults and not consistentIntents: |
| 779 | for i in range( numControllers ): |
| 780 | main.log.warn( |
| 781 | "ONOS" + str( i + 1 ) + " intents: ", |
| 782 | json.dumps( |
| 783 | json.loads( ONOSIntents[i] ), |
| 784 | sort_keys=True, |
| 785 | indent=4, |
| 786 | separators=( ',', ': ' ) ) ) |
| 787 | elif intentsResults and consistentIntents: |
| 788 | intentCheck = main.TRUE |
| 789 | intentState = ONOSIntents[ 0 ] |
| 790 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 791 | main.step( "Get the flows from each controller" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 792 | global flowState |
| 793 | flowState = [] |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 794 | ONOSFlows = [] |
| 795 | ONOSFlowsJson = [] |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 796 | flowCheck = main.FALSE |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 797 | consistentFlows = True |
| 798 | flowsResults = True |
| 799 | threads = [] |
| 800 | for i in range( numControllers ): |
| 801 | t = main.Thread( target=CLIs[i].flows, |
| 802 | threadID=self.threadID, |
| 803 | name="flows-" + str( i ), |
| 804 | args=[], |
| 805 | kwargs={ 'jsonFormat': True } ) |
| 806 | threads.append( t ) |
| 807 | t.start() |
| 808 | self.threadID += 1 |
| 809 | |
| 810 | for t in threads: |
| 811 | t.join() |
| 812 | result = t.result() |
| 813 | ONOSFlows.append( result ) |
| 814 | |
| 815 | for i in range( numControllers ): |
| 816 | num = str( i + 1 ) |
| 817 | if not ONOSFlows[ i ] or "Error" in ONOSFlows[ i ]: |
| 818 | main.log.report( "Error in getting ONOS" + num + " flows" ) |
| 819 | main.log.warn( "ONOS" + num + " flows response: " + |
| 820 | repr( ONOSFlows[ i ] ) ) |
| 821 | flowsResults = False |
| 822 | ONOSFlowsJson.append( None ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 823 | else: |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 824 | try: |
| 825 | ONOSFlowsJson.append( json.loads( ONOSFlows[ i ] ) ) |
| 826 | except ( ValueError, TypeError ): |
| 827 | # FIXME: change this to log.error? |
| 828 | main.log.exception( "Error in parsing ONOS" + num + |
| 829 | " response as json." ) |
| 830 | ONOSFlowsJson.append( None ) |
| 831 | flowsResults = False |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 832 | utilities.assert_equals( |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 833 | expect=True, |
| 834 | actual=flowsResults, |
| 835 | onpass="No error in reading flows output", |
| 836 | onfail="Error in reading flows from ONOS" ) |
| 837 | |
| 838 | main.step( "Check for consistency in Flows from each controller" ) |
| 839 | tmp = [ len( i ) == len( ONOSFlowsJson[ 0 ] ) for i in ONOSFlowsJson ] |
| 840 | if all( tmp ): |
| 841 | main.log.report( "Flow count is consistent across all ONOS nodes" ) |
| 842 | else: |
| 843 | consistentFlows = False |
| 844 | utilities.assert_equals( |
| 845 | expect=True, |
| 846 | actual=consistentFlows, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 847 | onpass="The flow count is consistent across all ONOS nodes", |
| 848 | onfail="ONOS nodes have different flow counts" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 849 | |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 850 | if flowsResults and not consistentFlows: |
| 851 | for i in range( numControllers ): |
| 852 | main.log.warn( |
| 853 | "ONOS" + str( i + 1 ) + " flows: ", |
| 854 | json.dumps( json.loads( ONOSFlows[i] ), sort_keys=True, |
| 855 | indent=4, separators=( ',', ': ' ) ) ) |
| 856 | elif flowsResults and consistentFlows: |
| 857 | flowCheck = main.TRUE |
| 858 | flowState = ONOSFlows[ 0 ] |
| 859 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 860 | main.step( "Get the OF Table entries" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 861 | global flows |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 862 | flows = [] |
| 863 | for i in range( 1, 29 ): |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 864 | flows.append( main.Mininet2.getFlowTable( 1.3, "s" + str( i ) ) ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 865 | if flowCheck == main.FALSE: |
| 866 | for table in flows: |
| 867 | main.log.warn( table ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 868 | # TODO: Compare switch flow tables with ONOS flow tables |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 869 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 870 | main.step( "Start continuous pings" ) |
| 871 | main.Mininet2.pingLong( |
| 872 | src=main.params[ 'PING' ][ 'source1' ], |
| 873 | target=main.params[ 'PING' ][ 'target1' ], |
| 874 | pingTime=500 ) |
| 875 | main.Mininet2.pingLong( |
| 876 | src=main.params[ 'PING' ][ 'source2' ], |
| 877 | target=main.params[ 'PING' ][ 'target2' ], |
| 878 | pingTime=500 ) |
| 879 | main.Mininet2.pingLong( |
| 880 | src=main.params[ 'PING' ][ 'source3' ], |
| 881 | target=main.params[ 'PING' ][ 'target3' ], |
| 882 | pingTime=500 ) |
| 883 | main.Mininet2.pingLong( |
| 884 | src=main.params[ 'PING' ][ 'source4' ], |
| 885 | target=main.params[ 'PING' ][ 'target4' ], |
| 886 | pingTime=500 ) |
| 887 | main.Mininet2.pingLong( |
| 888 | src=main.params[ 'PING' ][ 'source5' ], |
| 889 | target=main.params[ 'PING' ][ 'target5' ], |
| 890 | pingTime=500 ) |
| 891 | main.Mininet2.pingLong( |
| 892 | src=main.params[ 'PING' ][ 'source6' ], |
| 893 | target=main.params[ 'PING' ][ 'target6' ], |
| 894 | pingTime=500 ) |
| 895 | main.Mininet2.pingLong( |
| 896 | src=main.params[ 'PING' ][ 'source7' ], |
| 897 | target=main.params[ 'PING' ][ 'target7' ], |
| 898 | pingTime=500 ) |
| 899 | main.Mininet2.pingLong( |
| 900 | src=main.params[ 'PING' ][ 'source8' ], |
| 901 | target=main.params[ 'PING' ][ 'target8' ], |
| 902 | pingTime=500 ) |
| 903 | main.Mininet2.pingLong( |
| 904 | src=main.params[ 'PING' ][ 'source9' ], |
| 905 | target=main.params[ 'PING' ][ 'target9' ], |
| 906 | pingTime=500 ) |
| 907 | main.Mininet2.pingLong( |
| 908 | src=main.params[ 'PING' ][ 'source10' ], |
| 909 | target=main.params[ 'PING' ][ 'target10' ], |
| 910 | pingTime=500 ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 911 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 912 | main.step( "Create TestONTopology object" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 913 | ctrls = [] |
| 914 | count = 1 |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 915 | print " Testing new sts tuple..." |
| 916 | for node in nodes: |
| 917 | temp = ( node, node.name, node.ip_address, 6633 ) |
| 918 | print temp |
| 919 | ctrls.append( temp ) |
| 920 | print " Testing old sts tuple..." |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 921 | while True: |
| 922 | temp = () |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 923 | if ( 'ip' + str( count ) ) in main.params[ 'CTRL' ]: |
| 924 | temp = temp + ( getattr( main, ( 'ONOS' + str( count ) ) ), ) |
| 925 | temp = temp + ( "ONOS" + str( count ), ) |
| 926 | temp = temp + ( main.params[ 'CTRL' ][ 'ip' + str( count ) ], ) |
| 927 | temp = temp + \ |
| 928 | ( eval( main.params[ 'CTRL' ][ 'port' + str( count ) ] ), ) |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 929 | print temp |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 930 | ctrls.append( temp ) |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 931 | count += 1 |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 932 | else: |
| 933 | break |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 934 | MNTopo = TestONTopology( main.Mininet1, ctrls ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 935 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 936 | main.step( "Collecting topology information from ONOS" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 937 | devices = [] |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 938 | threads = [] |
| 939 | for i in range( numControllers ): |
| 940 | t = main.Thread( target=CLIs[i].devices, |
| 941 | threadID=self.threadID, |
| 942 | name="devices-" + str( i ), |
| 943 | args=[ ] ) |
| 944 | threads.append( t ) |
| 945 | t.start() |
| 946 | self.threadID += 1 |
| 947 | |
| 948 | for t in threads: |
| 949 | t.join() |
| 950 | devices.append( t.result ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 951 | hosts = [] |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 952 | threads = [] |
| 953 | for i in range( numControllers ): |
| 954 | t = main.Thread( target=CLIs[i].hosts, |
| 955 | threadID=self.threadID, |
| 956 | name="hosts-" + str( i ), |
| 957 | args=[ ] ) |
| 958 | threads.append( t ) |
| 959 | t.start() |
| 960 | self.threadID += 1 |
| 961 | |
| 962 | for t in threads: |
| 963 | t.join() |
| 964 | try: |
| 965 | hosts.append( json.loads( t.result ) ) |
| 966 | except ( ValueError, TypeError ): |
| 967 | # FIXME: better handling of this, print which node |
| 968 | # Maybe use thread name? |
| 969 | main.log.exception( "Error parsing json output of hosts" ) |
| 970 | |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 971 | ports = [] |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 972 | threads = [] |
| 973 | for i in range( numControllers ): |
| 974 | t = main.Thread( target=CLIs[i].ports, |
| 975 | threadID=self.threadID, |
| 976 | name="ports-" + str( i ), |
| 977 | args=[ ] ) |
| 978 | threads.append( t ) |
| 979 | t.start() |
| 980 | self.threadID += 1 |
| 981 | |
| 982 | for t in threads: |
| 983 | t.join() |
| 984 | ports.append( t.result ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 985 | links = [] |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 986 | threads = [] |
| 987 | for i in range( numControllers ): |
| 988 | t = main.Thread( target=CLIs[i].links, |
| 989 | threadID=self.threadID, |
| 990 | name="links-" + str( i ), |
| 991 | args=[ ] ) |
| 992 | threads.append( t ) |
| 993 | t.start() |
| 994 | self.threadID += 1 |
| 995 | |
| 996 | for t in threads: |
| 997 | t.join() |
| 998 | links.append( t.result ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 999 | clusters = [] |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1000 | threads = [] |
| 1001 | for i in range( numControllers ): |
| 1002 | t = main.Thread( target=CLIs[i].clusters, |
| 1003 | threadID=self.threadID, |
| 1004 | name="clusters-" + str( i ), |
| 1005 | args=[ ] ) |
| 1006 | threads.append( t ) |
| 1007 | t.start() |
| 1008 | self.threadID += 1 |
| 1009 | |
| 1010 | for t in threads: |
| 1011 | t.join() |
| 1012 | clusters.append( t.result ) |
Jon Hall | 529a37f | 2015-01-28 10:02:00 -0800 | [diff] [blame] | 1013 | # Compare json objects for hosts and dataplane clusters |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1014 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1015 | # hosts |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1016 | consistentHostsResult = main.TRUE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1017 | for controller in range( len( hosts ) ): |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1018 | controllerStr = str( controller + 1 ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1019 | if "Error" not in hosts[ controller ]: |
| 1020 | if hosts[ controller ] == hosts[ 0 ]: |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1021 | continue |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1022 | else: # hosts not consistent |
| 1023 | main.log.report( "hosts from ONOS" + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1024 | controllerStr + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1025 | " is inconsistent with ONOS1" ) |
| 1026 | main.log.warn( repr( hosts[ controller ] ) ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1027 | consistentHostsResult = main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1028 | |
| 1029 | else: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1030 | main.log.report( "Error in getting ONOS hosts from ONOS" + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1031 | controllerStr ) |
| 1032 | consistentHostsResult = main.FALSE |
| 1033 | main.log.warn( "ONOS" + controllerStr + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1034 | " hosts response: " + |
| 1035 | repr( hosts[ controller ] ) ) |
| 1036 | utilities.assert_equals( |
| 1037 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1038 | actual=consistentHostsResult, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1039 | onpass="Hosts view is consistent across all ONOS nodes", |
| 1040 | onfail="ONOS nodes have different views of hosts" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1041 | |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1042 | ipResult = main.TRUE |
| 1043 | for controller in range( 0, len( hosts ) ): |
| 1044 | controllerStr = str( controller + 1 ) |
| 1045 | for host in hosts[ controller ]: |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1046 | if not host.get( 'ips', [ ] ): |
| 1047 | main.log.error( "DEBUG:Error with host ips on controller" + |
| 1048 | controllerStr + ": " + str( host ) ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1049 | ipResult = main.FALSE |
| 1050 | utilities.assert_equals( |
| 1051 | expect=main.TRUE, |
| 1052 | actual=ipResult, |
| 1053 | onpass="The ips of the hosts aren't empty", |
| 1054 | onfail="The ip of at least one host is missing" ) |
| 1055 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1056 | # Strongly connected clusters of devices |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1057 | consistentClustersResult = main.TRUE |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1058 | for controller in range( 0, len( clusters ) ): |
| 1059 | controllerStr = str( controller + 1 ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1060 | if "Error" not in clusters[ controller ]: |
| 1061 | if clusters[ controller ] == clusters[ 0 ]: |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1062 | continue |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1063 | else: # clusters not consistent |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1064 | main.log.report( "clusters from ONOS" + controllerStr + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1065 | " is inconsistent with ONOS1" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1066 | consistentClustersResult = main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1067 | |
| 1068 | else: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1069 | main.log.report( "Error in getting dataplane clusters " + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1070 | "from ONOS" + controllerStr ) |
| 1071 | consistentClustersResult = main.FALSE |
| 1072 | main.log.warn( "ONOS" + controllerStr + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1073 | " clusters response: " + |
| 1074 | repr( clusters[ controller ] ) ) |
| 1075 | utilities.assert_equals( |
| 1076 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1077 | actual=consistentClustersResult, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1078 | onpass="Clusters view is consistent across all ONOS nodes", |
| 1079 | onfail="ONOS nodes have different views of clusters" ) |
| 1080 | # there should always only be one cluster |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1081 | numClusters = len( json.loads( clusters[ 0 ] ) ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1082 | clusterResults = main.FALSE |
| 1083 | if numClusters == 1: |
| 1084 | clusterResults = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1085 | utilities.assert_equals( |
| 1086 | expect=1, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1087 | actual=numClusters, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1088 | onpass="ONOS shows 1 SCC", |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1089 | onfail="ONOS shows " + str( numClusters ) + " SCCs" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1090 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1091 | main.step( "Comparing ONOS topology to MN" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1092 | devicesResults = main.TRUE |
| 1093 | portsResults = main.TRUE |
| 1094 | linksResults = main.TRUE |
| 1095 | for controller in range( numControllers ): |
| 1096 | controllerStr = str( controller + 1 ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1097 | if devices[ controller ] or "Error" not in devices[ controller ]: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1098 | currentDevicesResult = main.Mininet1.compareSwitches( |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1099 | MNTopo, |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1100 | json.loads( devices[ controller ] ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1101 | else: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1102 | currentDevicesResult = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1103 | utilities.assert_equals( expect=main.TRUE, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1104 | actual=currentDevicesResult, |
| 1105 | onpass="ONOS" + controllerStr + |
| 1106 | " Switches view is correct", |
| 1107 | onfail="ONOS" + controllerStr + |
| 1108 | " Switches view is incorrect" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1109 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1110 | if ports[ controller ] or "Error" not in ports[ controller ]: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1111 | currentPortsResult = main.Mininet1.comparePorts( |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1112 | MNTopo, |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1113 | json.loads( ports[ controller ] ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1114 | else: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1115 | currentPortsResult = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1116 | utilities.assert_equals( expect=main.TRUE, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1117 | actual=currentPortsResult, |
| 1118 | onpass="ONOS" + controllerStr + |
| 1119 | " ports view is correct", |
| 1120 | onfail="ONOS" + controllerStr + |
| 1121 | " ports view is incorrect" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1122 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1123 | if links[ controller ] or "Error" not in links[ controller ]: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1124 | currentLinksResult = main.Mininet1.compareLinks( |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1125 | MNTopo, |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1126 | json.loads( links[ controller ] ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1127 | else: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1128 | currentLinksResult = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1129 | utilities.assert_equals( expect=main.TRUE, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1130 | actual=currentLinksResult, |
| 1131 | onpass="ONOS" + controllerStr + |
| 1132 | " links view is correct", |
| 1133 | onfail="ONOS" + controllerStr + |
| 1134 | " links view is incorrect" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1135 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1136 | devicesResults = devicesResults and currentDevicesResult |
| 1137 | portsResults = portsResults and currentPortsResult |
| 1138 | linksResults = linksResults and currentLinksResult |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1139 | |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1140 | topoResult = ( devicesResults and portsResults and linksResults |
| 1141 | and consistentHostsResult and consistentClustersResult |
| 1142 | and clusterResults and ipResult ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1143 | utilities.assert_equals( expect=main.TRUE, actual=topoResult, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1144 | onpass="Topology Check Test successful", |
| 1145 | onfail="Topology Check Test NOT successful" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1146 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1147 | finalAssert = main.TRUE |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1148 | finalAssert = ( finalAssert and topoResult and flowCheck |
| 1149 | and intentCheck and consistentMastership |
| 1150 | and rolesNotNull ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1151 | utilities.assert_equals( expect=main.TRUE, actual=finalAssert, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1152 | onpass="State check successful", |
| 1153 | onfail="State check NOT successful" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1154 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1155 | def CASE6( self, main ): |
| 1156 | """ |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1157 | The Failure case. Since this is the Sanity test, we do nothing. |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1158 | """ |
Jon Hall | 368769f | 2014-11-19 15:43:35 -0800 | [diff] [blame] | 1159 | import time |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1160 | main.log.report( "Wait 60 seconds instead of inducing a failure" ) |
| 1161 | time.sleep( 60 ) |
| 1162 | utilities.assert_equals( |
| 1163 | expect=main.TRUE, |
| 1164 | actual=main.TRUE, |
| 1165 | onpass="Sleeping 60 seconds", |
| 1166 | onfail="Something is terribly wrong with my math" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1167 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1168 | def CASE7( self, main ): |
| 1169 | """ |
Jon Hall | 368769f | 2014-11-19 15:43:35 -0800 | [diff] [blame] | 1170 | Check state after ONOS failure |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1171 | """ |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1172 | import json |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1173 | main.case( "Running ONOS Constant State Tests" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1174 | |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1175 | main.step( "Check that each switch has a master" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1176 | # Assert that each device has a master |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1177 | rolesNotNull = main.TRUE |
| 1178 | threads = [] |
| 1179 | for i in range( numControllers ): |
| 1180 | t = main.Thread( target=CLIs[i].rolesNotNull, |
| 1181 | threadID=self.threadID, |
| 1182 | name="rolesNotNull-" + str( i ), |
| 1183 | args=[ ] ) |
| 1184 | threads.append( t ) |
| 1185 | t.start() |
| 1186 | self.threadID += 1 |
| 1187 | |
| 1188 | for t in threads: |
| 1189 | t.join() |
| 1190 | rolesNotNull = rolesNotNull and t.result |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1191 | utilities.assert_equals( |
| 1192 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1193 | actual=rolesNotNull, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1194 | onpass="Each device has a master", |
| 1195 | onfail="Some devices don't have a master assigned" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1196 | |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1197 | ONOSMastership = [] |
| 1198 | mastershipCheck = main.FALSE |
| 1199 | consistentMastership = True |
| 1200 | rolesResults = True |
| 1201 | threads = [] |
| 1202 | for i in range( numControllers ): |
| 1203 | t = main.Thread( target=CLIs[i].roles, |
| 1204 | threadID=self.threadID, |
| 1205 | name="roles-" + str( i ), |
| 1206 | args=[] ) |
| 1207 | threads.append( t ) |
| 1208 | t.start() |
| 1209 | self.threadID += 1 |
| 1210 | |
| 1211 | for t in threads: |
| 1212 | t.join() |
| 1213 | ONOSMastership.append( t.result ) |
| 1214 | |
| 1215 | for i in range( numControllers ): |
| 1216 | if not ONOSMastership[i] or "Error" in ONOSMastership[i]: |
| 1217 | main.log.report( "Error in getting ONOS" + str( i + 1 ) + |
| 1218 | " roles" ) |
| 1219 | main.log.warn( |
| 1220 | "ONOS" + str( i + 1 ) + " mastership response: " + |
| 1221 | repr( ONOSMastership[i] ) ) |
| 1222 | rolesResults = False |
| 1223 | utilities.assert_equals( |
| 1224 | expect=True, |
| 1225 | actual=rolesResults, |
| 1226 | onpass="No error in reading roles output", |
| 1227 | onfail="Error in reading roles from ONOS" ) |
| 1228 | |
| 1229 | main.step( "Check for consistency in roles from each controller" ) |
| 1230 | if all([ i == ONOSMastership[ 0 ] for i in ONOSMastership ] ): |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1231 | main.log.report( |
| 1232 | "Switch roles are consistent across all ONOS nodes" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1233 | else: |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1234 | consistentMastership = False |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1235 | utilities.assert_equals( |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1236 | expect=True, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1237 | actual=consistentMastership, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1238 | onpass="Switch roles are consistent across all ONOS nodes", |
| 1239 | onfail="ONOS nodes have different views of switch roles" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1240 | |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1241 | if rolesResults and not consistentMastership: |
| 1242 | for i in range( numControllers ): |
| 1243 | main.log.warn( |
| 1244 | "ONOS" + str( i + 1 ) + " roles: ", |
| 1245 | json.dumps( |
| 1246 | json.loads( ONOSMastership[ i ] ), |
| 1247 | sort_keys=True, |
| 1248 | indent=4, |
| 1249 | separators=( ',', ': ' ) ) ) |
| 1250 | elif rolesResults and not consistentMastership: |
| 1251 | mastershipCheck = main.TRUE |
| 1252 | |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1253 | description2 = "Compare switch roles from before failure" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1254 | main.step( description2 ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1255 | |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1256 | currentJson = json.loads( ONOSMastership[0] ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1257 | oldJson = json.loads( mastershipState ) |
| 1258 | mastershipCheck = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1259 | for i in range( 1, 29 ): |
| 1260 | switchDPID = str( |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1261 | main.Mininet1.getSwitchDPID( switch="s" + str( i ) ) ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1262 | current = [ switch[ 'master' ] for switch in currentJson |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1263 | if switchDPID in switch[ 'id' ] ] |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1264 | old = [ switch[ 'master' ] for switch in oldJson |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1265 | if switchDPID in switch[ 'id' ] ] |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1266 | if current == old: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1267 | mastershipCheck = mastershipCheck and main.TRUE |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1268 | else: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1269 | main.log.warn( "Mastership of switch %s changed" % switchDPID ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1270 | mastershipCheck = main.FALSE |
| 1271 | if mastershipCheck == main.TRUE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1272 | main.log.report( "Mastership of Switches was not changed" ) |
| 1273 | utilities.assert_equals( |
| 1274 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1275 | actual=mastershipCheck, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1276 | onpass="Mastership of Switches was not changed", |
| 1277 | onfail="Mastership of some switches changed" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1278 | mastershipCheck = mastershipCheck and consistentMastership |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1279 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1280 | main.step( "Get the intents and compare across all nodes" ) |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1281 | ONOSIntents = [] |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1282 | intentCheck = main.FALSE |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1283 | consistentIntents = True |
| 1284 | intentsResults = True |
| 1285 | threads = [] |
| 1286 | for i in range( numControllers ): |
| 1287 | t = main.Thread( target=CLIs[i].intents, |
| 1288 | threadID=self.threadID, |
| 1289 | name="intents-" + str( i ), |
| 1290 | args=[], |
| 1291 | kwargs={ 'jsonFormat': True } ) |
| 1292 | threads.append( t ) |
| 1293 | t.start() |
| 1294 | self.threadID += 1 |
| 1295 | |
| 1296 | for t in threads: |
| 1297 | t.join() |
| 1298 | ONOSIntents.append( t.result ) |
| 1299 | |
| 1300 | for i in range( numControllers ): |
| 1301 | if not ONOSIntents[ i ] or "Error" in ONOSIntents[ i ]: |
| 1302 | main.log.report( "Error in getting ONOS" + str( i + 1 ) + |
| 1303 | " intents" ) |
| 1304 | main.log.warn( "ONOS" + str( i + 1 ) + " intents response: " + |
| 1305 | repr( ONOSIntents[ i ] ) ) |
| 1306 | intentsResults = False |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1307 | utilities.assert_equals( |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1308 | expect=True, |
| 1309 | actual=intentsResults, |
| 1310 | onpass="No error in reading intents output", |
| 1311 | onfail="Error in reading intents from ONOS" ) |
| 1312 | |
| 1313 | main.step( "Check for consistency in Intents from each controller" ) |
| 1314 | if all( [ i == ONOSIntents[ 0 ] for i in ONOSIntents ] ): |
| 1315 | main.log.report( "Intents are consistent across all ONOS " + |
| 1316 | "nodes" ) |
| 1317 | else: |
| 1318 | consistentIntents = False |
| 1319 | utilities.assert_equals( |
| 1320 | expect=True, |
| 1321 | actual=consistentIntents, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1322 | onpass="Intents are consistent across all ONOS nodes", |
| 1323 | onfail="ONOS nodes have different views of intents" ) |
Jon Hall | 1b8f54a | 2015-02-04 13:24:20 -0800 | [diff] [blame] | 1324 | intentStates = [] |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1325 | for node in ONOSIntents: # Iter through ONOS nodes |
Jon Hall | 1b8f54a | 2015-02-04 13:24:20 -0800 | [diff] [blame] | 1326 | nodeStates = [] |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1327 | # Iter through intents of a node |
| 1328 | for intent in json.loads( node ): |
Jon Hall | 1b8f54a | 2015-02-04 13:24:20 -0800 | [diff] [blame] | 1329 | nodeStates.append( intent[ 'state' ] ) |
| 1330 | intentStates.append( nodeStates ) |
| 1331 | out = [ (i, nodeStates.count( i ) ) for i in set( nodeStates ) ] |
| 1332 | main.log.info( dict( out ) ) |
| 1333 | |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1334 | if intentsResults and not consistentIntents: |
| 1335 | for i in range( numControllers ): |
| 1336 | main.log.warn( |
| 1337 | "ONOS" + str( i + 1 ) + " intents: ", |
| 1338 | json.dumps( |
| 1339 | json.loads( ONOSIntents[ i ] ), |
| 1340 | sort_keys=True, |
| 1341 | indent=4, |
| 1342 | separators=( ',', ': ' ) ) ) |
| 1343 | elif intentsResults and consistentIntents: |
| 1344 | intentCheck = main.TRUE |
| 1345 | intentState = ONOSIntents[ 0 ] |
| 1346 | |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1347 | # NOTE: Store has no durability, so intents are lost across system |
| 1348 | # restarts |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1349 | main.step( "Compare current intents with intents before the failure" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1350 | # NOTE: this requires case 5 to pass for intentState to be set. |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1351 | # maybe we should stop the test if that fails? |
Jon Hall | 1b8f54a | 2015-02-04 13:24:20 -0800 | [diff] [blame] | 1352 | sameIntents = main.TRUE |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1353 | if intentState and intentState == ONOSIntents[ 0 ]: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1354 | sameIntents = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1355 | main.log.report( "Intents are consistent with before failure" ) |
| 1356 | # TODO: possibly the states have changed? we may need to figure out |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1357 | # what the acceptable states are |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1358 | else: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1359 | try: |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1360 | main.log.warn( "ONOS intents: " ) |
| 1361 | print json.dumps( json.loads( ONOSIntents[ 0 ] ), |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1362 | sort_keys=True, indent=4, |
| 1363 | separators=( ',', ': ' ) ) |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1364 | except Exception: |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1365 | main.log.exception( "Exception printing intents" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1366 | sameIntents = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1367 | utilities.assert_equals( |
| 1368 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1369 | actual=sameIntents, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1370 | onpass="Intents are consistent with before failure", |
| 1371 | onfail="The Intents changed during failure" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1372 | intentCheck = intentCheck and sameIntents |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1373 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1374 | main.step( "Get the OF Table entries and compare to before " + |
| 1375 | "component failure" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1376 | FlowTables = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1377 | flows2 = [] |
| 1378 | for i in range( 28 ): |
| 1379 | main.log.info( "Checking flow table on s" + str( i + 1 ) ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1380 | tmpFlows = main.Mininet2.getFlowTable( 1.3, "s" + str( i + 1 ) ) |
| 1381 | flows2.append( tmpFlows ) |
| 1382 | tempResult = main.Mininet2.flowComp( |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1383 | flow1=flows[ i ], |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1384 | flow2=tmpFlows ) |
| 1385 | FlowTables = FlowTables and tempResult |
| 1386 | if FlowTables == main.FALSE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1387 | main.log.info( "Differences in flow table for switch: s" + |
| 1388 | str( i + 1 ) ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1389 | if FlowTables == main.TRUE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1390 | main.log.report( "No changes were found in the flow tables" ) |
| 1391 | utilities.assert_equals( |
| 1392 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1393 | actual=FlowTables, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1394 | onpass="No changes were found in the flow tables", |
| 1395 | onfail="Changes were found in the flow tables" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1396 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1397 | main.step( "Check the continuous pings to ensure that no packets " + |
| 1398 | "were dropped during component failure" ) |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1399 | main.Mininet2.pingKill( main.params[ 'TESTONUSER' ], |
| 1400 | main.params[ 'TESTONIP' ] ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1401 | LossInPings = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1402 | # NOTE: checkForLoss returns main.FALSE with 0% packet loss |
| 1403 | for i in range( 8, 18 ): |
| 1404 | main.log.info( |
| 1405 | "Checking for a loss in pings along flow from s" + |
| 1406 | str( i ) ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1407 | LossInPings = main.Mininet2.checkForLoss( |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1408 | "/tmp/ping.h" + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1409 | str( i ) ) or LossInPings |
| 1410 | if LossInPings == main.TRUE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1411 | main.log.info( "Loss in ping detected" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1412 | elif LossInPings == main.ERROR: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1413 | main.log.info( "There are multiple mininet process running" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1414 | elif LossInPings == main.FALSE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1415 | main.log.info( "No Loss in the pings" ) |
| 1416 | main.log.report( "No loss of dataplane connectivity" ) |
| 1417 | utilities.assert_equals( |
| 1418 | expect=main.FALSE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1419 | actual=LossInPings, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1420 | onpass="No Loss of connectivity", |
| 1421 | onfail="Loss of dataplane connectivity detected" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1422 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1423 | # Test of LeadershipElection |
| 1424 | # NOTE: this only works for the sanity test. In case of failures, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1425 | # leader will likely change |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1426 | leader = nodes[ 0 ].ip_address |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1427 | leaderResult = main.TRUE |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1428 | for node in nodes: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1429 | leaderN = node.electionTestLeader() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1430 | # verify leader is ONOS1 |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1431 | if leaderN == leader: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1432 | # all is well |
| 1433 | # NOTE: In failure scenario, this could be a new node, maybe |
| 1434 | # check != ONOS1 |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1435 | pass |
| 1436 | elif leaderN == main.FALSE: |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1437 | # error in response |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1438 | main.log.report( "Something is wrong with " + |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1439 | "electionTestLeader function, check the" + |
| 1440 | " error logs" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1441 | leaderResult = main.FALSE |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1442 | elif leader != leaderN: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1443 | leaderResult = main.FALSE |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1444 | main.log.report( node.name + " sees " + str( leaderN ) + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1445 | " as the leader of the election app. " + |
| 1446 | "Leader should be " + str( leader ) ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1447 | if leaderResult: |
| 1448 | main.log.report( "Leadership election tests passed( consistent " + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1449 | "view of leader across listeners and a new " + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1450 | "leader was re-elected if applicable )" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1451 | utilities.assert_equals( |
| 1452 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1453 | actual=leaderResult, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1454 | onpass="Leadership election passed", |
| 1455 | onfail="Something went wrong with Leadership election" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1456 | |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1457 | result = ( mastershipCheck and intentCheck and FlowTables and |
| 1458 | ( not LossInPings ) and rolesNotNull and leaderResult ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1459 | result = int( result ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1460 | if result == main.TRUE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1461 | main.log.report( "Constant State Tests Passed" ) |
| 1462 | utilities.assert_equals( expect=main.TRUE, actual=result, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1463 | onpass="Constant State Tests Passed", |
| 1464 | onfail="Constant state tests failed" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1465 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1466 | def CASE8( self, main ): |
| 1467 | """ |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1468 | Compare topo |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1469 | """ |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1470 | import sys |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1471 | # FIXME add this path to params |
| 1472 | sys.path.append( "/home/admin/sts" ) |
| 1473 | # assumes that sts is already in you PYTHONPATH |
| 1474 | from sts.topology.teston_topology import TestONTopology |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1475 | import json |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1476 | import time |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1477 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1478 | description = "Compare ONOS Topology view to Mininet topology" |
| 1479 | main.case( description ) |
| 1480 | main.log.report( description ) |
| 1481 | main.step( "Create TestONTopology object" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1482 | ctrls = [] |
| 1483 | count = 1 |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1484 | #FIXME: use the new method? |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1485 | while True: |
| 1486 | temp = () |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1487 | if ( 'ip' + str( count ) ) in main.params[ 'CTRL' ]: |
| 1488 | temp = temp + ( getattr( main, ( 'ONOS' + str( count ) ) ), ) |
| 1489 | temp = temp + ( "ONOS" + str( count ), ) |
| 1490 | temp = temp + ( main.params[ 'CTRL' ][ 'ip' + str( count ) ], ) |
| 1491 | temp = temp + \ |
| 1492 | ( eval( main.params[ 'CTRL' ][ 'port' + str( count ) ] ), ) |
| 1493 | ctrls.append( temp ) |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1494 | count += 1 |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1495 | else: |
| 1496 | break |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1497 | MNTopo = TestONTopology( main.Mininet1, ctrls ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1498 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1499 | main.step( "Comparing ONOS topology to MN" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1500 | devicesResults = main.TRUE |
| 1501 | portsResults = main.TRUE |
| 1502 | linksResults = main.TRUE |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1503 | hostsResults = main.TRUE |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1504 | topoResult = main.FALSE |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1505 | elapsed = 0 |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 1506 | count = 0 |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1507 | main.step( "Collecting topology information from ONOS" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1508 | startTime = time.time() |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1509 | # Give time for Gossip to work |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1510 | while topoResult == main.FALSE and elapsed < 60: |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1511 | count += 1 |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1512 | if count > 1: |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1513 | # TODO: Deprecate STS usage |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1514 | MNTopo = TestONTopology( main.Mininet1, ctrls ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1515 | cliStart = time.time() |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1516 | devices = [] |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1517 | threads = [] |
| 1518 | for i in range( numControllers ): |
| 1519 | t = main.Thread( target=CLIs[i].devices, |
| 1520 | threadID=self.threadID, |
| 1521 | name="devices-" + str( i ), |
| 1522 | args=[ ] ) |
| 1523 | threads.append( t ) |
| 1524 | t.start() |
| 1525 | self.threadID += 1 |
| 1526 | |
| 1527 | for t in threads: |
| 1528 | t.join() |
| 1529 | devices.append( t.result ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1530 | hosts = [] |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1531 | ipResult = main.TRUE |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1532 | threads = [] |
| 1533 | for i in range( numControllers ): |
| 1534 | t = main.Thread( target=CLIs[i].hosts, |
| 1535 | threadID=self.threadID, |
| 1536 | name="hosts-" + str( i ), |
| 1537 | args=[ ] ) |
| 1538 | threads.append( t ) |
| 1539 | t.start() |
| 1540 | self.threadID += 1 |
| 1541 | |
| 1542 | for t in threads: |
| 1543 | t.join() |
| 1544 | hosts.append( json.loads( t.result ) ) |
Jon Hall | 529a37f | 2015-01-28 10:02:00 -0800 | [diff] [blame] | 1545 | for controller in range( 0, len( hosts ) ): |
| 1546 | controllerStr = str( controller + 1 ) |
| 1547 | for host in hosts[ controller ]: |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1548 | if host is None or host.get( 'ips', [] ) == []: |
Jon Hall | 529a37f | 2015-01-28 10:02:00 -0800 | [diff] [blame] | 1549 | main.log.error( |
| 1550 | "DEBUG:Error with host ips on controller" + |
| 1551 | controllerStr + ": " + str( host ) ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1552 | ipResult = main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1553 | ports = [] |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1554 | threads = [] |
| 1555 | for i in range( numControllers ): |
| 1556 | t = main.Thread( target=CLIs[i].ports, |
| 1557 | threadID=self.threadID, |
| 1558 | name="ports-" + str( i ), |
| 1559 | args=[ ] ) |
| 1560 | threads.append( t ) |
| 1561 | t.start() |
| 1562 | self.threadID += 1 |
| 1563 | |
| 1564 | for t in threads: |
| 1565 | t.join() |
| 1566 | ports.append( t.result ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1567 | links = [] |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1568 | threads = [] |
| 1569 | for i in range( numControllers ): |
| 1570 | t = main.Thread( target=CLIs[i].links, |
| 1571 | threadID=self.threadID, |
| 1572 | name="links-" + str( i ), |
| 1573 | args=[ ] ) |
| 1574 | threads.append( t ) |
| 1575 | t.start() |
| 1576 | self.threadID += 1 |
| 1577 | |
| 1578 | for t in threads: |
| 1579 | t.join() |
| 1580 | links.append( t.result ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1581 | clusters = [] |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1582 | threads = [] |
| 1583 | for i in range( numControllers ): |
| 1584 | t = main.Thread( target=CLIs[i].clusters, |
| 1585 | threadID=self.threadID, |
| 1586 | name="clusters-" + str( i ), |
| 1587 | args=[ ] ) |
| 1588 | threads.append( t ) |
| 1589 | t.start() |
| 1590 | self.threadID += 1 |
| 1591 | |
| 1592 | for t in threads: |
| 1593 | t.join() |
| 1594 | clusters.append( t.result ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1595 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1596 | elapsed = time.time() - startTime |
| 1597 | cliTime = time.time() - cliStart |
| 1598 | print "CLI time: " + str( cliTime ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1599 | |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1600 | for controller in range( numControllers ): |
| 1601 | controllerStr = str( controller + 1 ) |
| 1602 | if devices[ controller ] or "Error" not in devices[ |
| 1603 | controller ]: |
| 1604 | currentDevicesResult = main.Mininet1.compareSwitches( |
| 1605 | MNTopo, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1606 | json.loads( devices[ controller ] ) ) |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1607 | else: |
| 1608 | currentDevicesResult = main.FALSE |
| 1609 | utilities.assert_equals( expect=main.TRUE, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1610 | actual=currentDevicesResult, |
| 1611 | onpass="ONOS" + controllerStr + |
| 1612 | " Switches view is correct", |
| 1613 | onfail="ONOS" + controllerStr + |
| 1614 | " Switches view is incorrect" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1615 | |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1616 | if ports[ controller ] or "Error" not in ports[ controller ]: |
| 1617 | currentPortsResult = main.Mininet1.comparePorts( |
| 1618 | MNTopo, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1619 | json.loads( ports[ controller ] ) ) |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1620 | else: |
| 1621 | currentPortsResult = main.FALSE |
| 1622 | utilities.assert_equals( expect=main.TRUE, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1623 | actual=currentPortsResult, |
| 1624 | onpass="ONOS" + controllerStr + |
| 1625 | " ports view is correct", |
| 1626 | onfail="ONOS" + controllerStr + |
| 1627 | " ports view is incorrect" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1628 | |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1629 | if links[ controller ] or "Error" not in links[ controller ]: |
| 1630 | currentLinksResult = main.Mininet1.compareLinks( |
| 1631 | MNTopo, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1632 | json.loads( links[ controller ] ) ) |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1633 | else: |
| 1634 | currentLinksResult = main.FALSE |
| 1635 | utilities.assert_equals( expect=main.TRUE, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1636 | actual=currentLinksResult, |
| 1637 | onpass="ONOS" + controllerStr + |
| 1638 | " links view is correct", |
| 1639 | onfail="ONOS" + controllerStr + |
| 1640 | " links view is incorrect" ) |
| 1641 | |
| 1642 | if hosts[ controller ] or "Error" not in hosts[ controller ]: |
| 1643 | currentHostsResult = main.Mininet1.compareHosts( |
| 1644 | MNTopo, hosts[ controller ] ) |
| 1645 | else: |
| 1646 | currentHostsResult = main.FALSE |
| 1647 | utilities.assert_equals( expect=main.TRUE, |
| 1648 | actual=currentHostsResult, |
| 1649 | onpass="ONOS" + controllerStr + |
| 1650 | " hosts exist in Mininet", |
| 1651 | onfail="ONOS" + controllerStr + |
| 1652 | " hosts don't match Mininet" ) |
| 1653 | |
| 1654 | devicesResults = devicesResults and currentDevicesResult |
| 1655 | portsResults = portsResults and currentPortsResult |
| 1656 | linksResults = linksResults and currentLinksResult |
| 1657 | hostsResults = hostsResults and currentHostsResult |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1658 | |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1659 | # Compare json objects for hosts and dataplane clusters |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1660 | |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1661 | # hosts |
| 1662 | consistentHostsResult = main.TRUE |
| 1663 | for controller in range( len( hosts ) ): |
| 1664 | controllerStr = str( controller + 1 ) |
| 1665 | if "Error" not in hosts[ controller ]: |
| 1666 | if hosts[ controller ] == hosts[ 0 ]: |
| 1667 | continue |
| 1668 | else: # hosts not consistent |
| 1669 | main.log.report( "hosts from ONOS" + controllerStr + |
| 1670 | " is inconsistent with ONOS1" ) |
| 1671 | main.log.warn( repr( hosts[ controller ] ) ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1672 | consistentHostsResult = main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1673 | |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1674 | else: |
| 1675 | main.log.report( "Error in getting ONOS hosts from ONOS" + |
| 1676 | controllerStr ) |
| 1677 | consistentHostsResult = main.FALSE |
| 1678 | main.log.warn( "ONOS" + controllerStr + |
| 1679 | " hosts response: " + |
| 1680 | repr( hosts[ controller ] ) ) |
| 1681 | utilities.assert_equals( |
| 1682 | expect=main.TRUE, |
| 1683 | actual=consistentHostsResult, |
| 1684 | onpass="Hosts view is consistent across all ONOS nodes", |
| 1685 | onfail="ONOS nodes have different views of hosts" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1686 | |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1687 | # Strongly connected clusters of devices |
| 1688 | consistentClustersResult = main.TRUE |
| 1689 | for controller in range( len( clusters ) ): |
| 1690 | controllerStr = str( controller + 1 ) |
| 1691 | if "Error" not in clusters[ controller ]: |
| 1692 | if clusters[ controller ] == clusters[ 0 ]: |
| 1693 | continue |
| 1694 | else: # clusters not consistent |
| 1695 | main.log.report( "clusters from ONOS" + |
| 1696 | controllerStr + |
| 1697 | " is inconsistent with ONOS1" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1698 | consistentClustersResult = main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1699 | |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1700 | else: |
| 1701 | main.log.report( "Error in getting dataplane clusters " + |
| 1702 | "from ONOS" + controllerStr ) |
| 1703 | consistentClustersResult = main.FALSE |
| 1704 | main.log.warn( "ONOS" + controllerStr + |
| 1705 | " clusters response: " + |
| 1706 | repr( clusters[ controller ] ) ) |
| 1707 | utilities.assert_equals( |
| 1708 | expect=main.TRUE, |
| 1709 | actual=consistentClustersResult, |
| 1710 | onpass="Clusters view is consistent across all ONOS nodes", |
| 1711 | onfail="ONOS nodes have different views of clusters" ) |
| 1712 | # there should always only be one cluster |
| 1713 | numClusters = len( json.loads( clusters[ 0 ] ) ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1714 | clusterResults = main.FALSE |
| 1715 | if numClusters == 1: |
| 1716 | clusterResults = main.TRUE |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1717 | utilities.assert_equals( |
| 1718 | expect=1, |
| 1719 | actual=numClusters, |
| 1720 | onpass="ONOS shows 1 SCC", |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1721 | onfail="ONOS shows " + str( numClusters ) + " SCCs" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1722 | |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1723 | topoResult = ( devicesResults and portsResults and linksResults |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1724 | and hostsResults and consistentHostsResult |
| 1725 | and consistentClustersResult and clusterResults |
| 1726 | and ipResult ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1727 | |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1728 | topoResult = topoResult and int( count <= 2 ) |
| 1729 | note = "note it takes about " + str( int( cliTime ) ) + \ |
| 1730 | " seconds for the test to make all the cli calls to fetch " +\ |
| 1731 | "the topology from each ONOS instance" |
| 1732 | main.log.info( |
| 1733 | "Very crass estimate for topology discovery/convergence( " + |
| 1734 | str( note ) + " ): " + str( elapsed ) + " seconds, " + |
| 1735 | str( count ) + " tries" ) |
| 1736 | utilities.assert_equals( expect=main.TRUE, actual=topoResult, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1737 | onpass="Topology Check Test successful", |
| 1738 | onfail="Topology Check Test NOT successful" ) |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1739 | if topoResult == main.TRUE: |
| 1740 | main.log.report( "ONOS topology view matches Mininet topology" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1741 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1742 | def CASE9( self, main ): |
| 1743 | """ |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1744 | Link s3-s28 down |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1745 | """ |
| 1746 | import time |
| 1747 | # NOTE: You should probably run a topology check after this |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1748 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1749 | linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1750 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1751 | description = "Turn off a link to ensure that Link Discovery " +\ |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1752 | "is working properly" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1753 | main.log.report( description ) |
| 1754 | main.case( description ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1755 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1756 | main.step( "Kill Link between s3 and s28" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1757 | LinkDown = main.Mininet1.link( END1="s3", END2="s28", OPTION="down" ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1758 | main.log.info( "Waiting " + str( linkSleep ) + |
| 1759 | " seconds for link down to be discovered" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1760 | time.sleep( linkSleep ) |
| 1761 | utilities.assert_equals( expect=main.TRUE, actual=LinkDown, |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1762 | onpass="Link down successful", |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1763 | onfail="Failed to bring link down" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1764 | # TODO do some sort of check here |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1765 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1766 | def CASE10( self, main ): |
| 1767 | """ |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1768 | Link s3-s28 up |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1769 | """ |
| 1770 | import time |
| 1771 | # NOTE: You should probably run a topology check after this |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1772 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1773 | linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1774 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1775 | description = "Restore a link to ensure that Link Discovery is " + \ |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 1776 | "working properly" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1777 | main.log.report( description ) |
| 1778 | main.case( description ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1779 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1780 | main.step( "Bring link between s3 and s28 back up" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1781 | LinkUp = main.Mininet1.link( END1="s3", END2="s28", OPTION="up" ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1782 | main.log.info( "Waiting " + str( linkSleep ) + |
| 1783 | " seconds for link up to be discovered" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1784 | time.sleep( linkSleep ) |
| 1785 | utilities.assert_equals( expect=main.TRUE, actual=LinkUp, |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1786 | onpass="Link up successful", |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1787 | onfail="Failed to bring link up" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1788 | # TODO do some sort of check here |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1789 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1790 | def CASE11( self, main ): |
| 1791 | """ |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1792 | Switch Down |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1793 | """ |
| 1794 | # NOTE: You should probably run a topology check after this |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1795 | import time |
| 1796 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1797 | switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1798 | |
| 1799 | description = "Killing a switch to ensure it is discovered correctly" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1800 | main.log.report( description ) |
| 1801 | main.case( description ) |
| 1802 | switch = main.params[ 'kill' ][ 'switch' ] |
| 1803 | switchDPID = main.params[ 'kill' ][ 'dpid' ] |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1804 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1805 | # TODO: Make this switch parameterizable |
| 1806 | main.step( "Kill " + switch ) |
| 1807 | main.log.report( "Deleting " + switch ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1808 | main.Mininet1.delSwitch( switch ) |
| 1809 | main.log.info( "Waiting " + str( switchSleep ) + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1810 | " seconds for switch down to be discovered" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1811 | time.sleep( switchSleep ) |
| 1812 | device = main.ONOScli1.getDevice( dpid=switchDPID ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1813 | # Peek at the deleted switch |
| 1814 | main.log.warn( str( device ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1815 | result = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1816 | if device and device[ 'available' ] is False: |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1817 | result = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1818 | utilities.assert_equals( expect=main.TRUE, actual=result, |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1819 | onpass="Kill switch successful", |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1820 | onfail="Failed to kill switch?" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1821 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1822 | def CASE12( self, main ): |
| 1823 | """ |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1824 | Switch Up |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1825 | """ |
| 1826 | # NOTE: You should probably run a topology check after this |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1827 | import time |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1828 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1829 | switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1830 | switch = main.params[ 'kill' ][ 'switch' ] |
| 1831 | switchDPID = main.params[ 'kill' ][ 'dpid' ] |
| 1832 | links = main.params[ 'kill' ][ 'links' ].split() |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1833 | description = "Adding a switch to ensure it is discovered correctly" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1834 | main.log.report( description ) |
| 1835 | main.case( description ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1836 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1837 | main.step( "Add back " + switch ) |
| 1838 | main.log.report( "Adding back " + switch ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1839 | main.Mininet1.addSwitch( switch, dpid=switchDPID ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1840 | for peer in links: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1841 | main.Mininet1.addLink( switch, peer ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1842 | main.Mininet1.assignSwController( sw=switch.split( 's' )[ 1 ], |
| 1843 | count=numControllers, |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1844 | ip1=nodes[ 0 ].ip_address, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1845 | port1=ONOS1Port, |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1846 | ip2=nodes[ 1 ].ip_address, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1847 | port2=ONOS2Port, |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1848 | ip3=nodes[ 2 ].ip_address, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1849 | port3=ONOS3Port, |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1850 | ip4=nodes[ 3 ].ip_address, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1851 | port4=ONOS4Port, |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1852 | ip5=nodes[ 4 ].ip_address, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1853 | port5=ONOS5Port, |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1854 | ip6=nodes[ 5 ].ip_address, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1855 | port6=ONOS6Port, |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1856 | ip7=nodes[ 6 ].ip_address, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1857 | port7=ONOS7Port ) |
| 1858 | main.log.info( "Waiting " + str( switchSleep ) + |
| 1859 | " seconds for switch up to be discovered" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1860 | time.sleep( switchSleep ) |
| 1861 | device = main.ONOScli1.getDevice( dpid=switchDPID ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1862 | # Peek at the deleted switch |
| 1863 | main.log.warn( str( device ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1864 | result = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1865 | if device and device[ 'available' ]: |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1866 | result = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1867 | utilities.assert_equals( expect=main.TRUE, actual=result, |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1868 | onpass="add switch successful", |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1869 | onfail="Failed to add switch?" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1870 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1871 | def CASE13( self, main ): |
| 1872 | """ |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1873 | Clean up |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1874 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1875 | import os |
| 1876 | import time |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1877 | |
| 1878 | # printing colors to terminal |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1879 | colors = { 'cyan': '\033[96m', 'purple': '\033[95m', |
| 1880 | 'blue': '\033[94m', 'green': '\033[92m', |
| 1881 | 'yellow': '\033[93m', 'red': '\033[91m', 'end': '\033[0m' } |
Jon Hall | 368769f | 2014-11-19 15:43:35 -0800 | [diff] [blame] | 1882 | description = "Test Cleanup" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1883 | main.log.report( description ) |
| 1884 | main.case( description ) |
| 1885 | main.step( "Killing tcpdumps" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1886 | main.Mininet2.stopTcpdump() |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1887 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1888 | main.step( "Copying MN pcap and ONOS log files to test station" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1889 | testname = main.TEST |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1890 | teststationUser = main.params[ 'TESTONUSER' ] |
| 1891 | teststationIP = main.params[ 'TESTONIP' ] |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1892 | # NOTE: MN Pcap file is being saved to ~/packet_captures |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1893 | # 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] | 1894 | # FIXME: scp |
| 1895 | # mn files |
| 1896 | # TODO: Load these from params |
| 1897 | # NOTE: must end in / |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1898 | logFolder = "/opt/onos/log/" |
| 1899 | logFiles = [ "karaf.log", "karaf.log.1" ] |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1900 | # NOTE: must end in / |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1901 | dstDir = "~/packet_captures/" |
| 1902 | for f in logFiles: |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1903 | for node in nodes: |
| 1904 | main.ONOSbench.handle.sendline( "scp sdn@" + node.ip_address + |
| 1905 | ":" + logFolder + f + " " + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1906 | teststationUser + "@" + |
| 1907 | teststationIP + ":" + |
| 1908 | dstDir + str( testname ) + |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1909 | "-" + node.name + "-" + f ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1910 | main.ONOSbench.handle.expect( "\$" ) |
| 1911 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1912 | # std*.log's |
| 1913 | # NOTE: must end in / |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1914 | logFolder = "/opt/onos/var/" |
| 1915 | logFiles = [ "stderr.log", "stdout.log" ] |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1916 | # NOTE: must end in / |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1917 | dstDir = "~/packet_captures/" |
| 1918 | for f in logFiles: |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1919 | for node in nodes: |
| 1920 | main.ONOSbench.handle.sendline( "scp sdn@" + node.ip_address + |
| 1921 | ":" + logFolder + f + " " + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1922 | teststationUser + "@" + |
| 1923 | teststationIP + ":" + |
| 1924 | dstDir + str( testname ) + |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1925 | "-" + node.name + "-" + f ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1926 | main.ONOSbench.handle.expect( "\$" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1927 | # sleep so scp can finish |
| 1928 | time.sleep( 10 ) |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1929 | |
| 1930 | main.step( "Stopping Mininet" ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1931 | main.Mininet1.stopNet() |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1932 | |
| 1933 | main.step( "Checking ONOS Logs for errors" ) |
| 1934 | for node in nodes: |
| 1935 | print colors[ 'purple' ] + "Checking logs for errors on " + \ |
| 1936 | node.name + ":" + colors[ 'end' ] |
| 1937 | print main.ONOSbench.checkLogs( node.ip_address ) |
| 1938 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1939 | main.step( "Packing and rotating pcap archives" ) |
| 1940 | os.system( "~/TestON/dependencies/rotate.sh " + str( testname ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1941 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1942 | # TODO: actually check something here |
| 1943 | utilities.assert_equals( expect=main.TRUE, actual=main.TRUE, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1944 | onpass="Test cleanup successful", |
| 1945 | onfail="Test cleanup NOT successful" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1946 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1947 | def CASE14( self, main ): |
| 1948 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1949 | start election app on all onos nodes |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1950 | """ |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1951 | leaderResult = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1952 | # install app on onos 1 |
| 1953 | main.log.info( "Install leadership election app" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1954 | main.ONOScli1.featureInstall( "onos-app-election" ) |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1955 | leader = nodes[0].ip_address |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1956 | # wait for election |
| 1957 | # check for leader |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1958 | leader1 = main.ONOScli1.electionTestLeader() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1959 | # verify leader is ONOS1 |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1960 | if leader1 == leader: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1961 | # all is well |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1962 | pass |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1963 | elif leader1 is None: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1964 | # No leader elected |
| 1965 | main.log.report( "No leader was elected" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1966 | leaderResult = main.FALSE |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1967 | elif leader1 == main.FALSE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1968 | # error in response |
| 1969 | # TODO: add check for "Command not found:" in the driver, this |
| 1970 | # means the app isn't loaded |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1971 | main.log.report( "Something is wrong with electionTestLeader" + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1972 | " function, check the error logs" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1973 | leaderResult = main.FALSE |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1974 | else: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1975 | # error in response |
| 1976 | main.log.report( |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1977 | "Unexpected response from electionTestLeader function:'" + |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1978 | str( leader1 ) + "'" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1979 | leaderResult = main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1980 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1981 | # install on other nodes and check for leader. |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1982 | # Leader should be ONOS1 and each app should show the same leader |
| 1983 | for node in nodes[ 1: ]: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1984 | node.featureInstall( "onos-app-election" ) |
| 1985 | leaderN = node.electionTestLeader() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1986 | # verify leader is ONOS1 |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1987 | if leaderN == leader: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1988 | # all is well |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1989 | pass |
| 1990 | elif leaderN == main.FALSE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1991 | # error in response |
| 1992 | # TODO: add check for "Command not found:" in the driver, this |
| 1993 | # means the app isn't loaded |
| 1994 | main.log.report( "Something is wrong with " + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1995 | "electionTestLeader function, check the" + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1996 | " error logs" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1997 | leaderResult = main.FALSE |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1998 | elif leader != leaderN: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1999 | leaderResult = main.FALSE |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 2000 | main.log.report( node.names + " sees " + str( leaderN ) + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2001 | " as the leader of the election app. Leader" + |
| 2002 | " should be " + |
| 2003 | str( leader ) ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2004 | if leaderResult: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2005 | main.log.report( "Leadership election tests passed( consistent " + |
| 2006 | "view of leader across listeners and a leader " + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2007 | "was elected )" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2008 | utilities.assert_equals( |
| 2009 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2010 | actual=leaderResult, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2011 | onpass="Leadership election passed", |
| 2012 | onfail="Something went wrong with Leadership election" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2013 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2014 | def CASE15( self, main ): |
| 2015 | """ |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2016 | Check that Leadership Election is still functional |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2017 | """ |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2018 | leaderResult = main.TRUE |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2019 | description = "Check that Leadership Election is still functional" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2020 | main.log.report( description ) |
| 2021 | main.case( description ) |
| 2022 | main.step( "Find current leader and withdraw" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2023 | leader = main.ONOScli1.electionTestLeader() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2024 | # TODO: do some sanity checking on leader before using it |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2025 | withdrawResult = main.FALSE |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 2026 | oldLeader = None |
| 2027 | if leader is None or leader == main.FALSE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2028 | main.log.report( |
| 2029 | "Leader for the election app should be an ONOS node," + |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 2030 | "instead got '" + str( leader ) + "'" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2031 | leaderResult = main.FALSE |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 2032 | oldLeader = None |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 2033 | for i in range( len( CLIs ) ): |
| 2034 | if leader == nodes[ i ].ip_address: |
| 2035 | oldLeader = CLIs[ i ] |
| 2036 | break |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 2037 | else: |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 2038 | main.log.error( "Leader election, could not find current leader" ) |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 2039 | if oldLeader: |
| 2040 | withdrawResult = oldLeader.electionTestWithdraw() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2041 | utilities.assert_equals( |
| 2042 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2043 | actual=withdrawResult, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2044 | onpass="App was withdrawn from election", |
| 2045 | onfail="App was not withdrawn from election" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2046 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2047 | main.step( "Make sure new leader is elected" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2048 | leaderList = [] |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 2049 | for node in nodes: |
| 2050 | leaderN = node.electionTestLeader() |
| 2051 | leaderList.append( leaderN ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2052 | if leaderN == leader: |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 2053 | main.log.report( node.name + " still sees " + str( leader ) + |
| 2054 | " as leader after they withdrew" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2055 | leaderResult = main.FALSE |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2056 | elif leaderN == main.FALSE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2057 | # error in response |
| 2058 | # TODO: add check for "Command not found:" in the driver, this |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 2059 | # means the app isn't loaded |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2060 | main.log.report( "Something is wrong with " + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2061 | "electionTestLeader function, " + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2062 | "check the error logs" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2063 | leaderResult = main.FALSE |
| 2064 | consistentLeader = main.FALSE |
| 2065 | if len( set( leaderList ) ) == 1: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2066 | main.log.info( "Each Election-app sees '" + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2067 | str( leaderList[ 0 ] ) + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2068 | "' as the leader" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2069 | consistentLeader = main.TRUE |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2070 | else: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2071 | main.log.report( |
| 2072 | "Inconsistent responses for leader of Election-app:" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2073 | for n in range( len( leaderList ) ): |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2074 | main.log.report( "ONOS" + str( n + 1 ) + " response: " + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2075 | str( leaderList[ n ] ) ) |
| 2076 | if leaderResult: |
| 2077 | main.log.report( "Leadership election tests passed( consistent " + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2078 | "view of leader across listeners and a new " + |
| 2079 | "leader was elected when the old leader " + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2080 | "resigned )" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2081 | utilities.assert_equals( |
| 2082 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2083 | actual=leaderResult, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2084 | onpass="Leadership election passed", |
| 2085 | onfail="Something went wrong with Leadership election" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2086 | |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 2087 | main.step( "Run for election on old leader( just so everyone " + |
| 2088 | "is in the hat )" ) |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 2089 | if oldLeader: |
| 2090 | runResult = oldLeader.electionTestRun() |
| 2091 | else: |
| 2092 | runResult = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2093 | utilities.assert_equals( |
| 2094 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2095 | actual=runResult, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2096 | onpass="App re-ran for election", |
| 2097 | onfail="App failed to run for election" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2098 | if consistentLeader == main.TRUE: |
| 2099 | afterRun = main.ONOScli1.electionTestLeader() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2100 | # verify leader didn't just change |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2101 | if afterRun == leaderList[ 0 ]: |
| 2102 | leaderResult = main.TRUE |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2103 | else: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2104 | leaderResult = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2105 | # TODO: assert on run and withdraw results? |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2106 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2107 | utilities.assert_equals( |
| 2108 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2109 | actual=leaderResult, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2110 | onpass="Leadership election passed", |
| 2111 | onfail="Something went wrong with Leadership election after " + |
| 2112 | "the old leader re-ran for election" ) |