suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 1 | |
| 2 | # This is a sample template that starts up ONOS cluster, this template |
| 3 | # can be use as a base script for ONOS System Testing. |
| 4 | |
alison | 12f34c3 | 2016-06-10 14:39:21 -0700 | [diff] [blame] | 5 | class SAMPstartTemplate_3node: |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 6 | |
| 7 | def __init__( self ): |
| 8 | self.default = '' |
| 9 | |
| 10 | |
| 11 | def CASE0(self, main): |
| 12 | ''' |
alison | 12f34c3 | 2016-06-10 14:39:21 -0700 | [diff] [blame] | 13 | Pull specific ONOS branch, then Build ONOS on ONOS Bench. |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 14 | This step is usually skipped. Because in a Jenkins driven automated |
| 15 | test env. We want Jenkins jobs to pull&build for flexibility to handle |
| 16 | different versions of ONOS. |
| 17 | ''' |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 18 | try: |
| 19 | from tests.dependencies.ONOSSetup import ONOSSetup |
| 20 | except ImportError: |
| 21 | main.log.error( "ONOSSetup not found. exiting the test" ) |
| 22 | main.exit() |
| 23 | try: |
| 24 | main.testSetUp |
| 25 | except ( NameError, AttributeError ): |
| 26 | main.testSetUp = ONOSSetup() |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 27 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 28 | main.testSetUp.gitPulling() |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 29 | |
| 30 | |
| 31 | def CASE1( self, main ): |
| 32 | ''' |
| 33 | Set up global test variables; |
| 34 | Uninstall all running cells in test env defined in .topo file |
| 35 | |
| 36 | ''' |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 37 | try: |
| 38 | from tests.dependencies.ONOSSetup import ONOSSetup |
| 39 | except ImportError: |
| 40 | main.log.error( "ONOSSetup not found. exiting the test" ) |
| 41 | main.exit() |
| 42 | try: |
| 43 | main.testSetUp |
| 44 | except ( NameError, AttributeError ): |
| 45 | main.testSetUp = ONOSSetup() |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 46 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 47 | main.testSetUp.envSetupDescription() |
| 48 | stepResult = main.FALSE |
| 49 | try: |
| 50 | main.nodeList = main.params['CASE1']['NodeList'].split(",") |
| 51 | main.onosStartupSleep = float(main.params['CASE1']['SleepTimers']['onosStartup']) |
| 52 | main.onosCfgSleep = float(main.params['CASE1']['SleepTimers']['onosCfg']) |
| 53 | main.mnStartupSleep = float(main.params['CASE1']['SleepTimers']['mnStartup']) |
| 54 | main.mnCfgSleep = float(main.params['CASE1']['SleepTimers']['mnCfg']) |
| 55 | main.numCtrls = int( main.params['CASE10']['numNodes'] ) |
| 56 | stepResult = main.testSetUp.envSetup( includeGitPull=False ) |
| 57 | except Exception as e: |
| 58 | main.testSetUp.envSetupException( e ) |
| 59 | main.testSetUp.evnSetupConclusion( stepResult ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 60 | |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 61 | |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 62 | def CASE2( self, main ): |
| 63 | ''' |
| 64 | Report errors/warnings/exceptions |
| 65 | ''' |
| 66 | main.log.info("Error report: \n" ) |
You Wang | c669d21 | 2017-01-25 11:09:48 -0800 | [diff] [blame] | 67 | main.ONOSbench.logReport( main.ONOSip[0], |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 68 | [ "INFO", |
| 69 | "FOLLOWER", |
| 70 | "WARN", |
| 71 | "flow", |
| 72 | "ERROR", |
| 73 | "Except" ], |
| 74 | "s" ) |
| 75 | |
| 76 | def CASE10( self, main ): |
| 77 | """ |
| 78 | Start ONOS cluster (3 nodes in this example) in three steps: |
| 79 | 1) start a basic cluster with drivers app via ONOSDriver; |
| 80 | 2) activate apps via ONOSCliDriver; |
| 81 | 3) configure onos via ONOSCliDriver; |
| 82 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 83 | try: |
| 84 | from tests.dependencies.ONOSSetup import ONOSSetup |
| 85 | except ImportError: |
| 86 | main.log.error( "ONOSSetup not found. exiting the test" ) |
| 87 | main.exit() |
| 88 | try: |
| 89 | main.testSetUp |
| 90 | except ( NameError, AttributeError ): |
| 91 | main.testSetUp = ONOSSetup() |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 92 | |
| 93 | import time |
| 94 | |
You Wang | c669d21 | 2017-01-25 11:09:48 -0800 | [diff] [blame] | 95 | main.case( "Start up " + str( main.numCtrls ) + "-node onos cluster.") |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 96 | main.step( "Start ONOS cluster with basic (drivers) app.") |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 97 | stepResult = main.ONOSbench.startBasicONOS( nodeList=main.ONOSip, opSleep=200, |
| 98 | onosUser=main.ONOScli1.karafUser ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 99 | utilities.assert_equals( expect=main.TRUE, |
| 100 | actual=stepResult, |
| 101 | onpass="Successfully started basic ONOS cluster ", |
| 102 | onfail="Failed to start basic ONOS Cluster " ) |
| 103 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 104 | main.testSetUp.startOnosClis() |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 105 | |
| 106 | main.step( "Activate onos apps.") |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 107 | main.apps = main.params['CASE10'].get( 'Apps' ) |
| 108 | if main.apps: |
| 109 | main.log.info( "Apps to activate: " + main.apps ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 110 | activateResult = main.TRUE |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 111 | for a in main.apps.split(","): |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 112 | activateResult = activateResult & main.ONOScli1.activateApp(a) |
| 113 | # TODO: check this worked |
| 114 | time.sleep( main.onosCfgSleep ) # wait for apps to activate |
| 115 | else: |
| 116 | main.log.warn( "No configurations were specified to be changed after startup" ) |
| 117 | utilities.assert_equals( expect=main.TRUE, |
| 118 | actual=activateResult, |
| 119 | onpass="Successfully set config", |
| 120 | onfail="Failed to set config" ) |
| 121 | |
| 122 | main.step( "Set ONOS configurations" ) |
| 123 | config = main.params['CASE10'].get( 'ONOS_Configuration' ) |
| 124 | if config: |
| 125 | main.log.debug( config ) |
| 126 | checkResult = main.TRUE |
| 127 | for component in config: |
| 128 | for setting in config[component]: |
| 129 | value = config[component][setting] |
| 130 | check = main.ONOScli1.setCfg( component, setting, value ) |
| 131 | main.log.info( "Value was changed? {}".format( main.TRUE == check ) ) |
| 132 | checkResult = check and checkResult |
| 133 | utilities.assert_equals( expect=main.TRUE, |
| 134 | actual=checkResult, |
| 135 | onpass="Successfully set config", |
| 136 | onfail="Failed to set config" ) |
| 137 | else: |
| 138 | main.log.warn( "No configurations were specified to be changed after startup" ) |
| 139 | |
| 140 | def CASE11( self, main ): |
| 141 | """ |
| 142 | Start mininet and assign controllers |
| 143 | """ |
| 144 | import time |
| 145 | |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 146 | topology = main.params['CASE11']['topo'] |
| 147 | main.log.report( "Start Mininet topology" ) |
Jon Hall | 6509dbf | 2016-06-21 17:01:17 -0700 | [diff] [blame] | 148 | main.case( "Start Mininet topology" ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 149 | |
| 150 | main.step( "Starting Mininet Topology" ) |
alison | 12f34c3 | 2016-06-10 14:39:21 -0700 | [diff] [blame] | 151 | topoResult = main.Mininet1.startNet(mnCmd=topology ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 152 | stepResult = topoResult |
| 153 | utilities.assert_equals( expect=main.TRUE, |
| 154 | actual=stepResult, |
| 155 | onpass="Successfully loaded topology", |
| 156 | onfail="Failed to load topology" ) |
| 157 | # Exit if topology did not load properly |
| 158 | if not topoResult: |
| 159 | main.cleanup() |
| 160 | main.exit() |
| 161 | |
| 162 | main.step( "Assign switches to controllers.") |
| 163 | assignResult = main.TRUE |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 164 | for i in range(1, 8): |
| 165 | assignResult = assignResult & main.Mininet1.assignSwController( sw="s" + str( i ), |
You Wang | c669d21 | 2017-01-25 11:09:48 -0800 | [diff] [blame] | 166 | ip=main.ONOSip, |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 167 | port='6653' ) |
| 168 | time.sleep(main.mnCfgSleep) |
| 169 | utilities.assert_equals( expect=main.TRUE, |
| 170 | actual=stepResult, |
| 171 | onpass="Successfully assign switches to controllers", |
| 172 | onfail="Failed to assign switches to controllers" ) |
| 173 | |
| 174 | |
| 175 | def CASE12( self, main ): |
| 176 | """ |
| 177 | Tests using through ONOS CLI handles |
| 178 | """ |
| 179 | |
Jon Hall | 6509dbf | 2016-06-21 17:01:17 -0700 | [diff] [blame] | 180 | main.case( "Test some onos commands through CLI. ") |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 181 | main.log.debug( main.ONOScli1.sendline("summary") ) |
| 182 | main.log.debug( main.ONOScli3.sendline("devices") ) |
| 183 | |
| 184 | def CASE22( self, main ): |
| 185 | """ |
| 186 | Tests using ONOS REST API handles |
| 187 | """ |
| 188 | |
| 189 | main.case( " Sample tests using ONOS REST API handles. ") |
| 190 | main.log.debug( main.ONOSrest1.send("/devices") ) |
suibin zhang | c969ddd | 2016-05-23 12:01:52 -0700 | [diff] [blame] | 191 | main.log.debug( main.ONOSrest2.apps() ) |
alison | 12f34c3 | 2016-06-10 14:39:21 -0700 | [diff] [blame] | 192 | |
| 193 | def CASE32( self, main ): |
| 194 | """ |
| 195 | Configure fwd app from .params json string with parameter configured |
| 196 | Check if configuration successful |
| 197 | Run pingall to check connectivity |
| 198 | Check ONOS log for warning/error/exceptions |
| 199 | """ |
| 200 | main.case( "Configure onos-app-fwd and check if configuration successful. " ) |
| 201 | main.step( "Install reactive forwarding app." ) |
| 202 | installResults = main.ONOScli1.activateApp( "org.onosproject.fwd" ) |
| 203 | utilities.assert_equals( expect=main.TRUE, actual=installResults, |
| 204 | onpass= "Configure fwd successful", onfail= "Configure fwd failed" ) |
| 205 | main.step( "Run pingall to check connectivity. " ) |
| 206 | pingResult = main.FALSE |
| 207 | passMsg = "Reactive Pingall test passed" |
| 208 | pingResult = main.Mininet1.pingall() |
| 209 | if not pingResult: |
| 210 | main.log.warn("First pingall failed. Trying again...") |
| 211 | pingResult = main.Mininet1.pingall() |
| 212 | passMsg += "on the second try" |
| 213 | utilities.assert_equals( expect=main.TRUE, actual=pingResult, onpass=passMsg, onfail= "Reactive Pingall failed, " + "one or more ping pairs failed" ) |