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 | 606bd87 | 2021-06-29 23:42:36 +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 |
| 220 | with open( "%s%s.cfg%s" % ( main.configPath + main.forcfg, |
| 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 ) |
| 849 | main.log.warn( "Looking for allowed vlans for %s" % hostIp ) |
| 850 | vlans = [] |
| 851 | for obj in hostsJson: |
| 852 | if hostIp in obj['ipAddresses']: |
| 853 | for location in obj['locations']: |
| 854 | did = location['elementId'].encode( 'utf-8' ) |
| 855 | port = location['port'].encode( 'utf-8' ) |
| 856 | m = re.search( '\((\d+)\)', port ) |
| 857 | if m: |
| 858 | port = m.group(1) |
| 859 | portId = "%s/%s" % ( did, port ) |
| 860 | # Lookup ip assigned to this network port |
| 861 | # Valid host vlans: |
| 862 | # None if vlan-untagged |
| 863 | # vlanid if vlan-tagged: vlanid |
| 864 | # None if vlan-native + any vlan ids from vlan-tagged |
| 865 | intf = netcfgJson[ portId ][ 'interfaces' ][0] |
| 866 | for field in intf.keys(): |
| 867 | if "vlan-untagged" in field: |
| 868 | vlans.append( None ) |
| 869 | if "vlan-tagged" in field: |
| 870 | vlans.append( int( intf[ field ].encode( 'utf-8' ) ) ) |
| 871 | if "vlan-native" in field: |
| 872 | vlans.append( None ) |
| 873 | if len( vlans ) == 0: |
| 874 | main.log.debug( "Could not find vlan setting for %s" % hostname ) |
| 875 | vlans = set( vlans ) |
Siddesh | d984084 | 2021-08-06 19:26:05 +0000 | [diff] [blame] | 876 | hostComponent.interfaces[0][ 'vlan' ] = list( vlans ) |
Jon Hall | 326501b | 2021-08-31 10:14:55 -0700 | [diff] [blame] | 877 | main.log.debug( repr( hostComponent.interfaces[0] ) ) |
| 878 | main.log.debug( repr( hostComponent.interfaces[0].get( 'vlan' ) ) ) |
| 879 | except ValueError: |
| 880 | main.log.exception( "Error getting vlans for %s" % hostname ) |
| 881 | |
| 882 | |
| 883 | @staticmethod |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 884 | def killLink( main, end1, end2, switches, links, sleep=None ): |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 885 | """ |
| 886 | end1,end2: identify the switches, ex.: 'leaf1', 'spine1' |
| 887 | switches, links: number of expected switches and links after linkDown, ex.: '4', '6' |
| 888 | Kill a link and verify ONOS can see the proper link change |
| 889 | """ |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 890 | if sleep is None: |
| 891 | sleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] ) |
| 892 | else: |
| 893 | sleep = float( sleep ) |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 894 | main.step( "Kill link between %s and %s" % ( end1, end2 ) ) |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 895 | linkDown = main.Network.link( END1=end1, END2=end2, OPTION="down" ) |
| 896 | linkDown = linkDown and main.Network.link( END2=end1, END1=end2, OPTION="down" ) |
Jon Hall | 214f88b | 2020-09-21 10:21:42 -0700 | [diff] [blame] | 897 | utilities.assert_equals( expect=main.TRUE, actual=linkDown, |
| 898 | onpass="Link down successful", |
| 899 | onfail="Failed to turn off link?" ) |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 900 | # 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] | 901 | main.log.info( |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 902 | "Waiting %s seconds for link down to be discovered" % sleep ) |
| 903 | time.sleep( sleep ) |
Jon Hall | 214f88b | 2020-09-21 10:21:42 -0700 | [diff] [blame] | 904 | main.step( "Checking topology after link down" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 905 | topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus, |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 906 | main.FALSE, |
| 907 | kwargs={ 'numoswitch': switches, |
| 908 | 'numolink': links }, |
| 909 | attempts=10, |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 910 | sleep=sleep ) |
Jon Hall | 214f88b | 2020-09-21 10:21:42 -0700 | [diff] [blame] | 911 | utilities.assert_equals( expect=main.TRUE, actual=topology, |
| 912 | onpass="Topology after link down is correct", |
| 913 | onfail="Topology after link down is incorrect" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 914 | |
| 915 | @staticmethod |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 916 | def killLinkBatch( main, links, linksAfter, switches, sleep=None ): |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 917 | """ |
| 918 | links = list of links (src, dst) to bring down. |
| 919 | """ |
| 920 | |
| 921 | main.step("Killing a batch of links {0}".format(links)) |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 922 | if sleep is None: |
| 923 | sleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] ) |
| 924 | else: |
| 925 | sleep = float( sleep ) |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 926 | |
| 927 | for end1, end2 in links: |
| 928 | main.Network.link( END1=end1, END2=end2, OPTION="down") |
| 929 | main.Network.link( END1=end2, END2=end1, OPTION="down") |
| 930 | |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 931 | # 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] | 932 | main.log.info( |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 933 | "Waiting %s seconds for links down to be discovered" % sleep ) |
| 934 | time.sleep( sleep ) |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 935 | |
| 936 | topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus, |
| 937 | main.FALSE, |
| 938 | kwargs={ 'numoswitch': switches, |
| 939 | 'numolink': linksAfter }, |
| 940 | attempts=10, |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 941 | sleep=sleep ) |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 942 | |
You Wang | 2854bce | 2018-03-30 10:15:32 -0700 | [diff] [blame] | 943 | utilities.assert_equals( expect=main.TRUE, actual=topology, |
| 944 | onpass="Link batch down successful", |
| 945 | onfail="Link batch down failed" ) |
| 946 | |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 947 | @staticmethod |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 948 | def restoreLinkBatch( main, links, linksAfter, switches, sleep=None ): |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 949 | """ |
| 950 | links = list of link (src, dst) to bring up again. |
| 951 | """ |
| 952 | |
| 953 | main.step("Restoring a batch of links {0}".format(links)) |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 954 | if sleep is None: |
| 955 | sleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] ) |
| 956 | else: |
| 957 | sleep = float( sleep ) |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 958 | |
| 959 | for end1, end2 in links: |
| 960 | main.Network.link( END1=end1, END2=end2, OPTION="up") |
| 961 | main.Network.link( END1=end2, END2=end1, OPTION="up") |
| 962 | |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 963 | main.log.info( |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 964 | "Waiting %s seconds for links up to be discovered" % sleep ) |
| 965 | time.sleep( sleep ) |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 966 | |
| 967 | topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus, |
| 968 | main.FALSE, |
| 969 | kwargs={ 'numoswitch': switches, |
| 970 | 'numolink': linksAfter }, |
| 971 | attempts=10, |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 972 | sleep=sleep ) |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 973 | |
You Wang | 2854bce | 2018-03-30 10:15:32 -0700 | [diff] [blame] | 974 | utilities.assert_equals( expect=main.TRUE, actual=topology, |
| 975 | onpass="Link batch up successful", |
| 976 | onfail="Link batch up failed" ) |
| 977 | |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 978 | @staticmethod |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 979 | def disablePortBatch( main, ports, switches=None, links=None, sleep=None ): |
| 980 | """ |
| 981 | Disable a list of switch ports using 'portstate' and verify ONOS can see the proper link change |
| 982 | ports: a list of ports to disable ex. [ [ "of:0000000000000001", 1 ] ] |
| 983 | switches, links: number of expected switches and links after link change, ex.: '4', '6' |
| 984 | """ |
| 985 | if sleep is None: |
| 986 | sleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] ) |
| 987 | else: |
| 988 | sleep = float( sleep ) |
| 989 | main.step( "Disable a batch of ports" ) |
| 990 | for dpid, port in ports: |
| 991 | main.Cluster.active( 0 ).CLI.portstate( dpid=dpid, port=port, state="disable" ) |
| 992 | main.log.info( "Waiting {} seconds for port down to be discovered".format( sleep ) ) |
| 993 | time.sleep( sleep ) |
| 994 | if switches and links: |
| 995 | result = main.Cluster.active( 0 ).CLI.checkStatus( numoswitch=switches, |
| 996 | numolink=links ) |
| 997 | utilities.assert_equals( expect=main.TRUE, actual=result, |
| 998 | onpass="Port down successful", |
| 999 | onfail="Port down failed" ) |
| 1000 | |
| 1001 | @staticmethod |
| 1002 | def enablePortBatch( main, ports, switches, links, sleep=None ): |
| 1003 | """ |
| 1004 | Enable a list of switch ports using 'portstate' and verify ONOS can see the proper link change |
| 1005 | ports: a list of ports to enable ex. [ [ "of:0000000000000001", 1 ] ] |
| 1006 | switches, links: number of expected switches and links after link change, ex.: '4', '6' |
| 1007 | """ |
| 1008 | if sleep is None: |
| 1009 | sleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] ) |
| 1010 | else: |
| 1011 | sleep = float( sleep ) |
| 1012 | main.step( "Enable a batch of ports" ) |
| 1013 | for dpid, port in ports: |
| 1014 | main.Cluster.active( 0 ).CLI.portstate( dpid=dpid, port=port, state="enable" ) |
| 1015 | main.log.info( "Waiting {} seconds for port up to be discovered".format( sleep ) ) |
| 1016 | time.sleep( sleep ) |
| 1017 | if switches and links: |
| 1018 | result = main.Cluster.active( 0 ).CLI.checkStatus( numoswitch=switches, |
| 1019 | numolink=links ) |
| 1020 | utilities.assert_equals( expect=main.TRUE, actual=result, |
| 1021 | onpass="Port up successful", |
| 1022 | onfail="Port up failed" ) |
| 1023 | |
| 1024 | @staticmethod |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 1025 | def restoreLink( main, end1, end2, switches, links, |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1026 | portUp=False, dpid1='', dpid2='', port1='', port2='', sleep=None ): |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1027 | """ |
| 1028 | Params: |
| 1029 | end1,end2: identify the end switches, ex.: 'leaf1', 'spine1' |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 1030 | portUp: enable portstate after restoring link |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1031 | dpid1, dpid2: dpid of the end switches respectively, ex.: 'of:0000000000000002' |
| 1032 | port1, port2: respective port of the end switches that connects to the link, ex.:'1' |
| 1033 | switches, links: number of expected switches and links after linkDown, ex.: '4', '6' |
| 1034 | Kill a link and verify ONOS can see the proper link change |
| 1035 | """ |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 1036 | main.step( "Restore link between %s and %s" % ( end1, end2 ) ) |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1037 | if sleep is None: |
| 1038 | sleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] ) |
| 1039 | else: |
| 1040 | sleep = float( sleep ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1041 | result = False |
| 1042 | count = 0 |
| 1043 | while True: |
| 1044 | count += 1 |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1045 | ctrl = main.Cluster.next() |
You Wang | d587348 | 2018-01-24 12:30:00 -0800 | [diff] [blame] | 1046 | main.Network.link( END1=end1, END2=end2, OPTION="up" ) |
| 1047 | main.Network.link( END2=end1, END1=end2, OPTION="up" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1048 | main.log.info( |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1049 | "Waiting %s seconds for link up to be discovered" % sleep ) |
| 1050 | time.sleep( sleep ) |
Pier | fb719b1 | 2016-09-19 14:51:44 -0700 | [diff] [blame] | 1051 | |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 1052 | if portUp: |
| 1053 | ctrl.CLI.portstate( dpid=dpid1, port=port1, state='Enable' ) |
| 1054 | ctrl.CLI.portstate( dpid=dpid2, port=port2, state='Enable' ) |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1055 | main.log.info( |
| 1056 | "Waiting %s seconds for link up to be discovered" % sleep ) |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1057 | time.sleep( sleep ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1058 | |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1059 | result = ctrl.CLI.checkStatus( numoswitch=switches, |
| 1060 | numolink=links ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1061 | if count > 5 or result: |
| 1062 | break |
| 1063 | utilities.assert_equals( expect=main.TRUE, actual=result, |
| 1064 | onpass="Link up successful", |
| 1065 | onfail="Failed to bring link up" ) |
| 1066 | |
| 1067 | @staticmethod |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1068 | def killSwitch( main, switch, switches, links, sleep=None ): |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1069 | """ |
| 1070 | Params: switches, links: number of expected switches and links after SwitchDown, ex.: '4', '6' |
| 1071 | Completely kill a switch and verify ONOS can see the proper change |
| 1072 | """ |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1073 | if sleep is None: |
| 1074 | sleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] ) |
| 1075 | else: |
| 1076 | sleep = float( sleep ) |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 1077 | switch = switch if isinstance( switch, list ) else [ switch ] |
| 1078 | main.step( "Kill " + str( switch ) ) |
| 1079 | for s in switch: |
| 1080 | main.log.info( "Stopping " + s ) |
| 1081 | main.Network.switch( SW=s, OPTION="stop" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1082 | # todo make this repeatable |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1083 | |
| 1084 | # 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] | 1085 | main.log.info( "Waiting %s seconds for switch down to be discovered" % ( |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1086 | sleep ) ) |
| 1087 | time.sleep( sleep ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 1088 | topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus, |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1089 | main.FALSE, |
| 1090 | kwargs={ 'numoswitch': switches, |
| 1091 | 'numolink': links }, |
| 1092 | attempts=10, |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1093 | sleep=sleep ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1094 | utilities.assert_equals( expect=main.TRUE, actual=topology, |
| 1095 | onpass="Kill switch successful", |
| 1096 | onfail="Failed to kill switch?" ) |
| 1097 | |
| 1098 | @staticmethod |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1099 | def recoverSwitch( main, switch, switches, links, rediscoverHosts=False, hostsToDiscover=[], sleep=None ): |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1100 | """ |
| 1101 | Params: switches, links: number of expected switches and links after SwitchUp, ex.: '4', '6' |
| 1102 | Recover a switch and verify ONOS can see the proper change |
| 1103 | """ |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1104 | if sleep is None: |
| 1105 | sleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] ) |
| 1106 | else: |
| 1107 | sleep = float( sleep ) |
| 1108 | # TODO make this repeatable |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 1109 | switch = switch if isinstance( switch, list ) else [ switch ] |
| 1110 | main.step( "Recovering " + str( switch ) ) |
| 1111 | for s in switch: |
| 1112 | main.log.info( "Starting " + s ) |
| 1113 | main.Network.switch( SW=s, OPTION="start" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1114 | main.log.info( "Waiting %s seconds for switch up to be discovered" % ( |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1115 | sleep ) ) |
| 1116 | time.sleep( sleep ) |
Andreas Pantelopoulos | 74c7ff2 | 2018-05-01 15:42:02 -0700 | [diff] [blame] | 1117 | if rediscoverHosts: |
You Wang | 4838175 | 2018-05-07 13:50:57 -0700 | [diff] [blame] | 1118 | main.Network.discoverHosts( hostList=hostsToDiscover ) |
Andreas Pantelopoulos | 74c7ff2 | 2018-05-01 15:42:02 -0700 | [diff] [blame] | 1119 | main.log.info( "Waiting %s seconds for hosts to get re-discovered" % ( |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1120 | sleep ) ) |
| 1121 | time.sleep( sleep ) |
Andreas Pantelopoulos | 74c7ff2 | 2018-05-01 15:42:02 -0700 | [diff] [blame] | 1122 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 1123 | topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus, |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1124 | main.FALSE, |
| 1125 | kwargs={ 'numoswitch': switches, |
| 1126 | 'numolink': links }, |
| 1127 | attempts=10, |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1128 | sleep=sleep ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1129 | utilities.assert_equals( expect=main.TRUE, actual=topology, |
| 1130 | onpass="Switch recovery successful", |
| 1131 | onfail="Failed to recover switch?" ) |
| 1132 | |
Jonghwan Hyun | 25c98a6 | 2018-05-04 13:59:09 -0700 | [diff] [blame] | 1133 | @staticmethod |
You Wang | 0f745de | 2018-07-27 15:49:22 -0700 | [diff] [blame] | 1134 | def killRouter( main, router, sleep=None ): |
| 1135 | """ |
| 1136 | Kill bgpd process on a quagga router |
| 1137 | router: name of the router to be killed. E.g. "bgp1" |
| 1138 | """ |
| 1139 | sleep = float( sleep ) |
| 1140 | main.step( "Kill " + str( router ) ) |
| 1141 | if hasattr( main, 'Mininet1' ): |
| 1142 | main.Mininet1.handle.sendline( "px {}.stopProtocols()".format( router ) ) |
| 1143 | main.Mininet1.handle.expect( "mininet>" ) |
| 1144 | else: |
| 1145 | # TODO: support killing router in physical network |
| 1146 | pass |
| 1147 | main.log.info( "Waiting %s seconds for router down to be discovered" % ( sleep ) ) |
| 1148 | time.sleep( sleep ) |
| 1149 | |
| 1150 | @staticmethod |
| 1151 | def recoverRouter( main, router, sleep=None ): |
| 1152 | """ |
| 1153 | Restart bgpd process on a quagga router |
| 1154 | router: name of the router to be recovered. E.g. "bgp1" |
| 1155 | """ |
| 1156 | sleep = float( sleep ) |
| 1157 | main.step( "Recovering " + str( router ) ) |
| 1158 | if hasattr( main, 'Mininet1' ): |
| 1159 | main.Mininet1.handle.sendline( "px {}.startProtocols()".format( router ) ) |
| 1160 | main.Mininet1.handle.expect( "mininet>" ) |
| 1161 | else: |
| 1162 | # TODO: support recovering router in physical network |
| 1163 | pass |
| 1164 | main.log.info( "Waiting %s seconds for router up to be discovered" % ( sleep ) ) |
| 1165 | time.sleep( sleep ) |
| 1166 | |
| 1167 | @staticmethod |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 1168 | def cleanup( main, copyKarafLog=True, removeHostComponent=False ): |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1169 | """ |
| 1170 | Stop Onos-cluster. |
| 1171 | Stops Mininet |
| 1172 | Copies ONOS log |
| 1173 | """ |
You Wang | 4cc6191 | 2018-08-28 10:10:58 -0700 | [diff] [blame] | 1174 | from tests.dependencies.utils import Utils |
| 1175 | main.utils = Utils() |
Jon Hall | 627b157 | 2020-12-01 12:01:15 -0800 | [diff] [blame] | 1176 | if not main.persistentSetup: |
| 1177 | for ctrl in main.Cluster.active(): |
| 1178 | ctrl.CLI.log( "\"Ending Test - Shutting down ONOS and Network\"", level="INFO" ) |
You Wang | 4cc6191 | 2018-08-28 10:10:58 -0700 | [diff] [blame] | 1179 | # Clean up scapy hosts |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 1180 | if hasattr( main, "scapyHosts" ): |
| 1181 | scapyResult = main.TRUE |
| 1182 | for host in main.scapyHosts: |
| 1183 | scapyResult = host.stopScapy() and scapyResult |
| 1184 | main.log.info( "Stopped Scapy Host: {0}".format( host.name ) ) |
| 1185 | for host in main.scapyHosts: |
You Wang | 4cc6191 | 2018-08-28 10:10:58 -0700 | [diff] [blame] | 1186 | if hasattr( main, 'Mininet1' ): |
| 1187 | scapyResult = main.Scapy.removeHostComponent( host.name ) and scapyResult |
| 1188 | else: |
| 1189 | scapyResult = main.Network.removeHostComponent( host.name ) and scapyResult |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 1190 | main.log.info( "Removed Scapy Host Component: {0}".format( host.name ) ) |
| 1191 | main.scapyHosts = [] |
| 1192 | |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 1193 | if removeHostComponent: |
Jon Hall | 22a3bcf | 2021-07-23 11:40:11 -0700 | [diff] [blame] | 1194 | try: |
| 1195 | for host in main.internalIpv4Hosts + main.internalIpv6Hosts + main.externalIpv4Hosts + main.externalIpv6Hosts: |
| 1196 | if hasattr( main, host ): |
| 1197 | if hasattr( main, 'Mininet1' ): |
| 1198 | pass |
| 1199 | else: |
| 1200 | getattr( main, host ).disconnectInband() |
| 1201 | main.Network.removeHostComponent( host ) |
| 1202 | except AttributeError as e: |
| 1203 | main.log.warn( "Could not cleanup host components: " + repr( e ) ) |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 1204 | |
You Wang | 5df1c6d | 2018-04-06 18:02:02 -0700 | [diff] [blame] | 1205 | if hasattr( main, 'Mininet1' ): |
Pier | 6a0c4de | 2018-03-18 16:01:30 -0700 | [diff] [blame] | 1206 | main.utils.mininetCleanup( main.Mininet1 ) |
You Wang | 4cc6191 | 2018-08-28 10:10:58 -0700 | [diff] [blame] | 1207 | else: |
| 1208 | main.Network.disconnectInbandHosts() |
| 1209 | main.Network.disconnectFromNet() |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 1210 | |
You Wang | 5df1c6d | 2018-04-06 18:02:02 -0700 | [diff] [blame] | 1211 | if copyKarafLog: |
| 1212 | main.utils.copyKarafLog( "CASE%d" % main.CurrentTestCaseNumber, before=True, includeCaseDesc=False ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 1213 | |
Jon Hall | 627b157 | 2020-12-01 12:01:15 -0800 | [diff] [blame] | 1214 | if not main.persistentSetup: |
| 1215 | for ctrl in main.Cluster.active(): |
| 1216 | main.ONOSbench.onosStop( ctrl.ipAddress ) |
Jon Hall | 06fd0df | 2021-01-25 15:50:06 -0800 | [diff] [blame] | 1217 | else: |
| 1218 | Testcaselib.resetOnosLogLevels( main ) |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1219 | Testcaselib.mnDockerTeardown( main ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1220 | |
| 1221 | @staticmethod |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1222 | def verifyNodes( main ): |
| 1223 | """ |
| 1224 | Verifies Each active node in the cluster has an accurate view of other node's and their status |
| 1225 | |
| 1226 | Params: |
| 1227 | nodes, integer array with position of the ONOS nodes in the CLIs array |
| 1228 | """ |
| 1229 | nodeResults = utilities.retry( main.Cluster.nodesCheck, |
| 1230 | False, |
| 1231 | attempts=10, |
| 1232 | sleep=10 ) |
| 1233 | utilities.assert_equals( expect=True, actual=nodeResults, |
| 1234 | onpass="Nodes check successful", |
| 1235 | onfail="Nodes check NOT successful" ) |
| 1236 | |
| 1237 | if not nodeResults: |
| 1238 | for ctrl in main.Cluster.runningNodes: |
| 1239 | main.log.debug( "{} components not ACTIVE: \n{}".format( |
| 1240 | ctrl.name, |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 1241 | ctrl.CLI.sendline( "onos:scr-list | grep -v ACTIVE" ) ) ) |
You Wang | 0bed593 | 2018-12-11 14:45:41 -0800 | [diff] [blame] | 1242 | main.log.error( "Failed to verify nodes, stopping test" ) |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1243 | main.cleanAndExit() |
| 1244 | |
| 1245 | @staticmethod |
Jon Hall | 3957026 | 2020-11-17 12:18:19 -0800 | [diff] [blame] | 1246 | def verifyTopology( main, switches, links, expNodes, SCCs=1 ): |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1247 | """ |
| 1248 | Verifies that the ONOS cluster has an acuurate view of the topology |
| 1249 | |
| 1250 | Params: |
| 1251 | 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] | 1252 | 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] | 1253 | """ |
| 1254 | main.step( "Check number of topology elements" ) |
| 1255 | topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus, |
| 1256 | main.FALSE, |
| 1257 | kwargs={ 'numoswitch': switches, |
| 1258 | 'numolink': links, |
Jon Hall | 3957026 | 2020-11-17 12:18:19 -0800 | [diff] [blame] | 1259 | 'numoctrl': expNodes, |
| 1260 | 'numoSCCs': SCCs }, |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1261 | attempts=10, |
| 1262 | sleep=12 ) |
| 1263 | utilities.assert_equals( expect=main.TRUE, actual=topology, |
| 1264 | onpass="Number of topology elements are correct", |
Jon Hall | 3957026 | 2020-11-17 12:18:19 -0800 | [diff] [blame] | 1265 | onfail="Unexpected number of links, switches, and/or controllers: " + main.TOPOOUTPUT ) |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1266 | |
| 1267 | @staticmethod |
| 1268 | def killOnos( main, nodes, switches, links, expNodes, sleep=None ): |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1269 | """ |
| 1270 | Params: nodes, integer array with position of the ONOS nodes in the CLIs array |
| 1271 | switches, links, nodes: number of expected switches, links and nodes after KillOnos, ex.: '4', '6' |
| 1272 | Completely Kill an ONOS instance and verify the ONOS cluster can see the proper change |
| 1273 | """ |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1274 | # 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] | 1275 | main.step( "Killing ONOS instances with index(es): {}".format( nodes ) ) |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1276 | if sleep is None: |
| 1277 | sleep = float( main.params[ 'timers' ][ 'OnosDiscovery' ] ) |
| 1278 | else: |
| 1279 | sleep = float( sleep ) |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 1280 | |
Jon Hall | 214f88b | 2020-09-21 10:21:42 -0700 | [diff] [blame] | 1281 | stepResult = main.TRUE |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1282 | for i in nodes: |
Jon Hall | 214f88b | 2020-09-21 10:21:42 -0700 | [diff] [blame] | 1283 | node = main.Cluster.runningNodes[ i ] |
| 1284 | if node.inDocker: |
| 1285 | killResult = node.server.dockerStop( node.name ) |
| 1286 | else: |
| 1287 | killResult = main.ONOSbench.onosDie( node.ipAddress ) |
| 1288 | stepResult = stepResult and killResult |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 1289 | main.Cluster.runningNodes[ i ].active = False |
Jon Hall | 214f88b | 2020-09-21 10:21:42 -0700 | [diff] [blame] | 1290 | utilities.assert_equals( expect=main.TRUE, actual=stepResult, |
| 1291 | onpass="ONOS instance Killed", |
| 1292 | onfail="Error killing ONOS instance" ) |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1293 | main.Cluster.reset() |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1294 | main.log.debug( "sleeping %i seconds" % ( sleep ) ) |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1295 | time.sleep( sleep ) |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 1296 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 1297 | if len( nodes ) < main.Cluster.numCtrls: |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1298 | Testcaselib.verifyNodes( main ) |
| 1299 | Testcaselib.verifyTopology( main, switches, links, expNodes ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1300 | |
| 1301 | @staticmethod |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1302 | def recoverOnos( main, nodes, switches, links, expNodes, sleep=None ): |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1303 | """ |
| 1304 | Params: nodes, integer array with position of the ONOS nodes in the CLIs array |
| 1305 | switches, links, nodes: number of expected switches, links and nodes after recoverOnos, ex.: '4', '6' |
| 1306 | Recover an ONOS instance and verify the ONOS cluster can see the proper change |
| 1307 | """ |
Jon Hall | 3c91016 | 2018-03-07 14:42:16 -0800 | [diff] [blame] | 1308 | main.step( "Recovering ONOS instances with index(es): {}".format( nodes ) ) |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1309 | if sleep is None: |
| 1310 | sleep = float( main.params[ 'timers' ][ 'OnosDiscovery' ] ) |
| 1311 | else: |
| 1312 | sleep = float( sleep ) |
Jon Hall | 214f88b | 2020-09-21 10:21:42 -0700 | [diff] [blame] | 1313 | for i in nodes: |
| 1314 | node = main.Cluster.runningNodes[ i ] |
| 1315 | if node.inDocker: |
| 1316 | main.Cluster.startONOSDockerNode( i ) |
| 1317 | else: |
| 1318 | main.ONOSbench.onosStart( node.ipAddress ) |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1319 | main.log.debug( "sleeping %i seconds" % ( sleep ) ) |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1320 | time.sleep( sleep ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1321 | for i in nodes: |
Jon Hall | 3957026 | 2020-11-17 12:18:19 -0800 | [diff] [blame] | 1322 | node = main.Cluster.runningNodes[ i ] |
Jon Hall | 214f88b | 2020-09-21 10:21:42 -0700 | [diff] [blame] | 1323 | if node.inDocker: |
| 1324 | isUp = node.CLI.dockerExec( node.name, dockerPrompt=node.dockerPrompt ) |
| 1325 | isUp = isUp and node.CLI.prepareForCLI() |
| 1326 | isUp = isUp and node.CLI.onosSecureSSH( userName=node.karafUser, userPWD=node.karafPass ) |
| 1327 | else: |
| 1328 | isUp = main.ONOSbench.isup( node.ipAddress ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1329 | utilities.assert_equals( expect=main.TRUE, actual=isUp, |
| 1330 | onpass="ONOS service is ready", |
| 1331 | onfail="ONOS service did not start properly" ) |
| 1332 | for i in nodes: |
| 1333 | main.step( "Checking if ONOS CLI is ready" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 1334 | ctrl = main.Cluster.runningNodes[ i ] |
Jonghwan Hyun | 76a02b7 | 2018-01-30 16:40:48 +0900 | [diff] [blame] | 1335 | # ctrl.CLI.startCellCli() |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 1336 | cliResult = ctrl.CLI.startOnosCli( ctrl.ipAddress, |
| 1337 | commandlineTimeout=60, |
| 1338 | onosStartTimeout=100 ) |
| 1339 | ctrl.active = True |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1340 | utilities.assert_equals( expect=main.TRUE, |
| 1341 | actual=cliResult, |
| 1342 | onpass="ONOS CLI is ready", |
| 1343 | onfail="ONOS CLI is not ready" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1344 | |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1345 | main.Cluster.reset() |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 1346 | main.step( "Checking ONOS nodes" ) |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1347 | Testcaselib.verifyNodes( main ) |
| 1348 | Testcaselib.verifyTopology( main, switches, links, expNodes ) |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 1349 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 1350 | ready = utilities.retry( main.Cluster.active( 0 ).CLI.summary, |
You Wang | 5bf4959 | 2020-07-08 18:47:46 -0700 | [diff] [blame] | 1351 | [ None, main.FALSE ], |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 1352 | attempts=10, |
| 1353 | sleep=12 ) |
| 1354 | if ready: |
| 1355 | ready = main.TRUE |
| 1356 | utilities.assert_equals( expect=main.TRUE, actual=ready, |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1357 | onpass="ONOS summary command succeded", |
| 1358 | onfail="ONOS summary command failed" ) |
| 1359 | if not ready: |
| 1360 | main.log.error( "ONOS startup failed!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1361 | main.cleanAndExit() |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1362 | |
| 1363 | @staticmethod |
| 1364 | def addHostCfg( main ): |
| 1365 | """ |
| 1366 | Adds Host Configuration to ONOS |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 1367 | Updates expected state of the network ( pingChart ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1368 | """ |
| 1369 | import json |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 1370 | hostCfg = {} |
Devin Lim | 57221b0 | 2018-02-14 15:45:36 -0800 | [diff] [blame] | 1371 | with open( main.configPath + main.forJson + "extra.json" ) as template: |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1372 | hostCfg = json.load( template ) |
| 1373 | main.pingChart[ 'ip' ][ 'hosts' ] += [ 'in1' ] |
| 1374 | main.step( "Pushing new configuration" ) |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 1375 | mac, cfg = hostCfg[ 'hosts' ].popitem() |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 1376 | main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ], |
| 1377 | subjectClass="hosts", |
| 1378 | subjectKey=urllib.quote( mac, |
| 1379 | safe='' ), |
| 1380 | configKey="basic" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1381 | main.pingChart[ 'ip' ][ 'hosts' ] += [ 'out1' ] |
| 1382 | main.step( "Pushing new configuration" ) |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 1383 | mac, cfg = hostCfg[ 'hosts' ].popitem() |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 1384 | main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ], |
| 1385 | subjectClass="hosts", |
| 1386 | subjectKey=urllib.quote( mac, |
| 1387 | safe='' ), |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 1388 | configKey="basic" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1389 | main.pingChart.update( { 'vlan1': { "expect": "True", |
| 1390 | "hosts": [ "olt1", "vsg1" ] } } ) |
| 1391 | main.pingChart[ 'vlan5' ][ 'expect' ] = 0 |
| 1392 | main.pingChart[ 'vlan10' ][ 'expect' ] = 0 |
Jon Hall | 10e2ab8 | 2020-09-15 17:14:54 -0700 | [diff] [blame] | 1393 | main.Cluster.active( 0 ).REST.setXconnect( "of:0000000000000001", |
| 1394 | vlanId=1, |
| 1395 | port1=5, |
| 1396 | port2=6 ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1397 | |
| 1398 | @staticmethod |
| 1399 | def delHostCfg( main ): |
| 1400 | """ |
| 1401 | Removest Host Configuration from ONOS |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 1402 | Updates expected state of the network ( pingChart ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1403 | """ |
| 1404 | import json |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 1405 | hostCfg = {} |
Devin Lim | 57221b0 | 2018-02-14 15:45:36 -0800 | [diff] [blame] | 1406 | with open( main.configPath + main.forJson + "extra.json" ) as template: |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1407 | hostCfg = json.load( template ) |
| 1408 | main.step( "Removing host configuration" ) |
| 1409 | main.pingChart[ 'ip' ][ 'expect' ] = 0 |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 1410 | mac, cfg = hostCfg[ 'hosts' ].popitem() |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 1411 | main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts", |
| 1412 | subjectKey=urllib.quote( |
| 1413 | mac, |
| 1414 | safe='' ), |
| 1415 | configKey="basic" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1416 | main.step( "Removing configuration" ) |
| 1417 | main.pingChart[ 'ip' ][ 'expect' ] = 0 |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 1418 | mac, cfg = hostCfg[ 'hosts' ].popitem() |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 1419 | main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts", |
| 1420 | subjectKey=urllib.quote( |
| 1421 | mac, |
| 1422 | safe='' ), |
| 1423 | configKey="basic" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1424 | main.step( "Removing vlan configuration" ) |
| 1425 | main.pingChart[ 'vlan1' ][ 'expect' ] = 0 |
Jon Hall | 10e2ab8 | 2020-09-15 17:14:54 -0700 | [diff] [blame] | 1426 | main.Cluster.active( 0 ).REST.deleteXconnect( "of:0000000000000001", |
| 1427 | vlanId=1 ) |
You Wang | 53dba1e | 2018-02-02 17:45:44 -0800 | [diff] [blame] | 1428 | |
| 1429 | @staticmethod |
| 1430 | def verifyNetworkHostIp( main, attempts=10, sleep=10 ): |
| 1431 | """ |
| 1432 | Verifies IP address assignment from the hosts |
| 1433 | """ |
| 1434 | main.step( "Verify IP address assignment from hosts" ) |
| 1435 | ipResult = main.TRUE |
You Wang | d66de19 | 2018-04-30 17:30:12 -0700 | [diff] [blame] | 1436 | main.Network.update() |
You Wang | 6acb7a4 | 2018-05-04 15:12:25 -0700 | [diff] [blame] | 1437 | # Find out names of disconnected hosts |
| 1438 | disconnectedHosts = [] |
| 1439 | if hasattr( main, "disconnectedIpv4Hosts" ): |
| 1440 | for host in main.disconnectedIpv4Hosts: |
| 1441 | disconnectedHosts.append( host ) |
| 1442 | if hasattr( main, "disconnectedIpv6Hosts" ): |
| 1443 | for host in main.disconnectedIpv6Hosts: |
| 1444 | disconnectedHosts.append( host ) |
You Wang | 53dba1e | 2018-02-02 17:45:44 -0800 | [diff] [blame] | 1445 | for hostName, ip in main.expectedHosts[ "network" ].items(): |
You Wang | 6acb7a4 | 2018-05-04 15:12:25 -0700 | [diff] [blame] | 1446 | # Exclude disconnected hosts |
| 1447 | if hostName in disconnectedHosts: |
| 1448 | main.log.debug( "Skip verifying IP for {} as it's disconnected".format( hostName ) ) |
| 1449 | continue |
You Wang | 53dba1e | 2018-02-02 17:45:44 -0800 | [diff] [blame] | 1450 | ipResult = ipResult and utilities.retry( main.Network.verifyHostIp, |
| 1451 | main.FALSE, |
| 1452 | kwargs={ 'hostList': [ hostName ], |
You Wang | d66de19 | 2018-04-30 17:30:12 -0700 | [diff] [blame] | 1453 | 'prefix': ip, |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1454 | 'update': True }, |
You Wang | 53dba1e | 2018-02-02 17:45:44 -0800 | [diff] [blame] | 1455 | attempts=attempts, |
| 1456 | sleep=sleep ) |
| 1457 | utilities.assert_equals( expect=main.TRUE, actual=ipResult, |
| 1458 | onpass="Verify network host IP succeded", |
| 1459 | onfail="Verify network host IP failed" ) |
| 1460 | |
| 1461 | @staticmethod |
You Wang | aec6a09 | 2018-08-06 15:36:31 -0700 | [diff] [blame] | 1462 | def verifyOnosHostIp( main, attempts=10, sleep=10, skipOnFail=True ): |
You Wang | 53dba1e | 2018-02-02 17:45:44 -0800 | [diff] [blame] | 1463 | """ |
| 1464 | Verifies host IP address assignment from ONOS |
| 1465 | """ |
| 1466 | main.step( "Verify host IP address assignment in ONOS" ) |
| 1467 | ipResult = main.TRUE |
You Wang | 6acb7a4 | 2018-05-04 15:12:25 -0700 | [diff] [blame] | 1468 | # Find out IPs of disconnected hosts |
| 1469 | disconnectedIps = [] |
| 1470 | if hasattr( main, "disconnectedIpv4Hosts" ): |
| 1471 | for host in main.disconnectedIpv4Hosts: |
| 1472 | disconnectedIps.append( main.expectedHosts[ "network" ][ host ] ) |
| 1473 | if hasattr( main, "disconnectedIpv6Hosts" ): |
| 1474 | for host in main.disconnectedIpv6Hosts: |
| 1475 | disconnectedIps.append( main.expectedHosts[ "network" ][ host ] ) |
You Wang | 53dba1e | 2018-02-02 17:45:44 -0800 | [diff] [blame] | 1476 | for hostName, ip in main.expectedHosts[ "onos" ].items(): |
You Wang | 6acb7a4 | 2018-05-04 15:12:25 -0700 | [diff] [blame] | 1477 | # Exclude disconnected hosts |
| 1478 | if ip in disconnectedIps: |
| 1479 | main.log.debug( "Skip verifying IP for {} as it's disconnected".format( ip ) ) |
| 1480 | continue |
You Wang | 53dba1e | 2018-02-02 17:45:44 -0800 | [diff] [blame] | 1481 | ipResult = ipResult and utilities.retry( main.Cluster.active( 0 ).verifyHostIp, |
| 1482 | main.FALSE, |
| 1483 | kwargs={ 'hostList': [ hostName ], |
| 1484 | 'prefix': ip }, |
| 1485 | attempts=attempts, |
| 1486 | sleep=sleep ) |
| 1487 | utilities.assert_equals( expect=main.TRUE, actual=ipResult, |
| 1488 | onpass="Verify ONOS host IP succeded", |
| 1489 | onfail="Verify ONOS host IP failed" ) |
You Wang | aec6a09 | 2018-08-06 15:36:31 -0700 | [diff] [blame] | 1490 | if not ipResult and skipOnFail: |
| 1491 | Testcaselib.saveOnosDiagnostics( main ) |
You Wang | 8947715 | 2018-08-07 14:19:02 -0700 | [diff] [blame] | 1492 | Testcaselib.cleanup( main, copyKarafLog=False ) |
You Wang | aec6a09 | 2018-08-06 15:36:31 -0700 | [diff] [blame] | 1493 | main.skipCase() |
Andreas Pantelopoulos | 2eae324 | 2018-03-06 13:47:20 -0800 | [diff] [blame] | 1494 | |
Jonghwan Hyun | 812c70f | 2018-02-16 16:33:16 -0800 | [diff] [blame] | 1495 | @staticmethod |
| 1496 | def updateIntfCfg( main, connectPoint, ips=[], untagged=0, tagged=[], native=0 ): |
| 1497 | """ |
| 1498 | Description: |
| 1499 | Updates interface configuration in ONOS, with given IP and vlan parameters |
| 1500 | Required: |
| 1501 | * connectPoint: connect point to update configuration |
| 1502 | Optional: |
| 1503 | * ips: list of IP addresses, combined with '/xx' subnet representation, |
| 1504 | corresponding to 'ips' field in the configuration |
| 1505 | * untagged: vlan ID as an integer, corresponding to 'vlan-untagged' field in the configuration |
| 1506 | * tagged: integer list of vlan IDs, corresponding to 'vlan-tagged' field in the configuration |
| 1507 | * native: vlan ID as an integer, corresponding to 'vlan-native' field in the configuration |
| 1508 | """ |
| 1509 | cfg = dict() |
| 1510 | cfg[ "ports" ] = dict() |
| 1511 | cfg[ "ports" ][ connectPoint ] = dict() |
| 1512 | cfg[ "ports" ][ connectPoint ][ "interfaces" ] = [ dict() ] |
| 1513 | cfg[ "ports" ][ connectPoint ][ "interfaces" ][ 0 ][ "ips" ] = ips |
| 1514 | if untagged > 0: |
| 1515 | cfg[ "ports" ][ connectPoint ][ "interfaces" ][ 0 ][ "vlan-untagged" ] = untagged |
| 1516 | else: |
| 1517 | cfg[ "ports" ][ connectPoint ][ "interfaces" ][ 0 ][ "vlan-tagged" ] = tagged |
| 1518 | if native > 0: |
| 1519 | cfg[ "ports" ][ connectPoint ][ "interfaces" ][ 0 ][ "vlan-native" ] = native |
| 1520 | |
| 1521 | main.Cluster.active( 0 ).REST.setNetCfg( json.loads( json.dumps( cfg ) ) ) |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 1522 | |
| 1523 | @staticmethod |
You Wang | 2cb7017 | 2018-07-25 16:44:13 -0700 | [diff] [blame] | 1524 | def startScapyHosts( main, scapyNames=[], mininetNames=[] ): |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 1525 | """ |
| 1526 | Create host components and start Scapy CLIs |
You Wang | 2cb7017 | 2018-07-25 16:44:13 -0700 | [diff] [blame] | 1527 | scapyNames: list of names that will be used as component names for scapy hosts |
| 1528 | mininetNames: used when scapy host names are different from the host names |
| 1529 | in Mininet. E.g. when scapyNames=['h1Scapy'], it's required to specify the |
| 1530 | name of the corresponding Mininet host by mininetNames=['h1'] |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 1531 | """ |
| 1532 | main.step( "Start Scapy CLIs" ) |
You Wang | 4cc6191 | 2018-08-28 10:10:58 -0700 | [diff] [blame] | 1533 | main.scapyNames = scapyNames if scapyNames else main.params[ 'SCAPY' ][ 'HOSTNAMES' ].split( ',' ) |
| 1534 | main.scapyHosts = [] if not hasattr( main, "scapyHosts" ) else main.scapyHosts |
You Wang | 2cb7017 | 2018-07-25 16:44:13 -0700 | [diff] [blame] | 1535 | for scapyName in main.scapyNames: |
You Wang | 4cc6191 | 2018-08-28 10:10:58 -0700 | [diff] [blame] | 1536 | if hasattr( main, 'Mininet1' ): |
| 1537 | main.Scapy.createHostComponent( scapyName ) |
| 1538 | scapyHandle = getattr( main, scapyName ) |
| 1539 | if mininetNames: |
| 1540 | mininetName = mininetNames[ scapyNames.index( scapyName ) ] |
| 1541 | else: |
| 1542 | mininetName = None |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1543 | if 'MN_DOCKER' in main.params and main.params['MN_DOCKER']['args']: |
| 1544 | scapyHandle.mExecDir = "/tmp" |
| 1545 | scapyHandle.hostHome = main.params[ "MN_DOCKER" ][ "home" ] |
| 1546 | main.log.debug( "start mn host component in docker" ) |
| 1547 | scapyHandle.startHostCli( mininetName, |
| 1548 | execDir="/tmp", |
| 1549 | hostHome=main.params[ "MN_DOCKER" ][ "home" ] ) |
| 1550 | else: |
| 1551 | main.log.debug( "start mn host component" ) |
| 1552 | scapyHandle.startHostCli( mininetName ) |
You Wang | 2cb7017 | 2018-07-25 16:44:13 -0700 | [diff] [blame] | 1553 | else: |
You Wang | 0fc2170 | 2018-11-02 17:49:18 -0700 | [diff] [blame] | 1554 | main.Network.createHostComponent( scapyName ) |
You Wang | 4cc6191 | 2018-08-28 10:10:58 -0700 | [diff] [blame] | 1555 | scapyHandle = getattr( main, scapyName ) |
| 1556 | scapyHandle.connectInband() |
| 1557 | main.scapyHosts.append( scapyHandle ) |
You Wang | 2cb7017 | 2018-07-25 16:44:13 -0700 | [diff] [blame] | 1558 | scapyHandle.startScapy() |
| 1559 | scapyHandle.updateSelf() |
| 1560 | main.log.debug( scapyHandle.name ) |
| 1561 | main.log.debug( scapyHandle.hostIp ) |
| 1562 | main.log.debug( scapyHandle.hostMac ) |
| 1563 | |
| 1564 | @staticmethod |
| 1565 | def verifyTraffic( main, srcHosts, dstIp, dstHost, dstIntf, ipv6=False, expect=True, skipOnFail=True, maxRetry=2 ): |
| 1566 | """ |
| 1567 | Verify unicast traffic by pinging from source hosts to the destination IP |
| 1568 | and capturing the packets at the destination host using Scapy. |
| 1569 | srcHosts: List of host names to send the ping packets |
| 1570 | dstIp: destination IP of the ping packets |
| 1571 | dstHost: host that runs Scapy to capture the packets |
| 1572 | dstIntf: name of the interface on the destination host |
| 1573 | expect: use True if the ping is expected to be captured at destination; |
| 1574 | Otherwise False |
| 1575 | skipOnFail: skip the rest of this test case if result is not expected |
| 1576 | maxRetry: number of retries allowed |
| 1577 | """ |
| 1578 | from tests.dependencies.topology import Topology |
| 1579 | try: |
| 1580 | main.topo |
| 1581 | except ( NameError, AttributeError ): |
| 1582 | main.topo = Topology() |
| 1583 | main.step( "Verify traffic to {} by capturing packets on {}".format( dstIp, dstHost ) ) |
| 1584 | result = main.TRUE |
| 1585 | for srcHost in srcHosts: |
| 1586 | trafficResult = main.topo.pingAndCapture( srcHost, dstIp, dstHost, dstIntf, ipv6, |
| 1587 | expect, maxRetry, True ) |
| 1588 | if not trafficResult: |
You Wang | 2cb7017 | 2018-07-25 16:44:13 -0700 | [diff] [blame] | 1589 | result = main.FALSE |
| 1590 | main.log.warn( "Scapy result from {} to {} is not as expected".format( srcHost, dstIp ) ) |
| 1591 | utilities.assert_equals( expect=main.TRUE, |
| 1592 | actual=result, |
| 1593 | onpass="Verify traffic to {}: Pass".format( dstIp ), |
| 1594 | onfail="Verify traffic to {}: Fail".format( dstIp ) ) |
| 1595 | if skipOnFail and result != main.TRUE: |
| 1596 | Testcaselib.saveOnosDiagnostics( main ) |
| 1597 | Testcaselib.cleanup( main, copyKarafLog=False ) |
| 1598 | main.skipCase() |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 1599 | |
| 1600 | @staticmethod |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 1601 | def verifyMulticastTraffic( main, routeName, expect, skipOnFail=True, maxRetry=1 ): |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 1602 | """ |
| 1603 | Verify multicast traffic using scapy |
| 1604 | """ |
You Wang | c564c6f | 2018-05-01 15:24:57 -0700 | [diff] [blame] | 1605 | from tests.dependencies.topology import Topology |
| 1606 | try: |
| 1607 | main.topo |
| 1608 | except ( NameError, AttributeError ): |
| 1609 | main.topo = Topology() |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 1610 | main.step( "Verify {} multicast traffic".format( routeName ) ) |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 1611 | routeData = main.multicastConfig[ routeName ] |
| 1612 | srcs = main.mcastRoutes[ routeName ][ "src" ] |
| 1613 | dsts = main.mcastRoutes[ routeName ][ "dst" ] |
| 1614 | main.log.info( "Sending multicast traffic from {} to {}".format( [ routeData[ "src" ][ i ][ "host" ] for i in srcs ], |
| 1615 | [ routeData[ "dst" ][ i ][ "host" ] for i in dsts ] ) ) |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 1616 | result = main.TRUE |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 1617 | for src in srcs: |
| 1618 | srcEntry = routeData[ "src" ][ src ] |
| 1619 | for dst in dsts: |
| 1620 | dstEntry = routeData[ "dst" ][ dst ] |
| 1621 | sender = getattr( main, srcEntry[ "host" ] ) |
| 1622 | receiver = getattr( main, dstEntry[ "host" ] ) |
| 1623 | main.Network.addRoute( str( srcEntry[ "host" ] ), |
| 1624 | str( routeData[ "group" ] ), |
| 1625 | str( srcEntry[ "interface" ] ), |
| 1626 | True if routeData[ "ipVersion" ] == 6 else False ) |
| 1627 | # Build the packet |
| 1628 | sender.buildEther( dst=str( srcEntry[ "Ether" ] ) ) |
| 1629 | if routeData[ "ipVersion" ] == 4: |
| 1630 | sender.buildIP( dst=str( routeData[ "group" ] ) ) |
| 1631 | elif routeData[ "ipVersion" ] == 6: |
| 1632 | sender.buildIPv6( dst=str( routeData[ "group" ] ) ) |
| 1633 | sender.buildUDP( ipVersion=routeData[ "ipVersion" ], dport=srcEntry[ "UDP" ] ) |
| 1634 | sIface = srcEntry[ "interface" ] |
| 1635 | dIface = dstEntry[ "interface" ] if "interface" in dstEntry.keys() else None |
| 1636 | pktFilter = srcEntry[ "filter" ] |
| 1637 | pkt = srcEntry[ "packet" ] |
| 1638 | # Send packet and check received packet |
| 1639 | expectedResult = expect.pop( 0 ) if isinstance( expect, list ) else expect |
You Wang | c564c6f | 2018-05-01 15:24:57 -0700 | [diff] [blame] | 1640 | 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] | 1641 | routeData[ "group" ], srcEntry[ "Ether" ] ) |
You Wang | c564c6f | 2018-05-01 15:24:57 -0700 | [diff] [blame] | 1642 | trafficResult = main.topo.sendScapyPackets( sender, receiver, pktFilter, pkt, sIface, dIface, |
| 1643 | expectedResult, maxRetry, True, t3Cmd ) |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 1644 | if not trafficResult: |
| 1645 | result = main.FALSE |
| 1646 | main.log.warn( "Scapy result from {} to {} is not as expected".format( srcEntry[ "host" ], |
| 1647 | dstEntry[ "host" ] ) ) |
| 1648 | utilities.assert_equals( expect=main.TRUE, |
| 1649 | actual=result, |
| 1650 | onpass="Verify {} multicast traffic: Pass".format( routeName ), |
| 1651 | onfail="Verify {} multicast traffic: Fail".format( routeName ) ) |
You Wang | ba823f0 | 2018-05-17 13:54:08 -0700 | [diff] [blame] | 1652 | if skipOnFail and result != main.TRUE: |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 1653 | Testcaselib.saveOnosDiagnostics( main ) |
| 1654 | Testcaselib.cleanup( main, copyKarafLog=False ) |
| 1655 | main.skipCase() |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 1656 | |
| 1657 | @staticmethod |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 1658 | def verifyPing( main, srcList, dstList, ipv6=False, expect=True, wait=1, |
You Wang | 54b1d67 | 2018-06-11 16:44:13 -0700 | [diff] [blame] | 1659 | acceptableFailed=0, skipOnFail=True, stepMsg="Verify Ping", |
| 1660 | t3Simple=True ): |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 1661 | """ |
| 1662 | Verify reachability from each host in srcList to each host in dstList |
| 1663 | """ |
| 1664 | from tests.dependencies.topology import Topology |
| 1665 | try: |
| 1666 | main.topo |
| 1667 | except ( NameError, AttributeError ): |
| 1668 | main.topo = Topology() |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 1669 | main.step( stepMsg ) |
You Wang | 54b1d67 | 2018-06-11 16:44:13 -0700 | [diff] [blame] | 1670 | pingResult = main.topo.ping( srcList, dstList, ipv6, expect, wait, acceptableFailed, skipOnFail, t3Simple ) |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 1671 | utilities.assert_equals( expect=main.TRUE, |
| 1672 | actual=pingResult, |
| 1673 | onpass="{}: Pass".format( stepMsg ), |
| 1674 | onfail="{}: Fail".format( stepMsg ) ) |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 1675 | if not pingResult and skipOnFail: |
| 1676 | Testcaselib.saveOnosDiagnostics( main ) |
| 1677 | Testcaselib.cleanup( main, copyKarafLog=False, removeHostComponent=True ) |
| 1678 | main.skipCase() |
You Wang | bc898b8 | 2018-05-03 16:22:34 -0700 | [diff] [blame] | 1679 | |
| 1680 | @staticmethod |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 1681 | def verifyHostLocations( main, locationDict, retry=2 ): |
You Wang | bc898b8 | 2018-05-03 16:22:34 -0700 | [diff] [blame] | 1682 | """ |
| 1683 | Verify if the specified host is discovered by ONOS on the given locations |
| 1684 | Required: |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 1685 | locationDict: a dictionary that maps host names to expected locations. |
| 1686 | locations could be a string or a list. |
| 1687 | ex. { "h1v4": ["of:0000000000000005/8"] } |
You Wang | bc898b8 | 2018-05-03 16:22:34 -0700 | [diff] [blame] | 1688 | Returns: |
| 1689 | main.TRUE if host is discovered on all locations provided, otherwise main.FALSE |
| 1690 | """ |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 1691 | main.step( "Verify locations of hosts {}".format( locationDict.keys() ) ) |
| 1692 | result = main.TRUE |
| 1693 | for hostName, locations in locationDict.items(): |
| 1694 | main.log.info( "Verify host {} is discovered at {}".format( hostName, locations ) ) |
| 1695 | hostIp = main.Network.getIPAddress( hostName, proto='IPV4' ) |
| 1696 | if not hostIp: |
| 1697 | hostIp = main.Network.getIPAddress( hostName, proto='IPV6' ) |
| 1698 | if not hostIp: |
| 1699 | main.log.warn( "Failed to find IP address for host {}, skipping location verification".format( hostName ) ) |
| 1700 | result = main.FALSE |
| 1701 | continue |
| 1702 | locationResult = utilities.retry( main.Cluster.active( 0 ).CLI.verifyHostLocation, |
| 1703 | main.FALSE, |
| 1704 | args=( hostIp, locations ), |
| 1705 | attempts=retry + 1, |
| 1706 | sleep=10 ) |
| 1707 | if not locationResult: |
| 1708 | result = main.FALSE |
| 1709 | main.log.warn( "location verification for host {} failed".format( hostName ) ) |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 1710 | utilities.assert_equals( expect=main.TRUE, actual=result, |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 1711 | onpass="Location verification passed", |
| 1712 | onfail="Location verification failed" ) |
Jonghwan Hyun | 785471d | 2018-05-14 14:48:19 -0700 | [diff] [blame] | 1713 | |
| 1714 | @staticmethod |
You Wang | 6e5b48e | 2018-07-23 16:17:38 -0700 | [diff] [blame] | 1715 | 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] | 1716 | """ |
| 1717 | Move specified host from srcSw to dstSw. |
| 1718 | If srcSw and dstSw are same, the host will be moved from current port to |
| 1719 | next available port. |
| 1720 | Required: |
| 1721 | hostName: name of the host. e.g., "h1" |
| 1722 | srcSw: name of the switch that the host is attached to. e.g., "leaf1" |
| 1723 | dstSw: name of the switch that the host will be moved to. e.g., "leaf2" |
| 1724 | gw: ip address of the gateway of the new location |
| 1725 | Optional: |
| 1726 | macAddr: if specified, change MAC address of the host to the specified MAC address. |
| 1727 | prefixLen: prefix length |
| 1728 | cfg: port configuration as JSON string |
| 1729 | ipv6: Use True to move IPv6 host |
You Wang | 6e5b48e | 2018-07-23 16:17:38 -0700 | [diff] [blame] | 1730 | vlan: vlan number of the host |
Jonghwan Hyun | 785471d | 2018-05-14 14:48:19 -0700 | [diff] [blame] | 1731 | """ |
Jonghwan Hyun | 785471d | 2018-05-14 14:48:19 -0700 | [diff] [blame] | 1732 | if not hasattr( main, 'Mininet1' ): |
| 1733 | main.log.warn( "moveHost is supposed to be used only in Mininet." ) |
| 1734 | return |
| 1735 | |
You Wang | 6e5b48e | 2018-07-23 16:17:38 -0700 | [diff] [blame] | 1736 | main.step( "Moving {} host {} from {} to {}".format( 'tagged' if vlan else 'untagged', hostName, srcSw, dstSw ) ) |
| 1737 | main.Mininet1.moveHost( hostName, srcSw, dstSw, macAddr, prefixLen, ipv6, vlan=vlan ) |
| 1738 | if not ipv6: |
You Wang | 6260ed5 | 2018-07-18 17:54:25 -0700 | [diff] [blame] | 1739 | main.Mininet1.changeDefaultGateway( hostName, gw ) |
Jonghwan Hyun | 785471d | 2018-05-14 14:48:19 -0700 | [diff] [blame] | 1740 | if cfg: |
| 1741 | main.Cluster.active( 0 ).REST.setNetCfg( json.loads( cfg ), |
| 1742 | subjectClass="ports" ) |
You Wang | 6260ed5 | 2018-07-18 17:54:25 -0700 | [diff] [blame] | 1743 | # Wait for the host to get RA for setting up default gateway |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1744 | main.log.debug( "sleeping %i seconds" % ( 5 ) ) |
You Wang | 6260ed5 | 2018-07-18 17:54:25 -0700 | [diff] [blame] | 1745 | time.sleep( 5 ) |
Jonghwan Hyun | 785471d | 2018-05-14 14:48:19 -0700 | [diff] [blame] | 1746 | |
| 1747 | main.Mininet1.discoverHosts( [ hostName, ] ) |
| 1748 | |
| 1749 | # Update expectedHost when MAC address is changed. |
| 1750 | if macAddr is not None: |
| 1751 | ipAddr = main.expectedHosts[ "network" ][ hostName ] |
| 1752 | if ipAddr is not None: |
| 1753 | for hostName, ip in main.expectedHosts[ "onos" ].items(): |
| 1754 | if ip == ipAddr: |
| 1755 | vlan = hostName.split( "/" )[ -1 ] |
| 1756 | del main.expectedHosts[ "onos" ][ hostName ] |
You Wang | 7ea9058 | 2018-07-19 15:27:58 -0700 | [diff] [blame] | 1757 | main.expectedHosts[ "onos" ][ "{}/{}".format( macAddr.upper(), vlan ) ] = ip |
Jonghwan Hyun | 785471d | 2018-05-14 14:48:19 -0700 | [diff] [blame] | 1758 | break |
Jonghwan Hyun | 5fad178 | 2018-05-21 14:11:16 -0700 | [diff] [blame] | 1759 | |
| 1760 | @staticmethod |
| 1761 | def moveDualHomedHost( main, hostName, srcSw, srcPairSw, dstSw, dstPairSw, gw, |
You Wang | 6e5b48e | 2018-07-23 16:17:38 -0700 | [diff] [blame] | 1762 | macAddr=None, prefixLen=24, cfg='', ipv6=False, vlan=None ): |
Jonghwan Hyun | 5fad178 | 2018-05-21 14:11:16 -0700 | [diff] [blame] | 1763 | """ |
| 1764 | Move specified dual-homed host from srcSw-srcPairSw to dstSw-dstPairSw. |
| 1765 | If srcSw-srcPairSw and dstSw-dstPairSw are same, the host will be moved from current port |
| 1766 | to next available port. |
| 1767 | Required: |
| 1768 | hostName: name of the host. e.g., "h1" |
| 1769 | srcSw: name of the switch that the host is attached to. e.g., "leaf1" |
| 1770 | srcPairSw: name of the paired-switch that the host is attached to. e.g., "leaf2" |
| 1771 | dstSw: name of the switch that the host will be moved to. e.g., "leaf1" |
| 1772 | dstPairSw: name of the paired-switch that the host will be moved to. e.g., "leaf2" |
| 1773 | gw: ip address of the gateway of the new location |
| 1774 | Optional: |
| 1775 | macAddr: if specified, change MAC address of the host to the specified MAC address. |
| 1776 | prefixLen: prefix length |
| 1777 | cfg: port configurations as JSON string |
You Wang | 7ea9058 | 2018-07-19 15:27:58 -0700 | [diff] [blame] | 1778 | ipv6: Use True to move IPv6 host |
You Wang | 6e5b48e | 2018-07-23 16:17:38 -0700 | [diff] [blame] | 1779 | vlan: vlan number of the host |
Jonghwan Hyun | 5fad178 | 2018-05-21 14:11:16 -0700 | [diff] [blame] | 1780 | """ |
Jonghwan Hyun | 5fad178 | 2018-05-21 14:11:16 -0700 | [diff] [blame] | 1781 | if not hasattr( main, 'Mininet1' ): |
| 1782 | main.log.warn( "moveDualHomedHost is supposed to be used only in Mininet." ) |
| 1783 | return |
| 1784 | |
You Wang | 6e5b48e | 2018-07-23 16:17:38 -0700 | [diff] [blame] | 1785 | main.step( "Moving {} host {} from {} and {} to {} and {}".format( 'tagged' if vlan else 'untagged', hostName, |
| 1786 | srcSw, srcPairSw, dstSw, dstPairSw ) ) |
| 1787 | main.Mininet1.moveDualHomedHost( hostName, srcSw, srcPairSw, dstSw, dstPairSw, |
| 1788 | macAddr=macAddr, prefixLen=prefixLen, ipv6=ipv6, vlan=vlan ) |
| 1789 | if not ipv6: |
You Wang | 7ea9058 | 2018-07-19 15:27:58 -0700 | [diff] [blame] | 1790 | main.Mininet1.changeDefaultGateway( hostName, gw ) |
Jonghwan Hyun | 5fad178 | 2018-05-21 14:11:16 -0700 | [diff] [blame] | 1791 | if cfg: |
| 1792 | main.Cluster.active( 0 ).REST.setNetCfg( json.loads( cfg ), |
| 1793 | subjectClass="ports" ) |
You Wang | 7ea9058 | 2018-07-19 15:27:58 -0700 | [diff] [blame] | 1794 | # Wait for the host to get RA for setting up default gateway |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1795 | main.log.debug( "sleeping %i seconds" % ( 5 ) ) |
You Wang | 7ea9058 | 2018-07-19 15:27:58 -0700 | [diff] [blame] | 1796 | time.sleep( 5 ) |
Jonghwan Hyun | 5fad178 | 2018-05-21 14:11:16 -0700 | [diff] [blame] | 1797 | |
| 1798 | main.Mininet1.discoverHosts( [ hostName, ] ) |
| 1799 | |
| 1800 | # Update expectedHost when MAC address is changed. |
| 1801 | if macAddr is not None: |
| 1802 | ipAddr = main.expectedHosts[ "network" ][ hostName ] |
| 1803 | if ipAddr is not None: |
| 1804 | for hostName, ip in main.expectedHosts[ "onos" ].items(): |
| 1805 | if ip == ipAddr: |
| 1806 | vlan = hostName.split( "/" )[ -1 ] |
| 1807 | del main.expectedHosts[ "onos" ][ hostName ] |
You Wang | 7ea9058 | 2018-07-19 15:27:58 -0700 | [diff] [blame] | 1808 | main.expectedHosts[ "onos" ][ "{}/{}".format( macAddr.upper(), vlan ) ] = ip |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1809 | |
| 1810 | @staticmethod |
| 1811 | def mnDockerSetup( main ): |
| 1812 | """ |
| 1813 | Optionally start and setup docker image for mininet |
| 1814 | """ |
Jon Hall | 9b0de1f | 2020-08-24 15:38:04 -0700 | [diff] [blame] | 1815 | try: |
| 1816 | if 'MN_DOCKER' in main.params and main.params['MN_DOCKER']['args']: |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1817 | |
Jon Hall | 9b0de1f | 2020-08-24 15:38:04 -0700 | [diff] [blame] | 1818 | main.log.info( "Creating Mininet Docker" ) |
| 1819 | handle = main.Mininet1.handle |
| 1820 | # build docker image |
| 1821 | dockerFilePath = "%s/../dependencies/" % main.testDir |
| 1822 | dockerName = "trellis_mininet" |
| 1823 | # Stop any leftover container |
| 1824 | main.Mininet1.dockerStop( dockerName ) |
| 1825 | # TODO: assert on these docker calls |
Jon Hall | 3957026 | 2020-11-17 12:18:19 -0800 | [diff] [blame] | 1826 | main.Mininet1.dockerBuild( dockerFilePath, dockerName, pull=True ) |
Jon Hall | f6aeda2 | 2020-07-28 09:12:56 -0700 | [diff] [blame] | 1827 | |
Jon Hall | 9b0de1f | 2020-08-24 15:38:04 -0700 | [diff] [blame] | 1828 | confDir = "/tmp/mn_conf/" |
| 1829 | # Try to ensure the destination exists |
| 1830 | main.log.info( "Create folder for network config files" ) |
| 1831 | handle.sendline( "rm -rf %s" % confDir ) |
| 1832 | handle.expect( main.Mininet1.Prompt() ) |
| 1833 | main.log.debug( handle.before + handle.after ) |
| 1834 | handle.sendline( "mkdir -p %s" % confDir ) |
| 1835 | handle.expect( main.Mininet1.Prompt() ) |
| 1836 | main.log.debug( handle.before + handle.after ) |
Jon Hall | 3957026 | 2020-11-17 12:18:19 -0800 | [diff] [blame] | 1837 | handle.sendline( "sudo rm -rf /tmp/mn-stratum/*" ) |
| 1838 | handle.expect( main.Mininet1.Prompt() ) |
Jon Hall | 9b0de1f | 2020-08-24 15:38:04 -0700 | [diff] [blame] | 1839 | # Make sure permissions are correct |
| 1840 | handle.sendline( "sudo chown %s:%s %s" % ( main.Mininet1.user_name, main.Mininet1.user_name, confDir ) ) |
| 1841 | handle.expect( main.Mininet1.Prompt() ) |
| 1842 | handle.sendline( "sudo chmod -R a+rwx %s" % ( confDir ) ) |
| 1843 | handle.expect( main.Mininet1.Prompt() ) |
| 1844 | main.log.debug( handle.before + handle.after ) |
| 1845 | # Start docker container |
| 1846 | runResponse = main.Mininet1.dockerRun( main.params[ 'MN_DOCKER' ][ 'name' ], |
| 1847 | dockerName, |
| 1848 | main.params[ 'MN_DOCKER' ][ 'args' ] ) |
| 1849 | if runResponse == main.FALSE: |
| 1850 | main.log.error( "Docker container already running, aborting test" ) |
| 1851 | main.cleanup() |
| 1852 | main.exit() |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1853 | |
Jon Hall | 9b0de1f | 2020-08-24 15:38:04 -0700 | [diff] [blame] | 1854 | main.Mininet1.dockerAttach( dockerName, dockerPrompt='~#' ) |
| 1855 | main.Mininet1.sudoRequired = False |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1856 | |
Jon Hall | 9b0de1f | 2020-08-24 15:38:04 -0700 | [diff] [blame] | 1857 | # Fow when we create component handles |
| 1858 | main.Mininet1.mExecDir = "/tmp" |
| 1859 | main.Mininet1.hostHome = main.params[ "MN_DOCKER" ][ "home" ] |
| 1860 | main.Mininet1.hostPrompt = "/home/root#" |
| 1861 | |
| 1862 | # For some reason docker isn't doing this |
| 1863 | main.Mininet1.handle.sendline( "echo \"127.0.0.1 $(cat /etc/hostname)\" >> /etc/hosts" ) |
| 1864 | main.Mininet1.handle.expect( "etc/hosts" ) |
| 1865 | main.Mininet1.handle.expect( main.Mininet1.Prompt() ) |
| 1866 | except Exception as e: |
| 1867 | main.log.exception( "Error seting up mininet" ) |
Jon Hall | 3957026 | 2020-11-17 12:18:19 -0800 | [diff] [blame] | 1868 | main.skipCase( result="FAIL", msg=e ) |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1869 | |
| 1870 | @staticmethod |
| 1871 | def mnDockerTeardown( main ): |
| 1872 | """ |
| 1873 | Optionally stop and cleanup docker image for mininet |
| 1874 | """ |
| 1875 | |
| 1876 | if hasattr( main, 'Mininet1' ): |
| 1877 | if 'MN_DOCKER' in main.params and main.params['MN_DOCKER']['args']: |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 1878 | main.log.info( "Exiting from Mininet Docker" ) |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1879 | |
| 1880 | # Detach from container |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1881 | try: |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 1882 | main.Mininet1.dockerDisconnect() |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1883 | main.Mininet1.sudoRequired = True |
| 1884 | except Exception as e: |
| 1885 | main.log.error( e ) |
| 1886 | |
Jon Hall | 3957026 | 2020-11-17 12:18:19 -0800 | [diff] [blame] | 1887 | # Save docker logs |
| 1888 | copyResult = main.ONOSbench.scp( main.Mininet1, |
| 1889 | "/tmp/mn-stratum/*", |
| 1890 | main.logdir, |
| 1891 | direction="from", |
| 1892 | options="-rp" ) |
| 1893 | |
| 1894 | |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1895 | @staticmethod |
| 1896 | def setOnosConfig( main ): |
| 1897 | """ |
| 1898 | Read and Set onos configurations from the params file |
| 1899 | """ |
| 1900 | main.step( "Set ONOS configurations" ) |
| 1901 | config = main.params.get( 'ONOS_Configuration' ) |
| 1902 | if config: |
| 1903 | main.log.debug( config ) |
| 1904 | checkResult = main.TRUE |
| 1905 | for component in config: |
| 1906 | for setting in config[ component ]: |
| 1907 | value = config[ component ][ setting ] |
| 1908 | check = main.Cluster.next().setCfg( component, setting, value ) |
| 1909 | main.log.info( "Value was changed? {}".format( main.TRUE == check ) ) |
| 1910 | checkResult = check and checkResult |
| 1911 | utilities.assert_equals( expect=main.TRUE, |
| 1912 | actual=checkResult, |
| 1913 | onpass="Successfully set config", |
| 1914 | onfail="Failed to set config" ) |
| 1915 | else: |
| 1916 | main.log.warn( "No configurations were specified to be changed after startup" ) |
| 1917 | |
| 1918 | @staticmethod |
| 1919 | def setOnosLogLevels( main ): |
| 1920 | """ |
| 1921 | Read and Set onos log levels from the params file |
| 1922 | """ |
| 1923 | main.step( 'Set logging levels' ) |
Jon Hall | 06fd0df | 2021-01-25 15:50:06 -0800 | [diff] [blame] | 1924 | # Get original values incase we want to reset them |
| 1925 | ctrl = main.Cluster.active(0) |
Jon Hall | a7b27e6 | 2021-06-29 12:13:51 -0700 | [diff] [blame] | 1926 | ctrl.CLI.clearBuffer( timeout=1 ) |
Jon Hall | 06fd0df | 2021-01-25 15:50:06 -0800 | [diff] [blame] | 1927 | ctrl.CLI.logList() |
| 1928 | |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1929 | logging = True |
| 1930 | try: |
| 1931 | logs = main.params.get( 'ONOS_Logging', False ) |
| 1932 | if logs: |
| 1933 | for namespace, level in logs.items(): |
| 1934 | for ctrl in main.Cluster.active(): |
| 1935 | ctrl.CLI.logSet( level, namespace ) |
| 1936 | except AttributeError: |
| 1937 | logging = False |
| 1938 | utilities.assert_equals( expect=True, actual=logging, |
| 1939 | onpass="Set log levels", |
| 1940 | onfail="Failed to set log levels" ) |
Jon Hall | 06fd0df | 2021-01-25 15:50:06 -0800 | [diff] [blame] | 1941 | |
| 1942 | @staticmethod |
| 1943 | def resetOnosLogLevels( main ): |
| 1944 | """ |
| 1945 | Read and reset onos log levels to a previously read set of values |
| 1946 | """ |
| 1947 | main.step( 'Reset logging levels' ) |
| 1948 | # Get original values incase we want to reset them |
| 1949 | ctrl = main.Cluster.active(0) |
Jon Hall | a7b27e6 | 2021-06-29 12:13:51 -0700 | [diff] [blame] | 1950 | ctrl.CLI.clearBuffer( timeout=1 ) |
Jon Hall | 06fd0df | 2021-01-25 15:50:06 -0800 | [diff] [blame] | 1951 | currentLevels = ctrl.CLI.logList( saveValues=False ) |
| 1952 | origLevels = ctrl.CLI.logLevels |
| 1953 | toBeSet = {} |
| 1954 | for logger, level in currentLevels.iteritems(): |
| 1955 | if logger not in origLevels: |
| 1956 | toBeSet[ logger ] = origLevels[ 'ROOT' ] |
| 1957 | else: |
| 1958 | oldLevel = origLevels[ logger ] |
| 1959 | if level != oldLevel: |
| 1960 | toBeSet[ logger ] = oldLevel |
Jon Hall | ef1480b | 2021-03-31 13:37:41 -0700 | [diff] [blame] | 1961 | # In case a previous test didn't reset |
| 1962 | logs = main.params.get( 'ONOS_Logging_Reset', False ) |
| 1963 | if logs: |
| 1964 | for namespace, level in logs.items(): |
| 1965 | toBeSet[ namespace ] = level |
Jon Hall | 06fd0df | 2021-01-25 15:50:06 -0800 | [diff] [blame] | 1966 | logging = True |
| 1967 | try: |
| 1968 | for logger, level in toBeSet.iteritems(): |
| 1969 | for ctrl in main.Cluster.active(): |
| 1970 | ctrl.CLI.logSet( level, logger ) |
| 1971 | except AttributeError: |
| 1972 | logging = False |
| 1973 | utilities.assert_equals( expect=True, actual=logging, |
| 1974 | onpass="Reset log levels", |
| 1975 | onfail="Failed to reset log levels" ) |