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