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