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