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