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