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