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