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