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