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