Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 1 | """ |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 2 | Copyright 2015 Open Networking Foundation ( ONF ) |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 3 | |
| 4 | Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 5 | the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 6 | or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg> |
| 7 | |
| 8 | TestON is free software: you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation, either version 2 of the License, or |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 11 | ( at your option ) any later version. |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 12 | |
| 13 | TestON is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with TestON. If not, see <http://www.gnu.org/licenses/>. |
| 20 | """ |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 21 | # Testing the basic intent functionality of ONOS |
| 22 | |
Jon Hall | bc080f9 | 2017-05-24 16:29:55 -0700 | [diff] [blame] | 23 | |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 24 | class FUNCnetCfg: |
| 25 | |
| 26 | def __init__( self ): |
| 27 | self.default = '' |
| 28 | |
| 29 | def CASE1( self, main ): |
| 30 | import imp |
| 31 | import re |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 32 | """ |
| 33 | - Construct tests variables |
| 34 | - GIT ( optional ) |
| 35 | - Checkout ONOS master branch |
| 36 | - Pull latest ONOS code |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 37 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 38 | try: |
| 39 | from tests.dependencies.ONOSSetup import ONOSSetup |
| 40 | main.testSetUp = ONOSSetup() |
| 41 | except ImportError: |
| 42 | main.log.error( "ONOSSetup not found. exiting the test" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 43 | main.cleanAndExit() |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 44 | main.testSetUp.envSetupDescription() |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 45 | stepResult = main.FALSE |
| 46 | |
| 47 | # Test variables |
| 48 | try: |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 49 | main.apps = main.params[ 'ENV' ][ 'cellApps' ] |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 50 | main.dependencyPath = main.testOnDirectory + \ |
| 51 | main.params[ 'DEPENDENCY' ][ 'path' ] |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 52 | wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ] |
| 53 | wrapperFile2 = main.params[ 'DEPENDENCY' ][ 'wrapper2' ] |
| 54 | wrapperFile3 = main.params[ 'DEPENDENCY' ][ 'wrapper3' ] |
| 55 | main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] ) |
Jon Hall | bc080f9 | 2017-05-24 16:29:55 -0700 | [diff] [blame] | 56 | main.gossipTime = int( main.params[ 'SLEEP' ][ 'cfgGossip' ] ) |
alison | 15124df | 2016-10-06 12:04:51 -0700 | [diff] [blame] | 57 | main.SetNetCfgSleep = int( main.params[ 'SLEEP' ][ 'SetNetCfgSleep' ] ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 58 | main.hostsData = {} |
Jeremy Ronquillo | 4a30ffe | 2017-06-07 11:36:35 -0700 | [diff] [blame] | 59 | main.retrytimes = int( main.params[ 'RETRY' ] ) |
Jeremy Ronquillo | 4cf537d | 2017-06-26 11:20:52 -0700 | [diff] [blame] | 60 | main.retrysleep = int( main.params[ 'RetrySleep' ] ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 61 | |
| 62 | # -- INIT SECTION, SHOULD ONLY BE RUN ONCE -- # |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 63 | main.netCfg = imp.load_source( wrapperFile2, |
| 64 | main.dependencyPath + |
| 65 | wrapperFile2 + |
| 66 | ".py" ) |
| 67 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 68 | stepResult = main.testSetUp.envSetup() |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 69 | except Exception as e: |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 70 | main.testSetUp.envSetupException( e ) |
| 71 | main.testSetUp.evnSetupConclusion( stepResult ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 72 | |
| 73 | def CASE2( self, main ): |
| 74 | """ |
| 75 | - Set up cell |
| 76 | - Create cell file |
| 77 | - Set cell file |
| 78 | - Verify cell file |
| 79 | - Kill ONOS process |
| 80 | - Uninstall ONOS cluster |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 81 | - Install ONOS cluster |
Jon Hall | 72ecaa0 | 2017-06-06 09:41:48 -0700 | [diff] [blame] | 82 | - Verify ONOS start up |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 83 | - Connect to cli |
| 84 | """ |
| 85 | import time |
You Wang | a0f6ff6 | 2018-01-11 15:46:30 -0800 | [diff] [blame] | 86 | main.testSetUp.ONOSSetUp( main.Cluster ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 87 | |
| 88 | def CASE8( self, main ): |
| 89 | """ |
| 90 | Compare Topo |
| 91 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 92 | try: |
| 93 | from tests.dependencies.topology import Topology |
| 94 | except ImportError: |
| 95 | main.log.error( "Topology not found exiting the test" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 96 | main.cleanAndExit() |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 97 | try: |
| 98 | main.topoRelated |
| 99 | except ( NameError, AttributeError ): |
| 100 | main.topoRelated = Topology() |
| 101 | main.topoRelated.compareTopos( main.Mininet1 ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 102 | |
| 103 | def CASE9( self, main ): |
Jon Hall | bc080f9 | 2017-05-24 16:29:55 -0700 | [diff] [blame] | 104 | """ |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 105 | Report errors/warnings/exceptions |
Jon Hall | bc080f9 | 2017-05-24 16:29:55 -0700 | [diff] [blame] | 106 | """ |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 107 | main.log.info( "Error report: \n" ) |
| 108 | main.ONOSbench.logReport( |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 109 | main.Cluster.active( 0 ).ipAddress, |
Jon Hall | bc080f9 | 2017-05-24 16:29:55 -0700 | [diff] [blame] | 110 | [ "INFO", "WARN", "ERROR", "Except" ], |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 111 | "s" ) |
Jon Hall | bc080f9 | 2017-05-24 16:29:55 -0700 | [diff] [blame] | 112 | # main.ONOSbench.logReport( globalONOSip[ 1 ], [ "INFO" ], "d" ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 113 | |
| 114 | def CASE10( self, main ): |
| 115 | """ |
| 116 | Start Mininet topology with OF 1.0 switches |
| 117 | """ |
| 118 | main.OFProtocol = "1.0" |
| 119 | main.log.report( "Start Mininet topology with OF 1.0 switches" ) |
| 120 | main.case( "Start Mininet topology with OF 1.0 switches" ) |
| 121 | main.caseExplanation = "Start mininet topology with OF 1.0 " +\ |
| 122 | "switches to test intents, exits out if " +\ |
| 123 | "topology did not start correctly" |
| 124 | |
| 125 | main.step( "Starting Mininet topology with OF 1.0 switches" ) |
Jon Hall | 53c5e66 | 2016-04-13 16:06:56 -0700 | [diff] [blame] | 126 | args = "--controller none --switch ovs,protocols=OpenFlow10" |
Jon Hall | bc080f9 | 2017-05-24 16:29:55 -0700 | [diff] [blame] | 127 | switches = int( main.params[ 'MININET' ][ 'switch' ] ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 128 | cmd = "mn --topo linear,{} {}".format( switches, args ) |
Jon Hall | bc080f9 | 2017-05-24 16:29:55 -0700 | [diff] [blame] | 129 | topoResult = main.Mininet1.startNet( mnCmd=cmd ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 130 | stepResult = topoResult |
| 131 | utilities.assert_equals( expect=main.TRUE, |
| 132 | actual=stepResult, |
| 133 | onpass="Successfully loaded topology", |
| 134 | onfail="Failed to load topology" ) |
| 135 | # Exit if topology did not load properly |
| 136 | if not topoResult: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 137 | main.cleanAndExit() |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 138 | |
| 139 | def CASE11( self, main ): |
| 140 | """ |
| 141 | Start Mininet topology with OF 1.3 switches |
| 142 | """ |
| 143 | import re |
| 144 | main.OFProtocol = "1.3" |
| 145 | main.log.report( "Start Mininet topology with OF 1.3 switches" ) |
| 146 | main.case( "Start Mininet topology with OF 1.3 switches" ) |
| 147 | main.caseExplanation = "Start mininet topology with OF 1.3 " +\ |
| 148 | "switches to test intents, exits out if " +\ |
| 149 | "topology did not start correctly" |
| 150 | |
| 151 | main.step( "Starting Mininet topology with OF 1.3 switches" ) |
Jon Hall | 53c5e66 | 2016-04-13 16:06:56 -0700 | [diff] [blame] | 152 | args = "--controller none --switch ovs,protocols=OpenFlow13" |
Jeremy Songster | 2baa44e | 2016-06-10 10:18:40 -0700 | [diff] [blame] | 153 | switches = int( main.params[ 'MININET' ][ 'switch' ] ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 154 | cmd = "mn --topo linear,{} {}".format( switches, args ) |
Jon Hall | bc080f9 | 2017-05-24 16:29:55 -0700 | [diff] [blame] | 155 | topoResult = main.Mininet1.startNet( mnCmd=cmd ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 156 | stepResult = topoResult |
| 157 | utilities.assert_equals( expect=main.TRUE, |
| 158 | actual=stepResult, |
| 159 | onpass="Successfully loaded topology", |
| 160 | onfail="Failed to load topology" ) |
| 161 | # Exit if topology did not load properly |
| 162 | if not topoResult: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 163 | main.cleanAndExit() |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 164 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 165 | tempONOSip = main.Cluster.getIps() |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 166 | |
| 167 | swList = [ "s" + str( i ) for i in range( 1, switches + 1 ) ] |
| 168 | assignResult = main.Mininet1.assignSwController( sw=swList, |
| 169 | ip=tempONOSip, |
| 170 | port='6653' ) |
| 171 | if not assignResult: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 172 | main.cleanAndExit() |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 173 | |
| 174 | assignResult = main.TRUE |
| 175 | for sw in swList: |
| 176 | response = main.Mininet1.getSwController( "s" + str( i ) ) |
| 177 | main.log.info( "Response is " + str( response ) ) |
| 178 | for ip in tempONOSip: |
| 179 | if re.search( "tcp:" + ip, response ): |
| 180 | assignResult = assignResult and main.TRUE |
| 181 | else: |
| 182 | assignResult = assignResult and main.FALSE |
| 183 | stepResult = assignResult |
| 184 | utilities.assert_equals( expect=main.TRUE, |
| 185 | actual=stepResult, |
| 186 | onpass="Successfully assigned switches" + |
| 187 | "to controller", |
| 188 | onfail="Failed to assign switches to " + |
| 189 | "controller" ) |
| 190 | |
| 191 | def CASE14( self, main ): |
| 192 | """ |
| 193 | Stop mininet |
| 194 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 195 | try: |
| 196 | from tests.dependencies.utils import Utils |
| 197 | except ImportError: |
| 198 | main.log.error( "Utils not found exiting the test" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 199 | main.cleanAndExit() |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 200 | try: |
| 201 | main.Utils |
| 202 | except ( NameError, AttributeError ): |
| 203 | main.Utils = Utils() |
| 204 | main.Utils.mininetCleanIntro() |
| 205 | topoResult = main.Utils.mininetCleanup( main.Mininet1 ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 206 | # Exit if topology did not load properly |
| 207 | if not topoResult: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 208 | main.cleanAndExit() |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 209 | |
| 210 | def CASE20( self, main ): |
| 211 | """ |
| 212 | Add some device configurations and then check they are distributed |
| 213 | to all nodes |
| 214 | """ |
alison | 15124df | 2016-10-06 12:04:51 -0700 | [diff] [blame] | 215 | import time |
Pratik Parab | c6083c2 | 2017-04-27 13:24:41 -0700 | [diff] [blame] | 216 | import json |
| 217 | import os |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 218 | main.case( "Add Network configurations to the cluster" ) |
| 219 | main.caseExplanation = "Add Network Configurations for devices" +\ |
| 220 | " not discovered yet. One device is allowed" +\ |
| 221 | ", the other disallowed." |
Jeremy Ronquillo | 4cf537d | 2017-06-26 11:20:52 -0700 | [diff] [blame] | 222 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 223 | pprint = main.Cluster.active( 0 ).REST.pprint |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 224 | |
| 225 | main.step( "Add Net Cfg for switch1" ) |
Pratik Parab | 6f41863 | 2017-04-25 17:05:50 -0700 | [diff] [blame] | 226 | |
Pratik Parab | 6f41863 | 2017-04-25 17:05:50 -0700 | [diff] [blame] | 227 | try: |
| 228 | with open( os.path.dirname( main.testFile ) + '/dependencies/s1Json', 'r' ) as s1Jsondata: |
| 229 | s1Json = json.load( s1Jsondata ) |
| 230 | except IOError: |
| 231 | main.log.exception( "s1Json File not found." ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 232 | main.cleanAndExit() |
Pratik Parab | 6f41863 | 2017-04-25 17:05:50 -0700 | [diff] [blame] | 233 | main.log.info( "s1Json:" + str( s1Json ) ) |
| 234 | |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 235 | main.s1Json = s1Json |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 236 | setS1Allow = main.Cluster.active( 0 ).REST.setNetCfg( s1Json, |
| 237 | subjectClass="devices", |
| 238 | subjectKey="of:0000000000000001", |
| 239 | configKey="basic" ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 240 | s1Result = False |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 241 | # Wait 5 secs after set up netCfg |
alison | 15124df | 2016-10-06 12:04:51 -0700 | [diff] [blame] | 242 | time.sleep( main.SetNetCfgSleep ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 243 | if setS1Allow: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 244 | getS1 = utilities.retry( f=main.Cluster.active( 0 ).REST.getNetCfg, |
Jeremy Ronquillo | 4a30ffe | 2017-06-07 11:36:35 -0700 | [diff] [blame] | 245 | retValue=False, |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 246 | kwargs={ "subjectClass": "devices", |
| 247 | "subjectKey": "of:0000000000000001", |
| 248 | "configKey": "basic" }, |
Jeremy Ronquillo | 4a30ffe | 2017-06-07 11:36:35 -0700 | [diff] [blame] | 249 | attempts=main.retrytimes, |
| 250 | sleep=main.retrysleep ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 251 | onosCfg = pprint( getS1 ) |
| 252 | sentCfg = pprint( s1Json ) |
| 253 | if onosCfg == sentCfg: |
alison | 15124df | 2016-10-06 12:04:51 -0700 | [diff] [blame] | 254 | main.log.info( "ONOS NetCfg match what was sent" ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 255 | s1Result = True |
| 256 | else: |
| 257 | main.log.error( "ONOS NetCfg doesn't match what was sent" ) |
| 258 | main.log.debug( "ONOS config: {}".format( onosCfg ) ) |
| 259 | main.log.debug( "Sent config: {}".format( sentCfg ) ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 260 | utilities.retry( f=main.Cluster.active( 0 ).REST.getNetCfg, |
| 261 | retValue=False, |
| 262 | attempts=main.retrytimes, |
| 263 | sleep=main.retrysleep ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 264 | utilities.assert_equals( expect=True, |
| 265 | actual=s1Result, |
| 266 | onpass="Net Cfg added for device s1", |
| 267 | onfail="Net Cfg for device s1 not correctly set" ) |
| 268 | |
| 269 | main.step( "Add Net Cfg for switch3" ) |
Pratik Parab | 6f41863 | 2017-04-25 17:05:50 -0700 | [diff] [blame] | 270 | |
| 271 | try: |
| 272 | with open( os.path.dirname( main.testFile ) + '/dependencies/s3Json', 'r' ) as s3Jsondata: |
| 273 | s3Json = json.load( s3Jsondata ) |
| 274 | except IOError: |
| 275 | main.log.exception( "s3Json File not found" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 276 | main.cleanAndExit() |
Jon Hall | bc080f9 | 2017-05-24 16:29:55 -0700 | [diff] [blame] | 277 | main.log.info( "s3Json:" + str( s3Json ) ) |
Pratik Parab | 6f41863 | 2017-04-25 17:05:50 -0700 | [diff] [blame] | 278 | |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 279 | main.s3Json = s3Json |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 280 | setS3Disallow = main.Cluster.active( 0 ).REST.setNetCfg( s3Json, |
| 281 | subjectClass="devices", |
| 282 | subjectKey="of:0000000000000003", |
| 283 | configKey="basic" ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 284 | s3Result = False |
alison | 15124df | 2016-10-06 12:04:51 -0700 | [diff] [blame] | 285 | time.sleep( main.SetNetCfgSleep ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 286 | if setS3Disallow: |
| 287 | # Check what we set is what is in ONOS |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 288 | getS3 = utilities.retry( f=main.Cluster.active( 0 ).REST.getNetCfg, |
Jeremy Ronquillo | 4a30ffe | 2017-06-07 11:36:35 -0700 | [diff] [blame] | 289 | retValue=False, |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 290 | kwargs={ "subjectClass": "devices", |
| 291 | "subjectKey": "of:0000000000000003", |
| 292 | "configKey": "basic" }, |
Jeremy Ronquillo | 4a30ffe | 2017-06-07 11:36:35 -0700 | [diff] [blame] | 293 | attempts=main.retrytimes, |
| 294 | sleep=main.retrysleep ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 295 | onosCfg = pprint( getS3 ) |
| 296 | sentCfg = pprint( s3Json ) |
| 297 | if onosCfg == sentCfg: |
Jon Hall | bc080f9 | 2017-05-24 16:29:55 -0700 | [diff] [blame] | 298 | main.log.info( "ONOS NetCfg match what was sent" ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 299 | s3Result = True |
| 300 | else: |
| 301 | main.log.error( "ONOS NetCfg doesn't match what was sent" ) |
| 302 | main.log.debug( "ONOS config: {}".format( onosCfg ) ) |
| 303 | main.log.debug( "Sent config: {}".format( sentCfg ) ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 304 | utilities.retry( f=main.Cluster.active( 0 ).REST.getNetCfg, |
| 305 | retValue=False, |
| 306 | attempts=main.retrytimes, |
| 307 | sleep=main.retrysleep ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 308 | utilities.assert_equals( expect=True, |
| 309 | actual=s3Result, |
| 310 | onpass="Net Cfg added for device s3", |
| 311 | onfail="Net Cfg for device s3 not correctly set" ) |
| 312 | main.netCfg.compareCfg( main, main.gossipTime ) |
| 313 | |
| 314 | def CASE21( self, main ): |
| 315 | """ |
| 316 | Initial check of devices |
| 317 | """ |
| 318 | import json |
| 319 | try: |
| 320 | assert main.s1Json, "s1Json not defined" |
| 321 | except AssertionError: |
| 322 | main.log.exception( "Case Prerequisites not set: " ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 323 | main.cleanAndExit() |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 324 | main.case( "Check Devices After they initially connect to ONOS" ) |
| 325 | |
| 326 | main.netCfg.compareCfg( main ) |
| 327 | |
| 328 | main.step( "ONOS should only show devices S1, S2, and S4" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 329 | devices = main.Cluster.active( 0 ).REST.devices() |
| 330 | main.log.debug( main.Cluster.active( 0 ).REST.pprint( devices ) ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 331 | allowedDevices = [ "of:{}".format( str( i ).zfill( 16 ) ) for i in [ 1, 2, 4 ] ] |
Jeremy Songster | 2baa44e | 2016-06-10 10:18:40 -0700 | [diff] [blame] | 332 | main.log.debug( allowedDevices ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 333 | onosDevices = [] |
Jeremy Songster | 5c3fdb4 | 2016-04-27 12:19:27 -0700 | [diff] [blame] | 334 | try: |
| 335 | for sw in json.loads( devices ): |
Jon Hall | bc080f9 | 2017-05-24 16:29:55 -0700 | [diff] [blame] | 336 | onosDevices.append( str( sw[ 'id' ] ) ) |
Jeremy Songster | 5c3fdb4 | 2016-04-27 12:19:27 -0700 | [diff] [blame] | 337 | onosDevices.sort() |
Jeremy Songster | 2baa44e | 2016-06-10 10:18:40 -0700 | [diff] [blame] | 338 | main.log.debug( onosDevices ) |
Jeremy Songster | 5c3fdb4 | 2016-04-27 12:19:27 -0700 | [diff] [blame] | 339 | except( TypeError, ValueError ): |
| 340 | main.log.error( "Problem loading devices" ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 341 | utilities.assert_equals( expect=allowedDevices, |
| 342 | actual=onosDevices, |
| 343 | onpass="Only allowed devices are in ONOS", |
| 344 | onfail="ONOS devices doesn't match the list" + |
| 345 | " of allowed devices" ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 346 | main.step( "Check device annotations" ) |
| 347 | keys = [ 'name', 'owner', 'rackAddress' ] |
Jeremy Songster | 5c3fdb4 | 2016-04-27 12:19:27 -0700 | [diff] [blame] | 348 | try: |
| 349 | for sw in json.loads( devices ): |
Jon Hall | bc080f9 | 2017-05-24 16:29:55 -0700 | [diff] [blame] | 350 | if "of:0000000000000001" in sw[ 'id' ]: |
Jeremy Songster | 5c3fdb4 | 2016-04-27 12:19:27 -0700 | [diff] [blame] | 351 | s1Correct = True |
| 352 | for k in keys: |
Jon Hall | bc080f9 | 2017-05-24 16:29:55 -0700 | [diff] [blame] | 353 | if str( sw.get( 'annotations', {} ).get( k ) ) != str( main.s1Json[ k ] ): |
Jeremy Songster | 5c3fdb4 | 2016-04-27 12:19:27 -0700 | [diff] [blame] | 354 | s1Correct = False |
| 355 | main.log.debug( "{} is wrong on s1".format( k ) ) |
| 356 | if not s1Correct: |
| 357 | main.log.error( "Annotations for s1 are incorrect: {}".format( sw ) ) |
| 358 | except( TypeError, ValueError ): |
| 359 | main.log.error( "Problem loading devices" ) |
| 360 | s1Correct = False |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 361 | try: |
| 362 | stepResult = s1Correct |
| 363 | except NameError: |
| 364 | stepResult = False |
| 365 | main.log.error( "s1 not found in devices" ) |
| 366 | utilities.assert_equals( expect=True, |
| 367 | actual=stepResult, |
| 368 | onpass="Configured device's annotations are correct", |
| 369 | onfail="Incorrect annotations for configured devices." ) |
| 370 | |
| 371 | def CASE22( self, main ): |
| 372 | """ |
| 373 | Add some device configurations for connected devices and then check |
| 374 | they are distributed to all nodes |
| 375 | """ |
| 376 | main.case( "Add Network configurations for connected devices to the cluster" ) |
| 377 | main.caseExplanation = "Add Network Configurations for discovered " +\ |
| 378 | "devices. One device is allowed" +\ |
| 379 | ", the other disallowed." |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 380 | pprint = main.Cluster.active( 0 ).REST.pprint |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 381 | |
| 382 | main.step( "Add Net Cfg for switch2" ) |
Pratik Parab | 6f41863 | 2017-04-25 17:05:50 -0700 | [diff] [blame] | 383 | try: |
| 384 | with open( os.path.dirname( main.testFile ) + '/dependencies/s2Json', 'r' ) as s2Jsondata: |
| 385 | s2Json = json.load( s2Jsondata ) |
| 386 | except IOError: |
| 387 | main.log.exception( "s2Json File not found" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 388 | main.cleanAndExit() |
Pratik Parab | 6f41863 | 2017-04-25 17:05:50 -0700 | [diff] [blame] | 389 | main.log.info( "s2Json:" + str( s2Json ) ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 390 | main.s2Json = s2Json |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 391 | setS2Allow = main.Cluster.active( 1 ).REST.setNetCfg( s2Json, |
| 392 | subjectClass="devices", |
| 393 | subjectKey="of:0000000000000002", |
| 394 | configKey="basic" ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 395 | s2Result = False |
| 396 | if setS2Allow: |
| 397 | # Check what we set is what is in ONOS |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 398 | getS2 = utilities.retry( f=main.Cluster.active( 1 ).REST.getNetCfg, |
Jeremy Ronquillo | 4a30ffe | 2017-06-07 11:36:35 -0700 | [diff] [blame] | 399 | retValue=False, |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 400 | kwargs={ "subjectClass": "devices", |
| 401 | "subjectKey": "of:0000000000000002", |
| 402 | "configKey": "basic" }, |
Jeremy Ronquillo | 4a30ffe | 2017-06-07 11:36:35 -0700 | [diff] [blame] | 403 | attempts=main.retrytimes, |
| 404 | sleep=main.retrysleep ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 405 | onosCfg = pprint( getS2 ) |
| 406 | sentCfg = pprint( s2Json ) |
| 407 | if onosCfg == sentCfg: |
| 408 | s2Result = True |
| 409 | else: |
| 410 | main.log.error( "ONOS NetCfg doesn't match what was sent" ) |
| 411 | main.log.debug( "ONOS config: {}".format( onosCfg ) ) |
| 412 | main.log.debug( "Sent config: {}".format( sentCfg ) ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 413 | utilities.retry( f=main.Cluster.active( 1 ).REST.getNetCfg, |
| 414 | retValue=False, |
| 415 | attempts=main.retrytimes, |
| 416 | sleep=main.retrysleep ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 417 | utilities.assert_equals( expect=True, |
| 418 | actual=s2Result, |
| 419 | onpass="Net Cfg added for device s2", |
| 420 | onfail="Net Cfg for device s2 not correctly set" ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 421 | main.step( "Add Net Cfg for switch4" ) |
Pratik Parab | 6f41863 | 2017-04-25 17:05:50 -0700 | [diff] [blame] | 422 | |
| 423 | try: |
| 424 | with open( os.path.dirname( main.testFile ) + '/dependencies/s4Json', 'r' ) as s4Jsondata: |
| 425 | s4Json = json.load( s4Jsondata ) |
| 426 | except IOError: |
| 427 | main.log.exception( "s4Json File not found" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 428 | main.cleanAndExit() |
Pratik Parab | 6f41863 | 2017-04-25 17:05:50 -0700 | [diff] [blame] | 429 | main.log.info( "s4Json:" + str( s4Json ) ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 430 | main.s4Json = s4Json |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 431 | setS4Disallow = main.Cluster.active( 2 ).REST.setNetCfg( s4Json, |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 432 | subjectClass="devices", |
| 433 | subjectKey="of:0000000000000004", |
| 434 | configKey="basic" ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 435 | s4Result = False |
| 436 | if setS4Disallow: |
| 437 | # Check what we set is what is in ONOS |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 438 | getS4 = utilities.retry( f=main.Cluster.active( 2 ).REST.getNetCfg, |
Jeremy Ronquillo | 4a30ffe | 2017-06-07 11:36:35 -0700 | [diff] [blame] | 439 | retValue=False, |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 440 | kwargs={ "subjectClass": "devices", |
| 441 | "subjectKey": "of:0000000000000004", |
| 442 | "configKey": "basic" }, |
Jeremy Ronquillo | 4a30ffe | 2017-06-07 11:36:35 -0700 | [diff] [blame] | 443 | attempts=main.retrytimes, |
| 444 | sleep=main.retrysleep ) |
| 445 | |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 446 | onosCfg = pprint( getS4 ) |
| 447 | sentCfg = pprint( s4Json ) |
| 448 | if onosCfg == sentCfg: |
| 449 | s4Result = True |
| 450 | else: |
| 451 | main.log.error( "ONOS NetCfg doesn't match what was sent" ) |
| 452 | main.log.debug( "ONOS config: {}".format( onosCfg ) ) |
| 453 | main.log.debug( "Sent config: {}".format( sentCfg ) ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 454 | main.step( "Retrying main.Cluster.active( 2 ).REST.getNetCfg" ) |
| 455 | utilities.retry( f=main.Cluster.active( 2 ).REST.getNetCfg, |
| 456 | retValue=False, |
| 457 | attempts=main.retrytimes, |
| 458 | sleep=main.retrysleep ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 459 | utilities.assert_equals( expect=True, |
| 460 | actual=s4Result, |
| 461 | onpass="Net Cfg added for device s4", |
Ming Yan Shu | db74bf2 | 2016-06-23 14:56:22 -0700 | [diff] [blame] | 462 | onfail="Net Cfg for device s4 not correctly set" ) |
Jeremy Ronquillo | 4cf537d | 2017-06-26 11:20:52 -0700 | [diff] [blame] | 463 | |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 464 | main.netCfg.compareCfg( main, main.gossipTime ) |
| 465 | |
| 466 | def CASE23( self, main ): |
| 467 | """ |
| 468 | Check of devices after all Network Configurations are set |
| 469 | """ |
| 470 | import json |
| 471 | try: |
| 472 | assert main.s1Json, "s1Json not defined" |
| 473 | assert main.s2Json, "s2Json not defined" |
| 474 | except AssertionError: |
| 475 | main.log.exception( "Case Prerequisites not set: " ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 476 | main.cleanAndExit() |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 477 | main.case( "Check Devices after all configurations are set" ) |
| 478 | |
| 479 | main.netCfg.compareCfg( main ) |
| 480 | |
| 481 | main.step( "ONOS should only show devices S1 and S2" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 482 | devices = main.Cluster.active( 0 ).REST.devices() |
| 483 | main.log.debug( main.Cluster.active( 0 ).REST.pprint( devices ) ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 484 | allowedDevices = [ "of:{}".format( str( i ).zfill( 16 ) ) for i in [ 1, 2 ] ] |
| 485 | onosDevices = [] |
Jeremy Songster | 5c3fdb4 | 2016-04-27 12:19:27 -0700 | [diff] [blame] | 486 | try: |
| 487 | for sw in json.loads( devices ): |
| 488 | onosDevices.append( str( sw.get( 'id' ) ) ) |
| 489 | onosDevices.sort() |
| 490 | failMsg = "ONOS devices doesn't match the list of allowed devices.\n" |
| 491 | failMsg += "Expected devices: {}\nActual devices: {}".format( allowedDevices, |
| 492 | onosDevices ) |
| 493 | except( TypeError, ValueError ): |
| 494 | main.log.error( "Problem loading devices" ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 495 | utilities.assert_equals( expect=allowedDevices, |
| 496 | actual=onosDevices, |
| 497 | onpass="Only allowed devices are in ONOS", |
| 498 | onfail=failMsg ) |
| 499 | |
| 500 | main.step( "Check device annotations" ) |
Jeremy Ronquillo | 4cf537d | 2017-06-26 11:20:52 -0700 | [diff] [blame] | 501 | stepResult = utilities.retry( f=main.netCfg.checkAllDeviceAnnotations, |
| 502 | args=( main, json ), |
| 503 | retValue=False, |
| 504 | attempts=main.retrytimes, |
| 505 | sleep=main.retrysleep ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 506 | utilities.assert_equals( expect=True, |
| 507 | actual=stepResult, |
Jeremy Ronquillo | 4cf537d | 2017-06-26 11:20:52 -0700 | [diff] [blame] | 508 | onpass="Configured devices' annotations are correct", |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 509 | onfail="Incorrect annotations for configured devices." ) |
| 510 | |
| 511 | def CASE24( self, main ): |
| 512 | """ |
| 513 | Testing removal of configurations |
| 514 | """ |
Jon Hall | 541b8e0 | 2015-12-14 19:29:01 -0800 | [diff] [blame] | 515 | import time |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 516 | try: |
| 517 | assert main.s1Json, "s1Json not defined" |
| 518 | assert main.s2Json, "s2Json not defined" |
| 519 | assert main.s3Json, "s3Json not defined" |
| 520 | assert main.s4Json, "s4Json not defined" |
| 521 | except AssertionError: |
| 522 | main.log.exception( "Case Prerequisites not set: " ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 523 | main.cleanAndExit() |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 524 | main.case( "Testing removal of configurations" ) |
| 525 | main.step( "Remove 'allowed' configuration from all devices" ) |
| 526 | |
| 527 | s1Json = main.s1Json # NOTE: This is a reference |
| 528 | try: |
Jon Hall | bc080f9 | 2017-05-24 16:29:55 -0700 | [diff] [blame] | 529 | del s1Json[ 'allowed' ] |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 530 | except KeyError: |
| 531 | main.log.exception( "Key not found" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 532 | setS1 = main.Cluster.active( 0 ).REST.setNetCfg( s1Json, |
| 533 | subjectClass="devices", |
| 534 | subjectKey="of:0000000000000001", |
| 535 | configKey="basic" ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 536 | |
| 537 | s2Json = main.s2Json # NOTE: This is a reference |
| 538 | try: |
Jon Hall | 541b8e0 | 2015-12-14 19:29:01 -0800 | [diff] [blame] | 539 | time.sleep( main.gossipTime ) |
Jon Hall | bc080f9 | 2017-05-24 16:29:55 -0700 | [diff] [blame] | 540 | del s2Json[ 'allowed' ] |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 541 | except KeyError: |
| 542 | main.log.exception( "Key not found" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 543 | setS2 = main.Cluster.active( 1 ).REST.setNetCfg( s2Json, |
| 544 | subjectClass="devices", |
| 545 | subjectKey="of:0000000000000002", |
| 546 | configKey="basic" ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 547 | |
| 548 | s3Json = main.s3Json # NOTE: This is a reference |
| 549 | try: |
Jon Hall | 541b8e0 | 2015-12-14 19:29:01 -0800 | [diff] [blame] | 550 | time.sleep( main.gossipTime ) |
Jon Hall | bc080f9 | 2017-05-24 16:29:55 -0700 | [diff] [blame] | 551 | del s3Json[ 'allowed' ] |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 552 | except KeyError: |
| 553 | main.log.exception( "Key not found" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 554 | setS3 = main.Cluster.active( 2 ).REST.setNetCfg( s3Json, |
| 555 | subjectClass="devices", |
| 556 | subjectKey="of:0000000000000003", |
| 557 | configKey="basic" ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 558 | |
| 559 | s4Json = main.s4Json # NOTE: This is a reference |
| 560 | try: |
Jon Hall | 541b8e0 | 2015-12-14 19:29:01 -0800 | [diff] [blame] | 561 | time.sleep( main.gossipTime ) |
Jon Hall | bc080f9 | 2017-05-24 16:29:55 -0700 | [diff] [blame] | 562 | del s4Json[ 'allowed' ] |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 563 | except KeyError: |
| 564 | main.log.exception( "Key not found" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 565 | setS4 = main.Cluster.active( 2 ).REST.setNetCfg( s4Json, |
| 566 | subjectClass="devices", |
| 567 | subjectKey="of:0000000000000004", |
| 568 | configKey="basic" ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 569 | removeAllowed = setS1 and setS2 and setS3 and setS4 |
| 570 | utilities.assert_equals( expect=main.TRUE, |
| 571 | actual=removeAllowed, |
| 572 | onpass="Successfully removed 'allowed' config from devices", |
| 573 | onfail="Failed to remove the 'allowed' config key." ) |
| 574 | |
| 575 | main.netCfg.compareCfg( main, main.gossipTime ) |
| 576 | |
| 577 | main.step( "Delete basic config for s1 and s2" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 578 | removeS1 = main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="devices", |
| 579 | subjectKey="of:0000000000000001", |
| 580 | configKey="basic" ) |
| 581 | removeS2 = main.Cluster.active( 1 ).REST.removeNetCfg( subjectClass="devices", |
| 582 | subjectKey="of:0000000000000002", |
| 583 | configKey="basic" ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 584 | removeSingles = removeS1 and removeS2 |
| 585 | utilities.assert_equals( expect=main.TRUE, |
| 586 | actual=removeSingles, |
| 587 | onpass="Successfully removed S1 and S2 basic config", |
| 588 | onfail="Failed to removed S1 and S2 basic config" ) |
| 589 | |
| 590 | main.netCfg.compareCfg( main, main.gossipTime ) |
| 591 | |
| 592 | main.step( "Delete the net config for S3" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 593 | removeS3 = main.Cluster.active( 2 ).REST.removeNetCfg( subjectClass="devices", |
| 594 | subjectKey="of:0000000000000003" ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 595 | utilities.assert_equals( expect=main.TRUE, |
| 596 | actual=removeS3, |
| 597 | onpass="Successfully removed S3's config", |
| 598 | onfail="Failed to removed S3's config" ) |
| 599 | |
| 600 | main.netCfg.compareCfg( main, main.gossipTime ) |
| 601 | |
| 602 | main.step( "Delete the net config for all devices" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 603 | remove = main.Cluster.active( 2 ).REST.removeNetCfg( subjectClass="devices" ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 604 | utilities.assert_equals( expect=main.TRUE, |
| 605 | actual=remove, |
| 606 | onpass="Successfully removed device config", |
| 607 | onfail="Failed to remove device config" ) |
| 608 | |
| 609 | main.netCfg.compareCfg( main, main.gossipTime ) |
| 610 | |
| 611 | main.step( "Assert the net config for devices is empty" ) |
Jeremy Ronquillo | 4a30ffe | 2017-06-07 11:36:35 -0700 | [diff] [blame] | 612 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 613 | get = utilities.retry( f=main.Cluster.active( 2 ).REST.getNetCfg, |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 614 | retValue=False, |
| 615 | kwargs={ "subjectClass": "devices" }, |
Jeremy Ronquillo | 4a30ffe | 2017-06-07 11:36:35 -0700 | [diff] [blame] | 616 | sleep=main.retrysleep, |
| 617 | attempts=main.retrytimes ) |
| 618 | |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 619 | utilities.assert_equals( expect='{}', |
| 620 | actual=get, |
| 621 | onpass="Successfully removed device config", |
| 622 | onfail="Failed to remove device config" ) |
Jeremy Songster | 2baa44e | 2016-06-10 10:18:40 -0700 | [diff] [blame] | 623 | |
| 624 | def CASE25( self, main ): |
| 625 | """ |
| 626 | Use network-cfg.json to configure devices during ONOS startup |
| 627 | """ |
| 628 | main.case( "Preparing network-cfg.json to load configurations" ) |
| 629 | main.step( "Moving network-cfg.json to $ONOS_ROOT/tools/package/config/" ) |
| 630 | prestartResult = main.TRUE |
| 631 | srcPath = "~/OnosSystemTest/TestON/tests/FUNC/FUNCnetCfg/dependencies/network-cfg.json" |
| 632 | dstPath = "~/onos/tools/package/config/network-cfg.json" |
| 633 | prestartResult = main.ONOSbench.scp( main.ONOSbench, srcPath, dstPath, direction="to" ) |
| 634 | utilities.assert_equals( expect=main.TRUE, |
| 635 | actual=prestartResult, |
| 636 | onpass="Successfully copied network-cfg.json to target directory", |
| 637 | onfail="Failed to copy network-cfg.json to target directory" ) |
| 638 | |
| 639 | def CASE26( self, main ): |
| 640 | """ |
| 641 | Check to see that pre-startup configurations were set correctly |
| 642 | """ |
| 643 | import json |
| 644 | main.case( "Check to see if the pre-startup configurations were set, then remove their allowed status" ) |
| 645 | main.step( "Checking configurations for Switches 5 and 6" ) |
Jon Hall | bc080f9 | 2017-05-24 16:29:55 -0700 | [diff] [blame] | 646 | main.step( "ONOS should only show devices S1, S2, S4, and S5" ) # and S6 |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 647 | devices = main.Cluster.active( 0 ).REST.devices() |
| 648 | main.log.debug( main.Cluster.active( 0 ).REST.pprint( devices ) ) |
Jon Hall | bc080f9 | 2017-05-24 16:29:55 -0700 | [diff] [blame] | 649 | allowedDevices = [ "of:{}".format( str( i ).zfill( 16 ) ) for i in [ 1, 2, 4, 5 ] ] # 6 |
Jeremy Songster | 2baa44e | 2016-06-10 10:18:40 -0700 | [diff] [blame] | 650 | main.log.debug( allowedDevices ) |
| 651 | onosDevices = [] |
| 652 | try: |
| 653 | for sw in json.loads( devices ): |
Jon Hall | bc080f9 | 2017-05-24 16:29:55 -0700 | [diff] [blame] | 654 | onosDevices.append( str( sw[ 'id' ] ) ) |
Jeremy Songster | 2baa44e | 2016-06-10 10:18:40 -0700 | [diff] [blame] | 655 | onosDevices.sort() |
| 656 | main.log.debug( onosDevices ) |
| 657 | except( TypeError, ValueError ): |
| 658 | main.log.error( "Problem loading devices" ) |
| 659 | utilities.assert_equals( expect=allowedDevices, |
| 660 | actual=onosDevices, |
| 661 | onpass="Only allowed devices are in ONOS", |
| 662 | onfail="ONOS devices doesn't match the list" + |
| 663 | " of allowed devices" ) |
| 664 | |
| 665 | main.step( "Removing allowed status from Switches 5 and 6" ) |
Pratik Parab | 6f41863 | 2017-04-25 17:05:50 -0700 | [diff] [blame] | 666 | try: |
| 667 | with open( os.path.dirname( main.testFile ) + '/dependencies/s5Json', 'r' ) as s5Jsondata: |
| 668 | main.s5Json = json.load( s5Jsondata ) |
| 669 | except IOError: |
| 670 | main.log.exception( "s5Json File not found" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 671 | main.cleanAndExit() |
Pratik Parab | 6f41863 | 2017-04-25 17:05:50 -0700 | [diff] [blame] | 672 | main.log.info( "s5Json:" + str( main.s5Json ) ) |
| 673 | |
| 674 | try: |
| 675 | with open( os.path.dirname( main.testFile ) + '/dependencies/s6Json', 'r' ) as s6Jsondata: |
| 676 | main.s6Json = json.load( s6Jsondata ) |
| 677 | except IOError: |
| 678 | main.log.exception( "s6Json File not found" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 679 | main.cleanAndExit() |
Pratik Parab | 6f41863 | 2017-04-25 17:05:50 -0700 | [diff] [blame] | 680 | main.log.info( "s6Json:" + str( main.s6Json ) ) |
| 681 | |
Jeremy Songster | 2baa44e | 2016-06-10 10:18:40 -0700 | [diff] [blame] | 682 | s5Json = main.s5Json |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 683 | setS1 = main.Cluster.active( 0 ).REST.setNetCfg( s5Json, |
| 684 | subjectClass="devices", |
| 685 | subjectKey="of:0000000000000005", |
| 686 | configKey="basic" ) |
Jeremy Songster | 2baa44e | 2016-06-10 10:18:40 -0700 | [diff] [blame] | 687 | |
Jeremy Ronquillo | 9865a4d | 2017-12-07 13:08:27 -0800 | [diff] [blame] | 688 | # Wait 5 secs after set up netCfg |
| 689 | time.sleep( main.SetNetCfgSleep ) |
| 690 | |
Jeremy Songster | 2baa44e | 2016-06-10 10:18:40 -0700 | [diff] [blame] | 691 | s6Json = main.s6Json |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 692 | setS1 = main.Cluster.active( 0 ).REST.setNetCfg( s6Json, |
| 693 | subjectClass="devices", |
| 694 | subjectKey="of:0000000000000006", |
| 695 | configKey="basic" ) |
Ming Yan Shu | db74bf2 | 2016-06-23 14:56:22 -0700 | [diff] [blame] | 696 | |
Jeremy Ronquillo | 9865a4d | 2017-12-07 13:08:27 -0800 | [diff] [blame] | 697 | # Wait 5 secs after set up netCfg |
| 698 | time.sleep( main.SetNetCfgSleep ) |
| 699 | |
Ming Yan Shu | db74bf2 | 2016-06-23 14:56:22 -0700 | [diff] [blame] | 700 | def CASE27( self, main ): |
| 701 | """ |
Jon Hall | bc080f9 | 2017-05-24 16:29:55 -0700 | [diff] [blame] | 702 | 1 ) A = get /network/configuration |
| 703 | 2 ) Post A |
| 704 | 3 ) Compare A with ONOS |
| 705 | 4 ) Modify A so S6 is disallowed |
| 706 | 5 ) Check |
Ming Yan Shu | db74bf2 | 2016-06-23 14:56:22 -0700 | [diff] [blame] | 707 | |
| 708 | """ |
| 709 | import json |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 710 | pprint = main.Cluster.active( 0 ).REST.pprint |
Ming Yan Shu | db74bf2 | 2016-06-23 14:56:22 -0700 | [diff] [blame] | 711 | main.case( "Posting network configurations to the top level web resource" ) |
| 712 | main.step( "Get json object from Net Cfg" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 713 | getinfo = utilities.retry( f=main.Cluster.active( 0 ).REST.getNetCfg, |
Jeremy Ronquillo | 4a30ffe | 2017-06-07 11:36:35 -0700 | [diff] [blame] | 714 | retValue=False, |
| 715 | sleep=main.retrysleep, |
| 716 | attempts=main.retrytimes ) |
| 717 | |
Ming Yan Shu | db74bf2 | 2016-06-23 14:56:22 -0700 | [diff] [blame] | 718 | main.log.debug( getinfo ) |
| 719 | main.step( "Posting json object to Net Cfg" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 720 | postinfo = main.Cluster.active( 0 ).REST.setNetCfg( json.loads( getinfo ) ) |
Ming Yan Shu | db74bf2 | 2016-06-23 14:56:22 -0700 | [diff] [blame] | 721 | main.step( "Compare device with ONOS" ) |
| 722 | main.netCfg.compareCfg( main ) |
Jon Hall | bc080f9 | 2017-05-24 16:29:55 -0700 | [diff] [blame] | 723 | main.step( "ONOS should only show devices S1, S2, S4, S5 and S6" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 724 | devices = main.Cluster.active( 0 ).REST.devices() |
| 725 | main.log.debug( main.Cluster.active( 0 ).REST.pprint( devices ) ) |
Ming Yan Shu | db74bf2 | 2016-06-23 14:56:22 -0700 | [diff] [blame] | 726 | allowedDevices = [ "of:{}".format( str( i ).zfill( 16 ) ) for i in [ 1, 2, 4, 5, 6 ] ] |
| 727 | onosDevices = [] |
| 728 | try: |
| 729 | for sw in json.loads( devices ): |
| 730 | onosDevices.append( str( sw.get( 'id' ) ) ) |
Jon Hall | bc080f9 | 2017-05-24 16:29:55 -0700 | [diff] [blame] | 731 | onosDevices.sort() |
Ming Yan Shu | db74bf2 | 2016-06-23 14:56:22 -0700 | [diff] [blame] | 732 | failMsg = "ONOS devices doesn't match the list of allowed devices. \n" |
| 733 | failMsg += "Expected devices: {}\nActual devices: {}".format( allowedDevices, onosDevices ) |
| 734 | except( TypeError, ValueError ): |
| 735 | main.log.error( "Problem loading devices" ) |
| 736 | utilities.assert_equals( expect=allowedDevices, actual=onosDevices, |
| 737 | onpass="Only allowed devices are in ONOS", onfail=failMsg ) |
| 738 | |
| 739 | main.step( "Modify json object so S6 is disallowed" ) |
| 740 | main.s6Json = { "allowed": False } |
| 741 | s6Json = main.s6Json |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 742 | setS6Disallow = main.Cluster.active( 0 ).REST.setNetCfg( s6Json, |
| 743 | subjectClass="devices", |
| 744 | subjectKey="of:0000000000000006", |
| 745 | configKey="basic" ) |
Ming Yan Shu | db74bf2 | 2016-06-23 14:56:22 -0700 | [diff] [blame] | 746 | s6Result = False |
| 747 | if setS6Disallow: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 748 | getS6 = utilities.retry( f=main.Cluster.active( 0 ).REST.getNetCfg, |
Jeremy Ronquillo | 4a30ffe | 2017-06-07 11:36:35 -0700 | [diff] [blame] | 749 | retValue=False, |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 750 | kwargs={ "subjectClass": "devices", |
| 751 | "subjectKey": "of:0000000000000006", |
| 752 | "configKey": "basic" }, |
Jeremy Ronquillo | 4a30ffe | 2017-06-07 11:36:35 -0700 | [diff] [blame] | 753 | sleep=main.retrysleep, |
| 754 | attempts=main.retrytimes ) |
Ming Yan Shu | db74bf2 | 2016-06-23 14:56:22 -0700 | [diff] [blame] | 755 | onosCfg = pprint( getS6 ) |
| 756 | sentCfg = pprint( s6Json ) |
| 757 | if onosCfg == sentCfg: |
| 758 | s6Result = True |
| 759 | else: |
| 760 | main.log.error( "ONOS NetCfg doesn't match what was sent" ) |
| 761 | main.log.debug( "ONOS config: {}".format( onosCfg ) ) |
| 762 | main.log.debug( "Sent config: {}".format( sentCfg ) ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 763 | utilities.retry( f=main.Cluster.active( 0 ).REST.getNetCfg, |
| 764 | retValue=False, |
| 765 | attempts=main.retrytimes, |
| 766 | sleep=main.retrysleep ) |
Ming Yan Shu | db74bf2 | 2016-06-23 14:56:22 -0700 | [diff] [blame] | 767 | utilities.assert_equals( expect=True, actual=s6Result, |
| 768 | onpass="Net Cfg added for devices s6", |
| 769 | onfail="Net Cfg for device s6 not correctly set" ) |