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