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