Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 1 | """ |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 2 | Copyright 2016 Open Networking Foundation ( ONF ) |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 3 | |
| 4 | Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 5 | the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 6 | or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg> |
| 7 | |
| 8 | TestON is free software: you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation, either version 2 of the License, or |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 11 | ( at your option ) any later version. |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 12 | |
| 13 | TestON is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with TestON. If not, see <http://www.gnu.org/licenses/>. |
| 20 | """ |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 21 | import os |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 22 | import time |
| 23 | import json |
| 24 | import urllib |
Andreas Pantelopoulos | df5061f | 2018-05-15 11:46:59 -0700 | [diff] [blame] | 25 | import re |
Jon Hall | f6aeda2 | 2020-07-28 09:12:56 -0700 | [diff] [blame] | 26 | import pexpect |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 27 | from core import utilities |
| 28 | |
| 29 | |
| 30 | class Testcaselib: |
Pier | fb719b1 | 2016-09-19 14:51:44 -0700 | [diff] [blame] | 31 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 32 | useSSH = True |
Pier | fb719b1 | 2016-09-19 14:51:44 -0700 | [diff] [blame] | 33 | |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 34 | @staticmethod |
| 35 | def initTest( main ): |
| 36 | """ |
| 37 | - Construct tests variables |
| 38 | - GIT ( optional ) |
| 39 | - Checkout ONOS master branch |
| 40 | - Pull latest ONOS code |
| 41 | - Building ONOS ( optional ) |
| 42 | - Install ONOS package |
| 43 | - Build ONOS package |
| 44 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 45 | try: |
| 46 | from tests.dependencies.ONOSSetup import ONOSSetup |
| 47 | main.testSetUp = ONOSSetup() |
| 48 | except ImportError: |
| 49 | main.log.error( "ONOSSetup not found. exiting the test" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 50 | main.cleanAndExit() |
You Wang | d587348 | 2018-01-24 12:30:00 -0800 | [diff] [blame] | 51 | from tests.dependencies.Network import Network |
Jon Hall | 627b157 | 2020-12-01 12:01:15 -0800 | [diff] [blame] | 52 | main.persistentSetup = main.params.get( "persistent_setup" ) |
You Wang | d587348 | 2018-01-24 12:30:00 -0800 | [diff] [blame] | 53 | main.Network = Network() |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 54 | main.physicalNet = False |
Devin Lim | 0c972b7 | 2018-02-08 14:53:59 -0800 | [diff] [blame] | 55 | main.testSetUp.envSetupDescription( False ) |
Jon Hall | 3957026 | 2020-11-17 12:18:19 -0800 | [diff] [blame] | 56 | main.logdirBase = main.logdir |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 57 | stepResult = main.FALSE |
| 58 | try: |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 59 | # Test variables |
| 60 | main.cellName = main.params[ 'ENV' ][ 'cellName' ] |
| 61 | main.apps = main.params[ 'ENV' ][ 'cellApps' ] |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 62 | main.path = os.path.dirname( main.testFile ) |
Devin Lim | 57221b0 | 2018-02-14 15:45:36 -0800 | [diff] [blame] | 63 | main.useCommonTopo = main.params[ 'DEPENDENCY' ][ 'useCommonTopo' ] == 'True' |
| 64 | main.topoPath = main.path + ( "/.." if main.useCommonTopo else "" ) + "/dependencies/" |
| 65 | main.useCommonConf = main.params[ 'DEPENDENCY' ][ 'useCommonConf' ] == 'True' |
You Wang | 68568b1 | 2019-03-04 11:49:57 -0800 | [diff] [blame] | 66 | if main.params[ 'DEPENDENCY' ].get( 'useBmv2' ): |
| 67 | main.useBmv2 = main.params[ 'DEPENDENCY' ][ 'useBmv2' ] == 'True' |
| 68 | else: |
| 69 | main.useBmv2 = False |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 70 | if main.useBmv2: |
| 71 | main.switchType = main.params[ 'DEPENDENCY' ].get( 'bmv2SwitchType', 'stratum' ) |
| 72 | else: |
| 73 | main.switchType = "ovs" |
| 74 | |
Devin Lim | 57221b0 | 2018-02-14 15:45:36 -0800 | [diff] [blame] | 75 | main.configPath = main.path + ( "/.." if main.useCommonConf else "" ) + "/dependencies/" |
Jon Hall | bc1c1c9 | 2020-05-27 09:29:30 -0700 | [diff] [blame] | 76 | main.bmv2Path = "/tools/dev/mininet/" |
Devin Lim | 57221b0 | 2018-02-14 15:45:36 -0800 | [diff] [blame] | 77 | main.forJson = "json/" |
Siddesh | de1d169 | 2021-09-15 18:12:57 +0000 | [diff] [blame] | 78 | # main.forcfg = "netcfg/" |
Devin Lim | 57221b0 | 2018-02-14 15:45:36 -0800 | [diff] [blame] | 79 | main.forChart = "chart/" |
| 80 | main.forConfig = "conf/" |
| 81 | main.forHost = "host/" |
You Wang | 2731757 | 2018-03-06 12:13:11 -0800 | [diff] [blame] | 82 | main.forSwitchFailure = "switchFailure/" |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 83 | main.forLinkFailure = "linkFailure/" |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 84 | main.forMulticast = "multicast/" |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 85 | main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ] |
You Wang | d87b231 | 2018-01-30 12:47:17 -0800 | [diff] [blame] | 86 | main.topologyLib = main.params[ 'DEPENDENCY' ][ 'lib' ] if 'lib' in main.params[ 'DEPENDENCY' ] else None |
| 87 | main.topologyConf = main.params[ 'DEPENDENCY' ][ 'conf' ] if 'conf' in main.params[ 'DEPENDENCY' ] else None |
You Wang | 68568b1 | 2019-03-04 11:49:57 -0800 | [diff] [blame] | 88 | main.bmv2 = "bmv2.py" |
Jon Hall | dac3eae | 2020-06-05 12:04:06 -0700 | [diff] [blame] | 89 | main.stratumRoot = main.params[ 'DEPENDENCY'][ 'stratumRoot'] if 'stratumRoot' in main.params[ 'DEPENDENCY' ] else None |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 90 | main.scale = ( main.params[ 'SCALE' ][ 'size' ] ).split( "," ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 91 | main.maxNodes = int( main.params[ 'SCALE' ][ 'max' ] ) |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 92 | main.trellisOar = main.params[ 'DEPENDENCY' ][ 'trellisOar' ] if 'trellisOar' in main.params[ 'DEPENDENCY' ] else None |
You Wang | 5bf4959 | 2020-07-08 18:47:46 -0700 | [diff] [blame] | 93 | main.t3Oar = main.params[ 'DEPENDENCY' ][ 't3Oar' ] if 't3Oar' in main.params[ 'DEPENDENCY' ] else None |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 94 | |
Devin Lim | 0c972b7 | 2018-02-08 14:53:59 -0800 | [diff] [blame] | 95 | stepResult = main.testSetUp.envSetup( False ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 96 | except Exception as e: |
| 97 | main.testSetUp.envSetupException( e ) |
Jonghwan Hyun | 3731d6a | 2017-10-19 11:59:31 -0700 | [diff] [blame] | 98 | |
Jon Hall | aa1d9b8 | 2020-07-30 13:49:42 -0700 | [diff] [blame] | 99 | main.testSetUp.envSetupConclusion( stepResult ) |
Jon Hall | 32c90f3 | 2021-06-24 16:32:44 -0700 | [diff] [blame] | 100 | |
Siddesh | 167bc88 | 2021-03-23 21:03:43 +0000 | [diff] [blame] | 101 | @staticmethod |
| 102 | def getTopo(): |
| 103 | topo = dict() |
| 104 | # TODO: Check minFlowCount of leaf for BMv2 switch |
| 105 | # (number of spine switch, number of leaf switch, dual-homed, description, minFlowCount - leaf (OvS), minFlowCount - leaf (BMv2)) |
| 106 | topo[ '0x1' ] = { 'spines': 0,'leaves': 1, 'mininetArgs': "--leaf=1 --spine=0", 'dual-homed': False,'description': 'single ToR','minFlow-OvS': 28,'minFlow-Stratum': 20,'dual-linked': False } |
| 107 | topo[ '0x2' ] = {'spines': 0,'leaves': 2, 'mininetArgs': "--leaf=2 --spine=0", 'dual-homed': True,'description': 'dual-homed ToR','minFlow-OvS': 37,'minFlow-Stratum': 37,'dual-linked': True } |
| 108 | topo[ '2x2' ] = {'spines': 2,'leaves': 2, 'mininetArgs': "--leaf=2 --spine=2", 'dual-homed': False,'description': '2x2 leaf-spine topology','minFlow-OvS': 37,'minFlow-Stratum': 32,'dual-linked': False } |
| 109 | topo[ '2x2 dual-linked' ] = {'spines': 2, 'leaves': 2, 'mininetArgs': "--leaf=2 --spine=2", 'dual-homed': False,'description': '2x2 aether dual-linked','minFlow-OvS': 37,'minFlow-Stratum': 32,'dual-linked': True } |
| 110 | topo[ '2x4' ] = { 'spines':2,'leaves': 4, 'mininetArgs': "--leaf=4 --spine=2",'dual-homed': True,'description': '2x4 dual-homed leaf-spine topology','minFlow-OvS': 53,'minFlow-Stratum': 53, 'dual-linked': False } |
| 111 | topo[ '4x4' ] = {'spines': 4,'leaves': 4, 'dual-homed': True, 'description': '4x4 dual-homed leaf-spine topology','dual-linked': True } |
| 112 | topo[ '2x2staging' ] = { 'spines': 2, 'leaves': 2,'dual-homed': True, 'description': '2x2 leaf-spine topology', 'minFlowOvS': 37, 'minFlow-Stratum': 32 } |
| 113 | return topo |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 114 | @staticmethod |
Andreas Pantelopoulos | 90f0b10 | 2018-02-01 13:21:45 -0800 | [diff] [blame] | 115 | def installOnos( main, vlanCfg=True, skipPackage=False, cliSleep=10, |
| 116 | parallel=True ): |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 117 | """ |
| 118 | - Set up cell |
| 119 | - Create cell file |
| 120 | - Set cell file |
| 121 | - Verify cell file |
| 122 | - Kill ONOS process |
| 123 | - Uninstall ONOS cluster |
| 124 | - Verify ONOS start up |
| 125 | - Install ONOS cluster |
| 126 | - Connect to cli |
| 127 | """ |
Siddesh | 1349297 | 2021-03-12 21:09:32 +0000 | [diff] [blame] | 128 | # Check params file for local repos on external apps. cd to repos, run the build command, potentially move o/p file to a different location |
| 129 | |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 130 | # main.scale[ 0 ] determines the current number of ONOS controller |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 131 | try: |
Jon Hall | 627b157 | 2020-12-01 12:01:15 -0800 | [diff] [blame] | 132 | if not main.persistentSetup and main.params.get( 'EXTERNAL_APPS' ): |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 133 | for app, url in main.params[ 'EXTERNAL_APPS' ].iteritems(): |
Jon Hall | 3957026 | 2020-11-17 12:18:19 -0800 | [diff] [blame] | 134 | main.log.info( "Downloading %s app from %s" % ( app, url ) ) |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 135 | main.ONOSbench.onosFetchApp( url ) |
| 136 | if not main.apps: |
| 137 | main.log.error( "App list is empty" ) |
| 138 | except Exception as e: |
| 139 | main.log.debug( e ) |
| 140 | main.cleanAndExit() |
Jon Hall | 3c91016 | 2018-03-07 14:42:16 -0800 | [diff] [blame] | 141 | main.log.info( "Cluster size: " + str( main.Cluster.numCtrls ) ) |
| 142 | main.log.info( "Cluster ips: " + ', '.join( main.Cluster.getIps() ) ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 143 | main.dynamicHosts = [ 'in1', 'out1' ] |
You Wang | a0f6ff6 | 2018-01-11 15:46:30 -0800 | [diff] [blame] | 144 | main.testSetUp.ONOSSetUp( main.Cluster, newCell=True, cellName=main.cellName, |
Andreas Pantelopoulos | 90f0b10 | 2018-02-01 13:21:45 -0800 | [diff] [blame] | 145 | skipPack=skipPackage, |
| 146 | useSSH=Testcaselib.useSSH, |
Devin Lim | 0c972b7 | 2018-02-08 14:53:59 -0800 | [diff] [blame] | 147 | installParallel=parallel, includeCaseDesc=False ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 148 | ready = utilities.retry( main.Cluster.active( 0 ).CLI.summary, |
You Wang | 5bf4959 | 2020-07-08 18:47:46 -0700 | [diff] [blame] | 149 | [ None, main.FALSE ], |
You Wang | 1cdc5f5 | 2017-12-19 16:47:51 -0800 | [diff] [blame] | 150 | sleep=cliSleep, |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 151 | attempts=10 ) |
| 152 | if ready: |
| 153 | ready = main.TRUE |
| 154 | utilities.assert_equals( expect=main.TRUE, actual=ready, |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 155 | onpass="ONOS summary command succeded", |
| 156 | onfail="ONOS summary command failed" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 157 | if not ready: |
| 158 | main.log.error( "ONOS startup failed!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 159 | main.cleanAndExit() |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 160 | |
You Wang | 5bf4959 | 2020-07-08 18:47:46 -0700 | [diff] [blame] | 161 | # Install segmentrouting and t3 app |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 162 | appInstallResult = main.TRUE |
| 163 | if main.trellisOar: |
| 164 | appInstallResult = appInstallResult and main.ONOSbench.onosAppInstall( main.Cluster.runningNodes[0].ipAddress, main.trellisOar) |
You Wang | 5bf4959 | 2020-07-08 18:47:46 -0700 | [diff] [blame] | 165 | if main.t3Oar: |
| 166 | appInstallResult = appInstallResult and main.ONOSbench.onosAppInstall( main.Cluster.runningNodes[0].ipAddress, main.t3Oar) |
| 167 | utilities.assert_equals( expect=main.TRUE, actual=appInstallResult, |
| 168 | onpass="SR app installation succeded", |
| 169 | onfail="SR app installation failed" ) |
| 170 | if not appInstallResult: |
| 171 | main.cleanAndExit() |
| 172 | |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 173 | # FIXME: move to somewhere else? |
| 174 | switchPrefix = main.params[ 'DEPENDENCY' ].get( 'switchPrefix' ) |
| 175 | # TODO: Support other pipeconfs/making this configurable |
| 176 | if switchPrefix == "tofino": |
| 177 | # It seems to take some time for the pipeconfs to be loaded |
| 178 | ctrl = main.Cluster.next() |
| 179 | for i in range( 120 ): |
| 180 | try: |
| 181 | main.log.debug( "Checking to see if pipeconfs are loaded" ) |
| 182 | output = ctrl.CLI.sendline( "pipeconfs" ) |
| 183 | if "tofino" in output: |
| 184 | main.log.debug( "Took around %s seconds for the pipeconf to be loaded" % i ) |
| 185 | break |
| 186 | time.sleep( 1 ) |
| 187 | except Exception as e: |
| 188 | main.log.error( e ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 189 | |
Jon Hall | 627b157 | 2020-12-01 12:01:15 -0800 | [diff] [blame] | 190 | # Install segmentrouting and t3 app |
| 191 | appInstallResult = main.TRUE |
| 192 | if not main.persistentSetup: |
| 193 | if main.trellisOar: |
| 194 | appInstallResult = appInstallResult and main.ONOSbench.onosAppInstall( main.Cluster.runningNodes[0].ipAddress, main.trellisOar) |
| 195 | if main.t3Oar: |
| 196 | appInstallResult = appInstallResult and main.ONOSbench.onosAppInstall( main.Cluster.runningNodes[0].ipAddress, main.t3Oar) |
| 197 | utilities.assert_equals( expect=main.TRUE, actual=appInstallResult, |
| 198 | onpass="SR app installation succeded", |
| 199 | onfail="SR app installation failed" ) |
| 200 | if not appInstallResult: |
| 201 | main.cleanAndExit() |
| 202 | |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 203 | Testcaselib.setOnosLogLevels( main ) |
| 204 | Testcaselib.setOnosConfig( main ) |
Jon Hall | dac3eae | 2020-06-05 12:04:06 -0700 | [diff] [blame] | 205 | |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 206 | @staticmethod |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 207 | def loadCount( main ): |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 208 | with open( "%s/count/%s.count" % ( main.configPath, main.cfgName ) ) as count: |
| 209 | main.count = json.load( count ) |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 210 | |
| 211 | @staticmethod |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 212 | def loadJson( main, suffix='' ): |
| 213 | with open( "%s%s.json%s" % ( main.configPath + main.forJson, |
| 214 | main.cfgName, suffix ) ) as cfg: |
Devin Lim | 57221b0 | 2018-02-14 15:45:36 -0800 | [diff] [blame] | 215 | main.Cluster.active( 0 ).REST.setNetCfg( json.load( cfg ) ) |
| 216 | |
| 217 | @staticmethod |
Siddesh | 606bd87 | 2021-06-29 23:42:36 +0000 | [diff] [blame] | 218 | def loadNewJson( main, suffix='' ): |
| 219 | returnValue = main.TRUE |
Siddesh | de1d169 | 2021-09-15 18:12:57 +0000 | [diff] [blame] | 220 | with open( "%s%s.json%s" % ( main.configPath + main.forJson, |
Siddesh | 606bd87 | 2021-06-29 23:42:36 +0000 | [diff] [blame] | 221 | main.cfgName, suffix ) ) as cfg: |
| 222 | desiredJSON = json.load ( cfg ) |
| 223 | for device in desiredJSON ["ports"].keys(): |
| 224 | deviceCfg = desiredJSON[ "ports" ][ device ] |
| 225 | currentJSON = main.Cluster.active( 0 ).REST.getNetCfg( subjectClass = "ports", subjectKey = device ) |
| 226 | |
| 227 | currentJSON = json.loads( currentJSON ) |
| 228 | if currentJSON['interfaces'][0]['ips'] != deviceCfg['interfaces'][0]['ips']: |
Siddesh | d984084 | 2021-08-06 19:26:05 +0000 | [diff] [blame] | 229 | currentJSON['interfaces'][0]['ips'] = deviceCfg['interfaces'][0]['ips'] |
Siddesh | 606bd87 | 2021-06-29 23:42:36 +0000 | [diff] [blame] | 230 | data = { 'interfaces': currentJSON['interfaces'] } |
| 231 | A = main.Cluster.active( 0 ).REST.setNetCfg( data , subjectClass = "ports", subjectKey = device ) |
| 232 | returnValue = returnValue and A |
| 233 | currentJSON['interfaces'] = deviceCfg['interfaces'] |
| 234 | data = { 'interfaces': currentJSON['interfaces'] } |
| 235 | B = main.Cluster.active( 0 ).REST.setNetCfg( data , subjectClass = "ports", subjectKey = device ) |
| 236 | returnValue = returnValue and B |
| 237 | return returnValue |
| 238 | |
| 239 | @staticmethod |
Jon Hall | 10e2ab8 | 2020-09-15 17:14:54 -0700 | [diff] [blame] | 240 | def loadXconnects( main, suffix='' ): |
| 241 | with open( "%s%s-xconnects.json%s" % ( main.configPath + main.forJson, |
| 242 | main.cfgName, suffix ) ) as cfg: |
| 243 | for xconnect in json.load( cfg ).get('xconnects'): |
| 244 | main.Cluster.active( 0 ).REST.setXconnectJson( xconnect ) |
| 245 | |
| 246 | @staticmethod |
Devin Lim | 57221b0 | 2018-02-14 15:45:36 -0800 | [diff] [blame] | 247 | def loadChart( main ): |
| 248 | try: |
Jon Hall | 32c90f3 | 2021-06-24 16:32:44 -0700 | [diff] [blame] | 249 | filename = "%s%s.chart" % ( main.configPath + main.forChart, |
| 250 | main.cfgName ) |
| 251 | with open( filename ) as chart: |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 252 | main.pingChart = json.load( chart ) |
Devin Lim | 57221b0 | 2018-02-14 15:45:36 -0800 | [diff] [blame] | 253 | except IOError: |
Jon Hall | 32c90f3 | 2021-06-24 16:32:44 -0700 | [diff] [blame] | 254 | main.log.warn( "No chart file found at %s" % filename ) |
Devin Lim | 57221b0 | 2018-02-14 15:45:36 -0800 | [diff] [blame] | 255 | |
| 256 | @staticmethod |
| 257 | def loadHost( main ): |
| 258 | with open( "%s%s.host" % ( main.configPath + main.forHost, |
| 259 | main.cfgName ) ) as host: |
| 260 | main.expectedHosts = json.load( host ) |
| 261 | |
| 262 | @staticmethod |
You Wang | 2731757 | 2018-03-06 12:13:11 -0800 | [diff] [blame] | 263 | def loadSwitchFailureChart( main ): |
| 264 | with open( "%s%s.switchFailureChart" % ( main.configPath + main.forSwitchFailure, |
| 265 | main.cfgName ) ) as sfc: |
| 266 | main.switchFailureChart = json.load( sfc ) |
| 267 | |
| 268 | @staticmethod |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 269 | def loadLinkFailureChart( main ): |
| 270 | with open( "%s%s.linkFailureChart" % ( main.configPath + main.forLinkFailure, |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 271 | main.cfgName ) ) as lfc: |
| 272 | main.linkFailureChart = json.load( lfc ) |
| 273 | |
| 274 | @staticmethod |
| 275 | def loadMulticastConfig( main ): |
| 276 | with open( "%s%s.multicastConfig" % ( main.configPath + main.forMulticast, |
| 277 | main.cfgName ) ) as cfg: |
| 278 | main.multicastConfig = json.load( cfg ) |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 279 | |
| 280 | @staticmethod |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 281 | def startMininet( main, topology, args="" ): |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 282 | main.log.info( "Copying mininet topology file to mininet machine" ) |
You Wang | d87b231 | 2018-01-30 12:47:17 -0800 | [diff] [blame] | 283 | copyResult = main.ONOSbench.scp( main.Mininet1, |
| 284 | main.topoPath + main.topology, |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 285 | main.Mininet1.home + "custom", |
You Wang | d87b231 | 2018-01-30 12:47:17 -0800 | [diff] [blame] | 286 | direction="to" ) |
| 287 | if main.topologyLib: |
| 288 | for lib in main.topologyLib.split(","): |
| 289 | copyResult = copyResult and main.ONOSbench.scp( main.Mininet1, |
| 290 | main.topoPath + lib, |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 291 | main.Mininet1.home + "custom", |
You Wang | d87b231 | 2018-01-30 12:47:17 -0800 | [diff] [blame] | 292 | direction="to" ) |
| 293 | if main.topologyConf: |
You Wang | a877ea4 | 2018-04-05 15:27:40 -0700 | [diff] [blame] | 294 | import re |
| 295 | controllerIPs = [ ctrl.ipAddress for ctrl in main.Cluster.runningNodes ] |
| 296 | index = 0 |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 297 | destDir = "~/" |
| 298 | if 'MN_DOCKER' in main.params and main.params['MN_DOCKER']['args']: |
| 299 | destDir = "/tmp/mn_conf/" |
| 300 | # Try to ensure the destination exists |
You Wang | d87b231 | 2018-01-30 12:47:17 -0800 | [diff] [blame] | 301 | for conf in main.topologyConf.split(","): |
You Wang | a877ea4 | 2018-04-05 15:27:40 -0700 | [diff] [blame] | 302 | # Update zebra configurations with correct ONOS instance IP |
| 303 | if conf in [ "zebradbgp1.conf", "zebradbgp2.conf" ]: |
| 304 | ip = controllerIPs[ index ] |
| 305 | index = ( index + 1 ) % len( controllerIPs ) |
| 306 | with open( main.configPath + main.forConfig + conf ) as f: |
| 307 | s = f.read() |
| 308 | s = re.sub( r"(fpm connection ip).*(port 2620)", r"\1 " + ip + r" \2", s ) |
| 309 | with open( main.configPath + main.forConfig + conf, "w" ) as f: |
| 310 | f.write( s ) |
You Wang | d87b231 | 2018-01-30 12:47:17 -0800 | [diff] [blame] | 311 | copyResult = copyResult and main.ONOSbench.scp( main.Mininet1, |
Devin Lim | 57221b0 | 2018-02-14 15:45:36 -0800 | [diff] [blame] | 312 | main.configPath + main.forConfig + conf, |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 313 | destDir, |
You Wang | d87b231 | 2018-01-30 12:47:17 -0800 | [diff] [blame] | 314 | direction="to" ) |
You Wang | 68568b1 | 2019-03-04 11:49:57 -0800 | [diff] [blame] | 315 | copyResult = copyResult and main.ONOSbench.scp( main.Mininet1, |
Jon Hall | bc1c1c9 | 2020-05-27 09:29:30 -0700 | [diff] [blame] | 316 | main.ONOSbench.home + main.bmv2Path + main.bmv2, |
You Wang | 68568b1 | 2019-03-04 11:49:57 -0800 | [diff] [blame] | 317 | main.Mininet1.home + "custom", |
| 318 | direction="to" ) |
Jon Hall | 9b0de1f | 2020-08-24 15:38:04 -0700 | [diff] [blame] | 319 | |
| 320 | if 'MN_DOCKER' in main.params and main.params['MN_DOCKER']['args']: |
| 321 | # move the config files into home |
| 322 | main.Mininet1.handle.sendline( "cp config/* . " ) |
| 323 | main.Mininet1.handle.expect( main.Mininet1.Prompt() ) |
| 324 | main.log.debug( main.Mininet1.handle.before + main.Mininet1.handle.after ) |
| 325 | main.Mininet1.handle.sendline( "ls -al " ) |
| 326 | main.Mininet1.handle.expect( main.Mininet1.Prompt() ) |
| 327 | main.log.debug( main.Mininet1.handle.before + main.Mininet1.handle.after ) |
| 328 | |
You Wang | d87b231 | 2018-01-30 12:47:17 -0800 | [diff] [blame] | 329 | stepResult = copyResult |
| 330 | utilities.assert_equals( expect=main.TRUE, |
| 331 | actual=stepResult, |
| 332 | onpass="Successfully copied topo files", |
| 333 | onfail="Failed to copy topo files" ) |
Jon Hall | dac3eae | 2020-06-05 12:04:06 -0700 | [diff] [blame] | 334 | if main.stratumRoot: |
| 335 | main.Mininet1.handle.sendline( "export STRATUM_ROOT=" + str( main.stratumRoot ) ) |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 336 | main.Mininet1.handle.expect( main.Mininet1.Prompt() ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 337 | main.step( "Starting Mininet Topology" ) |
Jonghwan Hyun | 3731d6a | 2017-10-19 11:59:31 -0700 | [diff] [blame] | 338 | arg = "--onos-ip=%s %s" % (",".join([ctrl.ipAddress for ctrl in main.Cluster.runningNodes]), args) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 339 | main.topology = topology |
| 340 | topoResult = main.Mininet1.startNet( |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 341 | topoFile=main.Mininet1.home + "custom/" + main.topology, args=arg ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 342 | stepResult = topoResult |
| 343 | utilities.assert_equals( expect=main.TRUE, |
| 344 | actual=stepResult, |
| 345 | onpass="Successfully loaded topology", |
| 346 | onfail="Failed to load topology" ) |
| 347 | # Exit if topology did not load properly |
| 348 | if not topoResult: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 349 | main.cleanAndExit() |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 350 | if main.useBmv2: |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 351 | main.step( "Configure switches in ONOS" ) |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 352 | # Upload the net-cfg file created for each switch |
| 353 | filename = "onos-netcfg.json" |
| 354 | switchPrefix = main.params[ 'DEPENDENCY' ].get( 'switchPrefix', "bmv2" ) |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 355 | switchNetCfg = main.TRUE |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 356 | for switch in main.Mininet1.getSwitches( switchRegex=r"(StratumBmv2Switch)|(Bmv2Switch)" ).keys(): |
| 357 | path = "/tmp/mn-stratum/%s/" % switch |
| 358 | dstPath = "/tmp/" |
| 359 | dstFileName = "%s-onos-netcfg.json" % switch |
| 360 | main.ONOSbench1.scp( main.Mininet1, |
| 361 | "%s%s" % ( path, filename ), |
| 362 | "%s%s" % ( dstPath, dstFileName ), |
| 363 | "from" ) |
| 364 | main.ONOSbench1.handle.sendline( "sudo sed -i 's/localhost/%s/g' %s%s" % ( main.Mininet1.ip_address, dstPath, dstFileName ) ) |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 365 | main.ONOSbench1.handle.expect( main.ONOSbench1.prompt ) |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 366 | # Configure managementAddress |
| 367 | main.ONOSbench1.handle.sendline( "sudo sed -i 's/localhost/%s/g' %s%s" % ( main.Mininet1.ip_address, dstPath, dstFileName ) ) |
| 368 | main.ONOSbench1.handle.expect( main.ONOSbench1.prompt ) |
| 369 | main.log.debug( main.ONOSbench1.handle.before + main.ONOSbench1.handle.after ) |
| 370 | # Configure device id |
| 371 | main.ONOSbench1.handle.sendline( "sudo sed -i 's/device:%s/device:%s:%s/g' %s%s" % ( switch, switchPrefix, switch, dstPath, dstFileName ) ) |
| 372 | main.ONOSbench1.handle.expect( main.ONOSbench1.prompt ) |
| 373 | main.log.debug( main.ONOSbench1.handle.before + main.ONOSbench1.handle.after ) |
| 374 | # Configure device name |
Jon Hall | 3957026 | 2020-11-17 12:18:19 -0800 | [diff] [blame] | 375 | main.ONOSbench1.handle.sendline( "sudo sed -i '/\"basic\"/a\ \"name\": \"%s:%s\",' %s%s" % ( switchPrefix, switch, dstPath, dstFileName ) ) |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 376 | main.ONOSbench1.handle.expect( main.ONOSbench1.prompt ) |
| 377 | main.log.debug( main.ONOSbench1.handle.before + main.ONOSbench1.handle.after ) |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 378 | node = main.Cluster.active(0) |
| 379 | switchNetCfg = switchNetCfg and node.onosNetCfg( node.server.ip_address, |
| 380 | dstPath, |
| 381 | dstFileName, |
| 382 | user=node.REST.user_name, |
| 383 | password=node.REST.pwd ) |
| 384 | # Stop test if we fail to push switch netcfg |
| 385 | utilities.assert_equals( expect=main.TRUE, |
| 386 | actual=switchNetCfg, |
| 387 | onpass="Successfully pushed switch netcfg", |
| 388 | onfail="Failed to configure switches in onos" ) |
| 389 | if not switchNetCfg: |
| 390 | main.cleanAndExit() |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 391 | # Make sure hosts make some noise |
| 392 | Testcaselib.discoverHosts( main ) |
| 393 | |
| 394 | @staticmethod |
| 395 | def discoverHosts( main ): |
| 396 | # TODO add option to only select specific hosts |
| 397 | if hasattr( main, "Mininet1" ): |
| 398 | network = main.Mininet1 |
| 399 | elif hasattr( main, "NetworkBench" ): |
| 400 | network = main.NetworkBench |
| 401 | else: |
| 402 | main.log.warn( "Could not find component for test network, skipping host discovery" ) |
| 403 | return |
| 404 | network.discoverHosts() |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 405 | |
| 406 | @staticmethod |
Jon Hall | 06fd0df | 2021-01-25 15:50:06 -0800 | [diff] [blame] | 407 | def connectToPhysicalNetwork( main, hostDiscovery=True ): |
You Wang | 84f981d | 2018-01-12 16:11:50 -0800 | [diff] [blame] | 408 | main.step( "Connecting to physical netowrk" ) |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 409 | main.physicalNet = True |
You Wang | 84f981d | 2018-01-12 16:11:50 -0800 | [diff] [blame] | 410 | topoResult = main.NetworkBench.connectToNet() |
| 411 | stepResult = topoResult |
| 412 | utilities.assert_equals( expect=main.TRUE, |
| 413 | actual=stepResult, |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 414 | onpass="Successfully connected to topology", |
| 415 | onfail="Failed to connect to topology" ) |
You Wang | 84f981d | 2018-01-12 16:11:50 -0800 | [diff] [blame] | 416 | # Exit if topology did not load properly |
| 417 | if not topoResult: |
| 418 | main.cleanAndExit() |
| 419 | |
Jon Hall | 627b157 | 2020-12-01 12:01:15 -0800 | [diff] [blame] | 420 | if not main.persistentSetup: |
| 421 | # Perform any optional setup |
| 422 | for switch in main.NetworkBench.switches: |
| 423 | if hasattr( switch, "setup" ): |
| 424 | switch.setup() # We might not need this |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 425 | |
Jon Hall | 627b157 | 2020-12-01 12:01:15 -0800 | [diff] [blame] | 426 | main.step( "Assign switches to controllers." ) |
| 427 | stepResult = main.TRUE |
| 428 | switches = main.NetworkBench.getSwitches() |
| 429 | pool = [] |
| 430 | for name in switches.keys(): |
| 431 | # NOTE: although this terminology is ovsdb centric, we can use this function for other switches too |
| 432 | # e.g. push onos net-cfg for stratum switches |
| 433 | thread = main.Thread( target=main.NetworkBench.assignSwController, |
| 434 | name="assignSwitchToController", |
| 435 | args=[ name, main.Cluster.getIps(), '6653' ] ) |
| 436 | pool.append( thread ) |
| 437 | thread.start() |
| 438 | for thread in pool: |
| 439 | thread.join( 300 ) |
| 440 | if not thread.result: |
| 441 | stepResult = main.FALSE |
| 442 | utilities.assert_equals( expect=main.TRUE, |
| 443 | actual=stepResult, |
| 444 | onpass="Successfully assign switches to controllers", |
| 445 | onfail="Failed to assign switches to controllers" ) |
You Wang | 84f981d | 2018-01-12 16:11:50 -0800 | [diff] [blame] | 446 | |
You Wang | 4cc6191 | 2018-08-28 10:10:58 -0700 | [diff] [blame] | 447 | # Check devices |
| 448 | Testcaselib.checkDevices( main, switches=int( main.params[ 'TOPO' ][ 'switchNum' ] ) ) |
You Wang | 4cc6191 | 2018-08-28 10:10:58 -0700 | [diff] [blame] | 449 | # Connecting to hosts that only have data plane connectivity |
| 450 | main.step( "Connecting inband hosts" ) |
| 451 | stepResult = main.Network.connectInbandHosts() |
| 452 | utilities.assert_equals( expect=main.TRUE, |
| 453 | actual=stepResult, |
| 454 | onpass="Successfully connected inband hosts", |
| 455 | onfail="Failed to connect inband hosts" ) |
Jon Hall | 06fd0df | 2021-01-25 15:50:06 -0800 | [diff] [blame] | 456 | if hostDiscovery: |
| 457 | Testcaselib.discoverHosts( main ) |
You Wang | 4cc6191 | 2018-08-28 10:10:58 -0700 | [diff] [blame] | 458 | |
You Wang | 84f981d | 2018-01-12 16:11:50 -0800 | [diff] [blame] | 459 | @staticmethod |
You Wang | 5df1c6d | 2018-04-06 18:02:02 -0700 | [diff] [blame] | 460 | def saveOnosDiagnostics( main ): |
| 461 | """ |
| 462 | Get onos-diags.tar.gz and save it to the log directory. |
| 463 | suffix: suffix string of the file name. E.g. onos-diags-case1.tar.gz |
| 464 | """ |
| 465 | main.log.info( "Collecting onos-diags..." ) |
Siddesh | a2938fe | 2021-04-06 02:46:06 +0000 | [diff] [blame] | 466 | for ctrl in main.Cluster.runningNodes: |
| 467 | main.ONOSbench.onosDiagnostics( [ctrl.ipAddress], main.logdir,"-CASE%d" % main.CurrentTestCaseNumber, onosPortnumber=ctrl.REST.port ) |
You Wang | 5df1c6d | 2018-04-06 18:02:02 -0700 | [diff] [blame] | 468 | |
| 469 | @staticmethod |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 470 | def config( main, cfgName ): |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 471 | main.spines = [] |
Pier | a2a7e1b | 2016-10-04 11:51:43 -0700 | [diff] [blame] | 472 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 473 | main.failures = int( main.params[ 'failures' ] ) |
| 474 | main.cfgName = cfgName |
Pier | a2a7e1b | 2016-10-04 11:51:43 -0700 | [diff] [blame] | 475 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 476 | if main.cfgName == '2x2': |
| 477 | spine = {} |
| 478 | spine[ 'name' ] = main.params[ 'switches' ][ 'spine1' ] |
| 479 | spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid1' ] |
| 480 | main.spines.append( spine ) |
Pier | a2a7e1b | 2016-10-04 11:51:43 -0700 | [diff] [blame] | 481 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 482 | spine = {} |
| 483 | spine[ 'name' ] = main.params[ 'switches' ][ 'spine2' ] |
| 484 | spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid2' ] |
| 485 | main.spines.append( spine ) |
Pier | a2a7e1b | 2016-10-04 11:51:43 -0700 | [diff] [blame] | 486 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 487 | elif main.cfgName == '4x4': |
| 488 | spine = {} |
| 489 | spine[ 'name' ] = main.params[ 'switches' ][ 'spine1' ] |
| 490 | spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid1' ] |
| 491 | main.spines.append( spine ) |
Pier | a2a7e1b | 2016-10-04 11:51:43 -0700 | [diff] [blame] | 492 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 493 | spine = {} |
| 494 | spine[ 'name' ] = main.params[ 'switches' ][ 'spine2' ] |
| 495 | spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid2' ] |
| 496 | main.spines.append( spine ) |
Pier | a2a7e1b | 2016-10-04 11:51:43 -0700 | [diff] [blame] | 497 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 498 | spine = {} |
| 499 | spine[ 'name' ] = main.params[ 'switches' ][ 'spine3' ] |
| 500 | spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid3' ] |
| 501 | main.spines.append( spine ) |
Pier | a2a7e1b | 2016-10-04 11:51:43 -0700 | [diff] [blame] | 502 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 503 | spine = {} |
| 504 | spine[ 'name' ] = main.params[ 'switches' ][ 'spine4' ] |
| 505 | spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid4' ] |
| 506 | main.spines.append( spine ) |
Pier | a2a7e1b | 2016-10-04 11:51:43 -0700 | [diff] [blame] | 507 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 508 | else: |
Pier | a2a7e1b | 2016-10-04 11:51:43 -0700 | [diff] [blame] | 509 | main.log.error( "Configuration failed!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 510 | main.cleanAndExit() |
You Wang | 2731757 | 2018-03-06 12:13:11 -0800 | [diff] [blame] | 511 | |
Andreas Pantelopoulos | 2eae324 | 2018-03-06 13:47:20 -0800 | [diff] [blame] | 512 | @staticmethod |
| 513 | def addStaticOnosRoute( main, subnet, intf): |
| 514 | """ |
| 515 | Adds an ONOS static route with the use route-add command. |
| 516 | """ |
Andreas Pantelopoulos | 2eae324 | 2018-03-06 13:47:20 -0800 | [diff] [blame] | 517 | routeResult = main.Cluster.active( 0 ).addStaticRoute(subnet, intf) |
| 518 | |
Pier | a2a7e1b | 2016-10-04 11:51:43 -0700 | [diff] [blame] | 519 | @staticmethod |
You Wang | c02f3be | 2018-05-18 12:14:23 -0700 | [diff] [blame] | 520 | def checkGroupsForBuckets( main, deviceId, subnetDict, routingTable=30 ): |
Andreas Pantelopoulos | df5061f | 2018-05-15 11:46:59 -0700 | [diff] [blame] | 521 | """ |
| 522 | Check number of groups for each subnet on device deviceId and matches |
| 523 | it with an expected value. subnetDict is a dictionarty containing values |
| 524 | of the type "10.0.1.0/24" : 5. |
| 525 | """ |
You Wang | c02f3be | 2018-05-18 12:14:23 -0700 | [diff] [blame] | 526 | main.step( "Checking if number of groups for subnets in device {0} is as expected.".format( deviceId ) ) |
| 527 | groups = main.Cluster.active( 0 ).CLI.getGroups( deviceId, groupType="select" ) |
| 528 | flows = main.Cluster.active( 0 ).CLI.flows( jsonFormat=False, device=deviceId ) |
Andreas Pantelopoulos | df5061f | 2018-05-15 11:46:59 -0700 | [diff] [blame] | 529 | |
You Wang | c02f3be | 2018-05-18 12:14:23 -0700 | [diff] [blame] | 530 | result = main.TRUE |
| 531 | for subnet, numberInSelect in subnetDict.iteritems(): |
Andreas Pantelopoulos | df5061f | 2018-05-15 11:46:59 -0700 | [diff] [blame] | 532 | for flow in flows.splitlines(): |
You Wang | c02f3be | 2018-05-18 12:14:23 -0700 | [diff] [blame] | 533 | if "tableId={0}".format( routingTable ) in flow and subnet in flow: |
Andreas Pantelopoulos | df5061f | 2018-05-15 11:46:59 -0700 | [diff] [blame] | 534 | # this will match the group id that this flow entry points to, for example : |
| 535 | # 0x70000041 in flow entry which contains "deferred=[GROUP:0x70000041], transition=TABLE:60," |
You Wang | c02f3be | 2018-05-18 12:14:23 -0700 | [diff] [blame] | 536 | groupId = re.search( r".*GROUP:(0x.*)], transition.*", flow ).groups()[0] |
Andreas Pantelopoulos | df5061f | 2018-05-15 11:46:59 -0700 | [diff] [blame] | 537 | count = 0 |
| 538 | for group in groups.splitlines(): |
You Wang | c02f3be | 2018-05-18 12:14:23 -0700 | [diff] [blame] | 539 | if 'id={0}'.format( groupId ) in group: |
Andreas Pantelopoulos | df5061f | 2018-05-15 11:46:59 -0700 | [diff] [blame] | 540 | count += 1 |
You Wang | c02f3be | 2018-05-18 12:14:23 -0700 | [diff] [blame] | 541 | if count - 1 != numberInSelect: |
| 542 | result = main.FALSE |
| 543 | main.log.warn( "Mismatch in number of buckets of select group, found {0}, expected {1} for subnet {2} on device {3}".format( count - 1, numberInSelect, subnet, deviceId ) ) |
| 544 | utilities.assert_equals( expect=main.TRUE, actual=result, |
| 545 | onpass="All bucket numbers are as expected", |
| 546 | onfail="Some bucket numbers are not as expected" ) |
Andreas Pantelopoulos | df5061f | 2018-05-15 11:46:59 -0700 | [diff] [blame] | 547 | |
| 548 | @staticmethod |
Jon Hall | 32c90f3 | 2021-06-24 16:32:44 -0700 | [diff] [blame] | 549 | def checkFlows( main, minFlowCount, tag="", dumpFlows=True, sleep=10 ): |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 550 | main.step( |
Jon Hall | 3957026 | 2020-11-17 12:18:19 -0800 | [diff] [blame] | 551 | "Check whether the flow count is >= %s" % minFlowCount ) |
Jonghwan Hyun | 76a02b7 | 2018-01-30 16:40:48 +0900 | [diff] [blame] | 552 | if tag == "": |
| 553 | tag = 'CASE%d' % main.CurrentTestCaseNumber |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 554 | count = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowCount, |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 555 | main.FALSE, |
| 556 | kwargs={ 'min': minFlowCount }, |
| 557 | attempts=10, |
You Wang | 1cdc5f5 | 2017-12-19 16:47:51 -0800 | [diff] [blame] | 558 | sleep=sleep ) |
steven30801 | eccfe21 | 2019-01-24 13:00:42 +0800 | [diff] [blame] | 559 | if count == main.FALSE: |
| 560 | count = main.Cluster.active( 0 ).CLI.checkFlowCount() |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 561 | utilities.assertEquals( |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 562 | expect=True, |
Jon Hall | 3957026 | 2020-11-17 12:18:19 -0800 | [diff] [blame] | 563 | actual=( count >= minFlowCount ), |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 564 | onpass="Flow count looks correct; found %s, expecting at least %s" % ( count, minFlowCount ), |
| 565 | onfail="Flow count looks wrong; found %s, expecting at least %s" % ( count, minFlowCount ) ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 566 | |
| 567 | main.step( "Check whether all flow status are ADDED" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 568 | flowCheck = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowsState, |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 569 | main.FALSE, |
| 570 | kwargs={ 'isPENDING': False }, |
Jonghwan Hyun | 98fb40a | 2018-01-04 16:16:28 -0800 | [diff] [blame] | 571 | attempts=5, |
You Wang | 1cdc5f5 | 2017-12-19 16:47:51 -0800 | [diff] [blame] | 572 | sleep=sleep ) |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 573 | utilities.assertEquals( |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 574 | expect=main.TRUE, |
| 575 | actual=flowCheck, |
| 576 | onpass="Flow status is correct!", |
| 577 | onfail="Flow status is wrong!" ) |
Jon Hall | 32c90f3 | 2021-06-24 16:32:44 -0700 | [diff] [blame] | 578 | if dumpFlows: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 579 | main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress, |
Pier | 50f0bc6 | 2016-09-07 17:53:40 -0700 | [diff] [blame] | 580 | "flows", |
| 581 | main.logdir, |
Jon Hall | 06fd0df | 2021-01-25 15:50:06 -0800 | [diff] [blame] | 582 | tag + "_FlowsBefore", |
| 583 | cliPort=main.Cluster.active(0).CLI.karafPort ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 584 | main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress, |
Pier | 50f0bc6 | 2016-09-07 17:53:40 -0700 | [diff] [blame] | 585 | "groups", |
| 586 | main.logdir, |
Jon Hall | 06fd0df | 2021-01-25 15:50:06 -0800 | [diff] [blame] | 587 | tag + "_GroupsBefore", |
| 588 | cliPort=main.Cluster.active(0).CLI.karafPort ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 589 | |
| 590 | @staticmethod |
Pier | 6a0c4de | 2018-03-18 16:01:30 -0700 | [diff] [blame] | 591 | def checkDevices( main, switches, tag="", sleep=10 ): |
| 592 | main.step( |
| 593 | "Check whether the switches count is equal to %s" % switches ) |
| 594 | if tag == "": |
| 595 | tag = 'CASE%d' % main.CurrentTestCaseNumber |
| 596 | result = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus, |
| 597 | main.FALSE, |
| 598 | kwargs={ 'numoswitch': switches}, |
| 599 | attempts=10, |
| 600 | sleep=sleep ) |
| 601 | utilities.assert_equals( expect=main.TRUE, actual=result, |
| 602 | onpass="Device up successful", |
| 603 | onfail="Failed to boot up devices?" ) |
| 604 | |
| 605 | @staticmethod |
Jonghwan Hyun | 98fb40a | 2018-01-04 16:16:28 -0800 | [diff] [blame] | 606 | def checkFlowsByDpid( main, dpid, minFlowCount, sleep=10 ): |
| 607 | main.step( |
Jon Hall | 3957026 | 2020-11-17 12:18:19 -0800 | [diff] [blame] | 608 | "Check whether the flow count of device %s >= than %s" % ( dpid, minFlowCount ) ) |
Jonghwan Hyun | cf2345c | 2018-02-26 11:07:54 -0800 | [diff] [blame] | 609 | count = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowAddedCount, |
| 610 | main.FALSE, |
| 611 | args=( dpid, minFlowCount ), |
Jonghwan Hyun | 98fb40a | 2018-01-04 16:16:28 -0800 | [diff] [blame] | 612 | attempts=5, |
| 613 | sleep=sleep ) |
steven30801 | eccfe21 | 2019-01-24 13:00:42 +0800 | [diff] [blame] | 614 | if count == main.FALSE: |
| 615 | count = main.Cluster.active( 0 ).CLI.checkFlowAddedCount( dpid ) |
Jonghwan Hyun | 98fb40a | 2018-01-04 16:16:28 -0800 | [diff] [blame] | 616 | utilities.assertEquals( |
Jonghwan Hyun | cf2345c | 2018-02-26 11:07:54 -0800 | [diff] [blame] | 617 | expect=True, |
Jon Hall | 3957026 | 2020-11-17 12:18:19 -0800 | [diff] [blame] | 618 | actual=( count >= minFlowCount ), |
Jonghwan Hyun | cf2345c | 2018-02-26 11:07:54 -0800 | [diff] [blame] | 619 | onpass="Flow count looks correct: " + str( count ), |
steven30801 | eccfe21 | 2019-01-24 13:00:42 +0800 | [diff] [blame] | 620 | onfail="Flow count looks wrong: " + str( count ) ) |
Jonghwan Hyun | 98fb40a | 2018-01-04 16:16:28 -0800 | [diff] [blame] | 621 | |
| 622 | @staticmethod |
Jon Hall | 9677ed3 | 2018-04-24 11:16:23 -0700 | [diff] [blame] | 623 | def checkFlowEqualityByDpid( main, dpid, flowCount, sleep=10 ): |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 624 | main.step( |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 625 | "Check whether the flow count of device %s is equal to %s" % ( dpid, flowCount ) ) |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 626 | count = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowAddedCount, |
| 627 | main.FALSE, |
Jon Hall | 9677ed3 | 2018-04-24 11:16:23 -0700 | [diff] [blame] | 628 | args=( dpid, flowCount, False, 1 ), |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 629 | attempts=5, |
| 630 | sleep=sleep ) |
steven30801 | eccfe21 | 2019-01-24 13:00:42 +0800 | [diff] [blame] | 631 | if count == main.FALSE: |
| 632 | count = main.Cluster.active( 0 ).CLI.checkFlowAddedCount( dpid ) |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 633 | utilities.assertEquals( |
| 634 | expect=True, |
steven30801 | eccfe21 | 2019-01-24 13:00:42 +0800 | [diff] [blame] | 635 | actual=( count == flowCount ), |
Jon Hall | 9677ed3 | 2018-04-24 11:16:23 -0700 | [diff] [blame] | 636 | onpass="Flow count looks correct: " + str( count ) , |
| 637 | onfail="Flow count looks wrong. found {}, should be {}.".format( count, flowCount ) ) |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 638 | |
| 639 | @staticmethod |
| 640 | def checkGroupEqualityByDpid( main, dpid, groupCount, sleep=10): |
| 641 | main.step( |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 642 | "Check whether the group count of device %s is equal to %s" % ( dpid, groupCount ) ) |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 643 | count = utilities.retry( main.Cluster.active( 0 ).CLI.checkGroupAddedCount, |
| 644 | main.FALSE, |
| 645 | args=( dpid, groupCount, False, 1), |
| 646 | attempts=5, |
| 647 | sleep=sleep ) |
steven30801 | eccfe21 | 2019-01-24 13:00:42 +0800 | [diff] [blame] | 648 | if count == main.FALSE: |
steven30801 | 2399797 | 2019-01-29 17:01:40 +0800 | [diff] [blame] | 649 | count = main.Cluster.active( 0 ).CLI.checkGroupAddedCount( dpid ) |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 650 | utilities.assertEquals( |
| 651 | expect=True, |
| 652 | actual=( count == groupCount ), |
Jon Hall | 9677ed3 | 2018-04-24 11:16:23 -0700 | [diff] [blame] | 653 | onpass="Group count looks correct: " + str( count ) , |
| 654 | onfail="Group count looks wrong. found {}, should be {}.".format( count, groupCount ) ) |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 655 | |
| 656 | @staticmethod |
Jon Hall | 9677ed3 | 2018-04-24 11:16:23 -0700 | [diff] [blame] | 657 | def checkFlowsGroupsFromFile( main ): |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 658 | |
| 659 | for dpid, values in main.count.items(): |
| 660 | flowCount = values["flows"] |
| 661 | groupCount = values["groups"] |
Jon Hall | 9677ed3 | 2018-04-24 11:16:23 -0700 | [diff] [blame] | 662 | main.log.report( "Check flow count for dpid " + str( dpid ) + |
| 663 | ", should be " + str( flowCount ) ) |
| 664 | Testcaselib.checkFlowEqualityByDpid( main, dpid, flowCount ) |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 665 | |
Jon Hall | 9677ed3 | 2018-04-24 11:16:23 -0700 | [diff] [blame] | 666 | main.log.report( "Check group count for dpid " + str( dpid ) + |
| 667 | ", should be " + str( groupCount ) ) |
| 668 | Testcaselib.checkGroupEqualityByDpid( main, dpid, groupCount ) |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 669 | |
| 670 | return |
| 671 | |
| 672 | @staticmethod |
Jon Hall | 32c90f3 | 2021-06-24 16:32:44 -0700 | [diff] [blame] | 673 | def pingAll( main, tag="", dumpFlows=True, acceptableFailed=0, basedOnIp=False, |
Jon Hall | 06fd0df | 2021-01-25 15:50:06 -0800 | [diff] [blame] | 674 | sleep=10, retryAttempts=1, skipOnFail=False, useScapy=True ): |
You Wang | f19d9f4 | 2018-02-23 16:34:19 -0800 | [diff] [blame] | 675 | ''' |
You Wang | ba231e7 | 2018-03-01 13:18:21 -0800 | [diff] [blame] | 676 | Verify connectivity between hosts according to the ping chart |
| 677 | acceptableFailed: max number of acceptable failed pings. |
You Wang | f19d9f4 | 2018-02-23 16:34:19 -0800 | [diff] [blame] | 678 | basedOnIp: if True, run ping or ping6 based on suffix of host names |
Jonghwan Hyun | 812c70f | 2018-02-16 16:33:16 -0800 | [diff] [blame] | 679 | retryAttempts: the number of retry ping. Only works for IPv4 hosts. |
You Wang | f19d9f4 | 2018-02-23 16:34:19 -0800 | [diff] [blame] | 680 | ''' |
You Wang | ba231e7 | 2018-03-01 13:18:21 -0800 | [diff] [blame] | 681 | main.log.report( "Check host connectivity" ) |
| 682 | main.log.debug( "Ping chart: %s" % main.pingChart ) |
Andreas Pantelopoulos | f6ed501 | 2018-02-08 21:26:01 -0800 | [diff] [blame] | 683 | if tag == "": |
| 684 | tag = 'CASE%d' % main.CurrentTestCaseNumber |
| 685 | for entry in main.pingChart.itervalues(): |
You Wang | ba231e7 | 2018-03-01 13:18:21 -0800 | [diff] [blame] | 686 | main.log.debug( "Entry in ping chart: %s" % entry ) |
| 687 | expect = entry[ 'expect' ] |
| 688 | if expect == "Unidirectional": |
| 689 | # Verify ping from each src host to each dst host |
| 690 | src = entry[ 'src' ] |
| 691 | dst = entry[ 'dst' ] |
| 692 | expect = main.TRUE |
| 693 | main.step( "Verify unidirectional connectivity from %s to %s with tag %s" % ( str( src ), str( dst ), tag ) ) |
| 694 | if basedOnIp: |
| 695 | if ("v4" in src[0]): |
| 696 | pa = main.Network.pingallHostsUnidirectional( src, dst, acceptableFailed=acceptableFailed ) |
| 697 | utilities.assert_equals( expect=expect, actual=pa, |
| 698 | onpass="IPv4 connectivity successfully tested", |
| 699 | onfail="IPv4 connectivity failed" ) |
| 700 | if ("v6" in src[0]): |
| 701 | pa = main.Network.pingallHostsUnidirectional( src, dst, ipv6=True, acceptableFailed=acceptableFailed ) |
| 702 | utilities.assert_equals( expect=expect, actual=pa, |
| 703 | onpass="IPv6 connectivity successfully tested", |
| 704 | onfail="IPv6 connectivity failed" ) |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 705 | elif main.physicalNet: |
| 706 | pa = main.NetworkBench.pingallHostsUnidirectional( src, dst, acceptableFailed=acceptableFailed, useScapy=True ) |
| 707 | utilities.assert_equals( expect=expect, actual=pa, |
| 708 | onpass="IP connectivity successfully tested", |
| 709 | onfail="IP connectivity failed" ) |
| 710 | |
You Wang | ba231e7 | 2018-03-01 13:18:21 -0800 | [diff] [blame] | 711 | else: |
| 712 | pa = main.Network.pingallHostsUnidirectional( src, dst, acceptableFailed=acceptableFailed ) |
| 713 | utilities.assert_equals( expect=expect, actual=pa, |
| 714 | onpass="IP connectivity successfully tested", |
| 715 | onfail="IP connectivity failed" ) |
| 716 | else: |
| 717 | # Verify ping between each host pair |
| 718 | hosts = entry[ 'hosts' ] |
| 719 | try: |
| 720 | expect = main.TRUE if str(expect).lower() == 'true' else main.FALSE |
| 721 | except: |
| 722 | expect = main.FALSE |
| 723 | main.step( "Verify full connectivity for %s with tag %s" % ( str( hosts ), tag ) ) |
| 724 | if basedOnIp: |
| 725 | if ("v4" in hosts[0]): |
Jonghwan Hyun | 812c70f | 2018-02-16 16:33:16 -0800 | [diff] [blame] | 726 | pa = utilities.retry( main.Network.pingallHosts, |
| 727 | main.FALSE if expect else main.TRUE, |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 728 | args=(hosts, ), |
| 729 | kwargs={ 'ipv6': False }, |
Jonghwan Hyun | 812c70f | 2018-02-16 16:33:16 -0800 | [diff] [blame] | 730 | attempts=retryAttempts, |
| 731 | sleep=sleep ) |
You Wang | ba231e7 | 2018-03-01 13:18:21 -0800 | [diff] [blame] | 732 | utilities.assert_equals( expect=expect, actual=pa, |
| 733 | onpass="IPv4 connectivity successfully tested", |
| 734 | onfail="IPv4 connectivity failed" ) |
| 735 | if ("v6" in hosts[0]): |
| 736 | pa = main.Network.pingIpv6Hosts( hosts, acceptableFailed=acceptableFailed ) |
| 737 | utilities.assert_equals( expect=expect, actual=pa, |
| 738 | onpass="IPv6 connectivity successfully tested", |
| 739 | onfail="IPv6 connectivity failed" ) |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 740 | elif main.physicalNet: |
Jon Hall | 06fd0df | 2021-01-25 15:50:06 -0800 | [diff] [blame] | 741 | pa = main.Network.pingallHosts( hosts, ipv6=True, useScapy=useScapy ) |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 742 | utilities.assert_equals( expect=expect, actual=pa, |
| 743 | onpass="IP connectivity successfully tested", |
| 744 | onfail="IP connectivity failed" ) |
You Wang | ba231e7 | 2018-03-01 13:18:21 -0800 | [diff] [blame] | 745 | else: |
You Wang | f19d9f4 | 2018-02-23 16:34:19 -0800 | [diff] [blame] | 746 | pa = main.Network.pingallHosts( hosts ) |
| 747 | utilities.assert_equals( expect=expect, actual=pa, |
You Wang | ba231e7 | 2018-03-01 13:18:21 -0800 | [diff] [blame] | 748 | onpass="IP connectivity successfully tested", |
| 749 | onfail="IP connectivity failed" ) |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 750 | if pa != expect: |
You Wang | 5df1c6d | 2018-04-06 18:02:02 -0700 | [diff] [blame] | 751 | Testcaselib.saveOnosDiagnostics( main ) |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 752 | if skipOnFail and pa != expect: |
You Wang | 24ad2f5 | 2018-04-10 10:47:12 -0700 | [diff] [blame] | 753 | Testcaselib.cleanup( main, copyKarafLog=False ) |
You Wang | 5df1c6d | 2018-04-06 18:02:02 -0700 | [diff] [blame] | 754 | main.skipCase() |
Andreas Pantelopoulos | f6ed501 | 2018-02-08 21:26:01 -0800 | [diff] [blame] | 755 | |
Jon Hall | 32c90f3 | 2021-06-24 16:32:44 -0700 | [diff] [blame] | 756 | if dumpFlows: |
| 757 | main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress, |
| 758 | "flows", |
| 759 | main.logdir, |
| 760 | tag + "_FlowsOn", |
| 761 | cliPort=main.Cluster.active(0).CLI.karafPort ) |
| 762 | main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress, |
| 763 | "groups", |
| 764 | main.logdir, |
| 765 | tag + "_GroupsOn", |
| 766 | cliPort=main.Cluster.active(0).CLI.karafPort ) |
| 767 | |
| 768 | @staticmethod |
| 769 | def pingAllFabricIntfs( main, srcList, tag="", dumpFlows=True, skipOnFail=False ): |
| 770 | ''' |
| 771 | Verify connectivity between hosts and their fabric interfaces |
| 772 | ''' |
| 773 | main.log.report( "Check host connectivity with fabric" ) |
| 774 | if tag == "": |
| 775 | tag = 'CASE%d' % main.CurrentTestCaseNumber |
| 776 | expect = main.TRUE |
| 777 | import json |
| 778 | import re |
| 779 | hostsJson = json.loads( main.Cluster.active( 0 ).hosts() ) |
| 780 | netcfgJson = json.loads( main.Cluster.active( 0 ).getNetCfg( subjectClass='ports') ) |
| 781 | for hostname in srcList: |
| 782 | try: |
| 783 | hostComponent = main.Network.hosts[ str( hostname ) ] |
| 784 | srcIface = hostComponent.interfaces[0].get( 'name' ) |
| 785 | main.step( "Verify fabric connectivity for %s with tag %s" % ( str( hostname ), tag ) ) |
| 786 | #Get host location, check netcfg for that port's ip |
| 787 | hostIp = hostComponent.getIPAddress( iface=srcIface ) |
| 788 | main.log.warn( "Looking for %s" % hostIp ) |
| 789 | ips = [] |
| 790 | for obj in hostsJson: |
| 791 | if hostIp in obj['ipAddresses']: |
| 792 | for location in obj['locations']: |
| 793 | main.log.debug( location ) |
| 794 | did = location['elementId'].encode( 'utf-8' ) |
| 795 | port = location['port'].encode( 'utf-8' ) |
| 796 | m = re.search( '\((\d+)\)', port ) |
| 797 | if m: |
| 798 | port = m.group(1) |
| 799 | portId = "%s/%s" % ( did, port ) |
| 800 | # Lookup ip assigned to this network port |
| 801 | ips.extend( [ x.encode( 'utf-8' ) for x in netcfgJson[ portId ][ 'interfaces' ][0][ 'ips' ] ] ) |
| 802 | ips = set( ips ) |
| 803 | ipRE = r'(\d+\.\d+\.\d+\.\d+)/\d+|([\w,:]*)/\d+' |
| 804 | for ip in ips: |
| 805 | ipMatch = re.search( ipRE, ip ) |
| 806 | if ipMatch: |
| 807 | fabricIntfIp = ipMatch.group(1) |
| 808 | main.log.debug( "Found %s as gateway ip for %s" % ( fabricIntfIp, hostname ) ) |
| 809 | pa = hostComponent.ping( fabricIntfIp, interface=srcIface ) |
| 810 | utilities.assert_equals( expect=expect, actual=pa, |
| 811 | onpass="IP connectivity successfully tested", |
| 812 | onfail="IP connectivity failed" ) |
| 813 | if pa != expect: |
| 814 | Testcaselib.saveOnosDiagnostics( main ) |
| 815 | if skipOnFail: |
| 816 | Testcaselib.cleanup( main, copyKarafLog=False ) |
| 817 | main.skipCase() |
| 818 | except ValueError: |
| 819 | main.log.exception( "Could not get gateway ip for %s" % hostname ) |
| 820 | |
| 821 | if dumpFlows: |
Andreas Pantelopoulos | f6ed501 | 2018-02-08 21:26:01 -0800 | [diff] [blame] | 822 | main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress, |
| 823 | "flows", |
| 824 | main.logdir, |
Jon Hall | 06fd0df | 2021-01-25 15:50:06 -0800 | [diff] [blame] | 825 | tag + "_FlowsOn", |
| 826 | cliPort=main.Cluster.active(0).CLI.karafPort ) |
Andreas Pantelopoulos | f6ed501 | 2018-02-08 21:26:01 -0800 | [diff] [blame] | 827 | main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress, |
| 828 | "groups", |
| 829 | main.logdir, |
Jon Hall | 06fd0df | 2021-01-25 15:50:06 -0800 | [diff] [blame] | 830 | tag + "_GroupsOn", |
| 831 | cliPort=main.Cluster.active(0).CLI.karafPort ) |
Andreas Pantelopoulos | f6ed501 | 2018-02-08 21:26:01 -0800 | [diff] [blame] | 832 | |
| 833 | @staticmethod |
Jon Hall | 326501b | 2021-08-31 10:14:55 -0700 | [diff] [blame] | 834 | def populateHostsVlan( main, hostList ): |
| 835 | """ |
| 836 | Set the vlan for each host. |
| 837 | Checks what interface the host is configured on and reads the netcfg for that interface |
| 838 | """ |
| 839 | import json |
| 840 | import re |
| 841 | hostsJson = json.loads( main.Cluster.active( 0 ).hosts() ) |
| 842 | netcfgJson = json.loads( main.Cluster.active( 0 ).getNetCfg( subjectClass='ports') ) |
| 843 | for hostname in hostList: |
| 844 | try: |
| 845 | hostComponent = main.Network.hosts[ str( hostname ) ] |
| 846 | srcIface = hostComponent.interfaces[0].get( 'name' ) |
| 847 | #Get host location, check netcfg for that port's ip |
| 848 | hostIp = hostComponent.getIPAddress( iface=srcIface ) |
Siddesh | de1d169 | 2021-09-15 18:12:57 +0000 | [diff] [blame] | 849 | if not hostIp: |
| 850 | hostIp=hostComponent.interfaces[0].get( 'ips' )[0] |
Jon Hall | 326501b | 2021-08-31 10:14:55 -0700 | [diff] [blame] | 851 | main.log.warn( "Looking for allowed vlans for %s" % hostIp ) |
| 852 | vlans = [] |
| 853 | for obj in hostsJson: |
| 854 | if hostIp in obj['ipAddresses']: |
| 855 | for location in obj['locations']: |
| 856 | did = location['elementId'].encode( 'utf-8' ) |
| 857 | port = location['port'].encode( 'utf-8' ) |
| 858 | m = re.search( '\((\d+)\)', port ) |
| 859 | if m: |
| 860 | port = m.group(1) |
| 861 | portId = "%s/%s" % ( did, port ) |
| 862 | # Lookup ip assigned to this network port |
| 863 | # Valid host vlans: |
| 864 | # None if vlan-untagged |
| 865 | # vlanid if vlan-tagged: vlanid |
| 866 | # None if vlan-native + any vlan ids from vlan-tagged |
| 867 | intf = netcfgJson[ portId ][ 'interfaces' ][0] |
Siddesh | de1d169 | 2021-09-15 18:12:57 +0000 | [diff] [blame] | 868 | main.log.debug( intf ) |
Jon Hall | 326501b | 2021-08-31 10:14:55 -0700 | [diff] [blame] | 869 | for field in intf.keys(): |
| 870 | if "vlan-untagged" in field: |
| 871 | vlans.append( None ) |
| 872 | if "vlan-tagged" in field: |
Siddesh | de1d169 | 2021-09-15 18:12:57 +0000 | [diff] [blame] | 873 | for VLAN in intf[ field ]: |
| 874 | vlans.append( VLAN ) |
Jon Hall | 326501b | 2021-08-31 10:14:55 -0700 | [diff] [blame] | 875 | if "vlan-native" in field: |
| 876 | vlans.append( None ) |
| 877 | if len( vlans ) == 0: |
| 878 | main.log.debug( "Could not find vlan setting for %s" % hostname ) |
| 879 | vlans = set( vlans ) |
Siddesh | d984084 | 2021-08-06 19:26:05 +0000 | [diff] [blame] | 880 | hostComponent.interfaces[0][ 'vlan' ] = list( vlans ) |
Jon Hall | 326501b | 2021-08-31 10:14:55 -0700 | [diff] [blame] | 881 | main.log.debug( repr( hostComponent.interfaces[0] ) ) |
| 882 | main.log.debug( repr( hostComponent.interfaces[0].get( 'vlan' ) ) ) |
| 883 | except ValueError: |
| 884 | main.log.exception( "Error getting vlans for %s" % hostname ) |
| 885 | |
| 886 | |
| 887 | @staticmethod |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 888 | def killLink( main, end1, end2, switches, links, sleep=None ): |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 889 | """ |
| 890 | end1,end2: identify the switches, ex.: 'leaf1', 'spine1' |
| 891 | switches, links: number of expected switches and links after linkDown, ex.: '4', '6' |
| 892 | Kill a link and verify ONOS can see the proper link change |
| 893 | """ |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 894 | if sleep is None: |
| 895 | sleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] ) |
| 896 | else: |
| 897 | sleep = float( sleep ) |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 898 | main.step( "Kill link between %s and %s" % ( end1, end2 ) ) |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 899 | linkDown = main.Network.link( END1=end1, END2=end2, OPTION="down" ) |
| 900 | linkDown = linkDown and main.Network.link( END2=end1, END1=end2, OPTION="down" ) |
Jon Hall | 214f88b | 2020-09-21 10:21:42 -0700 | [diff] [blame] | 901 | utilities.assert_equals( expect=main.TRUE, actual=linkDown, |
| 902 | onpass="Link down successful", |
| 903 | onfail="Failed to turn off link?" ) |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 904 | # TODO: Can remove this, since in the retry we will wait anyways if topology is incorrect |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 905 | main.log.info( |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 906 | "Waiting %s seconds for link down to be discovered" % sleep ) |
| 907 | time.sleep( sleep ) |
Jon Hall | 214f88b | 2020-09-21 10:21:42 -0700 | [diff] [blame] | 908 | main.step( "Checking topology after link down" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 909 | topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus, |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 910 | main.FALSE, |
| 911 | kwargs={ 'numoswitch': switches, |
| 912 | 'numolink': links }, |
| 913 | attempts=10, |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 914 | sleep=sleep ) |
Jon Hall | 214f88b | 2020-09-21 10:21:42 -0700 | [diff] [blame] | 915 | utilities.assert_equals( expect=main.TRUE, actual=topology, |
| 916 | onpass="Topology after link down is correct", |
| 917 | onfail="Topology after link down is incorrect" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 918 | |
| 919 | @staticmethod |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 920 | def killLinkBatch( main, links, linksAfter, switches, sleep=None ): |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 921 | """ |
| 922 | links = list of links (src, dst) to bring down. |
| 923 | """ |
| 924 | |
| 925 | main.step("Killing a batch of links {0}".format(links)) |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 926 | if sleep is None: |
| 927 | sleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] ) |
| 928 | else: |
| 929 | sleep = float( sleep ) |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 930 | |
| 931 | for end1, end2 in links: |
| 932 | main.Network.link( END1=end1, END2=end2, OPTION="down") |
| 933 | main.Network.link( END1=end2, END2=end1, OPTION="down") |
| 934 | |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 935 | # TODO: Can remove this, since in the retry we will wait anyways if topology is incorrect |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 936 | main.log.info( |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 937 | "Waiting %s seconds for links down to be discovered" % sleep ) |
| 938 | time.sleep( sleep ) |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 939 | |
| 940 | topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus, |
| 941 | main.FALSE, |
| 942 | kwargs={ 'numoswitch': switches, |
| 943 | 'numolink': linksAfter }, |
| 944 | attempts=10, |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 945 | sleep=sleep ) |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 946 | |
You Wang | 2854bce | 2018-03-30 10:15:32 -0700 | [diff] [blame] | 947 | utilities.assert_equals( expect=main.TRUE, actual=topology, |
| 948 | onpass="Link batch down successful", |
| 949 | onfail="Link batch down failed" ) |
| 950 | |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 951 | @staticmethod |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 952 | def restoreLinkBatch( main, links, linksAfter, switches, sleep=None ): |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 953 | """ |
| 954 | links = list of link (src, dst) to bring up again. |
| 955 | """ |
| 956 | |
| 957 | main.step("Restoring a batch of links {0}".format(links)) |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 958 | if sleep is None: |
| 959 | sleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] ) |
| 960 | else: |
| 961 | sleep = float( sleep ) |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 962 | |
| 963 | for end1, end2 in links: |
| 964 | main.Network.link( END1=end1, END2=end2, OPTION="up") |
| 965 | main.Network.link( END1=end2, END2=end1, OPTION="up") |
| 966 | |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 967 | main.log.info( |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 968 | "Waiting %s seconds for links up to be discovered" % sleep ) |
| 969 | time.sleep( sleep ) |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 970 | |
| 971 | topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus, |
| 972 | main.FALSE, |
| 973 | kwargs={ 'numoswitch': switches, |
| 974 | 'numolink': linksAfter }, |
| 975 | attempts=10, |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 976 | sleep=sleep ) |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 977 | |
You Wang | 2854bce | 2018-03-30 10:15:32 -0700 | [diff] [blame] | 978 | utilities.assert_equals( expect=main.TRUE, actual=topology, |
| 979 | onpass="Link batch up successful", |
| 980 | onfail="Link batch up failed" ) |
| 981 | |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 982 | @staticmethod |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 983 | def disablePortBatch( main, ports, switches=None, links=None, sleep=None ): |
| 984 | """ |
| 985 | Disable a list of switch ports using 'portstate' and verify ONOS can see the proper link change |
| 986 | ports: a list of ports to disable ex. [ [ "of:0000000000000001", 1 ] ] |
| 987 | switches, links: number of expected switches and links after link change, ex.: '4', '6' |
| 988 | """ |
| 989 | if sleep is None: |
| 990 | sleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] ) |
| 991 | else: |
| 992 | sleep = float( sleep ) |
| 993 | main.step( "Disable a batch of ports" ) |
| 994 | for dpid, port in ports: |
| 995 | main.Cluster.active( 0 ).CLI.portstate( dpid=dpid, port=port, state="disable" ) |
| 996 | main.log.info( "Waiting {} seconds for port down to be discovered".format( sleep ) ) |
| 997 | time.sleep( sleep ) |
| 998 | if switches and links: |
| 999 | result = main.Cluster.active( 0 ).CLI.checkStatus( numoswitch=switches, |
| 1000 | numolink=links ) |
| 1001 | utilities.assert_equals( expect=main.TRUE, actual=result, |
| 1002 | onpass="Port down successful", |
| 1003 | onfail="Port down failed" ) |
| 1004 | |
| 1005 | @staticmethod |
| 1006 | def enablePortBatch( main, ports, switches, links, sleep=None ): |
| 1007 | """ |
| 1008 | Enable a list of switch ports using 'portstate' and verify ONOS can see the proper link change |
| 1009 | ports: a list of ports to enable ex. [ [ "of:0000000000000001", 1 ] ] |
| 1010 | switches, links: number of expected switches and links after link change, ex.: '4', '6' |
| 1011 | """ |
| 1012 | if sleep is None: |
| 1013 | sleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] ) |
| 1014 | else: |
| 1015 | sleep = float( sleep ) |
| 1016 | main.step( "Enable a batch of ports" ) |
| 1017 | for dpid, port in ports: |
| 1018 | main.Cluster.active( 0 ).CLI.portstate( dpid=dpid, port=port, state="enable" ) |
| 1019 | main.log.info( "Waiting {} seconds for port up to be discovered".format( sleep ) ) |
| 1020 | time.sleep( sleep ) |
| 1021 | if switches and links: |
| 1022 | result = main.Cluster.active( 0 ).CLI.checkStatus( numoswitch=switches, |
| 1023 | numolink=links ) |
| 1024 | utilities.assert_equals( expect=main.TRUE, actual=result, |
| 1025 | onpass="Port up successful", |
| 1026 | onfail="Port up failed" ) |
| 1027 | |
| 1028 | @staticmethod |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 1029 | def restoreLink( main, end1, end2, switches, links, |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1030 | portUp=False, dpid1='', dpid2='', port1='', port2='', sleep=None ): |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1031 | """ |
| 1032 | Params: |
| 1033 | end1,end2: identify the end switches, ex.: 'leaf1', 'spine1' |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 1034 | portUp: enable portstate after restoring link |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1035 | dpid1, dpid2: dpid of the end switches respectively, ex.: 'of:0000000000000002' |
| 1036 | port1, port2: respective port of the end switches that connects to the link, ex.:'1' |
| 1037 | switches, links: number of expected switches and links after linkDown, ex.: '4', '6' |
| 1038 | Kill a link and verify ONOS can see the proper link change |
| 1039 | """ |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 1040 | main.step( "Restore link between %s and %s" % ( end1, end2 ) ) |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1041 | if sleep is None: |
| 1042 | sleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] ) |
| 1043 | else: |
| 1044 | sleep = float( sleep ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1045 | result = False |
| 1046 | count = 0 |
| 1047 | while True: |
| 1048 | count += 1 |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1049 | ctrl = main.Cluster.next() |
You Wang | d587348 | 2018-01-24 12:30:00 -0800 | [diff] [blame] | 1050 | main.Network.link( END1=end1, END2=end2, OPTION="up" ) |
| 1051 | main.Network.link( END2=end1, END1=end2, OPTION="up" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1052 | main.log.info( |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1053 | "Waiting %s seconds for link up to be discovered" % sleep ) |
| 1054 | time.sleep( sleep ) |
Pier | fb719b1 | 2016-09-19 14:51:44 -0700 | [diff] [blame] | 1055 | |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 1056 | if portUp: |
| 1057 | ctrl.CLI.portstate( dpid=dpid1, port=port1, state='Enable' ) |
| 1058 | ctrl.CLI.portstate( dpid=dpid2, port=port2, state='Enable' ) |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1059 | main.log.info( |
| 1060 | "Waiting %s seconds for link up to be discovered" % sleep ) |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1061 | time.sleep( sleep ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1062 | |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1063 | result = ctrl.CLI.checkStatus( numoswitch=switches, |
| 1064 | numolink=links ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1065 | if count > 5 or result: |
| 1066 | break |
| 1067 | utilities.assert_equals( expect=main.TRUE, actual=result, |
| 1068 | onpass="Link up successful", |
| 1069 | onfail="Failed to bring link up" ) |
| 1070 | |
| 1071 | @staticmethod |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1072 | def killSwitch( main, switch, switches, links, sleep=None ): |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1073 | """ |
| 1074 | Params: switches, links: number of expected switches and links after SwitchDown, ex.: '4', '6' |
| 1075 | Completely kill a switch and verify ONOS can see the proper change |
| 1076 | """ |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1077 | if sleep is None: |
| 1078 | sleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] ) |
| 1079 | else: |
| 1080 | sleep = float( sleep ) |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 1081 | switch = switch if isinstance( switch, list ) else [ switch ] |
| 1082 | main.step( "Kill " + str( switch ) ) |
| 1083 | for s in switch: |
| 1084 | main.log.info( "Stopping " + s ) |
| 1085 | main.Network.switch( SW=s, OPTION="stop" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1086 | # todo make this repeatable |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1087 | |
| 1088 | # TODO: Can remove this, since in the retry we will wait anyways if topology is incorrect |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1089 | main.log.info( "Waiting %s seconds for switch down to be discovered" % ( |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1090 | sleep ) ) |
| 1091 | time.sleep( sleep ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 1092 | topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus, |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1093 | main.FALSE, |
| 1094 | kwargs={ 'numoswitch': switches, |
| 1095 | 'numolink': links }, |
| 1096 | attempts=10, |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1097 | sleep=sleep ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1098 | utilities.assert_equals( expect=main.TRUE, actual=topology, |
| 1099 | onpass="Kill switch successful", |
| 1100 | onfail="Failed to kill switch?" ) |
| 1101 | |
| 1102 | @staticmethod |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1103 | def recoverSwitch( main, switch, switches, links, rediscoverHosts=False, hostsToDiscover=[], sleep=None ): |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1104 | """ |
| 1105 | Params: switches, links: number of expected switches and links after SwitchUp, ex.: '4', '6' |
| 1106 | Recover a switch and verify ONOS can see the proper change |
| 1107 | """ |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1108 | if sleep is None: |
| 1109 | sleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] ) |
| 1110 | else: |
| 1111 | sleep = float( sleep ) |
| 1112 | # TODO make this repeatable |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 1113 | switch = switch if isinstance( switch, list ) else [ switch ] |
| 1114 | main.step( "Recovering " + str( switch ) ) |
| 1115 | for s in switch: |
| 1116 | main.log.info( "Starting " + s ) |
| 1117 | main.Network.switch( SW=s, OPTION="start" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1118 | main.log.info( "Waiting %s seconds for switch up to be discovered" % ( |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1119 | sleep ) ) |
| 1120 | time.sleep( sleep ) |
Andreas Pantelopoulos | 74c7ff2 | 2018-05-01 15:42:02 -0700 | [diff] [blame] | 1121 | if rediscoverHosts: |
You Wang | 4838175 | 2018-05-07 13:50:57 -0700 | [diff] [blame] | 1122 | main.Network.discoverHosts( hostList=hostsToDiscover ) |
Andreas Pantelopoulos | 74c7ff2 | 2018-05-01 15:42:02 -0700 | [diff] [blame] | 1123 | main.log.info( "Waiting %s seconds for hosts to get re-discovered" % ( |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1124 | sleep ) ) |
| 1125 | time.sleep( sleep ) |
Andreas Pantelopoulos | 74c7ff2 | 2018-05-01 15:42:02 -0700 | [diff] [blame] | 1126 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 1127 | topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus, |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1128 | main.FALSE, |
| 1129 | kwargs={ 'numoswitch': switches, |
| 1130 | 'numolink': links }, |
| 1131 | attempts=10, |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1132 | sleep=sleep ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1133 | utilities.assert_equals( expect=main.TRUE, actual=topology, |
| 1134 | onpass="Switch recovery successful", |
| 1135 | onfail="Failed to recover switch?" ) |
| 1136 | |
Jonghwan Hyun | 25c98a6 | 2018-05-04 13:59:09 -0700 | [diff] [blame] | 1137 | @staticmethod |
You Wang | 0f745de | 2018-07-27 15:49:22 -0700 | [diff] [blame] | 1138 | def killRouter( main, router, sleep=None ): |
| 1139 | """ |
| 1140 | Kill bgpd process on a quagga router |
| 1141 | router: name of the router to be killed. E.g. "bgp1" |
| 1142 | """ |
| 1143 | sleep = float( sleep ) |
| 1144 | main.step( "Kill " + str( router ) ) |
| 1145 | if hasattr( main, 'Mininet1' ): |
| 1146 | main.Mininet1.handle.sendline( "px {}.stopProtocols()".format( router ) ) |
| 1147 | main.Mininet1.handle.expect( "mininet>" ) |
| 1148 | else: |
| 1149 | # TODO: support killing router in physical network |
| 1150 | pass |
| 1151 | main.log.info( "Waiting %s seconds for router down to be discovered" % ( sleep ) ) |
| 1152 | time.sleep( sleep ) |
| 1153 | |
| 1154 | @staticmethod |
| 1155 | def recoverRouter( main, router, sleep=None ): |
| 1156 | """ |
| 1157 | Restart bgpd process on a quagga router |
| 1158 | router: name of the router to be recovered. E.g. "bgp1" |
| 1159 | """ |
| 1160 | sleep = float( sleep ) |
| 1161 | main.step( "Recovering " + str( router ) ) |
| 1162 | if hasattr( main, 'Mininet1' ): |
| 1163 | main.Mininet1.handle.sendline( "px {}.startProtocols()".format( router ) ) |
| 1164 | main.Mininet1.handle.expect( "mininet>" ) |
| 1165 | else: |
| 1166 | # TODO: support recovering router in physical network |
| 1167 | pass |
| 1168 | main.log.info( "Waiting %s seconds for router up to be discovered" % ( sleep ) ) |
| 1169 | time.sleep( sleep ) |
| 1170 | |
| 1171 | @staticmethod |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 1172 | def cleanup( main, copyKarafLog=True, removeHostComponent=False ): |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1173 | """ |
| 1174 | Stop Onos-cluster. |
| 1175 | Stops Mininet |
| 1176 | Copies ONOS log |
| 1177 | """ |
You Wang | 4cc6191 | 2018-08-28 10:10:58 -0700 | [diff] [blame] | 1178 | from tests.dependencies.utils import Utils |
| 1179 | main.utils = Utils() |
Jon Hall | 627b157 | 2020-12-01 12:01:15 -0800 | [diff] [blame] | 1180 | if not main.persistentSetup: |
| 1181 | for ctrl in main.Cluster.active(): |
| 1182 | ctrl.CLI.log( "\"Ending Test - Shutting down ONOS and Network\"", level="INFO" ) |
You Wang | 4cc6191 | 2018-08-28 10:10:58 -0700 | [diff] [blame] | 1183 | # Clean up scapy hosts |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 1184 | if hasattr( main, "scapyHosts" ): |
| 1185 | scapyResult = main.TRUE |
| 1186 | for host in main.scapyHosts: |
| 1187 | scapyResult = host.stopScapy() and scapyResult |
| 1188 | main.log.info( "Stopped Scapy Host: {0}".format( host.name ) ) |
| 1189 | for host in main.scapyHosts: |
You Wang | 4cc6191 | 2018-08-28 10:10:58 -0700 | [diff] [blame] | 1190 | if hasattr( main, 'Mininet1' ): |
| 1191 | scapyResult = main.Scapy.removeHostComponent( host.name ) and scapyResult |
| 1192 | else: |
| 1193 | scapyResult = main.Network.removeHostComponent( host.name ) and scapyResult |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 1194 | main.log.info( "Removed Scapy Host Component: {0}".format( host.name ) ) |
| 1195 | main.scapyHosts = [] |
| 1196 | |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 1197 | if removeHostComponent: |
Jon Hall | 22a3bcf | 2021-07-23 11:40:11 -0700 | [diff] [blame] | 1198 | try: |
| 1199 | for host in main.internalIpv4Hosts + main.internalIpv6Hosts + main.externalIpv4Hosts + main.externalIpv6Hosts: |
| 1200 | if hasattr( main, host ): |
| 1201 | if hasattr( main, 'Mininet1' ): |
| 1202 | pass |
| 1203 | else: |
| 1204 | getattr( main, host ).disconnectInband() |
| 1205 | main.Network.removeHostComponent( host ) |
| 1206 | except AttributeError as e: |
| 1207 | main.log.warn( "Could not cleanup host components: " + repr( e ) ) |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 1208 | |
You Wang | 5df1c6d | 2018-04-06 18:02:02 -0700 | [diff] [blame] | 1209 | if hasattr( main, 'Mininet1' ): |
Pier | 6a0c4de | 2018-03-18 16:01:30 -0700 | [diff] [blame] | 1210 | main.utils.mininetCleanup( main.Mininet1 ) |
You Wang | 4cc6191 | 2018-08-28 10:10:58 -0700 | [diff] [blame] | 1211 | else: |
| 1212 | main.Network.disconnectInbandHosts() |
| 1213 | main.Network.disconnectFromNet() |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 1214 | |
You Wang | 5df1c6d | 2018-04-06 18:02:02 -0700 | [diff] [blame] | 1215 | if copyKarafLog: |
| 1216 | main.utils.copyKarafLog( "CASE%d" % main.CurrentTestCaseNumber, before=True, includeCaseDesc=False ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 1217 | |
Jon Hall | 627b157 | 2020-12-01 12:01:15 -0800 | [diff] [blame] | 1218 | if not main.persistentSetup: |
| 1219 | for ctrl in main.Cluster.active(): |
| 1220 | main.ONOSbench.onosStop( ctrl.ipAddress ) |
Jon Hall | 06fd0df | 2021-01-25 15:50:06 -0800 | [diff] [blame] | 1221 | else: |
| 1222 | Testcaselib.resetOnosLogLevels( main ) |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1223 | Testcaselib.mnDockerTeardown( main ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1224 | |
| 1225 | @staticmethod |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1226 | def verifyNodes( main ): |
| 1227 | """ |
| 1228 | Verifies Each active node in the cluster has an accurate view of other node's and their status |
| 1229 | |
| 1230 | Params: |
| 1231 | nodes, integer array with position of the ONOS nodes in the CLIs array |
| 1232 | """ |
| 1233 | nodeResults = utilities.retry( main.Cluster.nodesCheck, |
| 1234 | False, |
| 1235 | attempts=10, |
| 1236 | sleep=10 ) |
| 1237 | utilities.assert_equals( expect=True, actual=nodeResults, |
| 1238 | onpass="Nodes check successful", |
| 1239 | onfail="Nodes check NOT successful" ) |
| 1240 | |
| 1241 | if not nodeResults: |
| 1242 | for ctrl in main.Cluster.runningNodes: |
| 1243 | main.log.debug( "{} components not ACTIVE: \n{}".format( |
| 1244 | ctrl.name, |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 1245 | ctrl.CLI.sendline( "onos:scr-list | grep -v ACTIVE" ) ) ) |
You Wang | 0bed593 | 2018-12-11 14:45:41 -0800 | [diff] [blame] | 1246 | main.log.error( "Failed to verify nodes, stopping test" ) |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1247 | main.cleanAndExit() |
| 1248 | |
| 1249 | @staticmethod |
Jon Hall | 3957026 | 2020-11-17 12:18:19 -0800 | [diff] [blame] | 1250 | def verifyTopology( main, switches, links, expNodes, SCCs=1 ): |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1251 | """ |
| 1252 | Verifies that the ONOS cluster has an acuurate view of the topology |
| 1253 | |
| 1254 | Params: |
| 1255 | switches, links, expNodes: number of expected switches, links, and nodes at this point in the test ex.: '4', '6', '2' |
Jon Hall | 3957026 | 2020-11-17 12:18:19 -0800 | [diff] [blame] | 1256 | SCCs = Number of connected topology clusters within the control plane, defaults to 1 |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1257 | """ |
| 1258 | main.step( "Check number of topology elements" ) |
| 1259 | topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus, |
| 1260 | main.FALSE, |
| 1261 | kwargs={ 'numoswitch': switches, |
| 1262 | 'numolink': links, |
Jon Hall | 3957026 | 2020-11-17 12:18:19 -0800 | [diff] [blame] | 1263 | 'numoctrl': expNodes, |
| 1264 | 'numoSCCs': SCCs }, |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1265 | attempts=10, |
| 1266 | sleep=12 ) |
| 1267 | utilities.assert_equals( expect=main.TRUE, actual=topology, |
| 1268 | onpass="Number of topology elements are correct", |
Jon Hall | 3957026 | 2020-11-17 12:18:19 -0800 | [diff] [blame] | 1269 | onfail="Unexpected number of links, switches, and/or controllers: " + main.TOPOOUTPUT ) |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1270 | |
| 1271 | @staticmethod |
| 1272 | def killOnos( main, nodes, switches, links, expNodes, sleep=None ): |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1273 | """ |
| 1274 | Params: nodes, integer array with position of the ONOS nodes in the CLIs array |
| 1275 | switches, links, nodes: number of expected switches, links and nodes after KillOnos, ex.: '4', '6' |
| 1276 | Completely Kill an ONOS instance and verify the ONOS cluster can see the proper change |
| 1277 | """ |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1278 | # TODO: We have enough information in the Cluster instance to remove expNodes from here and verifyTopology |
Jon Hall | 3c91016 | 2018-03-07 14:42:16 -0800 | [diff] [blame] | 1279 | main.step( "Killing ONOS instances with index(es): {}".format( nodes ) ) |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1280 | if sleep is None: |
| 1281 | sleep = float( main.params[ 'timers' ][ 'OnosDiscovery' ] ) |
| 1282 | else: |
| 1283 | sleep = float( sleep ) |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 1284 | |
Jon Hall | 214f88b | 2020-09-21 10:21:42 -0700 | [diff] [blame] | 1285 | stepResult = main.TRUE |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1286 | for i in nodes: |
Jon Hall | 214f88b | 2020-09-21 10:21:42 -0700 | [diff] [blame] | 1287 | node = main.Cluster.runningNodes[ i ] |
| 1288 | if node.inDocker: |
| 1289 | killResult = node.server.dockerStop( node.name ) |
| 1290 | else: |
| 1291 | killResult = main.ONOSbench.onosDie( node.ipAddress ) |
| 1292 | stepResult = stepResult and killResult |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 1293 | main.Cluster.runningNodes[ i ].active = False |
Jon Hall | 214f88b | 2020-09-21 10:21:42 -0700 | [diff] [blame] | 1294 | utilities.assert_equals( expect=main.TRUE, actual=stepResult, |
| 1295 | onpass="ONOS instance Killed", |
| 1296 | onfail="Error killing ONOS instance" ) |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1297 | main.Cluster.reset() |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1298 | main.log.debug( "sleeping %i seconds" % ( sleep ) ) |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1299 | time.sleep( sleep ) |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 1300 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 1301 | if len( nodes ) < main.Cluster.numCtrls: |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1302 | Testcaselib.verifyNodes( main ) |
| 1303 | Testcaselib.verifyTopology( main, switches, links, expNodes ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1304 | |
| 1305 | @staticmethod |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1306 | def recoverOnos( main, nodes, switches, links, expNodes, sleep=None ): |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1307 | """ |
| 1308 | Params: nodes, integer array with position of the ONOS nodes in the CLIs array |
| 1309 | switches, links, nodes: number of expected switches, links and nodes after recoverOnos, ex.: '4', '6' |
| 1310 | Recover an ONOS instance and verify the ONOS cluster can see the proper change |
| 1311 | """ |
Jon Hall | 3c91016 | 2018-03-07 14:42:16 -0800 | [diff] [blame] | 1312 | main.step( "Recovering ONOS instances with index(es): {}".format( nodes ) ) |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1313 | if sleep is None: |
| 1314 | sleep = float( main.params[ 'timers' ][ 'OnosDiscovery' ] ) |
| 1315 | else: |
| 1316 | sleep = float( sleep ) |
Jon Hall | 214f88b | 2020-09-21 10:21:42 -0700 | [diff] [blame] | 1317 | for i in nodes: |
| 1318 | node = main.Cluster.runningNodes[ i ] |
| 1319 | if node.inDocker: |
| 1320 | main.Cluster.startONOSDockerNode( i ) |
| 1321 | else: |
| 1322 | main.ONOSbench.onosStart( node.ipAddress ) |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1323 | main.log.debug( "sleeping %i seconds" % ( sleep ) ) |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1324 | time.sleep( sleep ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1325 | for i in nodes: |
Jon Hall | 3957026 | 2020-11-17 12:18:19 -0800 | [diff] [blame] | 1326 | node = main.Cluster.runningNodes[ i ] |
Jon Hall | 214f88b | 2020-09-21 10:21:42 -0700 | [diff] [blame] | 1327 | if node.inDocker: |
| 1328 | isUp = node.CLI.dockerExec( node.name, dockerPrompt=node.dockerPrompt ) |
| 1329 | isUp = isUp and node.CLI.prepareForCLI() |
| 1330 | isUp = isUp and node.CLI.onosSecureSSH( userName=node.karafUser, userPWD=node.karafPass ) |
| 1331 | else: |
| 1332 | isUp = main.ONOSbench.isup( node.ipAddress ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1333 | utilities.assert_equals( expect=main.TRUE, actual=isUp, |
| 1334 | onpass="ONOS service is ready", |
| 1335 | onfail="ONOS service did not start properly" ) |
| 1336 | for i in nodes: |
| 1337 | main.step( "Checking if ONOS CLI is ready" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 1338 | ctrl = main.Cluster.runningNodes[ i ] |
Jonghwan Hyun | 76a02b7 | 2018-01-30 16:40:48 +0900 | [diff] [blame] | 1339 | # ctrl.CLI.startCellCli() |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 1340 | cliResult = ctrl.CLI.startOnosCli( ctrl.ipAddress, |
| 1341 | commandlineTimeout=60, |
| 1342 | onosStartTimeout=100 ) |
| 1343 | ctrl.active = True |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1344 | utilities.assert_equals( expect=main.TRUE, |
| 1345 | actual=cliResult, |
| 1346 | onpass="ONOS CLI is ready", |
| 1347 | onfail="ONOS CLI is not ready" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1348 | |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1349 | main.Cluster.reset() |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 1350 | main.step( "Checking ONOS nodes" ) |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1351 | Testcaselib.verifyNodes( main ) |
| 1352 | Testcaselib.verifyTopology( main, switches, links, expNodes ) |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 1353 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 1354 | ready = utilities.retry( main.Cluster.active( 0 ).CLI.summary, |
You Wang | 5bf4959 | 2020-07-08 18:47:46 -0700 | [diff] [blame] | 1355 | [ None, main.FALSE ], |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 1356 | attempts=10, |
| 1357 | sleep=12 ) |
| 1358 | if ready: |
| 1359 | ready = main.TRUE |
| 1360 | utilities.assert_equals( expect=main.TRUE, actual=ready, |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1361 | onpass="ONOS summary command succeded", |
| 1362 | onfail="ONOS summary command failed" ) |
| 1363 | if not ready: |
| 1364 | main.log.error( "ONOS startup failed!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1365 | main.cleanAndExit() |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1366 | |
| 1367 | @staticmethod |
| 1368 | def addHostCfg( main ): |
| 1369 | """ |
| 1370 | Adds Host Configuration to ONOS |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 1371 | Updates expected state of the network ( pingChart ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1372 | """ |
| 1373 | import json |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 1374 | hostCfg = {} |
Devin Lim | 57221b0 | 2018-02-14 15:45:36 -0800 | [diff] [blame] | 1375 | with open( main.configPath + main.forJson + "extra.json" ) as template: |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1376 | hostCfg = json.load( template ) |
| 1377 | main.pingChart[ 'ip' ][ 'hosts' ] += [ 'in1' ] |
| 1378 | main.step( "Pushing new configuration" ) |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 1379 | mac, cfg = hostCfg[ 'hosts' ].popitem() |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 1380 | main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ], |
| 1381 | subjectClass="hosts", |
| 1382 | subjectKey=urllib.quote( mac, |
| 1383 | safe='' ), |
| 1384 | configKey="basic" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1385 | main.pingChart[ 'ip' ][ 'hosts' ] += [ 'out1' ] |
| 1386 | main.step( "Pushing new configuration" ) |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 1387 | mac, cfg = hostCfg[ 'hosts' ].popitem() |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 1388 | main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ], |
| 1389 | subjectClass="hosts", |
| 1390 | subjectKey=urllib.quote( mac, |
| 1391 | safe='' ), |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 1392 | configKey="basic" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1393 | main.pingChart.update( { 'vlan1': { "expect": "True", |
| 1394 | "hosts": [ "olt1", "vsg1" ] } } ) |
| 1395 | main.pingChart[ 'vlan5' ][ 'expect' ] = 0 |
| 1396 | main.pingChart[ 'vlan10' ][ 'expect' ] = 0 |
Jon Hall | 10e2ab8 | 2020-09-15 17:14:54 -0700 | [diff] [blame] | 1397 | main.Cluster.active( 0 ).REST.setXconnect( "of:0000000000000001", |
| 1398 | vlanId=1, |
| 1399 | port1=5, |
| 1400 | port2=6 ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1401 | |
| 1402 | @staticmethod |
| 1403 | def delHostCfg( main ): |
| 1404 | """ |
| 1405 | Removest Host Configuration from ONOS |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 1406 | Updates expected state of the network ( pingChart ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1407 | """ |
| 1408 | import json |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 1409 | hostCfg = {} |
Devin Lim | 57221b0 | 2018-02-14 15:45:36 -0800 | [diff] [blame] | 1410 | with open( main.configPath + main.forJson + "extra.json" ) as template: |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1411 | hostCfg = json.load( template ) |
| 1412 | main.step( "Removing host configuration" ) |
| 1413 | main.pingChart[ 'ip' ][ 'expect' ] = 0 |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 1414 | mac, cfg = hostCfg[ 'hosts' ].popitem() |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 1415 | main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts", |
| 1416 | subjectKey=urllib.quote( |
| 1417 | mac, |
| 1418 | safe='' ), |
| 1419 | configKey="basic" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1420 | main.step( "Removing configuration" ) |
| 1421 | main.pingChart[ 'ip' ][ 'expect' ] = 0 |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 1422 | mac, cfg = hostCfg[ 'hosts' ].popitem() |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 1423 | main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts", |
| 1424 | subjectKey=urllib.quote( |
| 1425 | mac, |
| 1426 | safe='' ), |
| 1427 | configKey="basic" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1428 | main.step( "Removing vlan configuration" ) |
| 1429 | main.pingChart[ 'vlan1' ][ 'expect' ] = 0 |
Jon Hall | 10e2ab8 | 2020-09-15 17:14:54 -0700 | [diff] [blame] | 1430 | main.Cluster.active( 0 ).REST.deleteXconnect( "of:0000000000000001", |
| 1431 | vlanId=1 ) |
You Wang | 53dba1e | 2018-02-02 17:45:44 -0800 | [diff] [blame] | 1432 | |
| 1433 | @staticmethod |
| 1434 | def verifyNetworkHostIp( main, attempts=10, sleep=10 ): |
| 1435 | """ |
| 1436 | Verifies IP address assignment from the hosts |
| 1437 | """ |
| 1438 | main.step( "Verify IP address assignment from hosts" ) |
| 1439 | ipResult = main.TRUE |
You Wang | d66de19 | 2018-04-30 17:30:12 -0700 | [diff] [blame] | 1440 | main.Network.update() |
You Wang | 6acb7a4 | 2018-05-04 15:12:25 -0700 | [diff] [blame] | 1441 | # Find out names of disconnected hosts |
| 1442 | disconnectedHosts = [] |
| 1443 | if hasattr( main, "disconnectedIpv4Hosts" ): |
| 1444 | for host in main.disconnectedIpv4Hosts: |
| 1445 | disconnectedHosts.append( host ) |
| 1446 | if hasattr( main, "disconnectedIpv6Hosts" ): |
| 1447 | for host in main.disconnectedIpv6Hosts: |
| 1448 | disconnectedHosts.append( host ) |
You Wang | 53dba1e | 2018-02-02 17:45:44 -0800 | [diff] [blame] | 1449 | for hostName, ip in main.expectedHosts[ "network" ].items(): |
You Wang | 6acb7a4 | 2018-05-04 15:12:25 -0700 | [diff] [blame] | 1450 | # Exclude disconnected hosts |
| 1451 | if hostName in disconnectedHosts: |
| 1452 | main.log.debug( "Skip verifying IP for {} as it's disconnected".format( hostName ) ) |
| 1453 | continue |
You Wang | 53dba1e | 2018-02-02 17:45:44 -0800 | [diff] [blame] | 1454 | ipResult = ipResult and utilities.retry( main.Network.verifyHostIp, |
| 1455 | main.FALSE, |
| 1456 | kwargs={ 'hostList': [ hostName ], |
You Wang | d66de19 | 2018-04-30 17:30:12 -0700 | [diff] [blame] | 1457 | 'prefix': ip, |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1458 | 'update': True }, |
You Wang | 53dba1e | 2018-02-02 17:45:44 -0800 | [diff] [blame] | 1459 | attempts=attempts, |
| 1460 | sleep=sleep ) |
| 1461 | utilities.assert_equals( expect=main.TRUE, actual=ipResult, |
| 1462 | onpass="Verify network host IP succeded", |
| 1463 | onfail="Verify network host IP failed" ) |
| 1464 | |
| 1465 | @staticmethod |
You Wang | aec6a09 | 2018-08-06 15:36:31 -0700 | [diff] [blame] | 1466 | def verifyOnosHostIp( main, attempts=10, sleep=10, skipOnFail=True ): |
You Wang | 53dba1e | 2018-02-02 17:45:44 -0800 | [diff] [blame] | 1467 | """ |
| 1468 | Verifies host IP address assignment from ONOS |
| 1469 | """ |
| 1470 | main.step( "Verify host IP address assignment in ONOS" ) |
| 1471 | ipResult = main.TRUE |
You Wang | 6acb7a4 | 2018-05-04 15:12:25 -0700 | [diff] [blame] | 1472 | # Find out IPs of disconnected hosts |
| 1473 | disconnectedIps = [] |
| 1474 | if hasattr( main, "disconnectedIpv4Hosts" ): |
| 1475 | for host in main.disconnectedIpv4Hosts: |
| 1476 | disconnectedIps.append( main.expectedHosts[ "network" ][ host ] ) |
| 1477 | if hasattr( main, "disconnectedIpv6Hosts" ): |
| 1478 | for host in main.disconnectedIpv6Hosts: |
| 1479 | disconnectedIps.append( main.expectedHosts[ "network" ][ host ] ) |
You Wang | 53dba1e | 2018-02-02 17:45:44 -0800 | [diff] [blame] | 1480 | for hostName, ip in main.expectedHosts[ "onos" ].items(): |
You Wang | 6acb7a4 | 2018-05-04 15:12:25 -0700 | [diff] [blame] | 1481 | # Exclude disconnected hosts |
| 1482 | if ip in disconnectedIps: |
| 1483 | main.log.debug( "Skip verifying IP for {} as it's disconnected".format( ip ) ) |
| 1484 | continue |
You Wang | 53dba1e | 2018-02-02 17:45:44 -0800 | [diff] [blame] | 1485 | ipResult = ipResult and utilities.retry( main.Cluster.active( 0 ).verifyHostIp, |
| 1486 | main.FALSE, |
| 1487 | kwargs={ 'hostList': [ hostName ], |
| 1488 | 'prefix': ip }, |
| 1489 | attempts=attempts, |
| 1490 | sleep=sleep ) |
| 1491 | utilities.assert_equals( expect=main.TRUE, actual=ipResult, |
| 1492 | onpass="Verify ONOS host IP succeded", |
| 1493 | onfail="Verify ONOS host IP failed" ) |
You Wang | aec6a09 | 2018-08-06 15:36:31 -0700 | [diff] [blame] | 1494 | if not ipResult and skipOnFail: |
| 1495 | Testcaselib.saveOnosDiagnostics( main ) |
You Wang | 8947715 | 2018-08-07 14:19:02 -0700 | [diff] [blame] | 1496 | Testcaselib.cleanup( main, copyKarafLog=False ) |
You Wang | aec6a09 | 2018-08-06 15:36:31 -0700 | [diff] [blame] | 1497 | main.skipCase() |
Andreas Pantelopoulos | 2eae324 | 2018-03-06 13:47:20 -0800 | [diff] [blame] | 1498 | |
Jonghwan Hyun | 812c70f | 2018-02-16 16:33:16 -0800 | [diff] [blame] | 1499 | @staticmethod |
| 1500 | def updateIntfCfg( main, connectPoint, ips=[], untagged=0, tagged=[], native=0 ): |
| 1501 | """ |
| 1502 | Description: |
| 1503 | Updates interface configuration in ONOS, with given IP and vlan parameters |
| 1504 | Required: |
| 1505 | * connectPoint: connect point to update configuration |
| 1506 | Optional: |
| 1507 | * ips: list of IP addresses, combined with '/xx' subnet representation, |
| 1508 | corresponding to 'ips' field in the configuration |
| 1509 | * untagged: vlan ID as an integer, corresponding to 'vlan-untagged' field in the configuration |
| 1510 | * tagged: integer list of vlan IDs, corresponding to 'vlan-tagged' field in the configuration |
| 1511 | * native: vlan ID as an integer, corresponding to 'vlan-native' field in the configuration |
| 1512 | """ |
| 1513 | cfg = dict() |
| 1514 | cfg[ "ports" ] = dict() |
| 1515 | cfg[ "ports" ][ connectPoint ] = dict() |
| 1516 | cfg[ "ports" ][ connectPoint ][ "interfaces" ] = [ dict() ] |
| 1517 | cfg[ "ports" ][ connectPoint ][ "interfaces" ][ 0 ][ "ips" ] = ips |
| 1518 | if untagged > 0: |
| 1519 | cfg[ "ports" ][ connectPoint ][ "interfaces" ][ 0 ][ "vlan-untagged" ] = untagged |
| 1520 | else: |
| 1521 | cfg[ "ports" ][ connectPoint ][ "interfaces" ][ 0 ][ "vlan-tagged" ] = tagged |
| 1522 | if native > 0: |
| 1523 | cfg[ "ports" ][ connectPoint ][ "interfaces" ][ 0 ][ "vlan-native" ] = native |
| 1524 | |
| 1525 | main.Cluster.active( 0 ).REST.setNetCfg( json.loads( json.dumps( cfg ) ) ) |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 1526 | |
| 1527 | @staticmethod |
You Wang | 2cb7017 | 2018-07-25 16:44:13 -0700 | [diff] [blame] | 1528 | def startScapyHosts( main, scapyNames=[], mininetNames=[] ): |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 1529 | """ |
| 1530 | Create host components and start Scapy CLIs |
You Wang | 2cb7017 | 2018-07-25 16:44:13 -0700 | [diff] [blame] | 1531 | scapyNames: list of names that will be used as component names for scapy hosts |
| 1532 | mininetNames: used when scapy host names are different from the host names |
| 1533 | in Mininet. E.g. when scapyNames=['h1Scapy'], it's required to specify the |
| 1534 | name of the corresponding Mininet host by mininetNames=['h1'] |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 1535 | """ |
| 1536 | main.step( "Start Scapy CLIs" ) |
You Wang | 4cc6191 | 2018-08-28 10:10:58 -0700 | [diff] [blame] | 1537 | main.scapyNames = scapyNames if scapyNames else main.params[ 'SCAPY' ][ 'HOSTNAMES' ].split( ',' ) |
| 1538 | main.scapyHosts = [] if not hasattr( main, "scapyHosts" ) else main.scapyHosts |
You Wang | 2cb7017 | 2018-07-25 16:44:13 -0700 | [diff] [blame] | 1539 | for scapyName in main.scapyNames: |
You Wang | 4cc6191 | 2018-08-28 10:10:58 -0700 | [diff] [blame] | 1540 | if hasattr( main, 'Mininet1' ): |
| 1541 | main.Scapy.createHostComponent( scapyName ) |
| 1542 | scapyHandle = getattr( main, scapyName ) |
| 1543 | if mininetNames: |
| 1544 | mininetName = mininetNames[ scapyNames.index( scapyName ) ] |
| 1545 | else: |
| 1546 | mininetName = None |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1547 | if 'MN_DOCKER' in main.params and main.params['MN_DOCKER']['args']: |
| 1548 | scapyHandle.mExecDir = "/tmp" |
| 1549 | scapyHandle.hostHome = main.params[ "MN_DOCKER" ][ "home" ] |
| 1550 | main.log.debug( "start mn host component in docker" ) |
| 1551 | scapyHandle.startHostCli( mininetName, |
| 1552 | execDir="/tmp", |
| 1553 | hostHome=main.params[ "MN_DOCKER" ][ "home" ] ) |
| 1554 | else: |
| 1555 | main.log.debug( "start mn host component" ) |
| 1556 | scapyHandle.startHostCli( mininetName ) |
You Wang | 2cb7017 | 2018-07-25 16:44:13 -0700 | [diff] [blame] | 1557 | else: |
You Wang | 0fc2170 | 2018-11-02 17:49:18 -0700 | [diff] [blame] | 1558 | main.Network.createHostComponent( scapyName ) |
You Wang | 4cc6191 | 2018-08-28 10:10:58 -0700 | [diff] [blame] | 1559 | scapyHandle = getattr( main, scapyName ) |
| 1560 | scapyHandle.connectInband() |
| 1561 | main.scapyHosts.append( scapyHandle ) |
You Wang | 2cb7017 | 2018-07-25 16:44:13 -0700 | [diff] [blame] | 1562 | scapyHandle.startScapy() |
| 1563 | scapyHandle.updateSelf() |
| 1564 | main.log.debug( scapyHandle.name ) |
| 1565 | main.log.debug( scapyHandle.hostIp ) |
| 1566 | main.log.debug( scapyHandle.hostMac ) |
| 1567 | |
| 1568 | @staticmethod |
| 1569 | def verifyTraffic( main, srcHosts, dstIp, dstHost, dstIntf, ipv6=False, expect=True, skipOnFail=True, maxRetry=2 ): |
| 1570 | """ |
| 1571 | Verify unicast traffic by pinging from source hosts to the destination IP |
| 1572 | and capturing the packets at the destination host using Scapy. |
| 1573 | srcHosts: List of host names to send the ping packets |
| 1574 | dstIp: destination IP of the ping packets |
| 1575 | dstHost: host that runs Scapy to capture the packets |
| 1576 | dstIntf: name of the interface on the destination host |
| 1577 | expect: use True if the ping is expected to be captured at destination; |
| 1578 | Otherwise False |
| 1579 | skipOnFail: skip the rest of this test case if result is not expected |
| 1580 | maxRetry: number of retries allowed |
| 1581 | """ |
| 1582 | from tests.dependencies.topology import Topology |
| 1583 | try: |
| 1584 | main.topo |
| 1585 | except ( NameError, AttributeError ): |
| 1586 | main.topo = Topology() |
| 1587 | main.step( "Verify traffic to {} by capturing packets on {}".format( dstIp, dstHost ) ) |
| 1588 | result = main.TRUE |
| 1589 | for srcHost in srcHosts: |
| 1590 | trafficResult = main.topo.pingAndCapture( srcHost, dstIp, dstHost, dstIntf, ipv6, |
| 1591 | expect, maxRetry, True ) |
| 1592 | if not trafficResult: |
You Wang | 2cb7017 | 2018-07-25 16:44:13 -0700 | [diff] [blame] | 1593 | result = main.FALSE |
| 1594 | main.log.warn( "Scapy result from {} to {} is not as expected".format( srcHost, dstIp ) ) |
| 1595 | utilities.assert_equals( expect=main.TRUE, |
| 1596 | actual=result, |
| 1597 | onpass="Verify traffic to {}: Pass".format( dstIp ), |
| 1598 | onfail="Verify traffic to {}: Fail".format( dstIp ) ) |
| 1599 | if skipOnFail and result != main.TRUE: |
| 1600 | Testcaselib.saveOnosDiagnostics( main ) |
| 1601 | Testcaselib.cleanup( main, copyKarafLog=False ) |
| 1602 | main.skipCase() |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 1603 | |
| 1604 | @staticmethod |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 1605 | def verifyMulticastTraffic( main, routeName, expect, skipOnFail=True, maxRetry=1 ): |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 1606 | """ |
| 1607 | Verify multicast traffic using scapy |
| 1608 | """ |
You Wang | c564c6f | 2018-05-01 15:24:57 -0700 | [diff] [blame] | 1609 | from tests.dependencies.topology import Topology |
| 1610 | try: |
| 1611 | main.topo |
| 1612 | except ( NameError, AttributeError ): |
| 1613 | main.topo = Topology() |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 1614 | main.step( "Verify {} multicast traffic".format( routeName ) ) |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 1615 | routeData = main.multicastConfig[ routeName ] |
| 1616 | srcs = main.mcastRoutes[ routeName ][ "src" ] |
| 1617 | dsts = main.mcastRoutes[ routeName ][ "dst" ] |
| 1618 | main.log.info( "Sending multicast traffic from {} to {}".format( [ routeData[ "src" ][ i ][ "host" ] for i in srcs ], |
| 1619 | [ routeData[ "dst" ][ i ][ "host" ] for i in dsts ] ) ) |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 1620 | result = main.TRUE |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 1621 | for src in srcs: |
| 1622 | srcEntry = routeData[ "src" ][ src ] |
| 1623 | for dst in dsts: |
| 1624 | dstEntry = routeData[ "dst" ][ dst ] |
| 1625 | sender = getattr( main, srcEntry[ "host" ] ) |
| 1626 | receiver = getattr( main, dstEntry[ "host" ] ) |
| 1627 | main.Network.addRoute( str( srcEntry[ "host" ] ), |
| 1628 | str( routeData[ "group" ] ), |
| 1629 | str( srcEntry[ "interface" ] ), |
| 1630 | True if routeData[ "ipVersion" ] == 6 else False ) |
| 1631 | # Build the packet |
| 1632 | sender.buildEther( dst=str( srcEntry[ "Ether" ] ) ) |
| 1633 | if routeData[ "ipVersion" ] == 4: |
| 1634 | sender.buildIP( dst=str( routeData[ "group" ] ) ) |
| 1635 | elif routeData[ "ipVersion" ] == 6: |
| 1636 | sender.buildIPv6( dst=str( routeData[ "group" ] ) ) |
| 1637 | sender.buildUDP( ipVersion=routeData[ "ipVersion" ], dport=srcEntry[ "UDP" ] ) |
| 1638 | sIface = srcEntry[ "interface" ] |
| 1639 | dIface = dstEntry[ "interface" ] if "interface" in dstEntry.keys() else None |
| 1640 | pktFilter = srcEntry[ "filter" ] |
| 1641 | pkt = srcEntry[ "packet" ] |
| 1642 | # Send packet and check received packet |
| 1643 | expectedResult = expect.pop( 0 ) if isinstance( expect, list ) else expect |
You Wang | c564c6f | 2018-05-01 15:24:57 -0700 | [diff] [blame] | 1644 | t3Cmd = "t3-troubleshoot -vv -sp {} -et ipv{} -d {} -dm {}".format( srcEntry[ "port" ], routeData[ "ipVersion" ], |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1645 | routeData[ "group" ], srcEntry[ "Ether" ] ) |
You Wang | c564c6f | 2018-05-01 15:24:57 -0700 | [diff] [blame] | 1646 | trafficResult = main.topo.sendScapyPackets( sender, receiver, pktFilter, pkt, sIface, dIface, |
| 1647 | expectedResult, maxRetry, True, t3Cmd ) |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 1648 | if not trafficResult: |
| 1649 | result = main.FALSE |
| 1650 | main.log.warn( "Scapy result from {} to {} is not as expected".format( srcEntry[ "host" ], |
| 1651 | dstEntry[ "host" ] ) ) |
| 1652 | utilities.assert_equals( expect=main.TRUE, |
| 1653 | actual=result, |
| 1654 | onpass="Verify {} multicast traffic: Pass".format( routeName ), |
| 1655 | onfail="Verify {} multicast traffic: Fail".format( routeName ) ) |
You Wang | ba823f0 | 2018-05-17 13:54:08 -0700 | [diff] [blame] | 1656 | if skipOnFail and result != main.TRUE: |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 1657 | Testcaselib.saveOnosDiagnostics( main ) |
| 1658 | Testcaselib.cleanup( main, copyKarafLog=False ) |
| 1659 | main.skipCase() |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 1660 | |
| 1661 | @staticmethod |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 1662 | def verifyPing( main, srcList, dstList, ipv6=False, expect=True, wait=1, |
You Wang | 54b1d67 | 2018-06-11 16:44:13 -0700 | [diff] [blame] | 1663 | acceptableFailed=0, skipOnFail=True, stepMsg="Verify Ping", |
| 1664 | t3Simple=True ): |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 1665 | """ |
| 1666 | Verify reachability from each host in srcList to each host in dstList |
| 1667 | """ |
| 1668 | from tests.dependencies.topology import Topology |
| 1669 | try: |
| 1670 | main.topo |
| 1671 | except ( NameError, AttributeError ): |
| 1672 | main.topo = Topology() |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 1673 | main.step( stepMsg ) |
You Wang | 54b1d67 | 2018-06-11 16:44:13 -0700 | [diff] [blame] | 1674 | pingResult = main.topo.ping( srcList, dstList, ipv6, expect, wait, acceptableFailed, skipOnFail, t3Simple ) |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 1675 | utilities.assert_equals( expect=main.TRUE, |
| 1676 | actual=pingResult, |
| 1677 | onpass="{}: Pass".format( stepMsg ), |
| 1678 | onfail="{}: Fail".format( stepMsg ) ) |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 1679 | if not pingResult and skipOnFail: |
| 1680 | Testcaselib.saveOnosDiagnostics( main ) |
| 1681 | Testcaselib.cleanup( main, copyKarafLog=False, removeHostComponent=True ) |
| 1682 | main.skipCase() |
You Wang | bc898b8 | 2018-05-03 16:22:34 -0700 | [diff] [blame] | 1683 | |
| 1684 | @staticmethod |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 1685 | def verifyHostLocations( main, locationDict, retry=2 ): |
You Wang | bc898b8 | 2018-05-03 16:22:34 -0700 | [diff] [blame] | 1686 | """ |
| 1687 | Verify if the specified host is discovered by ONOS on the given locations |
| 1688 | Required: |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 1689 | locationDict: a dictionary that maps host names to expected locations. |
| 1690 | locations could be a string or a list. |
| 1691 | ex. { "h1v4": ["of:0000000000000005/8"] } |
You Wang | bc898b8 | 2018-05-03 16:22:34 -0700 | [diff] [blame] | 1692 | Returns: |
| 1693 | main.TRUE if host is discovered on all locations provided, otherwise main.FALSE |
| 1694 | """ |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 1695 | main.step( "Verify locations of hosts {}".format( locationDict.keys() ) ) |
| 1696 | result = main.TRUE |
| 1697 | for hostName, locations in locationDict.items(): |
| 1698 | main.log.info( "Verify host {} is discovered at {}".format( hostName, locations ) ) |
| 1699 | hostIp = main.Network.getIPAddress( hostName, proto='IPV4' ) |
| 1700 | if not hostIp: |
| 1701 | hostIp = main.Network.getIPAddress( hostName, proto='IPV6' ) |
| 1702 | if not hostIp: |
| 1703 | main.log.warn( "Failed to find IP address for host {}, skipping location verification".format( hostName ) ) |
| 1704 | result = main.FALSE |
| 1705 | continue |
| 1706 | locationResult = utilities.retry( main.Cluster.active( 0 ).CLI.verifyHostLocation, |
| 1707 | main.FALSE, |
| 1708 | args=( hostIp, locations ), |
| 1709 | attempts=retry + 1, |
| 1710 | sleep=10 ) |
| 1711 | if not locationResult: |
| 1712 | result = main.FALSE |
| 1713 | main.log.warn( "location verification for host {} failed".format( hostName ) ) |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 1714 | utilities.assert_equals( expect=main.TRUE, actual=result, |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 1715 | onpass="Location verification passed", |
| 1716 | onfail="Location verification failed" ) |
Jonghwan Hyun | 785471d | 2018-05-14 14:48:19 -0700 | [diff] [blame] | 1717 | |
| 1718 | @staticmethod |
You Wang | 6e5b48e | 2018-07-23 16:17:38 -0700 | [diff] [blame] | 1719 | def moveHost( main, hostName, srcSw, dstSw, gw, macAddr=None, prefixLen=None, cfg='', ipv6=False, vlan=None ): |
Jonghwan Hyun | 785471d | 2018-05-14 14:48:19 -0700 | [diff] [blame] | 1720 | """ |
| 1721 | Move specified host from srcSw to dstSw. |
| 1722 | If srcSw and dstSw are same, the host will be moved from current port to |
| 1723 | next available port. |
| 1724 | Required: |
| 1725 | hostName: name of the host. e.g., "h1" |
| 1726 | srcSw: name of the switch that the host is attached to. e.g., "leaf1" |
| 1727 | dstSw: name of the switch that the host will be moved to. e.g., "leaf2" |
| 1728 | gw: ip address of the gateway of the new location |
| 1729 | Optional: |
| 1730 | macAddr: if specified, change MAC address of the host to the specified MAC address. |
| 1731 | prefixLen: prefix length |
| 1732 | cfg: port configuration as JSON string |
| 1733 | ipv6: Use True to move IPv6 host |
You Wang | 6e5b48e | 2018-07-23 16:17:38 -0700 | [diff] [blame] | 1734 | vlan: vlan number of the host |
Jonghwan Hyun | 785471d | 2018-05-14 14:48:19 -0700 | [diff] [blame] | 1735 | """ |
Jonghwan Hyun | 785471d | 2018-05-14 14:48:19 -0700 | [diff] [blame] | 1736 | if not hasattr( main, 'Mininet1' ): |
| 1737 | main.log.warn( "moveHost is supposed to be used only in Mininet." ) |
| 1738 | return |
| 1739 | |
You Wang | 6e5b48e | 2018-07-23 16:17:38 -0700 | [diff] [blame] | 1740 | main.step( "Moving {} host {} from {} to {}".format( 'tagged' if vlan else 'untagged', hostName, srcSw, dstSw ) ) |
| 1741 | main.Mininet1.moveHost( hostName, srcSw, dstSw, macAddr, prefixLen, ipv6, vlan=vlan ) |
| 1742 | if not ipv6: |
You Wang | 6260ed5 | 2018-07-18 17:54:25 -0700 | [diff] [blame] | 1743 | main.Mininet1.changeDefaultGateway( hostName, gw ) |
Jonghwan Hyun | 785471d | 2018-05-14 14:48:19 -0700 | [diff] [blame] | 1744 | if cfg: |
| 1745 | main.Cluster.active( 0 ).REST.setNetCfg( json.loads( cfg ), |
| 1746 | subjectClass="ports" ) |
You Wang | 6260ed5 | 2018-07-18 17:54:25 -0700 | [diff] [blame] | 1747 | # Wait for the host to get RA for setting up default gateway |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1748 | main.log.debug( "sleeping %i seconds" % ( 5 ) ) |
You Wang | 6260ed5 | 2018-07-18 17:54:25 -0700 | [diff] [blame] | 1749 | time.sleep( 5 ) |
Jonghwan Hyun | 785471d | 2018-05-14 14:48:19 -0700 | [diff] [blame] | 1750 | |
| 1751 | main.Mininet1.discoverHosts( [ hostName, ] ) |
| 1752 | |
| 1753 | # Update expectedHost when MAC address is changed. |
| 1754 | if macAddr is not None: |
| 1755 | ipAddr = main.expectedHosts[ "network" ][ hostName ] |
| 1756 | if ipAddr is not None: |
| 1757 | for hostName, ip in main.expectedHosts[ "onos" ].items(): |
| 1758 | if ip == ipAddr: |
| 1759 | vlan = hostName.split( "/" )[ -1 ] |
| 1760 | del main.expectedHosts[ "onos" ][ hostName ] |
You Wang | 7ea9058 | 2018-07-19 15:27:58 -0700 | [diff] [blame] | 1761 | main.expectedHosts[ "onos" ][ "{}/{}".format( macAddr.upper(), vlan ) ] = ip |
Jonghwan Hyun | 785471d | 2018-05-14 14:48:19 -0700 | [diff] [blame] | 1762 | break |
Jonghwan Hyun | 5fad178 | 2018-05-21 14:11:16 -0700 | [diff] [blame] | 1763 | |
| 1764 | @staticmethod |
| 1765 | def moveDualHomedHost( main, hostName, srcSw, srcPairSw, dstSw, dstPairSw, gw, |
You Wang | 6e5b48e | 2018-07-23 16:17:38 -0700 | [diff] [blame] | 1766 | macAddr=None, prefixLen=24, cfg='', ipv6=False, vlan=None ): |
Jonghwan Hyun | 5fad178 | 2018-05-21 14:11:16 -0700 | [diff] [blame] | 1767 | """ |
| 1768 | Move specified dual-homed host from srcSw-srcPairSw to dstSw-dstPairSw. |
| 1769 | If srcSw-srcPairSw and dstSw-dstPairSw are same, the host will be moved from current port |
| 1770 | to next available port. |
| 1771 | Required: |
| 1772 | hostName: name of the host. e.g., "h1" |
| 1773 | srcSw: name of the switch that the host is attached to. e.g., "leaf1" |
| 1774 | srcPairSw: name of the paired-switch that the host is attached to. e.g., "leaf2" |
| 1775 | dstSw: name of the switch that the host will be moved to. e.g., "leaf1" |
| 1776 | dstPairSw: name of the paired-switch that the host will be moved to. e.g., "leaf2" |
| 1777 | gw: ip address of the gateway of the new location |
| 1778 | Optional: |
| 1779 | macAddr: if specified, change MAC address of the host to the specified MAC address. |
| 1780 | prefixLen: prefix length |
| 1781 | cfg: port configurations as JSON string |
You Wang | 7ea9058 | 2018-07-19 15:27:58 -0700 | [diff] [blame] | 1782 | ipv6: Use True to move IPv6 host |
You Wang | 6e5b48e | 2018-07-23 16:17:38 -0700 | [diff] [blame] | 1783 | vlan: vlan number of the host |
Jonghwan Hyun | 5fad178 | 2018-05-21 14:11:16 -0700 | [diff] [blame] | 1784 | """ |
Jonghwan Hyun | 5fad178 | 2018-05-21 14:11:16 -0700 | [diff] [blame] | 1785 | if not hasattr( main, 'Mininet1' ): |
| 1786 | main.log.warn( "moveDualHomedHost is supposed to be used only in Mininet." ) |
| 1787 | return |
| 1788 | |
You Wang | 6e5b48e | 2018-07-23 16:17:38 -0700 | [diff] [blame] | 1789 | main.step( "Moving {} host {} from {} and {} to {} and {}".format( 'tagged' if vlan else 'untagged', hostName, |
| 1790 | srcSw, srcPairSw, dstSw, dstPairSw ) ) |
| 1791 | main.Mininet1.moveDualHomedHost( hostName, srcSw, srcPairSw, dstSw, dstPairSw, |
| 1792 | macAddr=macAddr, prefixLen=prefixLen, ipv6=ipv6, vlan=vlan ) |
| 1793 | if not ipv6: |
You Wang | 7ea9058 | 2018-07-19 15:27:58 -0700 | [diff] [blame] | 1794 | main.Mininet1.changeDefaultGateway( hostName, gw ) |
Jonghwan Hyun | 5fad178 | 2018-05-21 14:11:16 -0700 | [diff] [blame] | 1795 | if cfg: |
| 1796 | main.Cluster.active( 0 ).REST.setNetCfg( json.loads( cfg ), |
| 1797 | subjectClass="ports" ) |
You Wang | 7ea9058 | 2018-07-19 15:27:58 -0700 | [diff] [blame] | 1798 | # Wait for the host to get RA for setting up default gateway |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1799 | main.log.debug( "sleeping %i seconds" % ( 5 ) ) |
You Wang | 7ea9058 | 2018-07-19 15:27:58 -0700 | [diff] [blame] | 1800 | time.sleep( 5 ) |
Jonghwan Hyun | 5fad178 | 2018-05-21 14:11:16 -0700 | [diff] [blame] | 1801 | |
| 1802 | main.Mininet1.discoverHosts( [ hostName, ] ) |
| 1803 | |
| 1804 | # Update expectedHost when MAC address is changed. |
| 1805 | if macAddr is not None: |
| 1806 | ipAddr = main.expectedHosts[ "network" ][ hostName ] |
| 1807 | if ipAddr is not None: |
| 1808 | for hostName, ip in main.expectedHosts[ "onos" ].items(): |
| 1809 | if ip == ipAddr: |
| 1810 | vlan = hostName.split( "/" )[ -1 ] |
| 1811 | del main.expectedHosts[ "onos" ][ hostName ] |
You Wang | 7ea9058 | 2018-07-19 15:27:58 -0700 | [diff] [blame] | 1812 | main.expectedHosts[ "onos" ][ "{}/{}".format( macAddr.upper(), vlan ) ] = ip |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1813 | |
| 1814 | @staticmethod |
| 1815 | def mnDockerSetup( main ): |
| 1816 | """ |
| 1817 | Optionally start and setup docker image for mininet |
| 1818 | """ |
Jon Hall | 9b0de1f | 2020-08-24 15:38:04 -0700 | [diff] [blame] | 1819 | try: |
| 1820 | if 'MN_DOCKER' in main.params and main.params['MN_DOCKER']['args']: |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1821 | |
Jon Hall | 9b0de1f | 2020-08-24 15:38:04 -0700 | [diff] [blame] | 1822 | main.log.info( "Creating Mininet Docker" ) |
| 1823 | handle = main.Mininet1.handle |
| 1824 | # build docker image |
| 1825 | dockerFilePath = "%s/../dependencies/" % main.testDir |
| 1826 | dockerName = "trellis_mininet" |
| 1827 | # Stop any leftover container |
| 1828 | main.Mininet1.dockerStop( dockerName ) |
| 1829 | # TODO: assert on these docker calls |
Jon Hall | 3957026 | 2020-11-17 12:18:19 -0800 | [diff] [blame] | 1830 | main.Mininet1.dockerBuild( dockerFilePath, dockerName, pull=True ) |
Jon Hall | f6aeda2 | 2020-07-28 09:12:56 -0700 | [diff] [blame] | 1831 | |
Jon Hall | 9b0de1f | 2020-08-24 15:38:04 -0700 | [diff] [blame] | 1832 | confDir = "/tmp/mn_conf/" |
| 1833 | # Try to ensure the destination exists |
| 1834 | main.log.info( "Create folder for network config files" ) |
| 1835 | handle.sendline( "rm -rf %s" % confDir ) |
| 1836 | handle.expect( main.Mininet1.Prompt() ) |
| 1837 | main.log.debug( handle.before + handle.after ) |
| 1838 | handle.sendline( "mkdir -p %s" % confDir ) |
| 1839 | handle.expect( main.Mininet1.Prompt() ) |
| 1840 | main.log.debug( handle.before + handle.after ) |
Jon Hall | 3957026 | 2020-11-17 12:18:19 -0800 | [diff] [blame] | 1841 | handle.sendline( "sudo rm -rf /tmp/mn-stratum/*" ) |
| 1842 | handle.expect( main.Mininet1.Prompt() ) |
Jon Hall | 9b0de1f | 2020-08-24 15:38:04 -0700 | [diff] [blame] | 1843 | # Make sure permissions are correct |
| 1844 | handle.sendline( "sudo chown %s:%s %s" % ( main.Mininet1.user_name, main.Mininet1.user_name, confDir ) ) |
| 1845 | handle.expect( main.Mininet1.Prompt() ) |
| 1846 | handle.sendline( "sudo chmod -R a+rwx %s" % ( confDir ) ) |
| 1847 | handle.expect( main.Mininet1.Prompt() ) |
| 1848 | main.log.debug( handle.before + handle.after ) |
| 1849 | # Start docker container |
| 1850 | runResponse = main.Mininet1.dockerRun( main.params[ 'MN_DOCKER' ][ 'name' ], |
| 1851 | dockerName, |
| 1852 | main.params[ 'MN_DOCKER' ][ 'args' ] ) |
| 1853 | if runResponse == main.FALSE: |
| 1854 | main.log.error( "Docker container already running, aborting test" ) |
| 1855 | main.cleanup() |
| 1856 | main.exit() |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1857 | |
Jon Hall | 9b0de1f | 2020-08-24 15:38:04 -0700 | [diff] [blame] | 1858 | main.Mininet1.dockerAttach( dockerName, dockerPrompt='~#' ) |
| 1859 | main.Mininet1.sudoRequired = False |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1860 | |
Jon Hall | 9b0de1f | 2020-08-24 15:38:04 -0700 | [diff] [blame] | 1861 | # Fow when we create component handles |
| 1862 | main.Mininet1.mExecDir = "/tmp" |
| 1863 | main.Mininet1.hostHome = main.params[ "MN_DOCKER" ][ "home" ] |
| 1864 | main.Mininet1.hostPrompt = "/home/root#" |
| 1865 | |
| 1866 | # For some reason docker isn't doing this |
| 1867 | main.Mininet1.handle.sendline( "echo \"127.0.0.1 $(cat /etc/hostname)\" >> /etc/hosts" ) |
| 1868 | main.Mininet1.handle.expect( "etc/hosts" ) |
| 1869 | main.Mininet1.handle.expect( main.Mininet1.Prompt() ) |
| 1870 | except Exception as e: |
| 1871 | main.log.exception( "Error seting up mininet" ) |
Jon Hall | 3957026 | 2020-11-17 12:18:19 -0800 | [diff] [blame] | 1872 | main.skipCase( result="FAIL", msg=e ) |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1873 | |
| 1874 | @staticmethod |
| 1875 | def mnDockerTeardown( main ): |
| 1876 | """ |
| 1877 | Optionally stop and cleanup docker image for mininet |
| 1878 | """ |
| 1879 | |
| 1880 | if hasattr( main, 'Mininet1' ): |
| 1881 | if 'MN_DOCKER' in main.params and main.params['MN_DOCKER']['args']: |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 1882 | main.log.info( "Exiting from Mininet Docker" ) |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1883 | |
| 1884 | # Detach from container |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1885 | try: |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 1886 | main.Mininet1.dockerDisconnect() |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1887 | main.Mininet1.sudoRequired = True |
| 1888 | except Exception as e: |
| 1889 | main.log.error( e ) |
| 1890 | |
Jon Hall | 3957026 | 2020-11-17 12:18:19 -0800 | [diff] [blame] | 1891 | # Save docker logs |
| 1892 | copyResult = main.ONOSbench.scp( main.Mininet1, |
| 1893 | "/tmp/mn-stratum/*", |
| 1894 | main.logdir, |
| 1895 | direction="from", |
| 1896 | options="-rp" ) |
| 1897 | |
| 1898 | |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1899 | @staticmethod |
| 1900 | def setOnosConfig( main ): |
| 1901 | """ |
| 1902 | Read and Set onos configurations from the params file |
| 1903 | """ |
| 1904 | main.step( "Set ONOS configurations" ) |
| 1905 | config = main.params.get( 'ONOS_Configuration' ) |
| 1906 | if config: |
| 1907 | main.log.debug( config ) |
| 1908 | checkResult = main.TRUE |
| 1909 | for component in config: |
| 1910 | for setting in config[ component ]: |
| 1911 | value = config[ component ][ setting ] |
| 1912 | check = main.Cluster.next().setCfg( component, setting, value ) |
| 1913 | main.log.info( "Value was changed? {}".format( main.TRUE == check ) ) |
| 1914 | checkResult = check and checkResult |
| 1915 | utilities.assert_equals( expect=main.TRUE, |
| 1916 | actual=checkResult, |
| 1917 | onpass="Successfully set config", |
| 1918 | onfail="Failed to set config" ) |
| 1919 | else: |
| 1920 | main.log.warn( "No configurations were specified to be changed after startup" ) |
| 1921 | |
| 1922 | @staticmethod |
| 1923 | def setOnosLogLevels( main ): |
| 1924 | """ |
| 1925 | Read and Set onos log levels from the params file |
| 1926 | """ |
| 1927 | main.step( 'Set logging levels' ) |
Jon Hall | 06fd0df | 2021-01-25 15:50:06 -0800 | [diff] [blame] | 1928 | # Get original values incase we want to reset them |
| 1929 | ctrl = main.Cluster.active(0) |
Jon Hall | a7b27e6 | 2021-06-29 12:13:51 -0700 | [diff] [blame] | 1930 | ctrl.CLI.clearBuffer( timeout=1 ) |
Jon Hall | 06fd0df | 2021-01-25 15:50:06 -0800 | [diff] [blame] | 1931 | ctrl.CLI.logList() |
| 1932 | |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1933 | logging = True |
| 1934 | try: |
| 1935 | logs = main.params.get( 'ONOS_Logging', False ) |
| 1936 | if logs: |
| 1937 | for namespace, level in logs.items(): |
| 1938 | for ctrl in main.Cluster.active(): |
| 1939 | ctrl.CLI.logSet( level, namespace ) |
| 1940 | except AttributeError: |
| 1941 | logging = False |
| 1942 | utilities.assert_equals( expect=True, actual=logging, |
| 1943 | onpass="Set log levels", |
| 1944 | onfail="Failed to set log levels" ) |
Jon Hall | 06fd0df | 2021-01-25 15:50:06 -0800 | [diff] [blame] | 1945 | |
| 1946 | @staticmethod |
| 1947 | def resetOnosLogLevels( main ): |
| 1948 | """ |
| 1949 | Read and reset onos log levels to a previously read set of values |
| 1950 | """ |
| 1951 | main.step( 'Reset logging levels' ) |
| 1952 | # Get original values incase we want to reset them |
| 1953 | ctrl = main.Cluster.active(0) |
Jon Hall | a7b27e6 | 2021-06-29 12:13:51 -0700 | [diff] [blame] | 1954 | ctrl.CLI.clearBuffer( timeout=1 ) |
Jon Hall | 06fd0df | 2021-01-25 15:50:06 -0800 | [diff] [blame] | 1955 | currentLevels = ctrl.CLI.logList( saveValues=False ) |
| 1956 | origLevels = ctrl.CLI.logLevels |
| 1957 | toBeSet = {} |
| 1958 | for logger, level in currentLevels.iteritems(): |
| 1959 | if logger not in origLevels: |
| 1960 | toBeSet[ logger ] = origLevels[ 'ROOT' ] |
| 1961 | else: |
| 1962 | oldLevel = origLevels[ logger ] |
| 1963 | if level != oldLevel: |
| 1964 | toBeSet[ logger ] = oldLevel |
Jon Hall | ef1480b | 2021-03-31 13:37:41 -0700 | [diff] [blame] | 1965 | # In case a previous test didn't reset |
| 1966 | logs = main.params.get( 'ONOS_Logging_Reset', False ) |
| 1967 | if logs: |
| 1968 | for namespace, level in logs.items(): |
| 1969 | toBeSet[ namespace ] = level |
Jon Hall | 06fd0df | 2021-01-25 15:50:06 -0800 | [diff] [blame] | 1970 | logging = True |
| 1971 | try: |
| 1972 | for logger, level in toBeSet.iteritems(): |
| 1973 | for ctrl in main.Cluster.active(): |
| 1974 | ctrl.CLI.logSet( level, logger ) |
| 1975 | except AttributeError: |
| 1976 | logging = False |
| 1977 | utilities.assert_equals( expect=True, actual=logging, |
| 1978 | onpass="Reset log levels", |
| 1979 | onfail="Failed to reset log levels" ) |