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