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