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