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