Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2 | Description: This test is to determine if ONOS can handle |
| 3 | a minority of it's nodes restarting |
| 4 | |
| 5 | List of test cases: |
| 6 | CASE1: Compile ONOS and push it to the test machines |
Jon Hall | c9eabec | 2015-06-10 14:33:14 -0700 | [diff] [blame] | 7 | CASE2: Assign devices to controllers |
| 8 | CASE21: Assign mastership to controllers |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 9 | CASE3: Assign intents |
| 10 | CASE4: Ping across added host intents |
| 11 | CASE5: Reading state of ONOS |
| 12 | CASE6: The Failure case. |
| 13 | CASE7: Check state after control plane failure |
| 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 | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 22 | CASE16: Install Distributed Primitives app |
| 23 | CASE17: Check for basic functionality with distributed primitives |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 24 | """ |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 25 | |
| 26 | |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 27 | class HATestMinorityRestart: |
| 28 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 29 | def __init__( self ): |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 30 | self.default = '' |
| 31 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 32 | def CASE1( self, main ): |
| 33 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 34 | CASE1 is to compile ONOS and push it to the test machines |
| 35 | |
| 36 | Startup sequence: |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 37 | cell <name> |
| 38 | onos-verify-cell |
| 39 | NOTE: temporary - onos-remove-raft-logs |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 40 | onos-uninstall |
| 41 | start mininet |
| 42 | git pull |
| 43 | mvn clean install |
| 44 | onos-package |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 45 | onos-install -f |
| 46 | onos-wait-for-start |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 47 | start cli sessions |
| 48 | start tcpdump |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 49 | """ |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 50 | main.log.info( "ONOS HA test: Restart minority of ONOS nodes - " + |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 51 | "initialization" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 52 | main.case( "Setting up test environment" ) |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 53 | main.caseExplaination = "Setup the test environment including " +\ |
| 54 | "installing ONOS, starting Mininet and ONOS" +\ |
| 55 | "cli sessions." |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 56 | # TODO: save all the timers and output them for plotting |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 57 | |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 58 | # load some variables from the params file |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 59 | PULLCODE = False |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 60 | if main.params[ 'Git' ] == 'True': |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 61 | PULLCODE = True |
Jon Hall | 529a37f | 2015-01-28 10:02:00 -0800 | [diff] [blame] | 62 | gitBranch = main.params[ 'branch' ] |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 63 | cellName = main.params[ 'ENV' ][ 'cellName' ] |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 64 | |
| 65 | # set global variables |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 66 | global ONOS1Port |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 67 | global ONOS2Port |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 68 | global ONOS3Port |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 69 | global ONOS4Port |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 70 | global ONOS5Port |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 71 | global ONOS6Port |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 72 | global ONOS7Port |
| 73 | global numControllers |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 74 | numControllers = int( main.params[ 'num_controllers' ] ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 75 | |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 76 | # FIXME: just get controller port from params? |
| 77 | # TODO: do we really need all these? |
| 78 | ONOS1Port = main.params[ 'CTRL' ][ 'port1' ] |
| 79 | ONOS2Port = main.params[ 'CTRL' ][ 'port2' ] |
| 80 | ONOS3Port = main.params[ 'CTRL' ][ 'port3' ] |
| 81 | ONOS4Port = main.params[ 'CTRL' ][ 'port4' ] |
| 82 | ONOS5Port = main.params[ 'CTRL' ][ 'port5' ] |
| 83 | ONOS6Port = main.params[ 'CTRL' ][ 'port6' ] |
| 84 | ONOS7Port = main.params[ 'CTRL' ][ 'port7' ] |
| 85 | |
| 86 | global CLIs |
| 87 | CLIs = [] |
| 88 | global nodes |
| 89 | nodes = [] |
| 90 | for i in range( 1, numControllers + 1 ): |
| 91 | CLIs.append( getattr( main, 'ONOScli' + str( i ) ) ) |
| 92 | nodes.append( getattr( main, 'ONOS' + str( i ) ) ) |
| 93 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 94 | main.step( "Applying cell variable to environment" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 95 | cellResult = main.ONOSbench.setCell( cellName ) |
| 96 | verifyResult = main.ONOSbench.verifyCell() |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 97 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 98 | # FIXME:this is short term fix |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 99 | main.log.info( "Removing raft logs" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 100 | main.ONOSbench.onosRemoveRaftLogs() |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 101 | |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 102 | main.log.info( "Uninstalling ONOS" ) |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 103 | for node in nodes: |
| 104 | main.ONOSbench.onosUninstall( node.ip_address ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 105 | |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 106 | # Make sure ONOS is DEAD |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 107 | main.log.info( "Killing any ONOS processes" ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 108 | killResults = main.TRUE |
| 109 | for node in nodes: |
| 110 | killed = main.ONOSbench.onosKill( node.ip_address ) |
| 111 | killResults = killResults and killed |
| 112 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 113 | cleanInstallResult = main.TRUE |
| 114 | gitPullResult = main.TRUE |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 115 | |
Jon Hall | 97f3175 | 2015-02-04 12:01:04 -0800 | [diff] [blame] | 116 | main.step( "Starting Mininet" ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 117 | mnResult = main.Mininet1.startNet( ) |
| 118 | utilities.assert_equals( expect=main.TRUE, actual=mnResult, |
| 119 | onpass="Mininet Started", |
| 120 | onfail="Error starting Mininet" ) |
Jon Hall | 97f3175 | 2015-02-04 12:01:04 -0800 | [diff] [blame] | 121 | |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 122 | main.step( "Git checkout and pull " + gitBranch ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 123 | if PULLCODE: |
Jon Hall | 529a37f | 2015-01-28 10:02:00 -0800 | [diff] [blame] | 124 | main.ONOSbench.gitCheckout( gitBranch ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 125 | gitPullResult = main.ONOSbench.gitPull() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 126 | # values of 1 or 3 are good |
| 127 | utilities.assert_lesser( expect=0, actual=gitPullResult, |
| 128 | onpass="Git pull successful", |
| 129 | onfail="Git pull failed" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 130 | main.ONOSbench.getVersion( report=True ) |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 131 | |
| 132 | main.step( "Using mvn clean install" ) |
| 133 | cleanInstallResult = main.TRUE |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 134 | if PULLCODE and gitPullResult == main.TRUE: |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 135 | cleanInstallResult = main.ONOSbench.cleanInstall() |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 136 | else: |
| 137 | main.log.warn( "Did not pull new code so skipping mvn " + |
| 138 | "clean install" ) |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 139 | utilities.assert_equals( expect=main.TRUE, |
| 140 | actual=cleanInstallResult, |
| 141 | onpass="MCI successful", |
| 142 | onfail="MCI failed" ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 143 | # GRAPHS |
| 144 | # NOTE: important params here: |
| 145 | # job = name of Jenkins job |
| 146 | # Plot Name = Plot-HA, only can be used if multiple plots |
| 147 | # index = The number of the graph under plot name |
| 148 | job = "HAMinorityRestart" |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 149 | plotName = "Plot-HA" |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 150 | graphs = '<ac:structured-macro ac:name="html">\n' |
| 151 | graphs += '<ac:plain-text-body><![CDATA[\n' |
| 152 | graphs += '<iframe src="https://onos-jenkins.onlab.us/job/' + job +\ |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 153 | '/plot/' + plotName + '/getPlot?index=0' +\ |
| 154 | '&width=500&height=300"' +\ |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 155 | 'noborder="0" width="500" height="300" scrolling="yes" ' +\ |
| 156 | 'seamless="seamless"></iframe>\n' |
| 157 | graphs += ']]></ac:plain-text-body>\n' |
| 158 | graphs += '</ac:structured-macro>\n' |
| 159 | main.log.wiki(graphs) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 160 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 161 | main.step( "Creating ONOS package" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 162 | packageResult = main.ONOSbench.onosPackage() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 163 | utilities.assert_equals( expect=main.TRUE, actual=packageResult, |
| 164 | onpass="ONOS package successful", |
| 165 | onfail="ONOS package failed" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 166 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 167 | main.step( "Installing ONOS package" ) |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 168 | onosInstallResult = main.TRUE |
| 169 | for node in nodes: |
| 170 | tmpResult = main.ONOSbench.onosInstall( options="-f", |
| 171 | node=node.ip_address ) |
| 172 | onosInstallResult = onosInstallResult and tmpResult |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 173 | utilities.assert_equals( expect=main.TRUE, actual=onosInstallResult, |
| 174 | onpass="ONOS install successful", |
| 175 | onfail="ONOS install failed" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 176 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 177 | main.step( "Checking if ONOS is up yet" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 178 | for i in range( 2 ): |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 179 | onosIsupResult = main.TRUE |
| 180 | for node in nodes: |
| 181 | started = main.ONOSbench.isup( node.ip_address ) |
| 182 | if not started: |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 183 | main.log.error( node.name + " didn't start!" ) |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 184 | main.ONOSbench.onosStop( node.ip_address ) |
| 185 | main.ONOSbench.onosStart( node.ip_address ) |
| 186 | onosIsupResult = onosIsupResult and started |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 187 | if onosIsupResult == main.TRUE: |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 188 | break |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 189 | utilities.assert_equals( expect=main.TRUE, actual=onosIsupResult, |
| 190 | onpass="ONOS startup successful", |
| 191 | onfail="ONOS startup failed" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 192 | |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 193 | main.log.step( "Starting ONOS CLI sessions" ) |
| 194 | cliResults = main.TRUE |
| 195 | threads = [] |
| 196 | for i in range( numControllers ): |
| 197 | t = main.Thread( target=CLIs[i].startOnosCli, |
| 198 | name="startOnosCli-" + str( i ), |
| 199 | args=[nodes[i].ip_address] ) |
| 200 | threads.append( t ) |
| 201 | t.start() |
| 202 | |
| 203 | for t in threads: |
| 204 | t.join() |
| 205 | cliResults = cliResults and t.result |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 206 | utilities.assert_equals( expect=main.TRUE, actual=cliResults, |
| 207 | onpass="ONOS cli startup successful", |
| 208 | onfail="ONOS cli startup failed" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 209 | |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 210 | if main.params[ 'tcpdump' ].lower() == "true": |
| 211 | main.step( "Start Packet Capture MN" ) |
| 212 | main.Mininet2.startTcpdump( |
| 213 | str( main.params[ 'MNtcpdump' ][ 'folder' ] ) + str( main.TEST ) |
| 214 | + "-MN.pcap", |
| 215 | intf=main.params[ 'MNtcpdump' ][ 'intf' ], |
| 216 | port=main.params[ 'MNtcpdump' ][ 'port' ] ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 217 | |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 218 | main.step( "App Ids check" ) |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 219 | appCheck = main.TRUE |
| 220 | threads = [] |
| 221 | for i in range( numControllers ): |
| 222 | t = main.Thread( target=CLIs[i].appToIDCheck, |
| 223 | name="appToIDCheck-" + str( i ), |
| 224 | args=[] ) |
| 225 | threads.append( t ) |
| 226 | t.start() |
| 227 | |
| 228 | for t in threads: |
| 229 | t.join() |
| 230 | appCheck = appCheck and t.result |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 231 | if appCheck != main.TRUE: |
| 232 | main.log.warn( CLIs[0].apps() ) |
| 233 | main.log.warn( CLIs[0].appIDs() ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 234 | utilities.assert_equals( expect=main.TRUE, actual=appCheck, |
| 235 | onpass="App Ids seem to be correct", |
| 236 | onfail="Something is wrong with app Ids" ) |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 237 | |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 238 | if cliResults == main.FALSE: |
| 239 | main.log.error( "Failed to start ONOS, stopping test" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 240 | main.cleanup() |
| 241 | main.exit() |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 242 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 243 | def CASE2( self, main ): |
| 244 | """ |
Jon Hall | c9eabec | 2015-06-10 14:33:14 -0700 | [diff] [blame] | 245 | Assign devices to controllers |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 246 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 247 | import re |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 248 | import time |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 249 | assert numControllers, "numControllers not defined" |
| 250 | assert main, "main not defined" |
| 251 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
| 252 | assert CLIs, "CLIs not defined" |
| 253 | assert nodes, "nodes not defined" |
| 254 | assert ONOS1Port, "ONOS1Port not defined" |
| 255 | assert ONOS2Port, "ONOS2Port not defined" |
| 256 | assert ONOS3Port, "ONOS3Port not defined" |
| 257 | assert ONOS4Port, "ONOS4Port not defined" |
| 258 | assert ONOS5Port, "ONOS5Port not defined" |
| 259 | assert ONOS6Port, "ONOS6Port not defined" |
| 260 | assert ONOS7Port, "ONOS7Port not defined" |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 261 | |
Jon Hall | c9eabec | 2015-06-10 14:33:14 -0700 | [diff] [blame] | 262 | main.case( "Assigning devices to controllers" ) |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 263 | main.caseExplaination = "Assign switches to ONOS using 'ovs-vsctl' " +\ |
| 264 | "and check that an ONOS node becomes the " +\ |
Jon Hall | c9eabec | 2015-06-10 14:33:14 -0700 | [diff] [blame] | 265 | "master of the device." |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 266 | main.step( "Assign switches to controllers" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 267 | |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 268 | # TODO: rewrite this function to take lists of ips and ports? |
| 269 | # or list of tuples? |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 270 | for i in range( 1, 29 ): |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 271 | main.Mininet1.assignSwController( |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 272 | sw=str( i ), |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 273 | count=numControllers, |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 274 | ip1=nodes[ 0 ].ip_address, port1=ONOS1Port, |
| 275 | ip2=nodes[ 1 ].ip_address, port2=ONOS2Port, |
| 276 | ip3=nodes[ 2 ].ip_address, port3=ONOS3Port, |
| 277 | ip4=nodes[ 3 ].ip_address, port4=ONOS4Port, |
| 278 | ip5=nodes[ 4 ].ip_address, port5=ONOS5Port, |
| 279 | ip6=nodes[ 5 ].ip_address, port6=ONOS6Port, |
| 280 | ip7=nodes[ 6 ].ip_address, port7=ONOS7Port ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 281 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 282 | mastershipCheck = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 283 | for i in range( 1, 29 ): |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 284 | response = main.Mininet1.getSwController( "s" + str( i ) ) |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 285 | try: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 286 | main.log.info( str( response ) ) |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 287 | except Exception: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 288 | main.log.info( repr( response ) ) |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 289 | for node in nodes: |
| 290 | if re.search( "tcp:" + node.ip_address, response ): |
| 291 | mastershipCheck = mastershipCheck and main.TRUE |
| 292 | else: |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 293 | main.log.error( "Error, node " + node.ip_address + " is " + |
| 294 | "not in the list of controllers s" + |
| 295 | str( i ) + " is connecting to." ) |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 296 | mastershipCheck = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 297 | utilities.assert_equals( |
| 298 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 299 | actual=mastershipCheck, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 300 | onpass="Switch mastership assigned correctly", |
| 301 | onfail="Switches not assigned correctly to controllers" ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 302 | |
Jon Hall | c9eabec | 2015-06-10 14:33:14 -0700 | [diff] [blame] | 303 | def CASE21( self, main ): |
| 304 | """ |
| 305 | Assign mastership to controllers |
| 306 | """ |
| 307 | import re |
| 308 | import time |
| 309 | assert numControllers, "numControllers not defined" |
| 310 | assert main, "main not defined" |
| 311 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
| 312 | assert CLIs, "CLIs not defined" |
| 313 | assert nodes, "nodes not defined" |
| 314 | assert ONOS1Port, "ONOS1Port not defined" |
| 315 | assert ONOS2Port, "ONOS2Port not defined" |
| 316 | assert ONOS3Port, "ONOS3Port not defined" |
| 317 | assert ONOS4Port, "ONOS4Port not defined" |
| 318 | assert ONOS5Port, "ONOS5Port not defined" |
| 319 | assert ONOS6Port, "ONOS6Port not defined" |
| 320 | assert ONOS7Port, "ONOS7Port not defined" |
| 321 | |
| 322 | main.case( "Assigning Controller roles for switches" ) |
| 323 | main.caseExplaination = "Check that ONOS is connected to each " +\ |
| 324 | "device. Then manually assign" +\ |
| 325 | " mastership to specific ONOS nodes using" +\ |
| 326 | " 'device-role'" |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 327 | main.step( "Assign mastership of switches to specific controllers" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 328 | # Manually assign mastership to the controller we want |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 329 | roleCall = main.TRUE |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 330 | |
| 331 | ipList = [ ] |
| 332 | deviceList = [] |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 333 | try: |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 334 | for i in range( 1, 29 ): # switches 1 through 28 |
| 335 | # set up correct variables: |
| 336 | if i == 1: |
| 337 | ip = nodes[ 0 ].ip_address # ONOS1 |
| 338 | deviceId = main.ONOScli1.getDevice( "1000" ).get( 'id' ) |
| 339 | elif i == 2: |
| 340 | ip = nodes[ 1 ].ip_address # ONOS2 |
| 341 | deviceId = main.ONOScli1.getDevice( "2000" ).get( 'id' ) |
| 342 | elif i == 3: |
| 343 | ip = nodes[ 1 ].ip_address # ONOS2 |
| 344 | deviceId = main.ONOScli1.getDevice( "3000" ).get( 'id' ) |
| 345 | elif i == 4: |
| 346 | ip = nodes[ 3 ].ip_address # ONOS4 |
| 347 | deviceId = main.ONOScli1.getDevice( "3004" ).get( 'id' ) |
| 348 | elif i == 5: |
| 349 | ip = nodes[ 2 ].ip_address # ONOS3 |
| 350 | deviceId = main.ONOScli1.getDevice( "5000" ).get( 'id' ) |
| 351 | elif i == 6: |
| 352 | ip = nodes[ 2 ].ip_address # ONOS3 |
| 353 | deviceId = main.ONOScli1.getDevice( "6000" ).get( 'id' ) |
| 354 | elif i == 7: |
| 355 | ip = nodes[ 5 ].ip_address # ONOS6 |
| 356 | deviceId = main.ONOScli1.getDevice( "6007" ).get( 'id' ) |
| 357 | elif i >= 8 and i <= 17: |
| 358 | ip = nodes[ 4 ].ip_address # ONOS5 |
| 359 | dpid = '3' + str( i ).zfill( 3 ) |
| 360 | deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' ) |
| 361 | elif i >= 18 and i <= 27: |
| 362 | ip = nodes[ 6 ].ip_address # ONOS7 |
| 363 | dpid = '6' + str( i ).zfill( 3 ) |
| 364 | deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' ) |
| 365 | elif i == 28: |
| 366 | ip = nodes[ 0 ].ip_address # ONOS1 |
| 367 | deviceId = main.ONOScli1.getDevice( "2800" ).get( 'id' ) |
| 368 | else: |
| 369 | main.log.error( "You didn't write an else statement for " + |
| 370 | "switch s" + str( i ) ) |
Jon Hall | c9eabec | 2015-06-10 14:33:14 -0700 | [diff] [blame] | 371 | roleCall = main.FALSE |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 372 | # Assign switch |
| 373 | assert deviceId, "No device id for s" + str( i ) + " in ONOS" |
| 374 | # TODO: make this controller dynamic |
| 375 | roleCall = roleCall and main.ONOScli1.deviceRole( deviceId, |
| 376 | ip ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 377 | ipList.append( ip ) |
| 378 | deviceList.append( deviceId ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 379 | except ( AttributeError, AssertionError ): |
| 380 | main.log.exception( "Something is wrong with ONOS device view" ) |
| 381 | main.log.info( main.ONOScli1.devices() ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 382 | utilities.assert_equals( |
| 383 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 384 | actual=roleCall, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 385 | onpass="Re-assigned switch mastership to designated controller", |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 386 | onfail="Something wrong with deviceRole calls" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 387 | |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 388 | main.step( "Check mastership was correctly assigned" ) |
| 389 | roleCheck = main.TRUE |
| 390 | # NOTE: This is due to the fact that device mastership change is not |
| 391 | # atomic and is actually a multi step process |
| 392 | time.sleep( 5 ) |
| 393 | for i in range( len( ipList ) ): |
| 394 | ip = ipList[i] |
| 395 | deviceId = deviceList[i] |
| 396 | # Check assignment |
| 397 | master = main.ONOScli1.getRole( deviceId ).get( 'master' ) |
| 398 | if ip in master: |
| 399 | roleCheck = roleCheck and main.TRUE |
| 400 | else: |
| 401 | roleCheck = roleCheck and main.FALSE |
| 402 | main.log.error( "Error, controller " + ip + " is not" + |
| 403 | " master " + "of device " + |
| 404 | str( deviceId ) + ". Master is " + |
| 405 | repr( master ) + "." ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 406 | utilities.assert_equals( |
| 407 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 408 | actual=roleCheck, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 409 | onpass="Switches were successfully reassigned to designated " + |
| 410 | "controller", |
| 411 | onfail="Switches were not successfully reassigned" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 412 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 413 | def CASE3( self, main ): |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 414 | """ |
| 415 | Assign intents |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 416 | """ |
| 417 | import time |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 418 | import json |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 419 | assert numControllers, "numControllers not defined" |
| 420 | assert main, "main not defined" |
| 421 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
| 422 | assert CLIs, "CLIs not defined" |
| 423 | assert nodes, "nodes not defined" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 424 | main.case( "Adding host Intents" ) |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 425 | main.caseExplaination = "Discover hosts by using pingall then " +\ |
| 426 | "assign predetermined host-to-host intents." +\ |
| 427 | " After installation, check that the intent" +\ |
| 428 | " is distributed to all nodes and the state" +\ |
| 429 | " is INSTALLED" |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 430 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 431 | # install onos-app-fwd |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 432 | main.step( "Install reactive forwarding app" ) |
| 433 | installResults = CLIs[0].activateApp( "org.onosproject.fwd" ) |
| 434 | utilities.assert_equals( expect=main.TRUE, actual=installResults, |
| 435 | onpass="Install fwd successful", |
| 436 | onfail="Install fwd failed" ) |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 437 | |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 438 | main.step( "Check app ids" ) |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 439 | appCheck = main.TRUE |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 440 | threads = [] |
| 441 | for i in range( numControllers ): |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 442 | t = main.Thread( target=CLIs[i].appToIDCheck, |
| 443 | name="appToIDCheck-" + str( i ), |
| 444 | args=[] ) |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 445 | threads.append( t ) |
| 446 | t.start() |
| 447 | |
| 448 | for t in threads: |
| 449 | t.join() |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 450 | appCheck = appCheck and t.result |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 451 | if appCheck != main.TRUE: |
| 452 | main.log.warn( CLIs[0].apps() ) |
| 453 | main.log.warn( CLIs[0].appIDs() ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 454 | utilities.assert_equals( expect=main.TRUE, actual=appCheck, |
| 455 | onpass="App Ids seem to be correct", |
| 456 | onfail="Something is wrong with app Ids" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 457 | |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 458 | main.step( "Discovering Hosts( Via pingall for now )" ) |
| 459 | # FIXME: Once we have a host discovery mechanism, use that instead |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 460 | # REACTIVE FWD test |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 461 | pingResult = main.FALSE |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 462 | for i in range(2): # Retry if pingall fails first time |
| 463 | time1 = time.time() |
| 464 | pingResult = main.Mininet1.pingall() |
| 465 | utilities.assert_equals( |
| 466 | expect=main.TRUE, |
| 467 | actual=pingResult, |
| 468 | onpass="Reactive Pingall test passed", |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 469 | onfail="Reactive Pingall failed, " + |
| 470 | "one or more ping pairs failed" ) |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 471 | time2 = time.time() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 472 | main.log.info( "Time for pingall: %2f seconds" % |
| 473 | ( time2 - time1 ) ) |
| 474 | # timeout for fwd flows |
| 475 | time.sleep( 11 ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 476 | # uninstall onos-app-fwd |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 477 | main.step( "Uninstall reactive forwarding app" ) |
| 478 | uninstallResult = CLIs[0].deactivateApp( "org.onosproject.fwd" ) |
| 479 | utilities.assert_equals( expect=main.TRUE, actual=uninstallResult, |
| 480 | onpass="Uninstall fwd successful", |
| 481 | onfail="Uninstall fwd failed" ) |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 482 | |
| 483 | main.step( "Check app ids" ) |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 484 | threads = [] |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 485 | appCheck2 = main.TRUE |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 486 | for i in range( numControllers ): |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 487 | t = main.Thread( target=CLIs[i].appToIDCheck, |
| 488 | name="appToIDCheck-" + str( i ), |
| 489 | args=[] ) |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 490 | threads.append( t ) |
| 491 | t.start() |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 492 | |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 493 | for t in threads: |
| 494 | t.join() |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 495 | appCheck2 = appCheck2 and t.result |
| 496 | if appCheck2 != main.TRUE: |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 497 | main.log.warn( CLIs[0].apps() ) |
| 498 | main.log.warn( CLIs[0].appIDs() ) |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 499 | utilities.assert_equals( expect=main.TRUE, actual=appCheck2, |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 500 | onpass="App Ids seem to be correct", |
| 501 | onfail="Something is wrong with app Ids" ) |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 502 | |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 503 | main.step( "Add host intents via cli" ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 504 | intentIds = [] |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 505 | # TODO: move the host numbers to params |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 506 | # Maybe look at all the paths we ping? |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 507 | intentAddResult = True |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 508 | hostResult = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 509 | for i in range( 8, 18 ): |
| 510 | main.log.info( "Adding host intent between h" + str( i ) + |
| 511 | " and h" + str( i + 10 ) ) |
| 512 | host1 = "00:00:00:00:00:" + \ |
| 513 | str( hex( i )[ 2: ] ).zfill( 2 ).upper() |
| 514 | host2 = "00:00:00:00:00:" + \ |
| 515 | str( hex( i + 10 )[ 2: ] ).zfill( 2 ).upper() |
Jon Hall | 1b8f54a | 2015-02-04 13:24:20 -0800 | [diff] [blame] | 516 | # NOTE: getHost can return None |
| 517 | host1Dict = main.ONOScli1.getHost( host1 ) |
| 518 | host2Dict = main.ONOScli1.getHost( host2 ) |
| 519 | host1Id = None |
| 520 | host2Id = None |
| 521 | if host1Dict and host2Dict: |
| 522 | host1Id = host1Dict.get( 'id', None ) |
| 523 | host2Id = host2Dict.get( 'id', None ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 524 | if host1Id and host2Id: |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 525 | nodeNum = ( i % 7 ) |
| 526 | tmpId = CLIs[ nodeNum ].addHostIntent( host1Id, host2Id ) |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 527 | if tmpId: |
| 528 | main.log.info( "Added intent with id: " + tmpId ) |
| 529 | intentIds.append( tmpId ) |
| 530 | else: |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 531 | main.log.error( "addHostIntent returned: " + |
| 532 | repr( tmpId ) ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 533 | else: |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 534 | main.log.error( "Error, getHost() failed for h" + str( i ) + |
| 535 | " and/or h" + str( i + 10 ) ) |
| 536 | hosts = CLIs[ 0 ].hosts() |
| 537 | main.log.warn( "Hosts output: " ) |
| 538 | try: |
| 539 | main.log.warn( json.dumps( json.loads( hosts ), |
| 540 | sort_keys=True, |
| 541 | indent=4, |
| 542 | separators=( ',', ': ' ) ) ) |
| 543 | except ( ValueError, TypeError ): |
| 544 | main.log.warn( repr( hosts ) ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 545 | hostResult = main.FALSE |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 546 | utilities.assert_equals( expect=main.TRUE, actual=hostResult, |
| 547 | onpass="Found a host id for each host", |
| 548 | onfail="Error looking up host ids" ) |
| 549 | |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 550 | intentStart = time.time() |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 551 | onosIds = main.ONOScli1.getAllIntentsId() |
| 552 | main.log.info( "Submitted intents: " + str( intentIds ) ) |
| 553 | main.log.info( "Intents in ONOS: " + str( onosIds ) ) |
| 554 | for intent in intentIds: |
| 555 | if intent in onosIds: |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 556 | pass # intent submitted is in onos |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 557 | else: |
| 558 | intentAddResult = False |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 559 | if intentAddResult: |
| 560 | intentStop = time.time() |
| 561 | else: |
| 562 | intentStop = None |
Jon Hall | 1b8f54a | 2015-02-04 13:24:20 -0800 | [diff] [blame] | 563 | # Print the intent states |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 564 | intents = main.ONOScli1.intents() |
Jon Hall | 1b8f54a | 2015-02-04 13:24:20 -0800 | [diff] [blame] | 565 | intentStates = [] |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 566 | installedCheck = True |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 567 | main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) ) |
| 568 | count = 0 |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 569 | try: |
| 570 | for intent in json.loads( intents ): |
| 571 | state = intent.get( 'state', None ) |
| 572 | if "INSTALLED" not in state: |
| 573 | installedCheck = False |
| 574 | intentId = intent.get( 'id', None ) |
| 575 | intentStates.append( ( intentId, state ) ) |
| 576 | except ( ValueError, TypeError ): |
| 577 | main.log.exception( "Error parsing intents" ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 578 | # add submitted intents not in the store |
| 579 | tmplist = [ i for i, s in intentStates ] |
| 580 | missingIntents = False |
| 581 | for i in intentIds: |
| 582 | if i not in tmplist: |
| 583 | intentStates.append( ( i, " - " ) ) |
| 584 | missingIntents = True |
| 585 | intentStates.sort() |
| 586 | for i, s in intentStates: |
| 587 | count += 1 |
| 588 | main.log.info( "%-6s%-15s%-15s" % |
| 589 | ( str( count ), str( i ), str( s ) ) ) |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 590 | leaders = main.ONOScli1.leaders() |
| 591 | try: |
Jon Hall | c9eabec | 2015-06-10 14:33:14 -0700 | [diff] [blame] | 592 | missing = False |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 593 | if leaders: |
| 594 | parsedLeaders = json.loads( leaders ) |
| 595 | main.log.warn( json.dumps( parsedLeaders, |
| 596 | sort_keys=True, |
| 597 | indent=4, |
| 598 | separators=( ',', ': ' ) ) ) |
| 599 | # check for all intent partitions |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 600 | topics = [] |
| 601 | for i in range( 14 ): |
| 602 | topics.append( "intent-partition-" + str( i ) ) |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 603 | main.log.debug( topics ) |
| 604 | ONOStopics = [ j['topic'] for j in parsedLeaders ] |
| 605 | for topic in topics: |
| 606 | if topic not in ONOStopics: |
| 607 | main.log.error( "Error: " + topic + |
| 608 | " not in leaders" ) |
Jon Hall | c9eabec | 2015-06-10 14:33:14 -0700 | [diff] [blame] | 609 | missing = True |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 610 | else: |
| 611 | main.log.error( "leaders() returned None" ) |
| 612 | except ( ValueError, TypeError ): |
| 613 | main.log.exception( "Error parsing leaders" ) |
| 614 | main.log.error( repr( leaders ) ) |
Jon Hall | c9eabec | 2015-06-10 14:33:14 -0700 | [diff] [blame] | 615 | # Check all nodes |
| 616 | if missing: |
| 617 | for node in CLIs: |
| 618 | response = node.leaders( jsonFormat=False) |
| 619 | main.log.warn( str( node.name ) + " leaders output: \n" + |
| 620 | str( response ) ) |
| 621 | |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 622 | partitions = main.ONOScli1.partitions() |
| 623 | try: |
| 624 | if partitions : |
| 625 | parsedPartitions = json.loads( partitions ) |
| 626 | main.log.warn( json.dumps( parsedPartitions, |
| 627 | sort_keys=True, |
| 628 | indent=4, |
| 629 | separators=( ',', ': ' ) ) ) |
| 630 | # TODO check for a leader in all paritions |
| 631 | # TODO check for consistency among nodes |
| 632 | else: |
| 633 | main.log.error( "partitions() returned None" ) |
| 634 | except ( ValueError, TypeError ): |
| 635 | main.log.exception( "Error parsing partitions" ) |
| 636 | main.log.error( repr( partitions ) ) |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 637 | pendingMap = main.ONOScli1.pendingMap() |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 638 | try: |
| 639 | if pendingMap : |
| 640 | parsedPending = json.loads( pendingMap ) |
| 641 | main.log.warn( json.dumps( parsedPending, |
| 642 | sort_keys=True, |
| 643 | indent=4, |
| 644 | separators=( ',', ': ' ) ) ) |
| 645 | # TODO check something here? |
| 646 | else: |
| 647 | main.log.error( "pendingMap() returned None" ) |
| 648 | except ( ValueError, TypeError ): |
| 649 | main.log.exception( "Error parsing pending map" ) |
| 650 | main.log.error( repr( pendingMap ) ) |
| 651 | |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 652 | intentAddResult = bool( intentAddResult and not missingIntents and |
| 653 | installedCheck ) |
| 654 | if not intentAddResult: |
| 655 | main.log.error( "Error in pushing host intents to ONOS" ) |
| 656 | |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 657 | main.step( "Intent Anti-Entropy dispersion" ) |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 658 | for i in range(100): |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 659 | correct = True |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 660 | main.log.info( "Submitted intents: " + str( sorted( intentIds ) ) ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 661 | for cli in CLIs: |
| 662 | onosIds = [] |
| 663 | ids = cli.getAllIntentsId() |
| 664 | onosIds.append( ids ) |
| 665 | main.log.debug( "Intents in " + cli.name + ": " + |
| 666 | str( sorted( onosIds ) ) ) |
| 667 | if sorted( ids ) != sorted( intentIds ): |
Jon Hall | c9eabec | 2015-06-10 14:33:14 -0700 | [diff] [blame] | 668 | main.log.debug( "Set of intent IDs doesn't match" ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 669 | correct = False |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 670 | break |
| 671 | else: |
| 672 | intents = json.loads( cli.intents() ) |
| 673 | for intent in intents: |
| 674 | if intent[ 'state' ] != "INSTALLED": |
Jon Hall | c9eabec | 2015-06-10 14:33:14 -0700 | [diff] [blame] | 675 | main.log.warn( "Intent " + intent[ 'id' ] + |
| 676 | " is " + intent[ 'state' ] ) |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 677 | correct = False |
| 678 | break |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 679 | if correct: |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 680 | break |
| 681 | else: |
| 682 | time.sleep(1) |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 683 | if not intentStop: |
| 684 | intentStop = time.time() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 685 | global gossipTime |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 686 | gossipTime = intentStop - intentStart |
| 687 | main.log.info( "It took about " + str( gossipTime ) + |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 688 | " seconds for all intents to appear in each node" ) |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 689 | # FIXME: make this time configurable/calculate based off of number of |
| 690 | # nodes and gossip rounds |
| 691 | utilities.assert_greater_equals( |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 692 | expect=40, actual=gossipTime, |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 693 | onpass="ECM anti-entropy for intents worked within " + |
| 694 | "expected time", |
| 695 | onfail="Intent ECM anti-entropy took too long" ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 696 | if gossipTime <= 40: |
Jon Hall | 678f451 | 2015-03-31 09:48:31 -0700 | [diff] [blame] | 697 | intentAddResult = True |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 698 | |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 699 | if not intentAddResult or "key" in pendingMap: |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 700 | import time |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 701 | installedCheck = True |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 702 | main.log.info( "Sleeping 60 seconds to see if intents are found" ) |
| 703 | time.sleep( 60 ) |
| 704 | onosIds = main.ONOScli1.getAllIntentsId() |
| 705 | main.log.info( "Submitted intents: " + str( intentIds ) ) |
| 706 | main.log.info( "Intents in ONOS: " + str( onosIds ) ) |
| 707 | # Print the intent states |
| 708 | intents = main.ONOScli1.intents() |
| 709 | intentStates = [] |
| 710 | main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) ) |
| 711 | count = 0 |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 712 | try: |
| 713 | for intent in json.loads( intents ): |
| 714 | # Iter through intents of a node |
| 715 | state = intent.get( 'state', None ) |
| 716 | if "INSTALLED" not in state: |
| 717 | installedCheck = False |
| 718 | intentId = intent.get( 'id', None ) |
| 719 | intentStates.append( ( intentId, state ) ) |
| 720 | except ( ValueError, TypeError ): |
| 721 | main.log.exception( "Error parsing intents" ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 722 | # add submitted intents not in the store |
| 723 | tmplist = [ i for i, s in intentStates ] |
| 724 | for i in intentIds: |
| 725 | if i not in tmplist: |
| 726 | intentStates.append( ( i, " - " ) ) |
| 727 | intentStates.sort() |
| 728 | for i, s in intentStates: |
| 729 | count += 1 |
| 730 | main.log.info( "%-6s%-15s%-15s" % |
| 731 | ( str( count ), str( i ), str( s ) ) ) |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 732 | leaders = main.ONOScli1.leaders() |
| 733 | try: |
Jon Hall | c9eabec | 2015-06-10 14:33:14 -0700 | [diff] [blame] | 734 | missing = False |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 735 | if leaders: |
| 736 | parsedLeaders = json.loads( leaders ) |
| 737 | main.log.warn( json.dumps( parsedLeaders, |
| 738 | sort_keys=True, |
| 739 | indent=4, |
| 740 | separators=( ',', ': ' ) ) ) |
| 741 | # check for all intent partitions |
| 742 | # check for election |
| 743 | topics = [] |
| 744 | for i in range( 14 ): |
| 745 | topics.append( "intent-partition-" + str( i ) ) |
| 746 | # FIXME: this should only be after we start the app |
| 747 | topics.append( "org.onosproject.election" ) |
| 748 | main.log.debug( topics ) |
| 749 | ONOStopics = [ j['topic'] for j in parsedLeaders ] |
| 750 | for topic in topics: |
| 751 | if topic not in ONOStopics: |
| 752 | main.log.error( "Error: " + topic + |
| 753 | " not in leaders" ) |
Jon Hall | c9eabec | 2015-06-10 14:33:14 -0700 | [diff] [blame] | 754 | missing = True |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 755 | else: |
| 756 | main.log.error( "leaders() returned None" ) |
| 757 | except ( ValueError, TypeError ): |
| 758 | main.log.exception( "Error parsing leaders" ) |
| 759 | main.log.error( repr( leaders ) ) |
Jon Hall | c9eabec | 2015-06-10 14:33:14 -0700 | [diff] [blame] | 760 | # Check all nodes |
| 761 | if missing: |
| 762 | for node in CLIs: |
| 763 | response = node.leaders( jsonFormat=False) |
| 764 | main.log.warn( str( node.name ) + " leaders output: \n" + |
| 765 | str( response ) ) |
| 766 | |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 767 | partitions = main.ONOScli1.partitions() |
| 768 | try: |
| 769 | if partitions : |
| 770 | parsedPartitions = json.loads( partitions ) |
| 771 | main.log.warn( json.dumps( parsedPartitions, |
| 772 | sort_keys=True, |
| 773 | indent=4, |
| 774 | separators=( ',', ': ' ) ) ) |
| 775 | # TODO check for a leader in all paritions |
| 776 | # TODO check for consistency among nodes |
| 777 | else: |
| 778 | main.log.error( "partitions() returned None" ) |
| 779 | except ( ValueError, TypeError ): |
| 780 | main.log.exception( "Error parsing partitions" ) |
| 781 | main.log.error( repr( partitions ) ) |
| 782 | pendingMap = main.ONOScli1.pendingMap() |
| 783 | try: |
| 784 | if pendingMap : |
| 785 | parsedPending = json.loads( pendingMap ) |
| 786 | main.log.warn( json.dumps( parsedPending, |
| 787 | sort_keys=True, |
| 788 | indent=4, |
| 789 | separators=( ',', ': ' ) ) ) |
| 790 | # TODO check something here? |
| 791 | else: |
| 792 | main.log.error( "pendingMap() returned None" ) |
| 793 | except ( ValueError, TypeError ): |
| 794 | main.log.exception( "Error parsing pending map" ) |
| 795 | main.log.error( repr( pendingMap ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 796 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 797 | def CASE4( self, main ): |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 798 | """ |
| 799 | Ping across added host intents |
| 800 | """ |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 801 | import json |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 802 | import time |
| 803 | assert numControllers, "numControllers not defined" |
| 804 | assert main, "main not defined" |
| 805 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
| 806 | assert CLIs, "CLIs not defined" |
| 807 | assert nodes, "nodes not defined" |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 808 | main.case( "Verify connectivity by sendind traffic across Intents" ) |
| 809 | main.caseExplaination = "Ping across added host intents to check " +\ |
| 810 | "functionality and check the state of " +\ |
| 811 | "the intent" |
| 812 | main.step( "Ping across added host intents" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 813 | PingResult = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 814 | for i in range( 8, 18 ): |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 815 | ping = main.Mininet1.pingHost( src="h" + str( i ), |
| 816 | target="h" + str( i + 10 ) ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 817 | PingResult = PingResult and ping |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 818 | if ping == main.FALSE: |
| 819 | main.log.warn( "Ping failed between h" + str( i ) + |
| 820 | " and h" + str( i + 10 ) ) |
| 821 | elif ping == main.TRUE: |
| 822 | main.log.info( "Ping test passed!" ) |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 823 | # Don't set PingResult or you'd override failures |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 824 | if PingResult == main.FALSE: |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 825 | main.log.error( |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 826 | "Intents have not been installed correctly, pings failed." ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 827 | # TODO: pretty print |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 828 | main.log.warn( "ONOS1 intents: " ) |
| 829 | try: |
| 830 | tmpIntents = main.ONOScli1.intents() |
| 831 | main.log.warn( json.dumps( json.loads( tmpIntents ), |
| 832 | sort_keys=True, |
| 833 | indent=4, |
| 834 | separators=( ',', ': ' ) ) ) |
| 835 | except ( ValueError, TypeError ): |
| 836 | main.log.warn( repr( tmpIntents ) ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 837 | utilities.assert_equals( |
| 838 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 839 | actual=PingResult, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 840 | onpass="Intents have been installed correctly and pings work", |
| 841 | onfail="Intents have not been installed correctly, pings failed." ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 842 | |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 843 | main.step( "Check Intent state" ) |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 844 | installedCheck = False |
Jon Hall | c9eabec | 2015-06-10 14:33:14 -0700 | [diff] [blame] | 845 | loopCount = 0 |
| 846 | while not installedCheck and loopCount < 40: |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 847 | installedCheck = True |
| 848 | # Print the intent states |
| 849 | intents = main.ONOScli1.intents() |
| 850 | intentStates = [] |
| 851 | main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) ) |
| 852 | count = 0 |
| 853 | # Iter through intents of a node |
| 854 | try: |
| 855 | for intent in json.loads( intents ): |
| 856 | state = intent.get( 'state', None ) |
| 857 | if "INSTALLED" not in state: |
| 858 | installedCheck = False |
| 859 | intentId = intent.get( 'id', None ) |
| 860 | intentStates.append( ( intentId, state ) ) |
| 861 | except ( ValueError, TypeError ): |
| 862 | main.log.exception( "Error parsing intents." ) |
| 863 | # Print states |
| 864 | intentStates.sort() |
| 865 | for i, s in intentStates: |
| 866 | count += 1 |
| 867 | main.log.info( "%-6s%-15s%-15s" % |
| 868 | ( str( count ), str( i ), str( s ) ) ) |
| 869 | if not installedCheck: |
| 870 | time.sleep( 1 ) |
Jon Hall | c9eabec | 2015-06-10 14:33:14 -0700 | [diff] [blame] | 871 | loopCount += 1 |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 872 | utilities.assert_equals( expect=True, actual=installedCheck, |
| 873 | onpass="Intents are all INSTALLED", |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 874 | onfail="Intents are not all in " + |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 875 | "INSTALLED state" ) |
| 876 | |
| 877 | main.step( "Check leadership of topics" ) |
| 878 | leaders = main.ONOScli1.leaders() |
| 879 | topicCheck = main.TRUE |
| 880 | try: |
| 881 | if leaders: |
| 882 | parsedLeaders = json.loads( leaders ) |
| 883 | main.log.warn( json.dumps( parsedLeaders, |
| 884 | sort_keys=True, |
| 885 | indent=4, |
| 886 | separators=( ',', ': ' ) ) ) |
| 887 | # check for all intent partitions |
| 888 | # check for election |
| 889 | # TODO: Look at Devices as topics now that it uses this system |
| 890 | topics = [] |
| 891 | for i in range( 14 ): |
| 892 | topics.append( "intent-partition-" + str( i ) ) |
| 893 | # FIXME: this should only be after we start the app |
| 894 | # FIXME: topics.append( "org.onosproject.election" ) |
| 895 | # Print leaders output |
| 896 | main.log.debug( topics ) |
| 897 | ONOStopics = [ j['topic'] for j in parsedLeaders ] |
| 898 | for topic in topics: |
| 899 | if topic not in ONOStopics: |
| 900 | main.log.error( "Error: " + topic + |
| 901 | " not in leaders" ) |
| 902 | topicCheck = main.FALSE |
| 903 | else: |
| 904 | main.log.error( "leaders() returned None" ) |
| 905 | topicCheck = main.FALSE |
| 906 | except ( ValueError, TypeError ): |
| 907 | topicCheck = main.FALSE |
| 908 | main.log.exception( "Error parsing leaders" ) |
| 909 | main.log.error( repr( leaders ) ) |
| 910 | # TODO: Check for a leader of these topics |
Jon Hall | c9eabec | 2015-06-10 14:33:14 -0700 | [diff] [blame] | 911 | # Check all nodes |
| 912 | if topicCheck: |
| 913 | for node in CLIs: |
| 914 | response = node.leaders( jsonFormat=False) |
| 915 | main.log.warn( str( node.name ) + " leaders output: \n" + |
| 916 | str( response ) ) |
| 917 | |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 918 | utilities.assert_equals( expect=main.TRUE, actual=topicCheck, |
| 919 | onpass="intent Partitions is in leaders", |
| 920 | onfail="Some topics were lost " ) |
| 921 | # Print partitions |
| 922 | partitions = main.ONOScli1.partitions() |
| 923 | try: |
| 924 | if partitions : |
| 925 | parsedPartitions = json.loads( partitions ) |
| 926 | main.log.warn( json.dumps( parsedPartitions, |
| 927 | sort_keys=True, |
| 928 | indent=4, |
| 929 | separators=( ',', ': ' ) ) ) |
| 930 | # TODO check for a leader in all paritions |
| 931 | # TODO check for consistency among nodes |
| 932 | else: |
| 933 | main.log.error( "partitions() returned None" ) |
| 934 | except ( ValueError, TypeError ): |
| 935 | main.log.exception( "Error parsing partitions" ) |
| 936 | main.log.error( repr( partitions ) ) |
| 937 | # Print Pending Map |
| 938 | pendingMap = main.ONOScli1.pendingMap() |
| 939 | try: |
| 940 | if pendingMap : |
| 941 | parsedPending = json.loads( pendingMap ) |
| 942 | main.log.warn( json.dumps( parsedPending, |
| 943 | sort_keys=True, |
| 944 | indent=4, |
| 945 | separators=( ',', ': ' ) ) ) |
| 946 | # TODO check something here? |
| 947 | else: |
| 948 | main.log.error( "pendingMap() returned None" ) |
| 949 | except ( ValueError, TypeError ): |
| 950 | main.log.exception( "Error parsing pending map" ) |
| 951 | main.log.error( repr( pendingMap ) ) |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 952 | |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 953 | if not installedCheck: |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 954 | main.log.info( "Waiting 60 seconds to see if the state of " + |
| 955 | "intents change" ) |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 956 | time.sleep( 60 ) |
| 957 | # Print the intent states |
| 958 | intents = main.ONOScli1.intents() |
| 959 | intentStates = [] |
| 960 | main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) ) |
| 961 | count = 0 |
| 962 | # Iter through intents of a node |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 963 | try: |
| 964 | for intent in json.loads( intents ): |
| 965 | state = intent.get( 'state', None ) |
| 966 | if "INSTALLED" not in state: |
| 967 | installedCheck = False |
| 968 | intentId = intent.get( 'id', None ) |
| 969 | intentStates.append( ( intentId, state ) ) |
| 970 | except ( ValueError, TypeError ): |
| 971 | main.log.exception( "Error parsing intents." ) |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 972 | intentStates.sort() |
| 973 | for i, s in intentStates: |
| 974 | count += 1 |
| 975 | main.log.info( "%-6s%-15s%-15s" % |
| 976 | ( str( count ), str( i ), str( s ) ) ) |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 977 | leaders = main.ONOScli1.leaders() |
| 978 | try: |
Jon Hall | c9eabec | 2015-06-10 14:33:14 -0700 | [diff] [blame] | 979 | missing = False |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 980 | if leaders: |
| 981 | parsedLeaders = json.loads( leaders ) |
| 982 | main.log.warn( json.dumps( parsedLeaders, |
| 983 | sort_keys=True, |
| 984 | indent=4, |
| 985 | separators=( ',', ': ' ) ) ) |
| 986 | # check for all intent partitions |
| 987 | # check for election |
| 988 | topics = [] |
| 989 | for i in range( 14 ): |
| 990 | topics.append( "intent-partition-" + str( i ) ) |
| 991 | # FIXME: this should only be after we start the app |
| 992 | topics.append( "org.onosproject.election" ) |
| 993 | main.log.debug( topics ) |
| 994 | ONOStopics = [ j['topic'] for j in parsedLeaders ] |
| 995 | for topic in topics: |
| 996 | if topic not in ONOStopics: |
| 997 | main.log.error( "Error: " + topic + |
| 998 | " not in leaders" ) |
Jon Hall | c9eabec | 2015-06-10 14:33:14 -0700 | [diff] [blame] | 999 | missing = True |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1000 | else: |
| 1001 | main.log.error( "leaders() returned None" ) |
| 1002 | except ( ValueError, TypeError ): |
| 1003 | main.log.exception( "Error parsing leaders" ) |
| 1004 | main.log.error( repr( leaders ) ) |
Jon Hall | c9eabec | 2015-06-10 14:33:14 -0700 | [diff] [blame] | 1005 | if missing: |
| 1006 | for node in CLIs: |
| 1007 | response = node.leaders( jsonFormat=False) |
| 1008 | main.log.warn( str( node.name ) + " leaders output: \n" + |
| 1009 | str( response ) ) |
| 1010 | |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1011 | partitions = main.ONOScli1.partitions() |
| 1012 | try: |
| 1013 | if partitions : |
| 1014 | parsedPartitions = json.loads( partitions ) |
| 1015 | main.log.warn( json.dumps( parsedPartitions, |
| 1016 | sort_keys=True, |
| 1017 | indent=4, |
| 1018 | separators=( ',', ': ' ) ) ) |
| 1019 | # TODO check for a leader in all paritions |
| 1020 | # TODO check for consistency among nodes |
| 1021 | else: |
| 1022 | main.log.error( "partitions() returned None" ) |
| 1023 | except ( ValueError, TypeError ): |
| 1024 | main.log.exception( "Error parsing partitions" ) |
| 1025 | main.log.error( repr( partitions ) ) |
| 1026 | pendingMap = main.ONOScli1.pendingMap() |
| 1027 | try: |
| 1028 | if pendingMap : |
| 1029 | parsedPending = json.loads( pendingMap ) |
| 1030 | main.log.warn( json.dumps( parsedPending, |
| 1031 | sort_keys=True, |
| 1032 | indent=4, |
| 1033 | separators=( ',', ': ' ) ) ) |
| 1034 | # TODO check something here? |
| 1035 | else: |
| 1036 | main.log.error( "pendingMap() returned None" ) |
| 1037 | except ( ValueError, TypeError ): |
| 1038 | main.log.exception( "Error parsing pending map" ) |
| 1039 | main.log.error( repr( pendingMap ) ) |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 1040 | # Print flowrules |
| 1041 | main.log.debug( CLIs[0].flows( jsonFormat=False ) ) |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 1042 | main.step( "Wait a minute then ping again" ) |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 1043 | # the wait is above |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 1044 | PingResult = main.TRUE |
| 1045 | for i in range( 8, 18 ): |
| 1046 | ping = main.Mininet1.pingHost( src="h" + str( i ), |
| 1047 | target="h" + str( i + 10 ) ) |
| 1048 | PingResult = PingResult and ping |
| 1049 | if ping == main.FALSE: |
| 1050 | main.log.warn( "Ping failed between h" + str( i ) + |
| 1051 | " and h" + str( i + 10 ) ) |
| 1052 | elif ping == main.TRUE: |
| 1053 | main.log.info( "Ping test passed!" ) |
| 1054 | # Don't set PingResult or you'd override failures |
| 1055 | if PingResult == main.FALSE: |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 1056 | main.log.error( |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 1057 | "Intents have not been installed correctly, pings failed." ) |
| 1058 | # TODO: pretty print |
| 1059 | main.log.warn( "ONOS1 intents: " ) |
| 1060 | try: |
| 1061 | tmpIntents = main.ONOScli1.intents() |
| 1062 | main.log.warn( json.dumps( json.loads( tmpIntents ), |
| 1063 | sort_keys=True, |
| 1064 | indent=4, |
| 1065 | separators=( ',', ': ' ) ) ) |
| 1066 | except ( ValueError, TypeError ): |
| 1067 | main.log.warn( repr( tmpIntents ) ) |
| 1068 | utilities.assert_equals( |
| 1069 | expect=main.TRUE, |
| 1070 | actual=PingResult, |
| 1071 | onpass="Intents have been installed correctly and pings work", |
| 1072 | onfail="Intents have not been installed correctly, pings failed." ) |
| 1073 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1074 | def CASE5( self, main ): |
| 1075 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1076 | Reading state of ONOS |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1077 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1078 | import json |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1079 | import time |
| 1080 | assert numControllers, "numControllers not defined" |
| 1081 | assert main, "main not defined" |
| 1082 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
| 1083 | assert CLIs, "CLIs not defined" |
| 1084 | assert nodes, "nodes not defined" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1085 | # assumes that sts is already in you PYTHONPATH |
| 1086 | from sts.topology.teston_topology import TestONTopology |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1087 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1088 | main.case( "Setting up and gathering data for current state" ) |
| 1089 | # The general idea for this test case is to pull the state of |
| 1090 | # ( intents,flows, topology,... ) from each ONOS node |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1091 | # We can then compare them with each other and also with past states |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1092 | |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1093 | main.step( "Check that each switch has a master" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1094 | global mastershipState |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1095 | mastershipState = '[]' |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1096 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1097 | # Assert that each device has a master |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1098 | rolesNotNull = main.TRUE |
| 1099 | threads = [] |
| 1100 | for i in range( numControllers ): |
| 1101 | t = main.Thread( target=CLIs[i].rolesNotNull, |
| 1102 | name="rolesNotNull-" + str( i ), |
| 1103 | args=[] ) |
| 1104 | threads.append( t ) |
| 1105 | t.start() |
| 1106 | |
| 1107 | for t in threads: |
| 1108 | t.join() |
| 1109 | rolesNotNull = rolesNotNull and t.result |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1110 | utilities.assert_equals( |
| 1111 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1112 | actual=rolesNotNull, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1113 | onpass="Each device has a master", |
| 1114 | onfail="Some devices don't have a master assigned" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1115 | |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1116 | main.step( "Get the Mastership of each switch from each controller" ) |
| 1117 | ONOSMastership = [] |
| 1118 | mastershipCheck = main.FALSE |
| 1119 | consistentMastership = True |
| 1120 | rolesResults = True |
| 1121 | threads = [] |
| 1122 | for i in range( numControllers ): |
| 1123 | t = main.Thread( target=CLIs[i].roles, |
| 1124 | name="roles-" + str( i ), |
| 1125 | args=[] ) |
| 1126 | threads.append( t ) |
| 1127 | t.start() |
| 1128 | |
| 1129 | for t in threads: |
| 1130 | t.join() |
| 1131 | ONOSMastership.append( t.result ) |
| 1132 | |
| 1133 | for i in range( numControllers ): |
| 1134 | if not ONOSMastership[i] or "Error" in ONOSMastership[i]: |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 1135 | main.log.error( "Error in getting ONOS" + str( i + 1 ) + |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1136 | " roles" ) |
| 1137 | main.log.warn( |
| 1138 | "ONOS" + str( i + 1 ) + " mastership response: " + |
| 1139 | repr( ONOSMastership[i] ) ) |
| 1140 | rolesResults = False |
| 1141 | utilities.assert_equals( |
| 1142 | expect=True, |
| 1143 | actual=rolesResults, |
| 1144 | onpass="No error in reading roles output", |
| 1145 | onfail="Error in reading roles from ONOS" ) |
| 1146 | |
| 1147 | main.step( "Check for consistency in roles from each controller" ) |
| 1148 | if all([ i == ONOSMastership[ 0 ] for i in ONOSMastership ] ): |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 1149 | main.log.info( |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1150 | "Switch roles are consistent across all ONOS nodes" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1151 | else: |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1152 | consistentMastership = False |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1153 | utilities.assert_equals( |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1154 | expect=True, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1155 | actual=consistentMastership, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1156 | onpass="Switch roles are consistent across all ONOS nodes", |
| 1157 | onfail="ONOS nodes have different views of switch roles" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1158 | |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1159 | if rolesResults and not consistentMastership: |
| 1160 | for i in range( numControllers ): |
| 1161 | try: |
| 1162 | main.log.warn( |
| 1163 | "ONOS" + str( i + 1 ) + " roles: ", |
| 1164 | json.dumps( |
| 1165 | json.loads( ONOSMastership[ i ] ), |
| 1166 | sort_keys=True, |
| 1167 | indent=4, |
| 1168 | separators=( ',', ': ' ) ) ) |
| 1169 | except ( ValueError, TypeError ): |
| 1170 | main.log.warn( repr( ONOSMastership[ i ] ) ) |
| 1171 | elif rolesResults and consistentMastership: |
| 1172 | mastershipCheck = main.TRUE |
| 1173 | mastershipState = ONOSMastership[ 0 ] |
| 1174 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1175 | main.step( "Get the intents from each controller" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1176 | global intentState |
| 1177 | intentState = [] |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1178 | ONOSIntents = [] |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1179 | intentCheck = main.FALSE |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1180 | consistentIntents = True |
| 1181 | intentsResults = True |
| 1182 | threads = [] |
| 1183 | for i in range( numControllers ): |
| 1184 | t = main.Thread( target=CLIs[i].intents, |
| 1185 | name="intents-" + str( i ), |
| 1186 | args=[], |
| 1187 | kwargs={ 'jsonFormat': True } ) |
| 1188 | threads.append( t ) |
| 1189 | t.start() |
| 1190 | |
| 1191 | for t in threads: |
| 1192 | t.join() |
| 1193 | ONOSIntents.append( t.result ) |
| 1194 | |
| 1195 | for i in range( numControllers ): |
| 1196 | if not ONOSIntents[ i ] or "Error" in ONOSIntents[ i ]: |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 1197 | main.log.error( "Error in getting ONOS" + str( i + 1 ) + |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1198 | " intents" ) |
| 1199 | main.log.warn( "ONOS" + str( i + 1 ) + " intents response: " + |
| 1200 | repr( ONOSIntents[ i ] ) ) |
| 1201 | intentsResults = False |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1202 | utilities.assert_equals( |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1203 | expect=True, |
| 1204 | actual=intentsResults, |
| 1205 | onpass="No error in reading intents output", |
| 1206 | onfail="Error in reading intents from ONOS" ) |
| 1207 | |
| 1208 | main.step( "Check for consistency in Intents from each controller" ) |
| 1209 | if all([ sorted( i ) == sorted( ONOSIntents[ 0 ] ) for i in ONOSIntents ] ): |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 1210 | main.log.info( "Intents are consistent across all ONOS " + |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1211 | "nodes" ) |
| 1212 | else: |
| 1213 | consistentIntents = False |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 1214 | main.log.error( "Intents not consistent" ) |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1215 | utilities.assert_equals( |
| 1216 | expect=True, |
| 1217 | actual=consistentIntents, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1218 | onpass="Intents are consistent across all ONOS nodes", |
| 1219 | onfail="ONOS nodes have different views of intents" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1220 | |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 1221 | if intentsResults: |
| 1222 | # Try to make it easy to figure out what is happening |
| 1223 | # |
| 1224 | # Intent ONOS1 ONOS2 ... |
| 1225 | # 0x01 INSTALLED INSTALLING |
| 1226 | # ... ... ... |
| 1227 | # ... ... ... |
| 1228 | title = " Id" |
| 1229 | for n in range( numControllers ): |
| 1230 | title += " " * 10 + "ONOS" + str( n + 1 ) |
| 1231 | main.log.warn( title ) |
| 1232 | # get all intent keys in the cluster |
| 1233 | keys = [] |
| 1234 | for nodeStr in ONOSIntents: |
| 1235 | node = json.loads( nodeStr ) |
| 1236 | for intent in node: |
| 1237 | keys.append( intent.get( 'id' ) ) |
| 1238 | keys = set( keys ) |
| 1239 | for key in keys: |
| 1240 | row = "%-13s" % key |
| 1241 | for nodeStr in ONOSIntents: |
| 1242 | node = json.loads( nodeStr ) |
| 1243 | for intent in node: |
| 1244 | if intent.get( 'id', "Error" ) == key: |
| 1245 | row += "%-15s" % intent.get( 'state' ) |
| 1246 | main.log.warn( row ) |
| 1247 | # End table view |
| 1248 | |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1249 | if intentsResults and not consistentIntents: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 1250 | # print the json objects |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1251 | n = len(ONOSIntents) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 1252 | main.log.debug( "ONOS" + str( n ) + " intents: " ) |
| 1253 | main.log.debug( json.dumps( json.loads( ONOSIntents[ -1 ] ), |
| 1254 | sort_keys=True, |
| 1255 | indent=4, |
| 1256 | separators=( ',', ': ' ) ) ) |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1257 | for i in range( numControllers ): |
| 1258 | if ONOSIntents[ i ] != ONOSIntents[ -1 ]: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 1259 | main.log.debug( "ONOS" + str( i + 1 ) + " intents: " ) |
| 1260 | main.log.debug( json.dumps( json.loads( ONOSIntents[i] ), |
| 1261 | sort_keys=True, |
| 1262 | indent=4, |
| 1263 | separators=( ',', ': ' ) ) ) |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1264 | else: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 1265 | main.log.debug( nodes[ i ].name + " intents match ONOS" + |
| 1266 | str( n ) + " intents" ) |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1267 | elif intentsResults and consistentIntents: |
| 1268 | intentCheck = main.TRUE |
| 1269 | intentState = ONOSIntents[ 0 ] |
| 1270 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1271 | main.step( "Get the flows from each controller" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1272 | global flowState |
| 1273 | flowState = [] |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1274 | ONOSFlows = [] |
| 1275 | ONOSFlowsJson = [] |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1276 | flowCheck = main.FALSE |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1277 | consistentFlows = True |
| 1278 | flowsResults = True |
| 1279 | threads = [] |
| 1280 | for i in range( numControllers ): |
| 1281 | t = main.Thread( target=CLIs[i].flows, |
| 1282 | name="flows-" + str( i ), |
| 1283 | args=[], |
| 1284 | kwargs={ 'jsonFormat': True } ) |
| 1285 | threads.append( t ) |
| 1286 | t.start() |
| 1287 | |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 1288 | # NOTE: Flows command can take some time to run |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1289 | time.sleep(30) |
| 1290 | for t in threads: |
| 1291 | t.join() |
| 1292 | result = t.result |
| 1293 | ONOSFlows.append( result ) |
| 1294 | |
| 1295 | for i in range( numControllers ): |
| 1296 | num = str( i + 1 ) |
| 1297 | if not ONOSFlows[ i ] or "Error" in ONOSFlows[ i ]: |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 1298 | main.log.error( "Error in getting ONOS" + num + " flows" ) |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1299 | main.log.warn( "ONOS" + num + " flows response: " + |
| 1300 | repr( ONOSFlows[ i ] ) ) |
| 1301 | flowsResults = False |
| 1302 | ONOSFlowsJson.append( None ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1303 | else: |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1304 | try: |
| 1305 | ONOSFlowsJson.append( json.loads( ONOSFlows[ i ] ) ) |
| 1306 | except ( ValueError, TypeError ): |
| 1307 | # FIXME: change this to log.error? |
| 1308 | main.log.exception( "Error in parsing ONOS" + num + |
| 1309 | " response as json." ) |
| 1310 | main.log.error( repr( ONOSFlows[ i ] ) ) |
| 1311 | ONOSFlowsJson.append( None ) |
| 1312 | flowsResults = False |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1313 | utilities.assert_equals( |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1314 | expect=True, |
| 1315 | actual=flowsResults, |
| 1316 | onpass="No error in reading flows output", |
| 1317 | onfail="Error in reading flows from ONOS" ) |
| 1318 | |
| 1319 | main.step( "Check for consistency in Flows from each controller" ) |
| 1320 | tmp = [ len( i ) == len( ONOSFlowsJson[ 0 ] ) for i in ONOSFlowsJson ] |
| 1321 | if all( tmp ): |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 1322 | main.log.info( "Flow count is consistent across all ONOS nodes" ) |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1323 | else: |
| 1324 | consistentFlows = False |
| 1325 | utilities.assert_equals( |
| 1326 | expect=True, |
| 1327 | actual=consistentFlows, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1328 | onpass="The flow count is consistent across all ONOS nodes", |
| 1329 | onfail="ONOS nodes have different flow counts" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1330 | |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1331 | if flowsResults and not consistentFlows: |
| 1332 | for i in range( numControllers ): |
| 1333 | try: |
| 1334 | main.log.warn( |
| 1335 | "ONOS" + str( i + 1 ) + " flows: " + |
| 1336 | json.dumps( json.loads( ONOSFlows[i] ), sort_keys=True, |
| 1337 | indent=4, separators=( ',', ': ' ) ) ) |
| 1338 | except ( ValueError, TypeError ): |
| 1339 | main.log.warn( |
| 1340 | "ONOS" + str( i + 1 ) + " flows: " + |
| 1341 | repr( ONOSFlows[ i ] ) ) |
| 1342 | elif flowsResults and consistentFlows: |
| 1343 | flowCheck = main.TRUE |
| 1344 | flowState = ONOSFlows[ 0 ] |
| 1345 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1346 | main.step( "Get the OF Table entries" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1347 | global flows |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1348 | flows = [] |
| 1349 | for i in range( 1, 29 ): |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1350 | flows.append( main.Mininet2.getFlowTable( 1.3, "s" + str( i ) ) ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1351 | if flowCheck == main.FALSE: |
| 1352 | for table in flows: |
| 1353 | main.log.warn( table ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1354 | # TODO: Compare switch flow tables with ONOS flow tables |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1355 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1356 | main.step( "Start continuous pings" ) |
| 1357 | main.Mininet2.pingLong( |
| 1358 | src=main.params[ 'PING' ][ 'source1' ], |
| 1359 | target=main.params[ 'PING' ][ 'target1' ], |
| 1360 | pingTime=500 ) |
| 1361 | main.Mininet2.pingLong( |
| 1362 | src=main.params[ 'PING' ][ 'source2' ], |
| 1363 | target=main.params[ 'PING' ][ 'target2' ], |
| 1364 | pingTime=500 ) |
| 1365 | main.Mininet2.pingLong( |
| 1366 | src=main.params[ 'PING' ][ 'source3' ], |
| 1367 | target=main.params[ 'PING' ][ 'target3' ], |
| 1368 | pingTime=500 ) |
| 1369 | main.Mininet2.pingLong( |
| 1370 | src=main.params[ 'PING' ][ 'source4' ], |
| 1371 | target=main.params[ 'PING' ][ 'target4' ], |
| 1372 | pingTime=500 ) |
| 1373 | main.Mininet2.pingLong( |
| 1374 | src=main.params[ 'PING' ][ 'source5' ], |
| 1375 | target=main.params[ 'PING' ][ 'target5' ], |
| 1376 | pingTime=500 ) |
| 1377 | main.Mininet2.pingLong( |
| 1378 | src=main.params[ 'PING' ][ 'source6' ], |
| 1379 | target=main.params[ 'PING' ][ 'target6' ], |
| 1380 | pingTime=500 ) |
| 1381 | main.Mininet2.pingLong( |
| 1382 | src=main.params[ 'PING' ][ 'source7' ], |
| 1383 | target=main.params[ 'PING' ][ 'target7' ], |
| 1384 | pingTime=500 ) |
| 1385 | main.Mininet2.pingLong( |
| 1386 | src=main.params[ 'PING' ][ 'source8' ], |
| 1387 | target=main.params[ 'PING' ][ 'target8' ], |
| 1388 | pingTime=500 ) |
| 1389 | main.Mininet2.pingLong( |
| 1390 | src=main.params[ 'PING' ][ 'source9' ], |
| 1391 | target=main.params[ 'PING' ][ 'target9' ], |
| 1392 | pingTime=500 ) |
| 1393 | main.Mininet2.pingLong( |
| 1394 | src=main.params[ 'PING' ][ 'source10' ], |
| 1395 | target=main.params[ 'PING' ][ 'target10' ], |
| 1396 | pingTime=500 ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1397 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1398 | main.step( "Create TestONTopology object" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1399 | ctrls = [] |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1400 | for node in nodes: |
| 1401 | temp = ( node, node.name, node.ip_address, 6633 ) |
| 1402 | ctrls.append( temp ) |
| 1403 | MNTopo = TestONTopology( main.Mininet1, ctrls ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1404 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1405 | main.step( "Collecting topology information from ONOS" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1406 | devices = [] |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1407 | threads = [] |
| 1408 | for i in range( numControllers ): |
| 1409 | t = main.Thread( target=CLIs[i].devices, |
| 1410 | name="devices-" + str( i ), |
| 1411 | args=[ ] ) |
| 1412 | threads.append( t ) |
| 1413 | t.start() |
| 1414 | |
| 1415 | for t in threads: |
| 1416 | t.join() |
| 1417 | devices.append( t.result ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1418 | hosts = [] |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1419 | threads = [] |
| 1420 | for i in range( numControllers ): |
| 1421 | t = main.Thread( target=CLIs[i].hosts, |
| 1422 | name="hosts-" + str( i ), |
| 1423 | args=[ ] ) |
| 1424 | threads.append( t ) |
| 1425 | t.start() |
| 1426 | |
| 1427 | for t in threads: |
| 1428 | t.join() |
| 1429 | try: |
| 1430 | hosts.append( json.loads( t.result ) ) |
| 1431 | except ( ValueError, TypeError ): |
| 1432 | # FIXME: better handling of this, print which node |
| 1433 | # Maybe use thread name? |
| 1434 | main.log.exception( "Error parsing json output of hosts" ) |
| 1435 | # FIXME: should this be an empty json object instead? |
| 1436 | hosts.append( None ) |
| 1437 | |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1438 | ports = [] |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1439 | threads = [] |
| 1440 | for i in range( numControllers ): |
| 1441 | t = main.Thread( target=CLIs[i].ports, |
| 1442 | name="ports-" + str( i ), |
| 1443 | args=[ ] ) |
| 1444 | threads.append( t ) |
| 1445 | t.start() |
| 1446 | |
| 1447 | for t in threads: |
| 1448 | t.join() |
| 1449 | ports.append( t.result ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1450 | links = [] |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1451 | threads = [] |
| 1452 | for i in range( numControllers ): |
| 1453 | t = main.Thread( target=CLIs[i].links, |
| 1454 | name="links-" + str( i ), |
| 1455 | args=[ ] ) |
| 1456 | threads.append( t ) |
| 1457 | t.start() |
| 1458 | |
| 1459 | for t in threads: |
| 1460 | t.join() |
| 1461 | links.append( t.result ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1462 | clusters = [] |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1463 | threads = [] |
| 1464 | for i in range( numControllers ): |
| 1465 | t = main.Thread( target=CLIs[i].clusters, |
| 1466 | name="clusters-" + str( i ), |
| 1467 | args=[ ] ) |
| 1468 | threads.append( t ) |
| 1469 | t.start() |
| 1470 | |
| 1471 | for t in threads: |
| 1472 | t.join() |
| 1473 | clusters.append( t.result ) |
Jon Hall | 529a37f | 2015-01-28 10:02:00 -0800 | [diff] [blame] | 1474 | # Compare json objects for hosts and dataplane clusters |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1475 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1476 | # hosts |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 1477 | main.step( "Host view is consistent across ONOS nodes" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1478 | consistentHostsResult = main.TRUE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1479 | for controller in range( len( hosts ) ): |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1480 | controllerStr = str( controller + 1 ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1481 | if "Error" not in hosts[ controller ]: |
| 1482 | if hosts[ controller ] == hosts[ 0 ]: |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1483 | continue |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1484 | else: # hosts not consistent |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 1485 | main.log.error( "hosts from ONOS" + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1486 | controllerStr + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1487 | " is inconsistent with ONOS1" ) |
| 1488 | main.log.warn( repr( hosts[ controller ] ) ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1489 | consistentHostsResult = main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1490 | |
| 1491 | else: |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 1492 | main.log.error( "Error in getting ONOS hosts from ONOS" + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1493 | controllerStr ) |
| 1494 | consistentHostsResult = main.FALSE |
| 1495 | main.log.warn( "ONOS" + controllerStr + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1496 | " hosts response: " + |
| 1497 | repr( hosts[ controller ] ) ) |
| 1498 | utilities.assert_equals( |
| 1499 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1500 | actual=consistentHostsResult, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1501 | onpass="Hosts view is consistent across all ONOS nodes", |
| 1502 | onfail="ONOS nodes have different views of hosts" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1503 | |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 1504 | main.step( "Each host has an IP address" ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1505 | ipResult = main.TRUE |
| 1506 | for controller in range( 0, len( hosts ) ): |
| 1507 | controllerStr = str( controller + 1 ) |
| 1508 | for host in hosts[ controller ]: |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 1509 | if not host.get( 'ipAddresses', [ ] ): |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1510 | main.log.error( "DEBUG:Error with host ips on controller" + |
| 1511 | controllerStr + ": " + str( host ) ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1512 | ipResult = main.FALSE |
| 1513 | utilities.assert_equals( |
| 1514 | expect=main.TRUE, |
| 1515 | actual=ipResult, |
| 1516 | onpass="The ips of the hosts aren't empty", |
| 1517 | onfail="The ip of at least one host is missing" ) |
| 1518 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1519 | # Strongly connected clusters of devices |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 1520 | main.step( "Cluster view is consistent across ONOS nodes" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1521 | consistentClustersResult = main.TRUE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1522 | for controller in range( len( clusters ) ): |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1523 | controllerStr = str( controller + 1 ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1524 | if "Error" not in clusters[ controller ]: |
| 1525 | if clusters[ controller ] == clusters[ 0 ]: |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1526 | continue |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1527 | else: # clusters not consistent |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 1528 | main.log.error( "clusters from ONOS" + controllerStr + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1529 | " is inconsistent with ONOS1" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1530 | consistentClustersResult = main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1531 | |
| 1532 | else: |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 1533 | main.log.error( "Error in getting dataplane clusters " + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1534 | "from ONOS" + controllerStr ) |
| 1535 | consistentClustersResult = main.FALSE |
| 1536 | main.log.warn( "ONOS" + controllerStr + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1537 | " clusters response: " + |
| 1538 | repr( clusters[ controller ] ) ) |
| 1539 | utilities.assert_equals( |
| 1540 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1541 | actual=consistentClustersResult, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1542 | onpass="Clusters view is consistent across all ONOS nodes", |
| 1543 | onfail="ONOS nodes have different views of clusters" ) |
| 1544 | # there should always only be one cluster |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 1545 | main.step( "Cluster view correct across ONOS nodes" ) |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1546 | try: |
| 1547 | numClusters = len( json.loads( clusters[ 0 ] ) ) |
| 1548 | except ( ValueError, TypeError ): |
| 1549 | main.log.exception( "Error parsing clusters[0]: " + |
| 1550 | repr( clusters[ 0 ] ) ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1551 | clusterResults = main.FALSE |
| 1552 | if numClusters == 1: |
| 1553 | clusterResults = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1554 | utilities.assert_equals( |
| 1555 | expect=1, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1556 | actual=numClusters, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1557 | onpass="ONOS shows 1 SCC", |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1558 | onfail="ONOS shows " + str( numClusters ) + " SCCs" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1559 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1560 | main.step( "Comparing ONOS topology to MN" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1561 | devicesResults = main.TRUE |
| 1562 | portsResults = main.TRUE |
| 1563 | linksResults = main.TRUE |
| 1564 | for controller in range( numControllers ): |
| 1565 | controllerStr = str( controller + 1 ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1566 | if devices[ controller ] or "Error" not in devices[ controller ]: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1567 | currentDevicesResult = main.Mininet1.compareSwitches( |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1568 | MNTopo, |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1569 | json.loads( devices[ controller ] ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1570 | else: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1571 | currentDevicesResult = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1572 | utilities.assert_equals( expect=main.TRUE, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1573 | actual=currentDevicesResult, |
| 1574 | onpass="ONOS" + controllerStr + |
| 1575 | " Switches view is correct", |
| 1576 | onfail="ONOS" + controllerStr + |
| 1577 | " Switches view is incorrect" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1578 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1579 | if ports[ controller ] or "Error" not in ports[ controller ]: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1580 | currentPortsResult = main.Mininet1.comparePorts( |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1581 | MNTopo, |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1582 | json.loads( ports[ controller ] ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1583 | else: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1584 | currentPortsResult = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1585 | utilities.assert_equals( expect=main.TRUE, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1586 | actual=currentPortsResult, |
| 1587 | onpass="ONOS" + controllerStr + |
| 1588 | " ports view is correct", |
| 1589 | onfail="ONOS" + controllerStr + |
| 1590 | " ports view is incorrect" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1591 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1592 | if links[ controller ] or "Error" not in links[ controller ]: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1593 | currentLinksResult = main.Mininet1.compareLinks( |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1594 | MNTopo, |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1595 | json.loads( links[ controller ] ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1596 | else: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1597 | currentLinksResult = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1598 | utilities.assert_equals( expect=main.TRUE, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1599 | actual=currentLinksResult, |
| 1600 | onpass="ONOS" + controllerStr + |
| 1601 | " links view is correct", |
| 1602 | onfail="ONOS" + controllerStr + |
| 1603 | " links view is incorrect" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1604 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1605 | devicesResults = devicesResults and currentDevicesResult |
| 1606 | portsResults = portsResults and currentPortsResult |
| 1607 | linksResults = linksResults and currentLinksResult |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1608 | |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1609 | topoResult = ( devicesResults and portsResults and linksResults |
| 1610 | and consistentHostsResult and consistentClustersResult |
| 1611 | and clusterResults and ipResult ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1612 | utilities.assert_equals( expect=main.TRUE, actual=topoResult, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1613 | onpass="Topology Check Test successful", |
| 1614 | onfail="Topology Check Test NOT successful" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1615 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1616 | def CASE6( self, main ): |
| 1617 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1618 | The Failure case. |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1619 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1620 | import time |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1621 | assert numControllers, "numControllers not defined" |
| 1622 | assert main, "main not defined" |
| 1623 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
| 1624 | assert CLIs, "CLIs not defined" |
| 1625 | assert nodes, "nodes not defined" |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1626 | main.case( "Restart minority of ONOS nodes" ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 1627 | main.step( "Killing 3 ONOS nodes" ) |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 1628 | killTime = time.time() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 1629 | # TODO: Randomize these nodes or base this on partitions |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1630 | # TODO: use threads in this case |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 1631 | killResults = main.ONOSbench.onosKill( nodes[0].ip_address ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1632 | time.sleep( 10 ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 1633 | killResults = killResults and\ |
| 1634 | main.ONOSbench.onosKill( nodes[1].ip_address ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1635 | time.sleep( 10 ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 1636 | killResults = killResults and\ |
| 1637 | main.ONOSbench.onosKill( nodes[2].ip_address ) |
| 1638 | utilities.assert_equals( expect=main.TRUE, actual=killResults, |
| 1639 | onpass="ONOS Killed successfully", |
| 1640 | onfail="ONOS kill NOT successful" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1641 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1642 | main.step( "Checking if ONOS is up yet" ) |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 1643 | count = 0 |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1644 | onosIsupResult = main.FALSE |
| 1645 | while onosIsupResult == main.FALSE and count < 10: |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1646 | onos1Isup = main.ONOSbench.isup( nodes[0].ip_address ) |
| 1647 | onos2Isup = main.ONOSbench.isup( nodes[1].ip_address ) |
| 1648 | onos3Isup = main.ONOSbench.isup( nodes[2].ip_address ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1649 | onosIsupResult = onos1Isup and onos2Isup and onos3Isup |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 1650 | count = count + 1 |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1651 | # TODO: if it becomes an issue, we can retry this step a few times |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 1652 | utilities.assert_equals( expect=main.TRUE, actual=onosIsupResult, |
| 1653 | onpass="ONOS restarted successfully", |
| 1654 | onfail="ONOS restart NOT successful" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1655 | |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 1656 | main.step( "Restarting ONOS CLIs" ) |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1657 | cliResult1 = main.ONOScli1.startOnosCli( nodes[0].ip_address ) |
| 1658 | cliResult2 = main.ONOScli2.startOnosCli( nodes[1].ip_address ) |
| 1659 | cliResult3 = main.ONOScli3.startOnosCli( nodes[2].ip_address ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1660 | cliResults = cliResult1 and cliResult2 and cliResult3 |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 1661 | utilities.assert_equals( expect=main.TRUE, actual=cliResults, |
| 1662 | onpass="ONOS cli restarted", |
| 1663 | onfail="ONOS cli did not restart" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1664 | |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1665 | # Grab the time of restart so we chan check how long the gossip |
| 1666 | # protocol has had time to work |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 1667 | main.restartTime = time.time() - killTime |
| 1668 | main.log.debug( "Restart time: " + str( main.restartTime ) ) |
| 1669 | ''' |
| 1670 | # FIXME: revisit test plan for election with madan |
| 1671 | # Rerun for election on restarted nodes |
| 1672 | run1 = CLIs[0].electionTestRun() |
| 1673 | run2 = CLIs[1].electionTestRun() |
| 1674 | run3 = CLIs[2].electionTestRun() |
| 1675 | runResults = run1 and run2 and run3 |
| 1676 | utilities.assert_equals( expect=main.TRUE, actual=runResults, |
| 1677 | onpass="Reran for election", |
| 1678 | onfail="Failed to rerun for election" ) |
| 1679 | ''' |
| 1680 | # TODO: MAke this configurable. Also, we are breaking the above timer |
| 1681 | time.sleep( 60 ) |
| 1682 | main.log.debug( CLIs[0].nodes( jsonFormat=False ) ) |
| 1683 | main.log.debug( CLIs[0].leaders( jsonFormat=False ) ) |
| 1684 | main.log.debug( CLIs[0].partitions( jsonFormat=False ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1685 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1686 | def CASE7( self, main ): |
| 1687 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1688 | Check state after ONOS failure |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1689 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1690 | import json |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1691 | assert numControllers, "numControllers not defined" |
| 1692 | assert main, "main not defined" |
| 1693 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
| 1694 | assert CLIs, "CLIs not defined" |
| 1695 | assert nodes, "nodes not defined" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1696 | main.case( "Running ONOS Constant State Tests" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1697 | |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1698 | main.step( "Check that each switch has a master" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1699 | # Assert that each device has a master |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1700 | rolesNotNull = main.TRUE |
| 1701 | threads = [] |
| 1702 | for i in range( numControllers ): |
| 1703 | t = main.Thread( target=CLIs[i].rolesNotNull, |
| 1704 | name="rolesNotNull-" + str( i ), |
| 1705 | args=[ ] ) |
| 1706 | threads.append( t ) |
| 1707 | t.start() |
| 1708 | |
| 1709 | for t in threads: |
| 1710 | t.join() |
| 1711 | rolesNotNull = rolesNotNull and t.result |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1712 | utilities.assert_equals( |
| 1713 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1714 | actual=rolesNotNull, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1715 | onpass="Each device has a master", |
| 1716 | onfail="Some devices don't have a master assigned" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1717 | |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 1718 | main.step( "Read device roles from ONOS" ) |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1719 | ONOSMastership = [] |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1720 | consistentMastership = True |
| 1721 | rolesResults = True |
| 1722 | threads = [] |
| 1723 | for i in range( numControllers ): |
| 1724 | t = main.Thread( target=CLIs[i].roles, |
| 1725 | name="roles-" + str( i ), |
| 1726 | args=[] ) |
| 1727 | threads.append( t ) |
| 1728 | t.start() |
| 1729 | |
| 1730 | for t in threads: |
| 1731 | t.join() |
| 1732 | ONOSMastership.append( t.result ) |
| 1733 | |
| 1734 | for i in range( numControllers ): |
| 1735 | if not ONOSMastership[i] or "Error" in ONOSMastership[i]: |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 1736 | main.log.error( "Error in getting ONOS" + str( i + 1 ) + |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1737 | " roles" ) |
| 1738 | main.log.warn( |
| 1739 | "ONOS" + str( i + 1 ) + " mastership response: " + |
| 1740 | repr( ONOSMastership[i] ) ) |
| 1741 | rolesResults = False |
| 1742 | utilities.assert_equals( |
| 1743 | expect=True, |
| 1744 | actual=rolesResults, |
| 1745 | onpass="No error in reading roles output", |
| 1746 | onfail="Error in reading roles from ONOS" ) |
| 1747 | |
| 1748 | main.step( "Check for consistency in roles from each controller" ) |
| 1749 | if all([ i == ONOSMastership[ 0 ] for i in ONOSMastership ] ): |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 1750 | main.log.info( |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1751 | "Switch roles are consistent across all ONOS nodes" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1752 | else: |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1753 | consistentMastership = False |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1754 | utilities.assert_equals( |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1755 | expect=True, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1756 | actual=consistentMastership, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1757 | onpass="Switch roles are consistent across all ONOS nodes", |
| 1758 | onfail="ONOS nodes have different views of switch roles" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1759 | |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1760 | if rolesResults and not consistentMastership: |
| 1761 | for i in range( numControllers ): |
| 1762 | main.log.warn( |
| 1763 | "ONOS" + str( i + 1 ) + " roles: ", |
| 1764 | json.dumps( |
| 1765 | json.loads( ONOSMastership[ i ] ), |
| 1766 | sort_keys=True, |
| 1767 | indent=4, |
| 1768 | separators=( ',', ': ' ) ) ) |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1769 | |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 1770 | # NOTE: we expect mastership to change on controller failure |
| 1771 | ''' |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1772 | description2 = "Compare switch roles from before failure" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1773 | main.step( description2 ) |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1774 | try: |
| 1775 | currentJson = json.loads( ONOSMastership[0] ) |
| 1776 | oldJson = json.loads( mastershipState ) |
| 1777 | except ( ValueError, TypeError ): |
| 1778 | main.log.exception( "Something is wrong with parsing " + |
| 1779 | "ONOSMastership[0] or mastershipState" ) |
| 1780 | main.log.error( "ONOSMastership[0]: " + repr( ONOSMastership[0] ) ) |
| 1781 | main.log.error( "mastershipState" + repr( mastershipState ) ) |
| 1782 | main.cleanup() |
| 1783 | main.exit() |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1784 | mastershipCheck = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1785 | for i in range( 1, 29 ): |
| 1786 | switchDPID = str( |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1787 | main.Mininet1.getSwitchDPID( switch="s" + str( i ) ) ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1788 | current = [ switch[ 'master' ] for switch in currentJson |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1789 | if switchDPID in switch[ 'id' ] ] |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1790 | old = [ switch[ 'master' ] for switch in oldJson |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1791 | if switchDPID in switch[ 'id' ] ] |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1792 | if current == old: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1793 | mastershipCheck = mastershipCheck and main.TRUE |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1794 | else: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1795 | main.log.warn( "Mastership of switch %s changed" % switchDPID ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1796 | mastershipCheck = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1797 | utilities.assert_equals( |
| 1798 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1799 | actual=mastershipCheck, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1800 | onpass="Mastership of Switches was not changed", |
| 1801 | onfail="Mastership of some switches changed" ) |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 1802 | ''' |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1803 | |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1804 | main.step( "Get the intents and compare across all nodes" ) |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1805 | ONOSIntents = [] |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1806 | intentCheck = main.FALSE |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1807 | consistentIntents = True |
| 1808 | intentsResults = True |
| 1809 | threads = [] |
| 1810 | for i in range( numControllers ): |
| 1811 | t = main.Thread( target=CLIs[i].intents, |
| 1812 | name="intents-" + str( i ), |
| 1813 | args=[], |
| 1814 | kwargs={ 'jsonFormat': True } ) |
| 1815 | threads.append( t ) |
| 1816 | t.start() |
| 1817 | |
| 1818 | for t in threads: |
| 1819 | t.join() |
| 1820 | ONOSIntents.append( t.result ) |
| 1821 | |
| 1822 | for i in range( numControllers ): |
| 1823 | if not ONOSIntents[ i ] or "Error" in ONOSIntents[ i ]: |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 1824 | main.log.error( "Error in getting ONOS" + str( i + 1 ) + |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1825 | " intents" ) |
| 1826 | main.log.warn( "ONOS" + str( i + 1 ) + " intents response: " + |
| 1827 | repr( ONOSIntents[ i ] ) ) |
| 1828 | intentsResults = False |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1829 | utilities.assert_equals( |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1830 | expect=True, |
| 1831 | actual=intentsResults, |
| 1832 | onpass="No error in reading intents output", |
| 1833 | onfail="Error in reading intents from ONOS" ) |
| 1834 | |
| 1835 | main.step( "Check for consistency in Intents from each controller" ) |
| 1836 | if all([ sorted( i ) == sorted( ONOSIntents[ 0 ] ) for i in ONOSIntents ] ): |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 1837 | main.log.info( "Intents are consistent across all ONOS " + |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1838 | "nodes" ) |
| 1839 | else: |
| 1840 | consistentIntents = False |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 1841 | |
| 1842 | # Try to make it easy to figure out what is happening |
| 1843 | # |
| 1844 | # Intent ONOS1 ONOS2 ... |
| 1845 | # 0x01 INSTALLED INSTALLING |
| 1846 | # ... ... ... |
| 1847 | # ... ... ... |
| 1848 | title = " ID" |
| 1849 | for n in range( numControllers ): |
| 1850 | title += " " * 10 + "ONOS" + str( n + 1 ) |
| 1851 | main.log.warn( title ) |
| 1852 | # get all intent keys in the cluster |
| 1853 | keys = [] |
| 1854 | for nodeStr in ONOSIntents: |
| 1855 | node = json.loads( nodeStr ) |
| 1856 | for intent in node: |
| 1857 | keys.append( intent.get( 'id' ) ) |
| 1858 | keys = set( keys ) |
| 1859 | for key in keys: |
| 1860 | row = "%-13s" % key |
| 1861 | for nodeStr in ONOSIntents: |
| 1862 | node = json.loads( nodeStr ) |
| 1863 | for intent in node: |
| 1864 | if intent.get( 'id' ) == key: |
| 1865 | row += "%-15s" % intent.get( 'state' ) |
| 1866 | main.log.warn( row ) |
| 1867 | # End table view |
| 1868 | |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1869 | utilities.assert_equals( |
| 1870 | expect=True, |
| 1871 | actual=consistentIntents, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1872 | onpass="Intents are consistent across all ONOS nodes", |
| 1873 | onfail="ONOS nodes have different views of intents" ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1874 | intentStates = [] |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1875 | for node in ONOSIntents: # Iter through ONOS nodes |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1876 | nodeStates = [] |
| 1877 | # Iter through intents of a node |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1878 | try: |
| 1879 | for intent in json.loads( node ): |
| 1880 | nodeStates.append( intent[ 'state' ] ) |
| 1881 | except ( ValueError, TypeError ): |
| 1882 | main.log.exception( "Error in parsing intents" ) |
| 1883 | main.log.error( repr( node ) ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1884 | intentStates.append( nodeStates ) |
| 1885 | out = [ (i, nodeStates.count( i ) ) for i in set( nodeStates ) ] |
| 1886 | main.log.info( dict( out ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1887 | |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1888 | if intentsResults and not consistentIntents: |
| 1889 | for i in range( numControllers ): |
| 1890 | main.log.warn( "ONOS" + str( i + 1 ) + " intents: " ) |
| 1891 | main.log.warn( json.dumps( |
| 1892 | json.loads( ONOSIntents[ i ] ), |
| 1893 | sort_keys=True, |
| 1894 | indent=4, |
| 1895 | separators=( ',', ': ' ) ) ) |
| 1896 | elif intentsResults and consistentIntents: |
| 1897 | intentCheck = main.TRUE |
| 1898 | |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1899 | # NOTE: Store has no durability, so intents are lost across system |
| 1900 | # restarts |
| 1901 | main.step( "Compare current intents with intents before the failure" ) |
| 1902 | # NOTE: this requires case 5 to pass for intentState to be set. |
| 1903 | # maybe we should stop the test if that fails? |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 1904 | sameIntents = main.FALSE |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1905 | if intentState and intentState == ONOSIntents[ 0 ]: |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1906 | sameIntents = main.TRUE |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 1907 | main.log.info( "Intents are consistent with before failure" ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1908 | # TODO: possibly the states have changed? we may need to figure out |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1909 | # what the acceptable states are |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 1910 | elif len( intentState ) == len( ONOSIntents[ 0 ] ): |
| 1911 | sameIntents = main.TRUE |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1912 | try: |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 1913 | before = json.loads( intentState ) |
| 1914 | after = json.loads( ONOSIntents[ 0 ] ) |
| 1915 | for intent in before: |
| 1916 | if intent not in after: |
| 1917 | sameIntents = main.FALSE |
Jon Hall | c9eabec | 2015-06-10 14:33:14 -0700 | [diff] [blame] | 1918 | main.log.debug( "Intent is not currently in ONOS " + |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 1919 | "(at least in the same form):" ) |
| 1920 | main.log.debug( json.dumps( intent ) ) |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1921 | except ( ValueError, TypeError ): |
| 1922 | main.log.exception( "Exception printing intents" ) |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 1923 | main.log.debug( repr( ONOSIntents[0] ) ) |
| 1924 | main.log.debug( repr( intentState ) ) |
| 1925 | if sameIntents == main.FALSE: |
| 1926 | try: |
| 1927 | main.log.debug( "ONOS intents before: " ) |
| 1928 | main.log.debug( json.dumps( json.loads( intentState ), |
| 1929 | sort_keys=True, indent=4, |
| 1930 | separators=( ',', ': ' ) ) ) |
| 1931 | main.log.debug( "Current ONOS intents: " ) |
| 1932 | main.log.debug( json.dumps( json.loads( ONOSIntents[ 0 ] ), |
| 1933 | sort_keys=True, indent=4, |
| 1934 | separators=( ',', ': ' ) ) ) |
| 1935 | except ( ValueError, TypeError ): |
| 1936 | main.log.exception( "Exception printing intents" ) |
| 1937 | main.log.debug( repr( ONOSIntents[0] ) ) |
| 1938 | main.log.debug( repr( intentState ) ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1939 | utilities.assert_equals( |
| 1940 | expect=main.TRUE, |
| 1941 | actual=sameIntents, |
| 1942 | onpass="Intents are consistent with before failure", |
| 1943 | onfail="The Intents changed during failure" ) |
| 1944 | intentCheck = intentCheck and sameIntents |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1945 | |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1946 | main.step( "Get the OF Table entries and compare to before " + |
| 1947 | "component failure" ) |
| 1948 | FlowTables = main.TRUE |
| 1949 | flows2 = [] |
| 1950 | for i in range( 28 ): |
| 1951 | main.log.info( "Checking flow table on s" + str( i + 1 ) ) |
| 1952 | tmpFlows = main.Mininet2.getFlowTable( 1.3, "s" + str( i + 1 ) ) |
| 1953 | flows2.append( tmpFlows ) |
| 1954 | tempResult = main.Mininet2.flowComp( |
| 1955 | flow1=flows[ i ], |
| 1956 | flow2=tmpFlows ) |
| 1957 | FlowTables = FlowTables and tempResult |
| 1958 | if FlowTables == main.FALSE: |
| 1959 | main.log.info( "Differences in flow table for switch: s" + |
| 1960 | str( i + 1 ) ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1961 | utilities.assert_equals( |
| 1962 | expect=main.TRUE, |
| 1963 | actual=FlowTables, |
| 1964 | onpass="No changes were found in the flow tables", |
| 1965 | onfail="Changes were found in the flow tables" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1966 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1967 | main.step( "Check the continuous pings to ensure that no packets " + |
| 1968 | "were dropped during component failure" ) |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1969 | main.Mininet2.pingKill( main.params[ 'TESTONUSER' ], |
| 1970 | main.params[ 'TESTONIP' ] ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1971 | LossInPings = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1972 | # NOTE: checkForLoss returns main.FALSE with 0% packet loss |
| 1973 | for i in range( 8, 18 ): |
| 1974 | main.log.info( |
| 1975 | "Checking for a loss in pings along flow from s" + |
| 1976 | str( i ) ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1977 | LossInPings = main.Mininet2.checkForLoss( |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1978 | "/tmp/ping.h" + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1979 | str( i ) ) or LossInPings |
| 1980 | if LossInPings == main.TRUE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1981 | main.log.info( "Loss in ping detected" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1982 | elif LossInPings == main.ERROR: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1983 | main.log.info( "There are multiple mininet process running" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1984 | elif LossInPings == main.FALSE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1985 | main.log.info( "No Loss in the pings" ) |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 1986 | main.log.info( "No loss of dataplane connectivity" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1987 | utilities.assert_equals( |
| 1988 | expect=main.FALSE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1989 | actual=LossInPings, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1990 | onpass="No Loss of connectivity", |
| 1991 | onfail="Loss of dataplane connectivity detected" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1992 | |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 1993 | main.step( "Leadership Election is still functional" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1994 | # Test of LeadershipElection |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1995 | leaderList = [] |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 1996 | # FIXME: make sure this matches nodes that were restarted |
| 1997 | restarted = [ nodes[0].ip_address, nodes[1].ip_address, |
| 1998 | nodes[2].ip_address ] |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 1999 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2000 | leaderResult = main.TRUE |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 2001 | for cli in CLIs: |
| 2002 | leaderN = cli.electionTestLeader() |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2003 | leaderList.append( leaderN ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2004 | if leaderN == main.FALSE: |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 2005 | # error in response |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 2006 | main.log.error( "Something is wrong with " + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2007 | "electionTestLeader function, check the" + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2008 | " error logs" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2009 | leaderResult = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2010 | elif leaderN is None: |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 2011 | main.log.error( cli.name + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2012 | " shows no leader for the election-app was" + |
| 2013 | " elected after the old one died" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2014 | leaderResult = main.FALSE |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 2015 | elif leaderN in restarted: |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 2016 | main.log.error( cli.name + " shows " + str( leaderN ) + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2017 | " as leader for the election-app, but it " + |
| 2018 | "was restarted" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2019 | leaderResult = main.FALSE |
| 2020 | if len( set( leaderList ) ) != 1: |
| 2021 | leaderResult = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2022 | main.log.error( |
| 2023 | "Inconsistent view of leader for the election test app" ) |
| 2024 | # TODO: print the list |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2025 | utilities.assert_equals( |
| 2026 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2027 | actual=leaderResult, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2028 | onpass="Leadership election passed", |
| 2029 | onfail="Something went wrong with Leadership election" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2030 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2031 | def CASE8( self, main ): |
| 2032 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2033 | Compare topo |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2034 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2035 | import sys |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2036 | # FIXME add this path to params |
| 2037 | sys.path.append( "/home/admin/sts" ) |
| 2038 | # assumes that sts is already in you PYTHONPATH |
| 2039 | from sts.topology.teston_topology import TestONTopology |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2040 | import json |
| 2041 | import time |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 2042 | assert numControllers, "numControllers not defined" |
| 2043 | assert main, "main not defined" |
| 2044 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
| 2045 | assert CLIs, "CLIs not defined" |
| 2046 | assert nodes, "nodes not defined" |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2047 | |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 2048 | main.case( "Compare ONOS Topology view to Mininet topology" ) |
| 2049 | main.caseExplaination = "Compare topology objects between Mininet" +\ |
| 2050 | " and ONOS" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2051 | main.step( "Create TestONTopology object" ) |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 2052 | try: |
| 2053 | ctrls = [] |
| 2054 | for node in nodes: |
| 2055 | temp = ( node, node.name, node.ip_address, 6633 ) |
| 2056 | ctrls.append( temp ) |
| 2057 | MNTopo = TestONTopology( main.Mininet1, ctrls ) |
| 2058 | except Exception: |
| 2059 | objResult = main.FALSE |
| 2060 | else: |
| 2061 | objResult = main.TRUE |
| 2062 | utilities.assert_equals( expect=main.TRUE, actual=objResult, |
| 2063 | onpass="Created TestONTopology object", |
| 2064 | onfail="Exception while creating " + |
| 2065 | "TestONTopology object" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2066 | |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 2067 | main.step( "Comparing ONOS topology to MN" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2068 | devicesResults = main.TRUE |
| 2069 | portsResults = main.TRUE |
| 2070 | linksResults = main.TRUE |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 2071 | hostsResults = main.TRUE |
Jon Hall | c9eabec | 2015-06-10 14:33:14 -0700 | [diff] [blame] | 2072 | hostAttachmentResults = True |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2073 | topoResult = main.FALSE |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2074 | elapsed = 0 |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 2075 | count = 0 |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2076 | main.step( "Collecting topology information from ONOS" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2077 | startTime = time.time() |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 2078 | # Give time for Gossip to work |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2079 | while topoResult == main.FALSE and elapsed < 60: |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 2080 | count += 1 |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2081 | if count > 1: |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 2082 | # TODO: Deprecate STS usage |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 2083 | MNTopo = TestONTopology( main.Mininet1, ctrls ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2084 | cliStart = time.time() |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2085 | devices = [] |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 2086 | threads = [] |
| 2087 | for i in range( numControllers ): |
| 2088 | t = main.Thread( target=CLIs[i].devices, |
| 2089 | name="devices-" + str( i ), |
| 2090 | args=[ ] ) |
| 2091 | threads.append( t ) |
| 2092 | t.start() |
| 2093 | |
| 2094 | for t in threads: |
| 2095 | t.join() |
| 2096 | devices.append( t.result ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2097 | hosts = [] |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 2098 | ipResult = main.TRUE |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 2099 | threads = [] |
| 2100 | for i in range( numControllers ): |
| 2101 | t = main.Thread( target=CLIs[i].hosts, |
| 2102 | name="hosts-" + str( i ), |
| 2103 | args=[ ] ) |
| 2104 | threads.append( t ) |
| 2105 | t.start() |
| 2106 | |
| 2107 | for t in threads: |
| 2108 | t.join() |
| 2109 | try: |
| 2110 | hosts.append( json.loads( t.result ) ) |
| 2111 | except ( ValueError, TypeError ): |
| 2112 | main.log.exception( "Error parsing hosts results" ) |
| 2113 | main.log.error( repr( t.result ) ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2114 | for controller in range( 0, len( hosts ) ): |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2115 | controllerStr = str( controller + 1 ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2116 | for host in hosts[ controller ]: |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 2117 | if host is None or host.get( 'ipAddresses', [] ) == []: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2118 | main.log.error( |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 2119 | "DEBUG:Error with host ipAddresses on controller" + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2120 | controllerStr + ": " + str( host ) ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 2121 | ipResult = main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2122 | ports = [] |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 2123 | threads = [] |
| 2124 | for i in range( numControllers ): |
| 2125 | t = main.Thread( target=CLIs[i].ports, |
| 2126 | name="ports-" + str( i ), |
| 2127 | args=[ ] ) |
| 2128 | threads.append( t ) |
| 2129 | t.start() |
| 2130 | |
| 2131 | for t in threads: |
| 2132 | t.join() |
| 2133 | ports.append( t.result ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2134 | links = [] |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 2135 | threads = [] |
| 2136 | for i in range( numControllers ): |
| 2137 | t = main.Thread( target=CLIs[i].links, |
| 2138 | name="links-" + str( i ), |
| 2139 | args=[ ] ) |
| 2140 | threads.append( t ) |
| 2141 | t.start() |
| 2142 | |
| 2143 | for t in threads: |
| 2144 | t.join() |
| 2145 | links.append( t.result ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2146 | clusters = [] |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 2147 | threads = [] |
| 2148 | for i in range( numControllers ): |
| 2149 | t = main.Thread( target=CLIs[i].clusters, |
| 2150 | name="clusters-" + str( i ), |
| 2151 | args=[ ] ) |
| 2152 | threads.append( t ) |
| 2153 | t.start() |
| 2154 | |
| 2155 | for t in threads: |
| 2156 | t.join() |
| 2157 | clusters.append( t.result ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2158 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2159 | elapsed = time.time() - startTime |
| 2160 | cliTime = time.time() - cliStart |
Jon Hall | c9eabec | 2015-06-10 14:33:14 -0700 | [diff] [blame] | 2161 | print "Elapsed time: " + str( elapsed ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2162 | print "CLI time: " + str( cliTime ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2163 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2164 | for controller in range( numControllers ): |
| 2165 | controllerStr = str( controller + 1 ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2166 | if devices[ controller ] or "Error" not in devices[ |
| 2167 | controller ]: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2168 | currentDevicesResult = main.Mininet1.compareSwitches( |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2169 | MNTopo, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 2170 | json.loads( devices[ controller ] ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2171 | else: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2172 | currentDevicesResult = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2173 | utilities.assert_equals( expect=main.TRUE, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 2174 | actual=currentDevicesResult, |
| 2175 | onpass="ONOS" + controllerStr + |
| 2176 | " Switches view is correct", |
| 2177 | onfail="ONOS" + controllerStr + |
| 2178 | " Switches view is incorrect" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2179 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2180 | if ports[ controller ] or "Error" not in ports[ controller ]: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2181 | currentPortsResult = main.Mininet1.comparePorts( |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2182 | MNTopo, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 2183 | json.loads( ports[ controller ] ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2184 | else: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2185 | currentPortsResult = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2186 | utilities.assert_equals( expect=main.TRUE, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 2187 | actual=currentPortsResult, |
| 2188 | onpass="ONOS" + controllerStr + |
| 2189 | " ports view is correct", |
| 2190 | onfail="ONOS" + controllerStr + |
| 2191 | " ports view is incorrect" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2192 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2193 | if links[ controller ] or "Error" not in links[ controller ]: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2194 | currentLinksResult = main.Mininet1.compareLinks( |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2195 | MNTopo, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 2196 | json.loads( links[ controller ] ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2197 | else: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2198 | currentLinksResult = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2199 | utilities.assert_equals( expect=main.TRUE, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 2200 | actual=currentLinksResult, |
| 2201 | onpass="ONOS" + controllerStr + |
| 2202 | " links view is correct", |
| 2203 | onfail="ONOS" + controllerStr + |
| 2204 | " links view is incorrect" ) |
| 2205 | |
| 2206 | if hosts[ controller ] or "Error" not in hosts[ controller ]: |
| 2207 | currentHostsResult = main.Mininet1.compareHosts( |
| 2208 | MNTopo, hosts[ controller ] ) |
| 2209 | else: |
| 2210 | currentHostsResult = main.FALSE |
| 2211 | utilities.assert_equals( expect=main.TRUE, |
| 2212 | actual=currentHostsResult, |
| 2213 | onpass="ONOS" + controllerStr + |
| 2214 | " hosts exist in Mininet", |
| 2215 | onfail="ONOS" + controllerStr + |
| 2216 | " hosts don't match Mininet" ) |
Jon Hall | c9eabec | 2015-06-10 14:33:14 -0700 | [diff] [blame] | 2217 | # CHECKING HOST ATTACHMENT POINTS |
| 2218 | hostAttachment = True |
| 2219 | noHosts = False |
| 2220 | # FIXME: topo-HA/obelisk specific mappings: |
| 2221 | # key is mac and value is dpid |
| 2222 | mappings = {} |
| 2223 | for i in range( 1, 29 ): # hosts 1 through 28 |
| 2224 | # set up correct variables: |
| 2225 | macId = "00:" * 5 + hex( i ).split( "0x" )[1].upper().zfill(2) |
| 2226 | if i == 1: |
| 2227 | deviceId = "1000".zfill(16) |
| 2228 | elif i == 2: |
| 2229 | deviceId = "2000".zfill(16) |
| 2230 | elif i == 3: |
| 2231 | deviceId = "3000".zfill(16) |
| 2232 | elif i == 4: |
| 2233 | deviceId = "3004".zfill(16) |
| 2234 | elif i == 5: |
| 2235 | deviceId = "5000".zfill(16) |
| 2236 | elif i == 6: |
| 2237 | deviceId = "6000".zfill(16) |
| 2238 | elif i == 7: |
| 2239 | deviceId = "6007".zfill(16) |
| 2240 | elif i >= 8 and i <= 17: |
| 2241 | dpid = '3' + str( i ).zfill( 3 ) |
| 2242 | deviceId = dpid.zfill(16) |
| 2243 | elif i >= 18 and i <= 27: |
| 2244 | dpid = '6' + str( i ).zfill( 3 ) |
| 2245 | deviceId = dpid.zfill(16) |
| 2246 | elif i == 28: |
| 2247 | deviceId = "2800".zfill(16) |
| 2248 | mappings[ macId ] = deviceId |
| 2249 | if hosts[ controller ] or "Error" not in hosts[ controller ]: |
| 2250 | if hosts[ controller ] == []: |
| 2251 | main.log.warn( "There are no hosts discovered" ) |
| 2252 | noHosts = True |
| 2253 | else: |
| 2254 | for host in hosts[ controller ]: |
| 2255 | mac = None |
| 2256 | location = None |
| 2257 | device = None |
| 2258 | port = None |
| 2259 | try: |
| 2260 | mac = host.get( 'mac' ) |
| 2261 | assert mac, "mac field could not be found for this host object" |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 2262 | |
Jon Hall | c9eabec | 2015-06-10 14:33:14 -0700 | [diff] [blame] | 2263 | location = host.get( 'location' ) |
| 2264 | assert location, "location field could not be found for this host object" |
| 2265 | |
| 2266 | # Trim the protocol identifier off deviceId |
| 2267 | device = str( location.get( 'elementId' ) ).split(':')[1] |
| 2268 | assert device, "elementId field could not be found for this host location object" |
| 2269 | |
| 2270 | port = location.get( 'port' ) |
| 2271 | assert port, "port field could not be found for this host location object" |
| 2272 | |
| 2273 | # Now check if this matches where they should be |
| 2274 | if mac and device and port: |
| 2275 | if str( port ) != "1": |
| 2276 | main.log.error( "The attachment port is incorrect for " + |
| 2277 | "host " + str( mac ) + |
| 2278 | ". Expected: 1 Actual: " + str( port) ) |
| 2279 | hostAttachment = False |
| 2280 | if device != mappings[ str( mac ) ]: |
| 2281 | main.log.error( "The attachment device is incorrect for " + |
| 2282 | "host " + str( mac ) + |
| 2283 | ". Expected: " + mappings[ str( mac ) ] + |
| 2284 | " Actual: " + device ) |
| 2285 | hostAttachment = False |
| 2286 | else: |
| 2287 | hostAttachment = False |
| 2288 | except AssertionError: |
| 2289 | main.log.exception( "Json object not as expected" ) |
| 2290 | main.log.error( repr( host ) ) |
| 2291 | hostAttachment = False |
| 2292 | else: |
| 2293 | main.log.error( "No hosts json output or \"Error\"" + |
| 2294 | " in output. hosts = " + |
| 2295 | repr( hosts[ controller ] ) ) |
| 2296 | if noHosts is False: |
| 2297 | hostAttachment = True |
| 2298 | |
| 2299 | # END CHECKING HOST ATTACHMENT POINTS |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 2300 | devicesResults = devicesResults and currentDevicesResult |
| 2301 | portsResults = portsResults and currentPortsResult |
| 2302 | linksResults = linksResults and currentLinksResult |
| 2303 | hostsResults = hostsResults and currentHostsResult |
Jon Hall | c9eabec | 2015-06-10 14:33:14 -0700 | [diff] [blame] | 2304 | hostAttachmentResults = hostAttachmentResults and hostAttachment |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2305 | |
Jon Hall | c9eabec | 2015-06-10 14:33:14 -0700 | [diff] [blame] | 2306 | # Compare json objects for hosts and dataplane clusters |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2307 | |
Jon Hall | c9eabec | 2015-06-10 14:33:14 -0700 | [diff] [blame] | 2308 | # hosts |
| 2309 | main.step( "Hosts view is consistent across all ONOS nodes" ) |
| 2310 | consistentHostsResult = main.TRUE |
| 2311 | for controller in range( len( hosts ) ): |
| 2312 | controllerStr = str( controller + 1 ) |
| 2313 | if "Error" not in hosts[ controller ]: |
| 2314 | if hosts[ controller ] == hosts[ 0 ]: |
| 2315 | continue |
| 2316 | else: # hosts not consistent |
| 2317 | main.log.error( "hosts from ONOS" + controllerStr + |
| 2318 | " is inconsistent with ONOS1" ) |
| 2319 | main.log.warn( repr( hosts[ controller ] ) ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2320 | consistentHostsResult = main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2321 | |
Jon Hall | c9eabec | 2015-06-10 14:33:14 -0700 | [diff] [blame] | 2322 | else: |
| 2323 | main.log.error( "Error in getting ONOS hosts from ONOS" + |
| 2324 | controllerStr ) |
| 2325 | consistentHostsResult = main.FALSE |
| 2326 | main.log.warn( "ONOS" + controllerStr + |
| 2327 | " hosts response: " + |
| 2328 | repr( hosts[ controller ] ) ) |
| 2329 | utilities.assert_equals( |
| 2330 | expect=main.TRUE, |
| 2331 | actual=consistentHostsResult, |
| 2332 | onpass="Hosts view is consistent across all ONOS nodes", |
| 2333 | onfail="ONOS nodes have different views of hosts" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2334 | |
Jon Hall | c9eabec | 2015-06-10 14:33:14 -0700 | [diff] [blame] | 2335 | main.step( "Hosts information is correct" ) |
| 2336 | hostsResults = hostsResults and ipResult |
| 2337 | utilities.assert_equals( |
| 2338 | expect=main.TRUE, |
| 2339 | actual=hostsResults, |
| 2340 | onpass="Host information is correct", |
| 2341 | onfail="Host information is incorrect" ) |
| 2342 | |
| 2343 | main.step( "Host attachment points to the network" ) |
| 2344 | utilities.assert_equals( |
| 2345 | expect=True, |
| 2346 | actual=hostAttachmentResults, |
| 2347 | onpass="Hosts are correctly attached to the network", |
| 2348 | onfail="ONOS did not correctly attach hosts to the network" ) |
| 2349 | |
| 2350 | # Strongly connected clusters of devices |
| 2351 | main.step( "Clusters view is consistent across all ONOS nodes" ) |
| 2352 | consistentClustersResult = main.TRUE |
| 2353 | for controller in range( len( clusters ) ): |
| 2354 | controllerStr = str( controller + 1 ) |
| 2355 | if "Error" not in clusters[ controller ]: |
| 2356 | if clusters[ controller ] == clusters[ 0 ]: |
| 2357 | continue |
| 2358 | else: # clusters not consistent |
| 2359 | main.log.error( "clusters from ONOS" + |
| 2360 | controllerStr + |
| 2361 | " is inconsistent with ONOS1" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2362 | consistentClustersResult = main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2363 | |
Jon Hall | c9eabec | 2015-06-10 14:33:14 -0700 | [diff] [blame] | 2364 | else: |
| 2365 | main.log.error( "Error in getting dataplane clusters " + |
| 2366 | "from ONOS" + controllerStr ) |
| 2367 | consistentClustersResult = main.FALSE |
| 2368 | main.log.warn( "ONOS" + controllerStr + |
| 2369 | " clusters response: " + |
| 2370 | repr( clusters[ controller ] ) ) |
| 2371 | utilities.assert_equals( |
| 2372 | expect=main.TRUE, |
| 2373 | actual=consistentClustersResult, |
| 2374 | onpass="Clusters view is consistent across all ONOS nodes", |
| 2375 | onfail="ONOS nodes have different views of clusters" ) |
| 2376 | |
| 2377 | main.step( "There is only one SCC" ) |
| 2378 | # there should always only be one cluster |
| 2379 | try: |
| 2380 | numClusters = len( json.loads( clusters[ 0 ] ) ) |
| 2381 | except ( ValueError, TypeError ): |
| 2382 | main.log.exception( "Error parsing clusters[0]: " + |
| 2383 | repr( clusters[0] ) ) |
| 2384 | clusterResults = main.FALSE |
| 2385 | if numClusters == 1: |
| 2386 | clusterResults = main.TRUE |
| 2387 | utilities.assert_equals( |
| 2388 | expect=1, |
| 2389 | actual=numClusters, |
| 2390 | onpass="ONOS shows 1 SCC", |
| 2391 | onfail="ONOS shows " + str( numClusters ) + " SCCs" ) |
| 2392 | |
| 2393 | topoResult = ( devicesResults and portsResults and linksResults |
| 2394 | and hostsResults and consistentHostsResult |
| 2395 | and consistentClustersResult and clusterResults |
| 2396 | and ipResult and hostAttachmentResults ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2397 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2398 | topoResult = topoResult and int( count <= 2 ) |
| 2399 | note = "note it takes about " + str( int( cliTime ) ) + \ |
| 2400 | " seconds for the test to make all the cli calls to fetch " +\ |
| 2401 | "the topology from each ONOS instance" |
Jon Hall | 1b8f54a | 2015-02-04 13:24:20 -0800 | [diff] [blame] | 2402 | main.log.info( |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2403 | "Very crass estimate for topology discovery/convergence( " + |
| 2404 | str( note ) + " ): " + str( elapsed ) + " seconds, " + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2405 | str( count ) + " tries" ) |
Jon Hall | c9eabec | 2015-06-10 14:33:14 -0700 | [diff] [blame] | 2406 | |
| 2407 | main.step( "Device information is correct" ) |
| 2408 | utilities.assert_equals( |
| 2409 | expect=main.TRUE, |
| 2410 | actual=devicesResults, |
| 2411 | onpass="Device information is correct", |
| 2412 | onfail="Device information is incorrect" ) |
| 2413 | |
| 2414 | main.step( "Port information is correct" ) |
| 2415 | utilities.assert_equals( |
| 2416 | expect=main.TRUE, |
| 2417 | actual=portsResults, |
| 2418 | onpass="Port information is correct", |
| 2419 | onfail="Port information is incorrect" ) |
| 2420 | |
| 2421 | main.step( "Links are correct" ) |
| 2422 | utilities.assert_equals( |
| 2423 | expect=main.TRUE, |
| 2424 | actual=linksResults, |
| 2425 | onpass="Link are correct", |
| 2426 | onfail="Links are incorrect" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2427 | |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 2428 | # FIXME: move this to an ONOS state case |
| 2429 | main.step( "Checking ONOS nodes" ) |
| 2430 | nodesOutput = [] |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 2431 | nodeResults = main.TRUE |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 2432 | threads = [] |
| 2433 | for i in range( numControllers ): |
| 2434 | t = main.Thread( target=CLIs[i].nodes, |
| 2435 | name="nodes-" + str( i ), |
| 2436 | args=[ ] ) |
| 2437 | threads.append( t ) |
| 2438 | t.start() |
| 2439 | |
| 2440 | for t in threads: |
| 2441 | t.join() |
| 2442 | nodesOutput.append( t.result ) |
| 2443 | ips = [ node.ip_address for node in nodes ] |
| 2444 | for i in nodesOutput: |
| 2445 | try: |
| 2446 | current = json.loads( i ) |
| 2447 | for node in current: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 2448 | currentResult = main.FALSE |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 2449 | if node['ip'] in ips: # node in nodes() output is in cell |
| 2450 | if node['state'] == 'ACTIVE': |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 2451 | currentResult = main.TRUE |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 2452 | else: |
| 2453 | main.log.error( "Error in ONOS node availability" ) |
| 2454 | main.log.error( |
| 2455 | json.dumps( current, |
| 2456 | sort_keys=True, |
| 2457 | indent=4, |
| 2458 | separators=( ',', ': ' ) ) ) |
| 2459 | break |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 2460 | nodeResults = nodeResults and currentResult |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 2461 | except ( ValueError, TypeError ): |
| 2462 | main.log.error( "Error parsing nodes output" ) |
| 2463 | main.log.warn( repr( i ) ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 2464 | utilities.assert_equals( expect=main.TRUE, actual=nodeResults, |
| 2465 | onpass="Nodes check successful", |
| 2466 | onfail="Nodes check NOT successful" ) |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 2467 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2468 | def CASE9( self, main ): |
| 2469 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2470 | Link s3-s28 down |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2471 | """ |
| 2472 | import time |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 2473 | assert numControllers, "numControllers not defined" |
| 2474 | assert main, "main not defined" |
| 2475 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
| 2476 | assert CLIs, "CLIs not defined" |
| 2477 | assert nodes, "nodes not defined" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2478 | # NOTE: You should probably run a topology check after this |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2479 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2480 | linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2481 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2482 | description = "Turn off a link to ensure that Link Discovery " +\ |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 2483 | "is working properly" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2484 | main.case( description ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2485 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2486 | main.step( "Kill Link between s3 and s28" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2487 | LinkDown = main.Mininet1.link( END1="s3", END2="s28", OPTION="down" ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 2488 | main.log.info( "Waiting " + str( linkSleep ) + |
| 2489 | " seconds for link down to be discovered" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2490 | time.sleep( linkSleep ) |
| 2491 | utilities.assert_equals( expect=main.TRUE, actual=LinkDown, |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 2492 | onpass="Link down successful", |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 2493 | onfail="Failed to bring link down" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2494 | # TODO do some sort of check here |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2495 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2496 | def CASE10( self, main ): |
| 2497 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2498 | Link s3-s28 up |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2499 | """ |
| 2500 | import time |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 2501 | assert numControllers, "numControllers not defined" |
| 2502 | assert main, "main not defined" |
| 2503 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
| 2504 | assert CLIs, "CLIs not defined" |
| 2505 | assert nodes, "nodes not defined" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2506 | # NOTE: You should probably run a topology check after this |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2507 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2508 | linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2509 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2510 | description = "Restore a link to ensure that Link Discovery is " + \ |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 2511 | "working properly" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2512 | main.case( description ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2513 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2514 | main.step( "Bring link between s3 and s28 back up" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2515 | LinkUp = main.Mininet1.link( END1="s3", END2="s28", OPTION="up" ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 2516 | main.log.info( "Waiting " + str( linkSleep ) + |
| 2517 | " seconds for link up to be discovered" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2518 | time.sleep( linkSleep ) |
| 2519 | utilities.assert_equals( expect=main.TRUE, actual=LinkUp, |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 2520 | onpass="Link up successful", |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 2521 | onfail="Failed to bring link up" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2522 | # TODO do some sort of check here |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2523 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2524 | def CASE11( self, main ): |
| 2525 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2526 | Switch Down |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2527 | """ |
| 2528 | # NOTE: You should probably run a topology check after this |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2529 | import time |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 2530 | assert numControllers, "numControllers not defined" |
| 2531 | assert main, "main not defined" |
| 2532 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
| 2533 | assert CLIs, "CLIs not defined" |
| 2534 | assert nodes, "nodes not defined" |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2535 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2536 | switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2537 | |
| 2538 | description = "Killing a switch to ensure it is discovered correctly" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2539 | main.case( description ) |
| 2540 | switch = main.params[ 'kill' ][ 'switch' ] |
| 2541 | switchDPID = main.params[ 'kill' ][ 'dpid' ] |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2542 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2543 | # TODO: Make this switch parameterizable |
| 2544 | main.step( "Kill " + switch ) |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 2545 | main.log.info( "Deleting " + switch ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2546 | main.Mininet1.delSwitch( switch ) |
| 2547 | main.log.info( "Waiting " + str( switchSleep ) + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2548 | " seconds for switch down to be discovered" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2549 | time.sleep( switchSleep ) |
| 2550 | device = main.ONOScli1.getDevice( dpid=switchDPID ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2551 | # Peek at the deleted switch |
| 2552 | main.log.warn( str( device ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2553 | result = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2554 | if device and device[ 'available' ] is False: |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2555 | result = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2556 | utilities.assert_equals( expect=main.TRUE, actual=result, |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 2557 | onpass="Kill switch successful", |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 2558 | onfail="Failed to kill switch?" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2559 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2560 | def CASE12( self, main ): |
| 2561 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2562 | Switch Up |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2563 | """ |
| 2564 | # NOTE: You should probably run a topology check after this |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2565 | import time |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 2566 | assert numControllers, "numControllers not defined" |
| 2567 | assert main, "main not defined" |
| 2568 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
| 2569 | assert CLIs, "CLIs not defined" |
| 2570 | assert nodes, "nodes not defined" |
| 2571 | assert ONOS1Port, "ONOS1Port not defined" |
| 2572 | assert ONOS2Port, "ONOS2Port not defined" |
| 2573 | assert ONOS3Port, "ONOS3Port not defined" |
| 2574 | assert ONOS4Port, "ONOS4Port not defined" |
| 2575 | assert ONOS5Port, "ONOS5Port not defined" |
| 2576 | assert ONOS6Port, "ONOS6Port not defined" |
| 2577 | assert ONOS7Port, "ONOS7Port not defined" |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2578 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2579 | switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2580 | switch = main.params[ 'kill' ][ 'switch' ] |
| 2581 | switchDPID = main.params[ 'kill' ][ 'dpid' ] |
| 2582 | links = main.params[ 'kill' ][ 'links' ].split() |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2583 | description = "Adding a switch to ensure it is discovered correctly" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2584 | main.case( description ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2585 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2586 | main.step( "Add back " + switch ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2587 | main.Mininet1.addSwitch( switch, dpid=switchDPID ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2588 | for peer in links: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2589 | main.Mininet1.addLink( switch, peer ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 2590 | main.Mininet1.assignSwController( sw=switch.split( 's' )[ 1 ], |
| 2591 | count=numControllers, |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 2592 | ip1=nodes[ 0 ].ip_address, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 2593 | port1=ONOS1Port, |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 2594 | ip2=nodes[ 1 ].ip_address, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 2595 | port2=ONOS2Port, |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 2596 | ip3=nodes[ 2 ].ip_address, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 2597 | port3=ONOS3Port, |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 2598 | ip4=nodes[ 3 ].ip_address, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 2599 | port4=ONOS4Port, |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 2600 | ip5=nodes[ 4 ].ip_address, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 2601 | port5=ONOS5Port, |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 2602 | ip6=nodes[ 5 ].ip_address, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 2603 | port6=ONOS6Port, |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 2604 | ip7=nodes[ 6 ].ip_address, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 2605 | port7=ONOS7Port ) |
| 2606 | main.log.info( "Waiting " + str( switchSleep ) + |
| 2607 | " seconds for switch up to be discovered" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2608 | time.sleep( switchSleep ) |
| 2609 | device = main.ONOScli1.getDevice( dpid=switchDPID ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2610 | # Peek at the deleted switch |
| 2611 | main.log.warn( str( device ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2612 | result = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2613 | if device and device[ 'available' ]: |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2614 | result = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2615 | utilities.assert_equals( expect=main.TRUE, actual=result, |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 2616 | onpass="add switch successful", |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 2617 | onfail="Failed to add switch?" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2618 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2619 | def CASE13( self, main ): |
| 2620 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2621 | Clean up |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2622 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2623 | import os |
| 2624 | import time |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 2625 | assert numControllers, "numControllers not defined" |
| 2626 | assert main, "main not defined" |
| 2627 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
| 2628 | assert CLIs, "CLIs not defined" |
| 2629 | assert nodes, "nodes not defined" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2630 | |
| 2631 | # printing colors to terminal |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 2632 | colors = { 'cyan': '\033[96m', 'purple': '\033[95m', |
| 2633 | 'blue': '\033[94m', 'green': '\033[92m', |
| 2634 | 'yellow': '\033[93m', 'red': '\033[91m', 'end': '\033[0m' } |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 2635 | main.case( "Test Cleanup" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2636 | main.step( "Killing tcpdumps" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2637 | main.Mininet2.stopTcpdump() |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2638 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2639 | main.step( "Copying MN pcap and ONOS log files to test station" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2640 | testname = main.TEST |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2641 | teststationUser = main.params[ 'TESTONUSER' ] |
| 2642 | teststationIP = main.params[ 'TESTONIP' ] |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2643 | # NOTE: MN Pcap file is being saved to ~/packet_captures |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2644 | # 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] | 2645 | # FIXME: scp |
| 2646 | # mn files |
| 2647 | # TODO: Load these from params |
| 2648 | # NOTE: must end in / |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2649 | logFolder = "/opt/onos/log/" |
| 2650 | logFiles = [ "karaf.log", "karaf.log.1" ] |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2651 | # NOTE: must end in / |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2652 | dstDir = "~/packet_captures/" |
| 2653 | for f in logFiles: |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 2654 | for node in nodes: |
| 2655 | main.ONOSbench.handle.sendline( "scp sdn@" + node.ip_address + |
| 2656 | ":" + logFolder + f + " " + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2657 | teststationUser + "@" + |
| 2658 | teststationIP + ":" + |
| 2659 | dstDir + str( testname ) + |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 2660 | "-" + node.name + "-" + f ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 2661 | main.ONOSbench.handle.expect( "\$" ) |
| 2662 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2663 | # std*.log's |
| 2664 | # NOTE: must end in / |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2665 | logFolder = "/opt/onos/var/" |
| 2666 | logFiles = [ "stderr.log", "stdout.log" ] |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2667 | # NOTE: must end in / |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2668 | dstDir = "~/packet_captures/" |
| 2669 | for f in logFiles: |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 2670 | for node in nodes: |
| 2671 | main.ONOSbench.handle.sendline( "scp sdn@" + node.ip_address + |
| 2672 | ":" + logFolder + f + " " + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2673 | teststationUser + "@" + |
| 2674 | teststationIP + ":" + |
| 2675 | dstDir + str( testname ) + |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 2676 | "-" + node.name + "-" + f ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 2677 | main.ONOSbench.handle.expect( "\$" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2678 | # sleep so scp can finish |
| 2679 | time.sleep( 10 ) |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 2680 | |
| 2681 | main.step( "Stopping Mininet" ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 2682 | mnResult = main.Mininet1.stopNet() |
| 2683 | utilities.assert_equals( expect=main.TRUE, actual=mnResult, |
| 2684 | onpass="Mininet stopped", |
| 2685 | onfail="MN cleanup NOT successful" ) |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 2686 | |
| 2687 | main.step( "Checking ONOS Logs for errors" ) |
| 2688 | for node in nodes: |
| 2689 | print colors[ 'purple' ] + "Checking logs for errors on " + \ |
| 2690 | node.name + ":" + colors[ 'end' ] |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 2691 | print main.ONOSbench.checkLogs( node.ip_address, restart=True ) |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 2692 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2693 | main.step( "Packing and rotating pcap archives" ) |
| 2694 | os.system( "~/TestON/dependencies/rotate.sh " + str( testname ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2695 | |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 2696 | try: |
| 2697 | timerLog = open( main.logdir + "/Timers.csv", 'w') |
| 2698 | # Overwrite with empty line and close |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 2699 | labels = "Gossip Intents, Restart" |
| 2700 | data = str( gossipTime ) + ", " + str( main.restartTime ) |
| 2701 | timerLog.write( labels + "\n" + data ) |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 2702 | timerLog.close() |
| 2703 | except NameError, e: |
| 2704 | main.log.exception(e) |
| 2705 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2706 | def CASE14( self, main ): |
| 2707 | """ |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2708 | start election app on all onos nodes |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2709 | """ |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 2710 | assert numControllers, "numControllers not defined" |
| 2711 | assert main, "main not defined" |
| 2712 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
| 2713 | assert CLIs, "CLIs not defined" |
| 2714 | assert nodes, "nodes not defined" |
| 2715 | |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 2716 | main.case("Start Leadership Election app") |
| 2717 | main.step( "Install leadership election app" ) |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 2718 | appResult = main.ONOScli1.activateApp( "org.onosproject.election" ) |
| 2719 | utilities.assert_equals( |
| 2720 | expect=main.TRUE, |
| 2721 | actual=appResult, |
| 2722 | onpass="Election app installed", |
| 2723 | onfail="Something went wrong with installing Leadership election" ) |
| 2724 | |
| 2725 | main.step( "Run for election on each node" ) |
| 2726 | leaderResult = main.TRUE |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 2727 | leaders = [] |
| 2728 | for cli in CLIs: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 2729 | cli.electionTestRun() |
| 2730 | for cli in CLIs: |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 2731 | leader = cli.electionTestLeader() |
| 2732 | if leader is None or leader == main.FALSE: |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 2733 | main.log.error( cli.name + ": Leader for the election app " + |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 2734 | "should be an ONOS node, instead got '" + |
| 2735 | str( leader ) + "'" ) |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 2736 | leaderResult = main.FALSE |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 2737 | leaders.append( leader ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2738 | utilities.assert_equals( |
| 2739 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2740 | actual=leaderResult, |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 2741 | onpass="Successfully ran for leadership", |
| 2742 | onfail="Failed to run for leadership" ) |
| 2743 | |
| 2744 | main.step( "Check that each node shows the same leader" ) |
| 2745 | sameLeader = main.TRUE |
| 2746 | if len( set( leaders ) ) != 1: |
| 2747 | sameLeader = main.FALSE |
| 2748 | main.log.error( "Results of electionTestLeader is order of CLIs:" + |
| 2749 | str( leaders ) ) |
| 2750 | utilities.assert_equals( |
| 2751 | expect=main.TRUE, |
| 2752 | actual=sameLeader, |
| 2753 | onpass="Leadership is consistent for the election topic", |
| 2754 | onfail="Nodes have different leaders" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2755 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2756 | def CASE15( self, main ): |
| 2757 | """ |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2758 | Check that Leadership Election is still functional |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2759 | """ |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 2760 | import time |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 2761 | assert numControllers, "numControllers not defined" |
| 2762 | assert main, "main not defined" |
| 2763 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
| 2764 | assert CLIs, "CLIs not defined" |
| 2765 | assert nodes, "nodes not defined" |
| 2766 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2767 | leaderResult = main.TRUE |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2768 | description = "Check that Leadership Election is still functional" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2769 | main.case( description ) |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 2770 | |
| 2771 | main.step( "Check that each node shows the same leader" ) |
| 2772 | sameLeader = main.TRUE |
| 2773 | leaders = [] |
| 2774 | for cli in CLIs: |
| 2775 | leader = cli.electionTestLeader() |
| 2776 | leaders.append( leader ) |
| 2777 | if len( set( leaders ) ) != 1: |
| 2778 | sameLeader = main.FALSE |
| 2779 | main.log.error( "Results of electionTestLeader is order of CLIs:" + |
| 2780 | str( leaders ) ) |
| 2781 | utilities.assert_equals( |
| 2782 | expect=main.TRUE, |
| 2783 | actual=sameLeader, |
| 2784 | onpass="Leadership is consistent for the election topic", |
| 2785 | onfail="Nodes have different leaders" ) |
| 2786 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2787 | main.step( "Find current leader and withdraw" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2788 | leader = main.ONOScli1.electionTestLeader() |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 2789 | # do some sanity checking on leader before using it |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2790 | withdrawResult = main.FALSE |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 2791 | if leader is None or leader == main.FALSE: |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 2792 | main.log.error( |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2793 | "Leader for the election app should be an ONOS node," + |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 2794 | "instead got '" + str( leader ) + "'" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2795 | leaderResult = main.FALSE |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 2796 | oldLeader = None |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 2797 | for i in range( len( CLIs ) ): |
| 2798 | if leader == nodes[ i ].ip_address: |
| 2799 | oldLeader = CLIs[ i ] |
| 2800 | break |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 2801 | else: # FOR/ELSE statement |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 2802 | main.log.error( "Leader election, could not find current leader" ) |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 2803 | if oldLeader: |
| 2804 | withdrawResult = oldLeader.electionTestWithdraw() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2805 | utilities.assert_equals( |
| 2806 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2807 | actual=withdrawResult, |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 2808 | onpass="Node was withdrawn from election", |
| 2809 | onfail="Node was not withdrawn from election" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2810 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2811 | main.step( "Make sure new leader is elected" ) |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 2812 | # FIXME: use threads |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2813 | leaderList = [] |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 2814 | for cli in CLIs: |
| 2815 | leaderN = cli.electionTestLeader() |
| 2816 | leaderList.append( leaderN ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2817 | if leaderN == leader: |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 2818 | main.log.error( cli.name + " still sees " + str( leader ) + |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 2819 | " as leader after they withdrew" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2820 | leaderResult = main.FALSE |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2821 | elif leaderN == main.FALSE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2822 | # error in response |
| 2823 | # TODO: add check for "Command not found:" in the driver, this |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 2824 | # means the app isn't loaded |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 2825 | main.log.error( "Something is wrong with " + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2826 | "electionTestLeader function, " + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2827 | "check the error logs" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2828 | leaderResult = main.FALSE |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 2829 | elif leaderN is None: |
| 2830 | # node may not have recieved the event yet |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 2831 | time.sleep(7) |
Jon Hall | a9d26da | 2015-03-30 16:45:32 -0700 | [diff] [blame] | 2832 | leaderN = cli.electionTestLeader() |
| 2833 | leaderList.pop() |
| 2834 | leaderList.append( leaderN ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2835 | consistentLeader = main.FALSE |
| 2836 | if len( set( leaderList ) ) == 1: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2837 | main.log.info( "Each Election-app sees '" + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2838 | str( leaderList[ 0 ] ) + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2839 | "' as the leader" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2840 | consistentLeader = main.TRUE |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2841 | else: |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 2842 | main.log.error( |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2843 | "Inconsistent responses for leader of Election-app:" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2844 | for n in range( len( leaderList ) ): |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 2845 | main.log.error( "ONOS" + str( n + 1 ) + " response: " + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2846 | str( leaderList[ n ] ) ) |
Jon Hall | 5cfd23c | 2015-03-19 11:40:57 -0700 | [diff] [blame] | 2847 | leaderResult = leaderResult and consistentLeader |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2848 | utilities.assert_equals( |
| 2849 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2850 | actual=leaderResult, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2851 | onpass="Leadership election passed", |
| 2852 | onfail="Something went wrong with Leadership election" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2853 | |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 2854 | main.step( "Run for election on old leader( just so everyone " + |
| 2855 | "is in the hat )" ) |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 2856 | if oldLeader: |
| 2857 | runResult = oldLeader.electionTestRun() |
| 2858 | else: |
| 2859 | runResult = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2860 | utilities.assert_equals( |
| 2861 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2862 | actual=runResult, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2863 | onpass="App re-ran for election", |
| 2864 | onfail="App failed to run for election" ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 2865 | |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 2866 | main.step( "Leader did not change when old leader re-ran" ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 2867 | afterRun = main.ONOScli1.electionTestLeader() |
| 2868 | # verify leader didn't just change |
| 2869 | if afterRun == leaderList[ 0 ]: |
| 2870 | afterResult = main.TRUE |
| 2871 | else: |
| 2872 | afterResult = main.FALSE |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2873 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2874 | utilities.assert_equals( |
| 2875 | expect=main.TRUE, |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 2876 | actual=afterResult, |
| 2877 | onpass="Old leader successfully re-ran for election", |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2878 | onfail="Something went wrong with Leadership election after " + |
| 2879 | "the old leader re-ran for election" ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 2880 | |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 2881 | def CASE16( self, main ): |
| 2882 | """ |
| 2883 | Install Distributed Primitives app |
| 2884 | """ |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 2885 | import time |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 2886 | assert numControllers, "numControllers not defined" |
| 2887 | assert main, "main not defined" |
| 2888 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
| 2889 | assert CLIs, "CLIs not defined" |
| 2890 | assert nodes, "nodes not defined" |
| 2891 | |
| 2892 | # Variables for the distributed primitives tests |
| 2893 | global pCounterName |
| 2894 | global iCounterName |
| 2895 | global pCounterValue |
| 2896 | global iCounterValue |
| 2897 | global onosSet |
| 2898 | global onosSetName |
| 2899 | pCounterName = "TestON-Partitions" |
| 2900 | iCounterName = "TestON-inMemory" |
| 2901 | pCounterValue = 0 |
| 2902 | iCounterValue = 0 |
| 2903 | onosSet = set([]) |
| 2904 | onosSetName = "TestON-set" |
| 2905 | |
| 2906 | description = "Install Primitives app" |
| 2907 | main.case( description ) |
| 2908 | main.step( "Install Primitives app" ) |
| 2909 | appName = "org.onosproject.distributedprimitives" |
| 2910 | appResults = CLIs[0].activateApp( appName ) |
| 2911 | utilities.assert_equals( expect=main.TRUE, |
| 2912 | actual=appResults, |
| 2913 | onpass="Primitives app activated", |
| 2914 | onfail="Primitives app not activated" ) |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 2915 | time.sleep( 5 ) # To allow all nodes to activate |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 2916 | |
| 2917 | def CASE17( self, main ): |
| 2918 | """ |
| 2919 | Check for basic functionality with distributed primitives |
| 2920 | """ |
Jon Hall | c9eabec | 2015-06-10 14:33:14 -0700 | [diff] [blame] | 2921 | import json |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 2922 | # Make sure variables are defined/set |
| 2923 | assert numControllers, "numControllers not defined" |
| 2924 | assert main, "main not defined" |
| 2925 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
| 2926 | assert CLIs, "CLIs not defined" |
| 2927 | assert nodes, "nodes not defined" |
| 2928 | assert pCounterName, "pCounterName not defined" |
| 2929 | assert iCounterName, "iCounterName not defined" |
| 2930 | assert onosSetName, "onosSetName not defined" |
| 2931 | # NOTE: assert fails if value is 0/None/Empty/False |
| 2932 | try: |
| 2933 | pCounterValue |
| 2934 | except NameError: |
| 2935 | main.log.error( "pCounterValue not defined, setting to 0" ) |
| 2936 | pCounterValue = 0 |
| 2937 | try: |
| 2938 | iCounterValue |
| 2939 | except NameError: |
| 2940 | main.log.error( "iCounterValue not defined, setting to 0" ) |
| 2941 | iCounterValue = 0 |
| 2942 | try: |
| 2943 | onosSet |
| 2944 | except NameError: |
| 2945 | main.log.error( "onosSet not defined, setting to empty Set" ) |
| 2946 | onosSet = set([]) |
| 2947 | # Variables for the distributed primitives tests. These are local only |
| 2948 | addValue = "a" |
| 2949 | addAllValue = "a b c d e f" |
| 2950 | retainValue = "c d e f" |
| 2951 | |
| 2952 | description = "Check for basic functionality with distributed " +\ |
| 2953 | "primitives" |
| 2954 | main.case( description ) |
| 2955 | main.caseExplaination = "Test the methods of the distributed primitives (counters and sets) throught the cli" |
| 2956 | # DISTRIBUTED ATOMIC COUNTERS |
| 2957 | main.step( "Increment and get a default counter on each node" ) |
| 2958 | pCounters = [] |
| 2959 | threads = [] |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 2960 | addedPValues = [] |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 2961 | for i in range( numControllers ): |
| 2962 | t = main.Thread( target=CLIs[i].counterTestIncrement, |
| 2963 | name="counterIncrement-" + str( i ), |
| 2964 | args=[ pCounterName ] ) |
| 2965 | pCounterValue += 1 |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 2966 | addedPValues.append( pCounterValue ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 2967 | threads.append( t ) |
| 2968 | t.start() |
| 2969 | |
| 2970 | for t in threads: |
| 2971 | t.join() |
| 2972 | pCounters.append( t.result ) |
| 2973 | # Check that counter incremented numController times |
| 2974 | pCounterResults = True |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 2975 | for i in addedPValues: |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 2976 | tmpResult = i in pCounters |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 2977 | pCounterResults = pCounterResults and tmpResult |
| 2978 | if not tmpResult: |
| 2979 | main.log.error( str( i ) + " is not in partitioned " |
| 2980 | "counter incremented results" ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 2981 | utilities.assert_equals( expect=True, |
| 2982 | actual=pCounterResults, |
| 2983 | onpass="Default counter incremented", |
| 2984 | onfail="Error incrementing default" + |
| 2985 | " counter" ) |
| 2986 | |
| 2987 | main.step( "Increment and get an in memory counter on each node" ) |
| 2988 | iCounters = [] |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 2989 | addedIValues = [] |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 2990 | threads = [] |
| 2991 | for i in range( numControllers ): |
| 2992 | t = main.Thread( target=CLIs[i].counterTestIncrement, |
| 2993 | name="icounterIncrement-" + str( i ), |
| 2994 | args=[ iCounterName ], |
| 2995 | kwargs={ "inMemory": True } ) |
| 2996 | iCounterValue += 1 |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 2997 | addedIValues.append( iCounterValue ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 2998 | threads.append( t ) |
| 2999 | t.start() |
| 3000 | |
| 3001 | for t in threads: |
| 3002 | t.join() |
| 3003 | iCounters.append( t.result ) |
| 3004 | # Check that counter incremented numController times |
| 3005 | iCounterResults = True |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 3006 | for i in addedIValues: |
| 3007 | tmpResult = i in iCounters |
| 3008 | iCounterResults = iCounterResults and tmpResult |
| 3009 | if not tmpResult: |
| 3010 | main.log.error( str( i ) + " is not in the in-memory " |
| 3011 | "counter incremented results" ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3012 | utilities.assert_equals( expect=True, |
| 3013 | actual=iCounterResults, |
| 3014 | onpass="In memory counter incremented", |
| 3015 | onfail="Error incrementing in memory" + |
| 3016 | " counter" ) |
| 3017 | |
| 3018 | main.step( "Check counters are consistant across nodes" ) |
| 3019 | onosCounters = [] |
| 3020 | threads = [] |
| 3021 | for i in range( numControllers ): |
| 3022 | t = main.Thread( target=CLIs[i].counters, |
| 3023 | name="counters-" + str( i ) ) |
| 3024 | threads.append( t ) |
| 3025 | t.start() |
| 3026 | for t in threads: |
| 3027 | t.join() |
| 3028 | onosCounters.append( t.result ) |
| 3029 | tmp = [ i == onosCounters[ 0 ] for i in onosCounters ] |
| 3030 | if all( tmp ): |
| 3031 | main.log.info( "Counters are consistent across all nodes" ) |
| 3032 | consistentCounterResults = main.TRUE |
| 3033 | else: |
| 3034 | main.log.error( "Counters are not consistent across all nodes" ) |
| 3035 | consistentCounterResults = main.FALSE |
| 3036 | utilities.assert_equals( expect=main.TRUE, |
| 3037 | actual=consistentCounterResults, |
| 3038 | onpass="ONOS counters are consistent " + |
| 3039 | "across nodes", |
| 3040 | onfail="ONOS Counters are inconsistent " + |
| 3041 | "across nodes" ) |
| 3042 | |
| 3043 | main.step( "Counters we added have the correct values" ) |
| 3044 | correctResults = main.TRUE |
| 3045 | for i in range( numControllers ): |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 3046 | current = json.loads( onosCounters[i] ) |
| 3047 | pValue = None |
| 3048 | iValue = None |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3049 | try: |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 3050 | for database in current: |
| 3051 | partitioned = database.get( 'partitionedDatabaseCounters' ) |
| 3052 | if partitioned: |
| 3053 | for value in partitioned: |
| 3054 | if value.get( 'name' ) == pCounterName: |
| 3055 | pValue = value.get( 'value' ) |
| 3056 | break |
| 3057 | inMemory = database.get( 'inMemoryDatabaseCounters' ) |
| 3058 | if inMemory: |
| 3059 | for value in inMemory: |
| 3060 | if value.get( 'name' ) == iCounterName: |
| 3061 | iValue = value.get( 'value' ) |
| 3062 | break |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3063 | except AttributeError, e: |
| 3064 | main.log.error( "ONOS" + str( i + 1 ) + " counters result " + |
| 3065 | "is not as expected" ) |
| 3066 | correctResults = main.FALSE |
Jon Hall | 40d2cbd | 2015-06-03 16:24:29 -0700 | [diff] [blame] | 3067 | if pValue == pCounterValue: |
| 3068 | main.log.info( "Partitioned counter value is correct" ) |
| 3069 | else: |
| 3070 | main.log.error( "Partitioned counter value is incorrect," + |
| 3071 | " expected value: " + str( pCounterValue ) |
| 3072 | + " current value: " + str( pValue ) ) |
| 3073 | correctResults = main.FALSE |
| 3074 | if iValue == iCounterValue: |
| 3075 | main.log.info( "In memory counter value is correct" ) |
| 3076 | else: |
| 3077 | main.log.error( "In memory counter value is incorrect, " + |
| 3078 | "expected value: " + str( iCounterValue ) + |
| 3079 | " current value: " + str( iValue ) ) |
| 3080 | correctResults = main.FALSE |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3081 | utilities.assert_equals( expect=main.TRUE, |
| 3082 | actual=correctResults, |
| 3083 | onpass="Added counters are correct", |
| 3084 | onfail="Added counters are incorrect" ) |
| 3085 | # DISTRIBUTED SETS |
| 3086 | main.step( "Distributed Set get" ) |
| 3087 | size = len( onosSet ) |
| 3088 | getResponses = [] |
| 3089 | threads = [] |
| 3090 | for i in range( numControllers ): |
| 3091 | t = main.Thread( target=CLIs[i].setTestGet, |
| 3092 | name="setTestGet-" + str( i ), |
| 3093 | args=[ onosSetName ] ) |
| 3094 | threads.append( t ) |
| 3095 | t.start() |
| 3096 | for t in threads: |
| 3097 | t.join() |
| 3098 | getResponses.append( t.result ) |
| 3099 | |
| 3100 | getResults = main.TRUE |
| 3101 | for i in range( numControllers ): |
| 3102 | if isinstance( getResponses[ i ], list): |
| 3103 | current = set( getResponses[ i ] ) |
| 3104 | if len( current ) == len( getResponses[ i ] ): |
| 3105 | # no repeats |
| 3106 | if onosSet != current: |
| 3107 | main.log.error( "ONOS" + str( i + 1 ) + |
| 3108 | " has incorrect view" + |
| 3109 | " of set " + onosSetName + ":\n" + |
| 3110 | str( getResponses[ i ] ) ) |
| 3111 | main.log.debug( "Expected: " + str( onosSet ) ) |
| 3112 | main.log.debug( "Actual: " + str( current ) ) |
| 3113 | getResults = main.FALSE |
| 3114 | else: |
| 3115 | # error, set is not a set |
| 3116 | main.log.error( "ONOS" + str( i + 1 ) + |
| 3117 | " has repeat elements in" + |
| 3118 | " set " + onosSetName + ":\n" + |
| 3119 | str( getResponses[ i ] ) ) |
| 3120 | getResults = main.FALSE |
| 3121 | elif getResponses[ i ] == main.ERROR: |
| 3122 | getResults = main.FALSE |
| 3123 | utilities.assert_equals( expect=main.TRUE, |
| 3124 | actual=getResults, |
| 3125 | onpass="Set elements are correct", |
| 3126 | onfail="Set elements are incorrect" ) |
| 3127 | |
| 3128 | main.step( "Distributed Set size" ) |
| 3129 | sizeResponses = [] |
| 3130 | threads = [] |
| 3131 | for i in range( numControllers ): |
| 3132 | t = main.Thread( target=CLIs[i].setTestSize, |
| 3133 | name="setTestSize-" + str( i ), |
| 3134 | args=[ onosSetName ] ) |
| 3135 | threads.append( t ) |
| 3136 | t.start() |
| 3137 | for t in threads: |
| 3138 | t.join() |
| 3139 | sizeResponses.append( t.result ) |
| 3140 | |
| 3141 | sizeResults = main.TRUE |
| 3142 | for i in range( numControllers ): |
| 3143 | if size != sizeResponses[ i ]: |
| 3144 | sizeResults = main.FALSE |
| 3145 | main.log.error( "ONOS" + str( i + 1 ) + |
| 3146 | " expected a size of " + str( size ) + |
| 3147 | " for set " + onosSetName + |
| 3148 | " but got " + str( sizeResponses[ i ] ) ) |
| 3149 | utilities.assert_equals( expect=main.TRUE, |
| 3150 | actual=sizeResults, |
| 3151 | onpass="Set sizes are correct", |
| 3152 | onfail="Set sizes are incorrect" ) |
| 3153 | |
| 3154 | main.step( "Distributed Set add()" ) |
| 3155 | onosSet.add( addValue ) |
| 3156 | addResponses = [] |
| 3157 | threads = [] |
| 3158 | for i in range( numControllers ): |
| 3159 | t = main.Thread( target=CLIs[i].setTestAdd, |
| 3160 | name="setTestAdd-" + str( i ), |
| 3161 | args=[ onosSetName, addValue ] ) |
| 3162 | threads.append( t ) |
| 3163 | t.start() |
| 3164 | for t in threads: |
| 3165 | t.join() |
| 3166 | addResponses.append( t.result ) |
| 3167 | |
| 3168 | # main.TRUE = successfully changed the set |
| 3169 | # main.FALSE = action resulted in no change in set |
| 3170 | # main.ERROR - Some error in executing the function |
| 3171 | addResults = main.TRUE |
| 3172 | for i in range( numControllers ): |
| 3173 | if addResponses[ i ] == main.TRUE: |
| 3174 | # All is well |
| 3175 | pass |
| 3176 | elif addResponses[ i ] == main.FALSE: |
| 3177 | # Already in set, probably fine |
| 3178 | pass |
| 3179 | elif addResponses[ i ] == main.ERROR: |
| 3180 | # Error in execution |
| 3181 | addResults = main.FALSE |
| 3182 | else: |
| 3183 | # unexpected result |
| 3184 | addResults = main.FALSE |
| 3185 | if addResults != main.TRUE: |
| 3186 | main.log.error( "Error executing set add" ) |
| 3187 | |
| 3188 | # Check if set is still correct |
| 3189 | size = len( onosSet ) |
| 3190 | getResponses = [] |
| 3191 | threads = [] |
| 3192 | for i in range( numControllers ): |
| 3193 | t = main.Thread( target=CLIs[i].setTestGet, |
| 3194 | name="setTestGet-" + str( i ), |
| 3195 | args=[ onosSetName ] ) |
| 3196 | threads.append( t ) |
| 3197 | t.start() |
| 3198 | for t in threads: |
| 3199 | t.join() |
| 3200 | getResponses.append( t.result ) |
| 3201 | getResults = main.TRUE |
| 3202 | for i in range( numControllers ): |
| 3203 | if isinstance( getResponses[ i ], list): |
| 3204 | current = set( getResponses[ i ] ) |
| 3205 | if len( current ) == len( getResponses[ i ] ): |
| 3206 | # no repeats |
| 3207 | if onosSet != current: |
| 3208 | main.log.error( "ONOS" + str( i + 1 ) + |
| 3209 | " has incorrect view" + |
| 3210 | " of set " + onosSetName + ":\n" + |
| 3211 | str( getResponses[ i ] ) ) |
| 3212 | main.log.debug( "Expected: " + str( onosSet ) ) |
| 3213 | main.log.debug( "Actual: " + str( current ) ) |
| 3214 | getResults = main.FALSE |
| 3215 | else: |
| 3216 | # error, set is not a set |
| 3217 | main.log.error( "ONOS" + str( i + 1 ) + |
| 3218 | " has repeat elements in" + |
| 3219 | " set " + onosSetName + ":\n" + |
| 3220 | str( getResponses[ i ] ) ) |
| 3221 | getResults = main.FALSE |
| 3222 | elif getResponses[ i ] == main.ERROR: |
| 3223 | getResults = main.FALSE |
| 3224 | sizeResponses = [] |
| 3225 | threads = [] |
| 3226 | for i in range( numControllers ): |
| 3227 | t = main.Thread( target=CLIs[i].setTestSize, |
| 3228 | name="setTestSize-" + str( i ), |
| 3229 | args=[ onosSetName ] ) |
| 3230 | threads.append( t ) |
| 3231 | t.start() |
| 3232 | for t in threads: |
| 3233 | t.join() |
| 3234 | sizeResponses.append( t.result ) |
| 3235 | sizeResults = main.TRUE |
| 3236 | for i in range( numControllers ): |
| 3237 | if size != sizeResponses[ i ]: |
| 3238 | sizeResults = main.FALSE |
| 3239 | main.log.error( "ONOS" + str( i + 1 ) + |
| 3240 | " expected a size of " + str( size ) + |
| 3241 | " for set " + onosSetName + |
| 3242 | " but got " + str( sizeResponses[ i ] ) ) |
| 3243 | addResults = addResults and getResults and sizeResults |
| 3244 | utilities.assert_equals( expect=main.TRUE, |
| 3245 | actual=addResults, |
| 3246 | onpass="Set add correct", |
| 3247 | onfail="Set add was incorrect" ) |
| 3248 | |
| 3249 | main.step( "Distributed Set addAll()" ) |
| 3250 | onosSet.update( addAllValue.split() ) |
| 3251 | addResponses = [] |
| 3252 | threads = [] |
| 3253 | for i in range( numControllers ): |
| 3254 | t = main.Thread( target=CLIs[i].setTestAdd, |
| 3255 | name="setTestAddAll-" + str( i ), |
| 3256 | args=[ onosSetName, addAllValue ] ) |
| 3257 | threads.append( t ) |
| 3258 | t.start() |
| 3259 | for t in threads: |
| 3260 | t.join() |
| 3261 | addResponses.append( t.result ) |
| 3262 | |
| 3263 | # main.TRUE = successfully changed the set |
| 3264 | # main.FALSE = action resulted in no change in set |
| 3265 | # main.ERROR - Some error in executing the function |
| 3266 | addAllResults = main.TRUE |
| 3267 | for i in range( numControllers ): |
| 3268 | if addResponses[ i ] == main.TRUE: |
| 3269 | # All is well |
| 3270 | pass |
| 3271 | elif addResponses[ i ] == main.FALSE: |
| 3272 | # Already in set, probably fine |
| 3273 | pass |
| 3274 | elif addResponses[ i ] == main.ERROR: |
| 3275 | # Error in execution |
| 3276 | addAllResults = main.FALSE |
| 3277 | else: |
| 3278 | # unexpected result |
| 3279 | addAllResults = main.FALSE |
| 3280 | if addAllResults != main.TRUE: |
| 3281 | main.log.error( "Error executing set addAll" ) |
| 3282 | |
| 3283 | # Check if set is still correct |
| 3284 | size = len( onosSet ) |
| 3285 | getResponses = [] |
| 3286 | threads = [] |
| 3287 | for i in range( numControllers ): |
| 3288 | t = main.Thread( target=CLIs[i].setTestGet, |
| 3289 | name="setTestGet-" + str( i ), |
| 3290 | args=[ onosSetName ] ) |
| 3291 | threads.append( t ) |
| 3292 | t.start() |
| 3293 | for t in threads: |
| 3294 | t.join() |
| 3295 | getResponses.append( t.result ) |
| 3296 | getResults = main.TRUE |
| 3297 | for i in range( numControllers ): |
| 3298 | if isinstance( getResponses[ i ], list): |
| 3299 | current = set( getResponses[ i ] ) |
| 3300 | if len( current ) == len( getResponses[ i ] ): |
| 3301 | # no repeats |
| 3302 | if onosSet != current: |
| 3303 | main.log.error( "ONOS" + str( i + 1 ) + |
| 3304 | " has incorrect view" + |
| 3305 | " of set " + onosSetName + ":\n" + |
| 3306 | str( getResponses[ i ] ) ) |
| 3307 | main.log.debug( "Expected: " + str( onosSet ) ) |
| 3308 | main.log.debug( "Actual: " + str( current ) ) |
| 3309 | getResults = main.FALSE |
| 3310 | else: |
| 3311 | # error, set is not a set |
| 3312 | main.log.error( "ONOS" + str( i + 1 ) + |
| 3313 | " has repeat elements in" + |
| 3314 | " set " + onosSetName + ":\n" + |
| 3315 | str( getResponses[ i ] ) ) |
| 3316 | getResults = main.FALSE |
| 3317 | elif getResponses[ i ] == main.ERROR: |
| 3318 | getResults = main.FALSE |
| 3319 | sizeResponses = [] |
| 3320 | threads = [] |
| 3321 | for i in range( numControllers ): |
| 3322 | t = main.Thread( target=CLIs[i].setTestSize, |
| 3323 | name="setTestSize-" + str( i ), |
| 3324 | args=[ onosSetName ] ) |
| 3325 | threads.append( t ) |
| 3326 | t.start() |
| 3327 | for t in threads: |
| 3328 | t.join() |
| 3329 | sizeResponses.append( t.result ) |
| 3330 | sizeResults = main.TRUE |
| 3331 | for i in range( numControllers ): |
| 3332 | if size != sizeResponses[ i ]: |
| 3333 | sizeResults = main.FALSE |
| 3334 | main.log.error( "ONOS" + str( i + 1 ) + |
| 3335 | " expected a size of " + str( size ) + |
| 3336 | " for set " + onosSetName + |
| 3337 | " but got " + str( sizeResponses[ i ] ) ) |
| 3338 | addAllResults = addAllResults and getResults and sizeResults |
| 3339 | utilities.assert_equals( expect=main.TRUE, |
| 3340 | actual=addAllResults, |
| 3341 | onpass="Set addAll correct", |
| 3342 | onfail="Set addAll was incorrect" ) |
| 3343 | |
| 3344 | main.step( "Distributed Set contains()" ) |
| 3345 | containsResponses = [] |
| 3346 | threads = [] |
| 3347 | for i in range( numControllers ): |
| 3348 | t = main.Thread( target=CLIs[i].setTestGet, |
| 3349 | name="setContains-" + str( i ), |
| 3350 | args=[ onosSetName ], |
| 3351 | kwargs={ "values": addValue } ) |
| 3352 | threads.append( t ) |
| 3353 | t.start() |
| 3354 | for t in threads: |
| 3355 | t.join() |
| 3356 | # NOTE: This is the tuple |
| 3357 | containsResponses.append( t.result ) |
| 3358 | |
| 3359 | containsResults = main.TRUE |
| 3360 | for i in range( numControllers ): |
| 3361 | if containsResponses[ i ] == main.ERROR: |
| 3362 | containsResults = main.FALSE |
| 3363 | else: |
| 3364 | containsResults = containsResults and\ |
| 3365 | containsResponses[ i ][ 1 ] |
| 3366 | utilities.assert_equals( expect=main.TRUE, |
| 3367 | actual=containsResults, |
| 3368 | onpass="Set contains is functional", |
| 3369 | onfail="Set contains failed" ) |
| 3370 | |
| 3371 | main.step( "Distributed Set containsAll()" ) |
| 3372 | containsAllResponses = [] |
| 3373 | threads = [] |
| 3374 | for i in range( numControllers ): |
| 3375 | t = main.Thread( target=CLIs[i].setTestGet, |
| 3376 | name="setContainsAll-" + str( i ), |
| 3377 | args=[ onosSetName ], |
| 3378 | kwargs={ "values": addAllValue } ) |
| 3379 | threads.append( t ) |
| 3380 | t.start() |
| 3381 | for t in threads: |
| 3382 | t.join() |
| 3383 | # NOTE: This is the tuple |
| 3384 | containsAllResponses.append( t.result ) |
| 3385 | |
| 3386 | containsAllResults = main.TRUE |
| 3387 | for i in range( numControllers ): |
| 3388 | if containsResponses[ i ] == main.ERROR: |
| 3389 | containsResults = main.FALSE |
| 3390 | else: |
| 3391 | containsResults = containsResults and\ |
| 3392 | containsResponses[ i ][ 1 ] |
| 3393 | utilities.assert_equals( expect=main.TRUE, |
| 3394 | actual=containsAllResults, |
| 3395 | onpass="Set containsAll is functional", |
| 3396 | onfail="Set containsAll failed" ) |
| 3397 | |
| 3398 | main.step( "Distributed Set remove()" ) |
| 3399 | onosSet.remove( addValue ) |
| 3400 | removeResponses = [] |
| 3401 | threads = [] |
| 3402 | for i in range( numControllers ): |
| 3403 | t = main.Thread( target=CLIs[i].setTestRemove, |
| 3404 | name="setTestRemove-" + str( i ), |
| 3405 | args=[ onosSetName, addValue ] ) |
| 3406 | threads.append( t ) |
| 3407 | t.start() |
| 3408 | for t in threads: |
| 3409 | t.join() |
| 3410 | removeResponses.append( t.result ) |
| 3411 | |
| 3412 | # main.TRUE = successfully changed the set |
| 3413 | # main.FALSE = action resulted in no change in set |
| 3414 | # main.ERROR - Some error in executing the function |
| 3415 | removeResults = main.TRUE |
| 3416 | for i in range( numControllers ): |
| 3417 | if removeResponses[ i ] == main.TRUE: |
| 3418 | # All is well |
| 3419 | pass |
| 3420 | elif removeResponses[ i ] == main.FALSE: |
| 3421 | # not in set, probably fine |
| 3422 | pass |
| 3423 | elif removeResponses[ i ] == main.ERROR: |
| 3424 | # Error in execution |
| 3425 | removeResults = main.FALSE |
| 3426 | else: |
| 3427 | # unexpected result |
| 3428 | removeResults = main.FALSE |
| 3429 | if removeResults != main.TRUE: |
| 3430 | main.log.error( "Error executing set remove" ) |
| 3431 | |
| 3432 | # Check if set is still correct |
| 3433 | size = len( onosSet ) |
| 3434 | getResponses = [] |
| 3435 | threads = [] |
| 3436 | for i in range( numControllers ): |
| 3437 | t = main.Thread( target=CLIs[i].setTestGet, |
| 3438 | name="setTestGet-" + str( i ), |
| 3439 | args=[ onosSetName ] ) |
| 3440 | threads.append( t ) |
| 3441 | t.start() |
| 3442 | for t in threads: |
| 3443 | t.join() |
| 3444 | getResponses.append( t.result ) |
| 3445 | getResults = main.TRUE |
| 3446 | for i in range( numControllers ): |
| 3447 | if isinstance( getResponses[ i ], list): |
| 3448 | current = set( getResponses[ i ] ) |
| 3449 | if len( current ) == len( getResponses[ i ] ): |
| 3450 | # no repeats |
| 3451 | if onosSet != current: |
| 3452 | main.log.error( "ONOS" + str( i + 1 ) + |
| 3453 | " has incorrect view" + |
| 3454 | " of set " + onosSetName + ":\n" + |
| 3455 | str( getResponses[ i ] ) ) |
| 3456 | main.log.debug( "Expected: " + str( onosSet ) ) |
| 3457 | main.log.debug( "Actual: " + str( current ) ) |
| 3458 | getResults = main.FALSE |
| 3459 | else: |
| 3460 | # error, set is not a set |
| 3461 | main.log.error( "ONOS" + str( i + 1 ) + |
| 3462 | " has repeat elements in" + |
| 3463 | " set " + onosSetName + ":\n" + |
| 3464 | str( getResponses[ i ] ) ) |
| 3465 | getResults = main.FALSE |
| 3466 | elif getResponses[ i ] == main.ERROR: |
| 3467 | getResults = main.FALSE |
| 3468 | sizeResponses = [] |
| 3469 | threads = [] |
| 3470 | for i in range( numControllers ): |
| 3471 | t = main.Thread( target=CLIs[i].setTestSize, |
| 3472 | name="setTestSize-" + str( i ), |
| 3473 | args=[ onosSetName ] ) |
| 3474 | threads.append( t ) |
| 3475 | t.start() |
| 3476 | for t in threads: |
| 3477 | t.join() |
| 3478 | sizeResponses.append( t.result ) |
| 3479 | sizeResults = main.TRUE |
| 3480 | for i in range( numControllers ): |
| 3481 | if size != sizeResponses[ i ]: |
| 3482 | sizeResults = main.FALSE |
| 3483 | main.log.error( "ONOS" + str( i + 1 ) + |
| 3484 | " expected a size of " + str( size ) + |
| 3485 | " for set " + onosSetName + |
| 3486 | " but got " + str( sizeResponses[ i ] ) ) |
| 3487 | removeResults = removeResults and getResults and sizeResults |
| 3488 | utilities.assert_equals( expect=main.TRUE, |
| 3489 | actual=removeResults, |
| 3490 | onpass="Set remove correct", |
| 3491 | onfail="Set remove was incorrect" ) |
| 3492 | |
| 3493 | main.step( "Distributed Set removeAll()" ) |
| 3494 | onosSet.difference_update( addAllValue.split() ) |
| 3495 | removeAllResponses = [] |
| 3496 | threads = [] |
| 3497 | try: |
| 3498 | for i in range( numControllers ): |
| 3499 | t = main.Thread( target=CLIs[i].setTestRemove, |
| 3500 | name="setTestRemoveAll-" + str( i ), |
| 3501 | args=[ onosSetName, addAllValue ] ) |
| 3502 | threads.append( t ) |
| 3503 | t.start() |
| 3504 | for t in threads: |
| 3505 | t.join() |
| 3506 | removeAllResponses.append( t.result ) |
| 3507 | except Exception, e: |
| 3508 | main.log.exception(e) |
| 3509 | |
| 3510 | # main.TRUE = successfully changed the set |
| 3511 | # main.FALSE = action resulted in no change in set |
| 3512 | # main.ERROR - Some error in executing the function |
| 3513 | removeAllResults = main.TRUE |
| 3514 | for i in range( numControllers ): |
| 3515 | if removeAllResponses[ i ] == main.TRUE: |
| 3516 | # All is well |
| 3517 | pass |
| 3518 | elif removeAllResponses[ i ] == main.FALSE: |
| 3519 | # not in set, probably fine |
| 3520 | pass |
| 3521 | elif removeAllResponses[ i ] == main.ERROR: |
| 3522 | # Error in execution |
| 3523 | removeAllResults = main.FALSE |
| 3524 | else: |
| 3525 | # unexpected result |
| 3526 | removeAllResults = main.FALSE |
| 3527 | if removeAllResults != main.TRUE: |
| 3528 | main.log.error( "Error executing set removeAll" ) |
| 3529 | |
| 3530 | # Check if set is still correct |
| 3531 | size = len( onosSet ) |
| 3532 | getResponses = [] |
| 3533 | threads = [] |
| 3534 | for i in range( numControllers ): |
| 3535 | t = main.Thread( target=CLIs[i].setTestGet, |
| 3536 | name="setTestGet-" + str( i ), |
| 3537 | args=[ onosSetName ] ) |
| 3538 | threads.append( t ) |
| 3539 | t.start() |
| 3540 | for t in threads: |
| 3541 | t.join() |
| 3542 | getResponses.append( t.result ) |
| 3543 | getResults = main.TRUE |
| 3544 | for i in range( numControllers ): |
| 3545 | if isinstance( getResponses[ i ], list): |
| 3546 | current = set( getResponses[ i ] ) |
| 3547 | if len( current ) == len( getResponses[ i ] ): |
| 3548 | # no repeats |
| 3549 | if onosSet != current: |
| 3550 | main.log.error( "ONOS" + str( i + 1 ) + |
| 3551 | " has incorrect view" + |
| 3552 | " of set " + onosSetName + ":\n" + |
| 3553 | str( getResponses[ i ] ) ) |
| 3554 | main.log.debug( "Expected: " + str( onosSet ) ) |
| 3555 | main.log.debug( "Actual: " + str( current ) ) |
| 3556 | getResults = main.FALSE |
| 3557 | else: |
| 3558 | # error, set is not a set |
| 3559 | main.log.error( "ONOS" + str( i + 1 ) + |
| 3560 | " has repeat elements in" + |
| 3561 | " set " + onosSetName + ":\n" + |
| 3562 | str( getResponses[ i ] ) ) |
| 3563 | getResults = main.FALSE |
| 3564 | elif getResponses[ i ] == main.ERROR: |
| 3565 | getResults = main.FALSE |
| 3566 | sizeResponses = [] |
| 3567 | threads = [] |
| 3568 | for i in range( numControllers ): |
| 3569 | t = main.Thread( target=CLIs[i].setTestSize, |
| 3570 | name="setTestSize-" + str( i ), |
| 3571 | args=[ onosSetName ] ) |
| 3572 | threads.append( t ) |
| 3573 | t.start() |
| 3574 | for t in threads: |
| 3575 | t.join() |
| 3576 | sizeResponses.append( t.result ) |
| 3577 | sizeResults = main.TRUE |
| 3578 | for i in range( numControllers ): |
| 3579 | if size != sizeResponses[ i ]: |
| 3580 | sizeResults = main.FALSE |
| 3581 | main.log.error( "ONOS" + str( i + 1 ) + |
| 3582 | " expected a size of " + str( size ) + |
| 3583 | " for set " + onosSetName + |
| 3584 | " but got " + str( sizeResponses[ i ] ) ) |
| 3585 | removeAllResults = removeAllResults and getResults and sizeResults |
| 3586 | utilities.assert_equals( expect=main.TRUE, |
| 3587 | actual=removeAllResults, |
| 3588 | onpass="Set removeAll correct", |
| 3589 | onfail="Set removeAll was incorrect" ) |
| 3590 | |
| 3591 | main.step( "Distributed Set addAll()" ) |
| 3592 | onosSet.update( addAllValue.split() ) |
| 3593 | addResponses = [] |
| 3594 | threads = [] |
| 3595 | for i in range( numControllers ): |
| 3596 | t = main.Thread( target=CLIs[i].setTestAdd, |
| 3597 | name="setTestAddAll-" + str( i ), |
| 3598 | args=[ onosSetName, addAllValue ] ) |
| 3599 | threads.append( t ) |
| 3600 | t.start() |
| 3601 | for t in threads: |
| 3602 | t.join() |
| 3603 | addResponses.append( t.result ) |
| 3604 | |
| 3605 | # main.TRUE = successfully changed the set |
| 3606 | # main.FALSE = action resulted in no change in set |
| 3607 | # main.ERROR - Some error in executing the function |
| 3608 | addAllResults = main.TRUE |
| 3609 | for i in range( numControllers ): |
| 3610 | if addResponses[ i ] == main.TRUE: |
| 3611 | # All is well |
| 3612 | pass |
| 3613 | elif addResponses[ i ] == main.FALSE: |
| 3614 | # Already in set, probably fine |
| 3615 | pass |
| 3616 | elif addResponses[ i ] == main.ERROR: |
| 3617 | # Error in execution |
| 3618 | addAllResults = main.FALSE |
| 3619 | else: |
| 3620 | # unexpected result |
| 3621 | addAllResults = main.FALSE |
| 3622 | if addAllResults != main.TRUE: |
| 3623 | main.log.error( "Error executing set addAll" ) |
| 3624 | |
| 3625 | # Check if set is still correct |
| 3626 | size = len( onosSet ) |
| 3627 | getResponses = [] |
| 3628 | threads = [] |
| 3629 | for i in range( numControllers ): |
| 3630 | t = main.Thread( target=CLIs[i].setTestGet, |
| 3631 | name="setTestGet-" + str( i ), |
| 3632 | args=[ onosSetName ] ) |
| 3633 | threads.append( t ) |
| 3634 | t.start() |
| 3635 | for t in threads: |
| 3636 | t.join() |
| 3637 | getResponses.append( t.result ) |
| 3638 | getResults = main.TRUE |
| 3639 | for i in range( numControllers ): |
| 3640 | if isinstance( getResponses[ i ], list): |
| 3641 | current = set( getResponses[ i ] ) |
| 3642 | if len( current ) == len( getResponses[ i ] ): |
| 3643 | # no repeats |
| 3644 | if onosSet != current: |
| 3645 | main.log.error( "ONOS" + str( i + 1 ) + |
| 3646 | " has incorrect view" + |
| 3647 | " of set " + onosSetName + ":\n" + |
| 3648 | str( getResponses[ i ] ) ) |
| 3649 | main.log.debug( "Expected: " + str( onosSet ) ) |
| 3650 | main.log.debug( "Actual: " + str( current ) ) |
| 3651 | getResults = main.FALSE |
| 3652 | else: |
| 3653 | # error, set is not a set |
| 3654 | main.log.error( "ONOS" + str( i + 1 ) + |
| 3655 | " has repeat elements in" + |
| 3656 | " set " + onosSetName + ":\n" + |
| 3657 | str( getResponses[ i ] ) ) |
| 3658 | getResults = main.FALSE |
| 3659 | elif getResponses[ i ] == main.ERROR: |
| 3660 | getResults = main.FALSE |
| 3661 | sizeResponses = [] |
| 3662 | threads = [] |
| 3663 | for i in range( numControllers ): |
| 3664 | t = main.Thread( target=CLIs[i].setTestSize, |
| 3665 | name="setTestSize-" + str( i ), |
| 3666 | args=[ onosSetName ] ) |
| 3667 | threads.append( t ) |
| 3668 | t.start() |
| 3669 | for t in threads: |
| 3670 | t.join() |
| 3671 | sizeResponses.append( t.result ) |
| 3672 | sizeResults = main.TRUE |
| 3673 | for i in range( numControllers ): |
| 3674 | if size != sizeResponses[ i ]: |
| 3675 | sizeResults = main.FALSE |
| 3676 | main.log.error( "ONOS" + str( i + 1 ) + |
| 3677 | " expected a size of " + str( size ) + |
| 3678 | " for set " + onosSetName + |
| 3679 | " but got " + str( sizeResponses[ i ] ) ) |
| 3680 | addAllResults = addAllResults and getResults and sizeResults |
| 3681 | utilities.assert_equals( expect=main.TRUE, |
| 3682 | actual=addAllResults, |
| 3683 | onpass="Set addAll correct", |
| 3684 | onfail="Set addAll was incorrect" ) |
| 3685 | |
| 3686 | main.step( "Distributed Set clear()" ) |
| 3687 | onosSet.clear() |
| 3688 | clearResponses = [] |
| 3689 | threads = [] |
| 3690 | for i in range( numControllers ): |
| 3691 | t = main.Thread( target=CLIs[i].setTestRemove, |
| 3692 | name="setTestClear-" + str( i ), |
| 3693 | args=[ onosSetName, " "], # Values doesn't matter |
| 3694 | kwargs={ "clear": True } ) |
| 3695 | threads.append( t ) |
| 3696 | t.start() |
| 3697 | for t in threads: |
| 3698 | t.join() |
| 3699 | clearResponses.append( t.result ) |
| 3700 | |
| 3701 | # main.TRUE = successfully changed the set |
| 3702 | # main.FALSE = action resulted in no change in set |
| 3703 | # main.ERROR - Some error in executing the function |
| 3704 | clearResults = main.TRUE |
| 3705 | for i in range( numControllers ): |
| 3706 | if clearResponses[ i ] == main.TRUE: |
| 3707 | # All is well |
| 3708 | pass |
| 3709 | elif clearResponses[ i ] == main.FALSE: |
| 3710 | # Nothing set, probably fine |
| 3711 | pass |
| 3712 | elif clearResponses[ i ] == main.ERROR: |
| 3713 | # Error in execution |
| 3714 | clearResults = main.FALSE |
| 3715 | else: |
| 3716 | # unexpected result |
| 3717 | clearResults = main.FALSE |
| 3718 | if clearResults != main.TRUE: |
| 3719 | main.log.error( "Error executing set clear" ) |
| 3720 | |
| 3721 | # Check if set is still correct |
| 3722 | size = len( onosSet ) |
| 3723 | getResponses = [] |
| 3724 | threads = [] |
| 3725 | for i in range( numControllers ): |
| 3726 | t = main.Thread( target=CLIs[i].setTestGet, |
| 3727 | name="setTestGet-" + str( i ), |
| 3728 | args=[ onosSetName ] ) |
| 3729 | threads.append( t ) |
| 3730 | t.start() |
| 3731 | for t in threads: |
| 3732 | t.join() |
| 3733 | getResponses.append( t.result ) |
| 3734 | getResults = main.TRUE |
| 3735 | for i in range( numControllers ): |
| 3736 | if isinstance( getResponses[ i ], list): |
| 3737 | current = set( getResponses[ i ] ) |
| 3738 | if len( current ) == len( getResponses[ i ] ): |
| 3739 | # no repeats |
| 3740 | if onosSet != current: |
| 3741 | main.log.error( "ONOS" + str( i + 1 ) + |
| 3742 | " has incorrect view" + |
| 3743 | " of set " + onosSetName + ":\n" + |
| 3744 | str( getResponses[ i ] ) ) |
| 3745 | main.log.debug( "Expected: " + str( onosSet ) ) |
| 3746 | main.log.debug( "Actual: " + str( current ) ) |
| 3747 | getResults = main.FALSE |
| 3748 | else: |
| 3749 | # error, set is not a set |
| 3750 | main.log.error( "ONOS" + str( i + 1 ) + |
| 3751 | " has repeat elements in" + |
| 3752 | " set " + onosSetName + ":\n" + |
| 3753 | str( getResponses[ i ] ) ) |
| 3754 | getResults = main.FALSE |
| 3755 | elif getResponses[ i ] == main.ERROR: |
| 3756 | getResults = main.FALSE |
| 3757 | sizeResponses = [] |
| 3758 | threads = [] |
| 3759 | for i in range( numControllers ): |
| 3760 | t = main.Thread( target=CLIs[i].setTestSize, |
| 3761 | name="setTestSize-" + str( i ), |
| 3762 | args=[ onosSetName ] ) |
| 3763 | threads.append( t ) |
| 3764 | t.start() |
| 3765 | for t in threads: |
| 3766 | t.join() |
| 3767 | sizeResponses.append( t.result ) |
| 3768 | sizeResults = main.TRUE |
| 3769 | for i in range( numControllers ): |
| 3770 | if size != sizeResponses[ i ]: |
| 3771 | sizeResults = main.FALSE |
| 3772 | main.log.error( "ONOS" + str( i + 1 ) + |
| 3773 | " expected a size of " + str( size ) + |
| 3774 | " for set " + onosSetName + |
| 3775 | " but got " + str( sizeResponses[ i ] ) ) |
| 3776 | clearResults = clearResults and getResults and sizeResults |
| 3777 | utilities.assert_equals( expect=main.TRUE, |
| 3778 | actual=clearResults, |
| 3779 | onpass="Set clear correct", |
| 3780 | onfail="Set clear was incorrect" ) |
| 3781 | |
| 3782 | main.step( "Distributed Set addAll()" ) |
| 3783 | onosSet.update( addAllValue.split() ) |
| 3784 | addResponses = [] |
| 3785 | threads = [] |
| 3786 | for i in range( numControllers ): |
| 3787 | t = main.Thread( target=CLIs[i].setTestAdd, |
| 3788 | name="setTestAddAll-" + str( i ), |
| 3789 | args=[ onosSetName, addAllValue ] ) |
| 3790 | threads.append( t ) |
| 3791 | t.start() |
| 3792 | for t in threads: |
| 3793 | t.join() |
| 3794 | addResponses.append( t.result ) |
| 3795 | |
| 3796 | # main.TRUE = successfully changed the set |
| 3797 | # main.FALSE = action resulted in no change in set |
| 3798 | # main.ERROR - Some error in executing the function |
| 3799 | addAllResults = main.TRUE |
| 3800 | for i in range( numControllers ): |
| 3801 | if addResponses[ i ] == main.TRUE: |
| 3802 | # All is well |
| 3803 | pass |
| 3804 | elif addResponses[ i ] == main.FALSE: |
| 3805 | # Already in set, probably fine |
| 3806 | pass |
| 3807 | elif addResponses[ i ] == main.ERROR: |
| 3808 | # Error in execution |
| 3809 | addAllResults = main.FALSE |
| 3810 | else: |
| 3811 | # unexpected result |
| 3812 | addAllResults = main.FALSE |
| 3813 | if addAllResults != main.TRUE: |
| 3814 | main.log.error( "Error executing set addAll" ) |
| 3815 | |
| 3816 | # Check if set is still correct |
| 3817 | size = len( onosSet ) |
| 3818 | getResponses = [] |
| 3819 | threads = [] |
| 3820 | for i in range( numControllers ): |
| 3821 | t = main.Thread( target=CLIs[i].setTestGet, |
| 3822 | name="setTestGet-" + str( i ), |
| 3823 | args=[ onosSetName ] ) |
| 3824 | threads.append( t ) |
| 3825 | t.start() |
| 3826 | for t in threads: |
| 3827 | t.join() |
| 3828 | getResponses.append( t.result ) |
| 3829 | getResults = main.TRUE |
| 3830 | for i in range( numControllers ): |
| 3831 | if isinstance( getResponses[ i ], list): |
| 3832 | current = set( getResponses[ i ] ) |
| 3833 | if len( current ) == len( getResponses[ i ] ): |
| 3834 | # no repeats |
| 3835 | if onosSet != current: |
| 3836 | main.log.error( "ONOS" + str( i + 1 ) + |
| 3837 | " has incorrect view" + |
| 3838 | " of set " + onosSetName + ":\n" + |
| 3839 | str( getResponses[ i ] ) ) |
| 3840 | main.log.debug( "Expected: " + str( onosSet ) ) |
| 3841 | main.log.debug( "Actual: " + str( current ) ) |
| 3842 | getResults = main.FALSE |
| 3843 | else: |
| 3844 | # error, set is not a set |
| 3845 | main.log.error( "ONOS" + str( i + 1 ) + |
| 3846 | " has repeat elements in" + |
| 3847 | " set " + onosSetName + ":\n" + |
| 3848 | str( getResponses[ i ] ) ) |
| 3849 | getResults = main.FALSE |
| 3850 | elif getResponses[ i ] == main.ERROR: |
| 3851 | getResults = main.FALSE |
| 3852 | sizeResponses = [] |
| 3853 | threads = [] |
| 3854 | for i in range( numControllers ): |
| 3855 | t = main.Thread( target=CLIs[i].setTestSize, |
| 3856 | name="setTestSize-" + str( i ), |
| 3857 | args=[ onosSetName ] ) |
| 3858 | threads.append( t ) |
| 3859 | t.start() |
| 3860 | for t in threads: |
| 3861 | t.join() |
| 3862 | sizeResponses.append( t.result ) |
| 3863 | sizeResults = main.TRUE |
| 3864 | for i in range( numControllers ): |
| 3865 | if size != sizeResponses[ i ]: |
| 3866 | sizeResults = main.FALSE |
| 3867 | main.log.error( "ONOS" + str( i + 1 ) + |
| 3868 | " expected a size of " + str( size ) + |
| 3869 | " for set " + onosSetName + |
| 3870 | " but got " + str( sizeResponses[ i ] ) ) |
| 3871 | addAllResults = addAllResults and getResults and sizeResults |
| 3872 | utilities.assert_equals( expect=main.TRUE, |
| 3873 | actual=addAllResults, |
| 3874 | onpass="Set addAll correct", |
| 3875 | onfail="Set addAll was incorrect" ) |
| 3876 | |
| 3877 | main.step( "Distributed Set retain()" ) |
| 3878 | onosSet.intersection_update( retainValue.split() ) |
| 3879 | retainResponses = [] |
| 3880 | threads = [] |
| 3881 | for i in range( numControllers ): |
| 3882 | t = main.Thread( target=CLIs[i].setTestRemove, |
| 3883 | name="setTestRetain-" + str( i ), |
| 3884 | args=[ onosSetName, retainValue ], |
| 3885 | kwargs={ "retain": True } ) |
| 3886 | threads.append( t ) |
| 3887 | t.start() |
| 3888 | for t in threads: |
| 3889 | t.join() |
| 3890 | retainResponses.append( t.result ) |
| 3891 | |
| 3892 | # main.TRUE = successfully changed the set |
| 3893 | # main.FALSE = action resulted in no change in set |
| 3894 | # main.ERROR - Some error in executing the function |
| 3895 | retainResults = main.TRUE |
| 3896 | for i in range( numControllers ): |
| 3897 | if retainResponses[ i ] == main.TRUE: |
| 3898 | # All is well |
| 3899 | pass |
| 3900 | elif retainResponses[ i ] == main.FALSE: |
| 3901 | # Already in set, probably fine |
| 3902 | pass |
| 3903 | elif retainResponses[ i ] == main.ERROR: |
| 3904 | # Error in execution |
| 3905 | retainResults = main.FALSE |
| 3906 | else: |
| 3907 | # unexpected result |
| 3908 | retainResults = main.FALSE |
| 3909 | if retainResults != main.TRUE: |
| 3910 | main.log.error( "Error executing set retain" ) |
| 3911 | |
| 3912 | # Check if set is still correct |
| 3913 | size = len( onosSet ) |
| 3914 | getResponses = [] |
| 3915 | threads = [] |
| 3916 | for i in range( numControllers ): |
| 3917 | t = main.Thread( target=CLIs[i].setTestGet, |
| 3918 | name="setTestGet-" + str( i ), |
| 3919 | args=[ onosSetName ] ) |
| 3920 | threads.append( t ) |
| 3921 | t.start() |
| 3922 | for t in threads: |
| 3923 | t.join() |
| 3924 | getResponses.append( t.result ) |
| 3925 | getResults = main.TRUE |
| 3926 | for i in range( numControllers ): |
| 3927 | if isinstance( getResponses[ i ], list): |
| 3928 | current = set( getResponses[ i ] ) |
| 3929 | if len( current ) == len( getResponses[ i ] ): |
| 3930 | # no repeats |
| 3931 | if onosSet != current: |
| 3932 | main.log.error( "ONOS" + str( i + 1 ) + |
| 3933 | " has incorrect view" + |
| 3934 | " of set " + onosSetName + ":\n" + |
| 3935 | str( getResponses[ i ] ) ) |
| 3936 | main.log.debug( "Expected: " + str( onosSet ) ) |
| 3937 | main.log.debug( "Actual: " + str( current ) ) |
| 3938 | getResults = main.FALSE |
| 3939 | else: |
| 3940 | # error, set is not a set |
| 3941 | main.log.error( "ONOS" + str( i + 1 ) + |
| 3942 | " has repeat elements in" + |
| 3943 | " set " + onosSetName + ":\n" + |
| 3944 | str( getResponses[ i ] ) ) |
| 3945 | getResults = main.FALSE |
| 3946 | elif getResponses[ i ] == main.ERROR: |
| 3947 | getResults = main.FALSE |
| 3948 | sizeResponses = [] |
| 3949 | threads = [] |
| 3950 | for i in range( numControllers ): |
| 3951 | t = main.Thread( target=CLIs[i].setTestSize, |
| 3952 | name="setTestSize-" + str( i ), |
| 3953 | args=[ onosSetName ] ) |
| 3954 | threads.append( t ) |
| 3955 | t.start() |
| 3956 | for t in threads: |
| 3957 | t.join() |
| 3958 | sizeResponses.append( t.result ) |
| 3959 | sizeResults = main.TRUE |
| 3960 | for i in range( numControllers ): |
| 3961 | if size != sizeResponses[ i ]: |
| 3962 | sizeResults = main.FALSE |
| 3963 | main.log.error( "ONOS" + str( i + 1 ) + |
| 3964 | " expected a size of " + |
| 3965 | str( size ) + " for set " + onosSetName + |
| 3966 | " but got " + str( sizeResponses[ i ] ) ) |
| 3967 | retainResults = retainResults and getResults and sizeResults |
| 3968 | utilities.assert_equals( expect=main.TRUE, |
| 3969 | actual=retainResults, |
| 3970 | onpass="Set retain correct", |
| 3971 | onfail="Set retain was incorrect" ) |
| 3972 | |