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_1node: |
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 | ''' |
| 18 | gitPull = main.params['CASE0']['gitPull'] |
| 19 | gitBranch = main.params['CASE0']['gitBranch'] |
| 20 | |
| 21 | main.case("Pull onos branch and build onos on Teststation.") |
| 22 | |
| 23 | if gitPull == 'True': |
| 24 | main.step( "Git Checkout ONOS branch: " + gitBranch) |
| 25 | stepResult = main.ONOSbench.gitCheckout( branch = gitBranch ) |
| 26 | utilities.assert_equals( expect=main.TRUE, |
| 27 | actual=stepResult, |
| 28 | onpass="Successfully checkout onos branch.", |
| 29 | onfail="Failed to checkout onos branch. Exiting test..." ) |
| 30 | if not stepResult: main.exit() |
| 31 | |
| 32 | main.step( "Git Pull on ONOS branch:" + gitBranch) |
| 33 | stepResult = main.ONOSbench.gitPull( ) |
| 34 | utilities.assert_equals( expect=main.TRUE, |
| 35 | actual=stepResult, |
| 36 | onpass="Successfully pull onos. ", |
| 37 | onfail="Failed to pull onos. Exiting test ..." ) |
| 38 | if not stepResult: main.exit() |
| 39 | |
| 40 | main.step( "Building ONOS branch: " + gitBranch ) |
| 41 | stepResult = main.ONOSbench.cleanInstall( skipTest = True ) |
| 42 | utilities.assert_equals( expect=main.TRUE, |
| 43 | actual=stepResult, |
| 44 | onpass="Successfully build onos.", |
| 45 | onfail="Failed to build onos. Exiting test..." ) |
| 46 | if not stepResult: main.exit() |
| 47 | |
| 48 | else: |
| 49 | main.log.warn( "Skipped pulling onos and Skipped building ONOS" ) |
| 50 | |
| 51 | |
| 52 | def CASE1( self, main ): |
| 53 | ''' |
| 54 | Set up global test variables; |
| 55 | Uninstall all running cells in test env defined in .topo file |
| 56 | |
| 57 | ''' |
| 58 | |
| 59 | main.case( "Constructing global test variables and clean cluster env." ) |
| 60 | |
| 61 | main.step( "Constructing test variables" ) |
| 62 | main.branch = main.ONOSbench.getBranchName() |
| 63 | main.log.info( "Running onos branch: " + main.branch ) |
| 64 | main.commitNum = main.ONOSbench.getVersion().split(' ')[1] |
| 65 | main.log.info( "Running onos commit Number: " + main.commitNum) |
| 66 | main.nodeList = main.params['CASE1']['NodeList'].split(",") |
| 67 | main.onosStartupSleep = float( main.params['CASE1']['SleepTimers']['onosStartup'] ) |
| 68 | main.onosCfgSleep = float( main.params['CASE1']['SleepTimers']['onosCfg'] ) |
| 69 | main.mnStartupSleep = float( main.params['CASE1']['SleepTimers']['mnStartup'] ) |
| 70 | main.mnCfgSleep = float( main.params['CASE1']['SleepTimers']['mnCfg'] ) |
You Wang | c669d21 | 2017-01-25 11:09:48 -0800 | [diff] [blame] | 71 | main.numCtrls = int( main.params['CASE10']['numNodes'] ) |
| 72 | main.AllONOSip = main.ONOSbench.getOnosIps() |
| 73 | main.ONOSip = [] |
| 74 | for i in range( main.numCtrls ): |
| 75 | main.ONOSip.append( main.AllONOSip[i] ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 76 | utilities.assert_equals( expect=main.TRUE, |
| 77 | actual=main.TRUE, |
| 78 | onpass="Successfully construct " + |
| 79 | "test variables ", |
| 80 | onfail="Failed to construct test variables" ) |
| 81 | |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 82 | def CASE2( self, main ): |
| 83 | ''' |
| 84 | Report errors/warnings/exceptions |
| 85 | ''' |
| 86 | main.log.info("Error report: \n" ) |
You Wang | c669d21 | 2017-01-25 11:09:48 -0800 | [diff] [blame] | 87 | main.ONOSbench.logReport( main.ONOSip[0], |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 88 | [ "INFO", |
| 89 | "FOLLOWER", |
| 90 | "WARN", |
| 91 | "flow", |
| 92 | "ERROR", |
| 93 | "Except" ], |
| 94 | "s" ) |
| 95 | |
| 96 | def CASE10( self, main ): |
| 97 | """ |
alison | 12f34c3 | 2016-06-10 14:39:21 -0700 | [diff] [blame] | 98 | Start ONOS cluster (1 node in this example) in three steps: |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 99 | 1) start a basic cluster with drivers app via ONOSDriver; |
| 100 | 2) activate apps via ONOSCliDriver; |
| 101 | 3) configure onos via ONOSCliDriver; |
| 102 | """ |
| 103 | |
| 104 | import time |
| 105 | |
You Wang | c669d21 | 2017-01-25 11:09:48 -0800 | [diff] [blame] | 106 | main.case( "Start up " + str( main.numCtrls ) + "-node onos cluster.") |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 107 | main.step( "Start ONOS cluster with basic (drivers) app.") |
Devin Lim | 461f087 | 2017-06-05 16:49:33 -0700 | [diff] [blame^] | 108 | stepResult = main.ONOSbench.startBasicONOS( nodeList=main.ONOSip, opSleep=200, |
| 109 | onosUser=main.ONOScli1.user_name ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 110 | utilities.assert_equals( expect=main.TRUE, |
| 111 | actual=stepResult, |
| 112 | onpass="Successfully started basic ONOS cluster ", |
| 113 | onfail="Failed to start basic ONOS Cluster " ) |
| 114 | |
| 115 | main.step( "Establishing Handles on ONOS CLIs.") |
| 116 | cliResult = main.TRUE |
You Wang | c669d21 | 2017-01-25 11:09:48 -0800 | [diff] [blame] | 117 | for n in range( 1, main.numCtrls + 1 ): |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 118 | handle = "main.ONOScli" + str( n ) |
You Wang | c669d21 | 2017-01-25 11:09:48 -0800 | [diff] [blame] | 119 | cliResult = cliResult & ( eval( handle ).startOnosCli( main.ONOSip[ n-1 ] ) ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 120 | utilities.assert_equals( expect=main.TRUE, |
| 121 | actual=cliResult, |
| 122 | onpass="Successfully started onos cli's ", |
| 123 | onfail="Failed to start onos cli's " ) |
| 124 | |
| 125 | main.step( "Activate onos apps.") |
| 126 | apps = main.params['CASE10'].get( 'Apps' ) |
| 127 | if apps: |
| 128 | main.log.info( "Apps to activate: " + apps ) |
| 129 | activateResult = main.TRUE |
| 130 | for a in apps.split(","): |
| 131 | activateResult = activateResult & main.ONOScli1.activateApp(a) |
| 132 | # TODO: check this worked |
| 133 | time.sleep( main.onosCfgSleep ) # wait for apps to activate |
| 134 | else: |
| 135 | main.log.warn( "No configurations were specified to be changed after startup" ) |
| 136 | utilities.assert_equals( expect=main.TRUE, |
| 137 | actual=activateResult, |
| 138 | onpass="Successfully set config", |
| 139 | onfail="Failed to set config" ) |
| 140 | |
| 141 | main.step( "Set ONOS configurations" ) |
| 142 | config = main.params['CASE10'].get( 'ONOS_Configuration' ) |
| 143 | if config: |
| 144 | main.log.debug( config ) |
| 145 | checkResult = main.TRUE |
| 146 | for component in config: |
| 147 | for setting in config[component]: |
| 148 | value = config[component][setting] |
| 149 | check = main.ONOScli1.setCfg( component, setting, value ) |
| 150 | main.log.info( "Value was changed? {}".format( main.TRUE == check ) ) |
| 151 | checkResult = check and checkResult |
| 152 | utilities.assert_equals( expect=main.TRUE, |
| 153 | actual=checkResult, |
| 154 | onpass="Successfully set config", |
| 155 | onfail="Failed to set config" ) |
| 156 | else: |
| 157 | main.log.warn( "No configurations were specified to be changed after startup" ) |
| 158 | |
| 159 | def CASE11( self, main ): |
| 160 | """ |
| 161 | Start mininet and assign controllers |
| 162 | """ |
| 163 | import time |
| 164 | |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 165 | topology = main.params['CASE11']['topo'] |
| 166 | main.log.report( "Start Mininet topology" ) |
Jon Hall | 6509dbf | 2016-06-21 17:01:17 -0700 | [diff] [blame] | 167 | main.case( "Start Mininet topology" ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 168 | |
| 169 | main.step( "Starting Mininet Topology" ) |
alison | 12f34c3 | 2016-06-10 14:39:21 -0700 | [diff] [blame] | 170 | topoResult = main.Mininet1.startNet( mnCmd=topology ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 171 | stepResult = topoResult |
| 172 | utilities.assert_equals( expect=main.TRUE, |
| 173 | actual=stepResult, |
| 174 | onpass="Successfully loaded topology", |
| 175 | onfail="Failed to load topology" ) |
| 176 | # Exit if topology did not load properly |
| 177 | if not topoResult: |
| 178 | main.cleanup() |
| 179 | main.exit() |
| 180 | |
| 181 | main.step( "Assign switches to controllers.") |
| 182 | assignResult = main.TRUE |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 183 | for i in range(1, 8): |
| 184 | assignResult = assignResult & main.Mininet1.assignSwController( sw="s" + str( i ), |
You Wang | c669d21 | 2017-01-25 11:09:48 -0800 | [diff] [blame] | 185 | ip=main.ONOSip, |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 186 | port='6653' ) |
| 187 | time.sleep(main.mnCfgSleep) |
| 188 | utilities.assert_equals( expect=main.TRUE, |
| 189 | actual=stepResult, |
| 190 | onpass="Successfully assign switches to controllers", |
| 191 | onfail="Failed to assign switches to controllers" ) |
| 192 | |
| 193 | |
| 194 | def CASE12( self, main ): |
| 195 | """ |
| 196 | Tests using through ONOS CLI handles |
| 197 | """ |
| 198 | |
Jon Hall | 6509dbf | 2016-06-21 17:01:17 -0700 | [diff] [blame] | 199 | main.case( "Test some onos commands through CLI. ") |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 200 | main.log.debug( main.ONOScli1.sendline("summary") ) |
suibin zhang | c969ddd | 2016-05-23 12:01:52 -0700 | [diff] [blame] | 201 | main.log.debug( main.ONOScli1.sendline("devices") ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 202 | |
| 203 | def CASE22( self, main ): |
| 204 | """ |
| 205 | Tests using ONOS REST API handles |
| 206 | """ |
| 207 | |
| 208 | main.case( " Sample tests using ONOS REST API handles. ") |
| 209 | main.log.debug( main.ONOSrest1.send("/devices") ) |
alison | 12f34c3 | 2016-06-10 14:39:21 -0700 | [diff] [blame] | 210 | main.log.debug( main.ONOSrest1.apps() ) |
| 211 | |
| 212 | def CASE32( self, main ): |
| 213 | """ |
| 214 | Configure fwd app from .param json string with parameter configured. |
| 215 | Check if configuration successful |
| 216 | Run pingall to check connectivity |
| 217 | Check ONOS log for warning/error/exceptions |
| 218 | """ |
| 219 | main.case( "Configure onos-app-fwd and check if configuration successful. " ) |
| 220 | main.step( "Install reactive forwarding app." ) |
| 221 | installResults = main.ONOScli1.activateApp( "org.onosproject.fwd" ) |
| 222 | utilities.assert_equals( expect=main.TRUE, actual=installResults, |
| 223 | onpass = "Configure fwd successful", onfail="Configure fwd failed" ) |
| 224 | main.step( "Run pingall to check connectivity. " ) |
| 225 | pingResult = main.FALSE |
| 226 | passMsg = "Reactive Pingall test passed" |
| 227 | pingResult = main.Mininet1.pingall() |
| 228 | if not pingResult: |
| 229 | main.log.warn( "First pingall failed. Trying again..." ) |
| 230 | pingResult = main.Mininet1.pingall() |
| 231 | passMsg += "on the second try" |
| 232 | utilities.assert_equals( expect=main.TRUE, actual=pingResult, onpass=passMsg, onfail= "Reactive Pingall failed, " + "one or more ping pairs failed." ) |