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