Jeremy | fc567ca | 2016-02-16 15:08:25 -0800 | [diff] [blame] | 1 | # Testing the NETCONF protocol within ONOS |
| 2 | |
Jon Hall | 0c3f46f | 2017-05-24 16:34:46 -0700 | [diff] [blame] | 3 | |
Jeremy | fc567ca | 2016-02-16 15:08:25 -0800 | [diff] [blame] | 4 | class FUNCnetconf: |
| 5 | |
| 6 | def __init__( self ): |
| 7 | self.default = '' |
| 8 | |
| 9 | def CASE1( self, main ): |
| 10 | import time |
| 11 | import imp |
| 12 | import re |
| 13 | |
| 14 | """ |
| 15 | - Construct tests variables |
| 16 | - GIT ( optional ) |
| 17 | - Checkout ONOS master branch |
| 18 | - Pull latest ONOS code |
| 19 | - Building ONOS ( optional ) |
| 20 | - Install ONOS package |
| 21 | - Build ONOS package |
| 22 | """ |
Jeremy | fc567ca | 2016-02-16 15:08:25 -0800 | [diff] [blame] | 23 | main.case( "Constructing test variables and building ONOS package" ) |
| 24 | main.step( "Constructing test variables" ) |
| 25 | main.caseExplanation = "This test case is mainly for loading " +\ |
| 26 | "from params file, and pull and build the " +\ |
| 27 | " latest ONOS package" |
| 28 | stepResult = main.FALSE |
| 29 | |
| 30 | # Test variables |
| 31 | try: |
| 32 | main.testOnDirectory = re.sub( "(/tests)$", "", main.testDir ) |
| 33 | main.apps = main.params[ 'ENV' ][ 'cellApps' ] |
| 34 | gitBranch = main.params[ 'GIT' ][ 'branch' ] |
| 35 | main.dependencyPath = main.testOnDirectory + \ |
| 36 | main.params[ 'DEPENDENCY' ][ 'path' ] |
| 37 | # main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ] |
| 38 | main.scale = ( main.params[ 'SCALE' ][ 'size' ] ).split( "," ) |
| 39 | if main.ONOSbench.maxNodes: |
| 40 | main.maxNodes = int( main.ONOSbench.maxNodes ) |
| 41 | else: |
| 42 | main.maxNodes = 0 |
| 43 | wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ] |
| 44 | wrapperFile2 = main.params[ 'DEPENDENCY' ][ 'wrapper2' ] |
| 45 | wrapperFile3 = main.params[ 'DEPENDENCY' ][ 'wrapper3' ] |
| 46 | main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] ) |
| 47 | main.switchSleep = int( main.params[ 'SLEEP' ][ 'upSwitch' ] ) |
| 48 | main.checkTopoAttempts = int( main.params[ 'SLEEP' ][ 'topoAttempts' ] ) |
| 49 | main.numSwitch = int( main.params[ 'MININET' ][ 'switch' ] ) |
| 50 | |
| 51 | # Config file parameters |
| 52 | main.configDevicePort = main.params[ 'CONFIGURE' ][ 'cfgDevicePort' ] |
| 53 | main.configDriver = main.params[ 'CONFIGURE' ][ 'cfgDriver' ] |
| 54 | main.configApps = main.params[ 'CONFIGURE' ][ 'cfgApps' ] |
| 55 | main.configName = main.params[ 'CONFIGURE' ][ 'cfgName' ] |
| 56 | main.configPass = main.params[ 'CONFIGURE' ][ 'cfgPass' ] |
| 57 | main.configPort = main.params[ 'CONFIGURE' ][ 'cfgAppPort' ] |
Jon Hall | 0c3f46f | 2017-05-24 16:34:46 -0700 | [diff] [blame] | 58 | main.cycle = 0 # How many times FUNCintent has run through its tests |
Jeremy | fc567ca | 2016-02-16 15:08:25 -0800 | [diff] [blame] | 59 | |
| 60 | gitPull = main.params[ 'GIT' ][ 'pull' ] |
Jon Hall | 0c3f46f | 2017-05-24 16:34:46 -0700 | [diff] [blame] | 61 | main.cellData = {} # for creating cell file |
Jeremy | fc567ca | 2016-02-16 15:08:25 -0800 | [diff] [blame] | 62 | main.hostsData = {} |
| 63 | main.CLIs = [] |
| 64 | main.CLIs2 = [] |
| 65 | main.ONOSip = [] |
| 66 | main.assertReturnString = '' # Assembled assert return string |
| 67 | |
| 68 | main.ONOSip = main.ONOSbench.getOnosIps() |
| 69 | print main.ONOSip |
| 70 | |
| 71 | # Assigning ONOS cli handles to a list |
Jon Hall | 0c3f46f | 2017-05-24 16:34:46 -0700 | [diff] [blame] | 72 | for i in range( 1, main.maxNodes + 1 ): |
Jeremy | fc567ca | 2016-02-16 15:08:25 -0800 | [diff] [blame] | 73 | main.CLIs.append( getattr( main, 'ONOSrest' + str( i ) ) ) |
| 74 | main.CLIs2.append( getattr( main, 'ONOScli' + str( i ) ) ) |
| 75 | |
| 76 | # -- INIT SECTION, ONLY RUNS ONCE -- # |
| 77 | main.startUp = imp.load_source( wrapperFile1, |
| 78 | main.dependencyPath + |
| 79 | wrapperFile1 + |
| 80 | ".py" ) |
| 81 | |
| 82 | main.netconfFunction = imp.load_source( wrapperFile2, |
Jon Hall | 0c3f46f | 2017-05-24 16:34:46 -0700 | [diff] [blame] | 83 | main.dependencyPath + |
| 84 | wrapperFile2 + |
| 85 | ".py" ) |
Jeremy | fc567ca | 2016-02-16 15:08:25 -0800 | [diff] [blame] | 86 | |
| 87 | main.topo = imp.load_source( wrapperFile3, |
| 88 | main.dependencyPath + |
| 89 | wrapperFile3 + |
| 90 | ".py" ) |
| 91 | |
| 92 | # Uncomment out the following if a mininet topology is added |
| 93 | # copyResult1 = main.ONOSbench.scp( main.Mininet1, |
| 94 | # main.dependencyPath + |
| 95 | # main.topology, |
| 96 | # main.Mininet1.home + "custom/", |
| 97 | # direction="to" ) |
| 98 | |
| 99 | if main.CLIs and main.CLIs2: |
| 100 | stepResult = main.TRUE |
| 101 | else: |
| 102 | main.log.error( "Did not properly created list of ONOS CLI handle" ) |
| 103 | stepResult = main.FALSE |
| 104 | except Exception as e: |
Jon Hall | 0c3f46f | 2017-05-24 16:34:46 -0700 | [diff] [blame] | 105 | main.log.exception( e ) |
Jeremy | fc567ca | 2016-02-16 15:08:25 -0800 | [diff] [blame] | 106 | main.cleanup() |
| 107 | main.exit() |
| 108 | |
| 109 | utilities.assert_equals( expect=main.TRUE, |
| 110 | actual=stepResult, |
| 111 | onpass="Successfully construct " + |
| 112 | "test variables ", |
| 113 | onfail="Failed to construct test variables" ) |
| 114 | |
Jeremy | fc567ca | 2016-02-16 15:08:25 -0800 | [diff] [blame] | 115 | main.ONOSbench.getVersion( report=True ) |
| 116 | |
| 117 | def CASE2( self, main ): |
| 118 | """ |
| 119 | - Set up cell |
| 120 | - Create cell file |
| 121 | - Set cell file |
| 122 | - Verify cell file |
| 123 | - Kill ONOS process |
| 124 | - Uninstall ONOS cluster |
| 125 | - Verify ONOS start up |
| 126 | - Install ONOS cluster |
| 127 | - Connect to cli |
| 128 | """ |
Jeremy Songster | 17147f2 | 2016-05-31 18:30:52 -0700 | [diff] [blame] | 129 | main.cycle += 1 |
| 130 | |
Jeremy | fc567ca | 2016-02-16 15:08:25 -0800 | [diff] [blame] | 131 | # main.scale[ 0 ] determines the current number of ONOS controller |
| 132 | main.numCtrls = int( main.scale[ 0 ] ) |
| 133 | |
| 134 | main.case( "Starting up " + str( main.numCtrls ) + |
| 135 | " node(s) ONOS cluster" ) |
| 136 | main.caseExplanation = "Set up ONOS with " + str( main.numCtrls ) +\ |
| 137 | " node(s) ONOS cluster" |
| 138 | |
Jeremy | fc567ca | 2016-02-16 15:08:25 -0800 | [diff] [blame] | 139 | #kill off all onos processes |
| 140 | main.log.info( "Safety check, killing all ONOS processes" + |
| 141 | " before initiating environment setup" ) |
| 142 | |
Jeremy | fc567ca | 2016-02-16 15:08:25 -0800 | [diff] [blame] | 143 | time.sleep( main.startUpSleep ) |
| 144 | main.step( "Uninstalling ONOS package" ) |
| 145 | onosUninstallResult = main.TRUE |
| 146 | for ip in main.ONOSip: |
| 147 | onosUninstallResult = onosUninstallResult and \ |
| 148 | main.ONOSbench.onosUninstall( nodeIp=ip ) |
| 149 | stepResult = onosUninstallResult |
| 150 | utilities.assert_equals( expect=main.TRUE, |
| 151 | actual=stepResult, |
| 152 | onpass="Successfully uninstalled ONOS package", |
| 153 | onfail="Failed to uninstall ONOS package" ) |
| 154 | |
| 155 | for i in range( main.maxNodes ): |
| 156 | main.ONOSbench.onosDie( main.ONOSip[ i ] ) |
| 157 | |
| 158 | main.log.info( "NODE COUNT = " + str( main.numCtrls ) ) |
| 159 | |
| 160 | tempOnosIp = [] |
| 161 | for i in range( main.numCtrls ): |
Jon Hall | 0c3f46f | 2017-05-24 16:34:46 -0700 | [diff] [blame] | 162 | tempOnosIp.append( main.ONOSip[ i ] ) |
Jeremy | fc567ca | 2016-02-16 15:08:25 -0800 | [diff] [blame] | 163 | |
| 164 | main.ONOSbench.createCellFile( main.ONOSbench.ip_address, |
| 165 | "temp", main.Mininet1.ip_address, |
Devin Lim | 461f087 | 2017-06-05 16:49:33 -0700 | [diff] [blame] | 166 | main.apps, tempOnosIp, main.ONOScli1.user_name ) |
Jeremy | fc567ca | 2016-02-16 15:08:25 -0800 | [diff] [blame] | 167 | |
| 168 | main.step( "Apply cell to environment" ) |
| 169 | cellResult = main.ONOSbench.setCell( "temp" ) |
| 170 | verifyResult = main.ONOSbench.verifyCell() |
| 171 | stepResult = cellResult and verifyResult |
| 172 | utilities.assert_equals( expect=main.TRUE, |
| 173 | actual=stepResult, |
Jon Hall | 0c3f46f | 2017-05-24 16:34:46 -0700 | [diff] [blame] | 174 | onpass="Successfully applied cell to " + |
Jeremy | fc567ca | 2016-02-16 15:08:25 -0800 | [diff] [blame] | 175 | "environment", |
| 176 | onfail="Failed to apply cell to environment " ) |
| 177 | |
| 178 | main.step( "Creating ONOS package" ) |
Jon Hall | bd60ea0 | 2016-08-23 10:03:59 -0700 | [diff] [blame] | 179 | packageResult = main.ONOSbench.buckBuild() |
Jeremy | fc567ca | 2016-02-16 15:08:25 -0800 | [diff] [blame] | 180 | stepResult = packageResult |
| 181 | utilities.assert_equals( expect=main.TRUE, |
| 182 | actual=stepResult, |
| 183 | onpass="Successfully created ONOS package", |
| 184 | onfail="Failed to create ONOS package" ) |
| 185 | |
| 186 | time.sleep( main.startUpSleep ) |
| 187 | main.step( "Installing ONOS package" ) |
| 188 | onosInstallResult = main.TRUE |
| 189 | for i in range( main.numCtrls ): |
| 190 | onosInstallResult = onosInstallResult and \ |
| 191 | main.ONOSbench.onosInstall( node=main.ONOSip[ i ], options="" ) |
| 192 | stepResult = onosInstallResult |
| 193 | |
| 194 | utilities.assert_equals( expect=main.TRUE, |
| 195 | actual=stepResult, |
| 196 | onpass="Successfully installed ONOS package", |
| 197 | onfail="Failed to install ONOS package" ) |
| 198 | |
You Wang | f5de25b | 2017-01-06 15:13:01 -0800 | [diff] [blame] | 199 | main.step( "Set up ONOS secure SSH" ) |
| 200 | secureSshResult = main.TRUE |
| 201 | for i in range( int( main.numCtrls ) ): |
Jon Hall | 0c3f46f | 2017-05-24 16:34:46 -0700 | [diff] [blame] | 202 | secureSshResult = secureSshResult and main.ONOSbench.onosSecureSSH( node=main.ONOSip[ i ] ) |
You Wang | f5de25b | 2017-01-06 15:13:01 -0800 | [diff] [blame] | 203 | utilities.assert_equals( expect=main.TRUE, actual=secureSshResult, |
| 204 | onpass="Test step PASS", |
| 205 | onfail="Test step FAIL" ) |
| 206 | |
Jeremy | fc567ca | 2016-02-16 15:08:25 -0800 | [diff] [blame] | 207 | time.sleep( main.startUpSleep ) |
| 208 | main.step( "Starting ONOS service" ) |
| 209 | stopResult = main.TRUE |
| 210 | startResult = main.TRUE |
| 211 | onosIsUp = main.TRUE |
| 212 | |
| 213 | for i in range( main.numCtrls ): |
| 214 | onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] ) |
| 215 | if onosIsUp == main.TRUE: |
| 216 | main.log.report( "ONOS instance is up and ready" ) |
| 217 | else: |
| 218 | main.log.report( "ONOS instance may not be up, stop and " + |
| 219 | "start ONOS again " ) |
| 220 | for i in range( main.numCtrls ): |
| 221 | stopResult = stopResult and \ |
| 222 | main.ONOSbench.onosStop( main.ONOSip[ i ] ) |
| 223 | for i in range( main.numCtrls ): |
| 224 | startResult = startResult and \ |
| 225 | main.ONOSbench.onosStart( main.ONOSip[ i ] ) |
| 226 | stepResult = onosIsUp and stopResult and startResult |
| 227 | utilities.assert_equals( expect=main.TRUE, |
| 228 | actual=stepResult, |
| 229 | onpass="ONOS service is ready", |
| 230 | onfail="ONOS service did not start properly" ) |
| 231 | |
| 232 | # Start an ONOS cli to provide functionality that is not currently |
| 233 | # supported by the Rest API remove this when Leader Checking is supported |
| 234 | # by the REST API |
| 235 | |
| 236 | main.step( "Start ONOS cli" ) |
| 237 | cliResult = main.TRUE |
| 238 | for i in range( main.numCtrls ): |
| 239 | cliResult = cliResult and \ |
| 240 | main.CLIs2[ i ].startOnosCli( main.ONOSip[ i ] ) |
| 241 | stepResult = cliResult |
| 242 | utilities.assert_equals( expect=main.TRUE, |
| 243 | actual=stepResult, |
| 244 | onpass="Successfully start ONOS cli", |
| 245 | onfail="Failed to start ONOS cli" ) |
| 246 | |
| 247 | # Remove the first element in main.scale list |
| 248 | main.scale.remove( main.scale[ 0 ] ) |
| 249 | |
Jeremy Songster | 17147f2 | 2016-05-31 18:30:52 -0700 | [diff] [blame] | 250 | def CASE19( self, main ): |
| 251 | """ |
| 252 | Copy the karaf.log files after each testcase cycle |
| 253 | """ |
| 254 | main.log.report( "Copy karaf logs" ) |
| 255 | main.case( "Copy karaf logs" ) |
| 256 | main.caseExplanation = "Copying the karaf logs to preserve them through" +\ |
| 257 | "reinstalling ONOS" |
| 258 | main.step( "Copying karaf logs" ) |
Jeremy Songster | 31aad31 | 2016-06-13 16:32:11 -0700 | [diff] [blame] | 259 | stepResult = main.TRUE |
| 260 | scpResult = main.TRUE |
| 261 | copyResult = main.TRUE |
Jeremy Songster | cc5414b | 2016-07-11 10:59:53 -0700 | [diff] [blame] | 262 | for i in range( main.numCtrls ): |
Jeremy Songster | d2d687e | 2016-07-19 11:20:48 -0700 | [diff] [blame] | 263 | main.node = main.CLIs2[ i ] |
Jeremy Songster | 17147f2 | 2016-05-31 18:30:52 -0700 | [diff] [blame] | 264 | ip = main.ONOSip[ i ] |
| 265 | main.node.ip_address = ip |
Jon Hall | 0c3f46f | 2017-05-24 16:34:46 -0700 | [diff] [blame] | 266 | scpResult = scpResult and main.ONOSbench.scp( main.node, |
| 267 | "/opt/onos/log/karaf.log", |
| 268 | "/tmp/karaf.log", |
| 269 | direction="from" ) |
Jeremy Songster | 31aad31 | 2016-06-13 16:32:11 -0700 | [diff] [blame] | 270 | copyResult = copyResult and main.ONOSbench.cpLogsToDir( "/tmp/karaf.log", main.logdir, |
| 271 | copyFileName=( "karaf.log.node{0}.cycle{1}".format( str( i + 1 ), str( main.cycle ) ) ) ) |
| 272 | if scpResult and copyResult: |
Jon Hall | 0c3f46f | 2017-05-24 16:34:46 -0700 | [diff] [blame] | 273 | stepResult = main.TRUE and stepResult |
Jeremy Songster | 31aad31 | 2016-06-13 16:32:11 -0700 | [diff] [blame] | 274 | else: |
| 275 | stepResult = main.FALSE and stepResult |
Jeremy Songster | 31aad31 | 2016-06-13 16:32:11 -0700 | [diff] [blame] | 276 | utilities.assert_equals( expect=main.TRUE, |
| 277 | actual=stepResult, |
| 278 | onpass="Successfully copied remote ONOS logs", |
| 279 | onfail="Failed to copy remote ONOS logs" ) |
Jeremy Songster | 17147f2 | 2016-05-31 18:30:52 -0700 | [diff] [blame] | 280 | |
Jeremy | fc567ca | 2016-02-16 15:08:25 -0800 | [diff] [blame] | 281 | def CASE100( self, main ): |
| 282 | """ |
| 283 | Start NETCONF app and OFC-Server or make sure that they are already running |
| 284 | """ |
| 285 | assert main, "There is no main" |
| 286 | assert main.CLIs, "There is no main.CLIs" |
| 287 | assert main.numCtrls, "Placed the total number of switch topology in \ |
| 288 | main.numCtrls" |
| 289 | |
| 290 | testResult = main.FALSE |
| 291 | main.testName = "Start up NETCONF app in all nodes" |
| 292 | main.case( main.testName + " Test - " + str( main.numCtrls ) + |
| 293 | " NODE(S)" ) |
| 294 | main.step( "Starting NETCONF app" ) |
| 295 | main.assertReturnString = "Assertion result for starting NETCONF app" |
| 296 | testResult = main.netconfFunction.startApp( main ) |
| 297 | |
| 298 | utilities.assert_equals( expect=main.TRUE, |
| 299 | actual=testResult, |
| 300 | onpass=main.assertReturnString, |
| 301 | onfail=main.assertReturnString ) |
| 302 | |
| 303 | main.step( "Starting OFC-Server" ) |
| 304 | main.assertReturnString = "Assertion result for starting OFC-Server" |
| 305 | testResult = main.netconfFunction.startOFC( main ) |
| 306 | |
| 307 | utilities.assert_equals( expect=main.TRUE, |
| 308 | actual=testResult, |
| 309 | onpass=main.assertReturnString, |
| 310 | onfail=main.assertReturnString ) |
| 311 | time.sleep( main.startUpSleep ) |
| 312 | |
| 313 | def CASE200( self, main ): |
| 314 | """ |
| 315 | Create or modify a Configuration file |
| 316 | -The file is built from information loaded from the .params file |
| 317 | """ |
| 318 | assert main, "There is no main" |
| 319 | assert main.CLIs, "There is no main.CLIs" |
| 320 | assert main.numCtrls, "Placed the total number of switch topology in \ |
| 321 | main.numCtrls" |
| 322 | |
| 323 | main.testName = "Assemble the configuration" |
| 324 | main.case( main.testName + " Test - " + str( main.numCtrls ) + |
| 325 | " NODES(S)" ) |
| 326 | main.step( "Assembling configuration file" ) |
| 327 | main.assertReturnString = "Assertion result for assembling configuration file" |
| 328 | testResult = main.FALSE |
| 329 | testResult = main.netconfFunction.createConfig( main ) |
| 330 | |
| 331 | utilities.assert_equals( expect=main.TRUE, |
| 332 | actual=testResult, |
| 333 | onpass=main.assertReturnString, |
| 334 | onfail=main.assertReturnString ) |
| 335 | time.sleep( main.startUpSleep ) |
| 336 | |
| 337 | def CASE300( self, main ): |
| 338 | """ |
| 339 | Push a configuration and bring up a switch |
| 340 | """ |
| 341 | assert main, "There is no main" |
| 342 | assert main.CLIs, "There is no main.CLIs" |
| 343 | assert main.numCtrls, "Placed the total number of switch topology in \ |
| 344 | main.numCtrls" |
| 345 | |
| 346 | main.testName = "Uploading the configuration" |
| 347 | main.case( main.testName + " Test - " + str( main.numCtrls ) + |
| 348 | " NODES(S)" ) |
Jon Hall | 0c3f46f | 2017-05-24 16:34:46 -0700 | [diff] [blame] | 349 | main.step( "Sending the configuration file" ) |
Jeremy | fc567ca | 2016-02-16 15:08:25 -0800 | [diff] [blame] | 350 | main.assertReturnString = "Assertion result for sending the configuration file" |
| 351 | testResult = main.FALSE |
| 352 | |
| 353 | testResult = main.netconfFunction.sendConfig( main ) |
| 354 | |
| 355 | utilities.assert_equals( expect=main.TRUE, |
| 356 | actual=testResult, |
| 357 | onpass=main.assertReturnString, |
| 358 | onfail=main.assertReturnString ) |
| 359 | |
| 360 | time.sleep( main.switchSleep ) |
| 361 | |
| 362 | main.step( "Confirming the device was configured" ) |
| 363 | main.assertReturnString = "Assertion result for confirming a configuration." |
| 364 | testResult = main.FALSE |
| 365 | |
| 366 | testResult = main.netconfFunction.devices( main ) |
| 367 | |
| 368 | utilities.assert_equals( expect=main.TRUE, |
| 369 | actual=testResult, |
| 370 | onpass=main.assertReturnString, |
| 371 | onfail=main.assertReturnString ) |
| 372 | |
| 373 | def CASE400( self, main ): |
| 374 | """ |
| 375 | Bring down a switch |
| 376 | This test case is not yet possible, but the functionality needed to |
| 377 | perform it is planned to be added |
| 378 | There is a message that is sent "Device () has closed session" |
| 379 | when the device disconnects from onos for some reason. |
| 380 | Because of the triggers for this message are not practical |
| 381 | to activate this will likely not be used to implement the test |
| 382 | case at this time |
| 383 | Possible ways to do this may include bringing down mininet then checking |
| 384 | ONOS to see if it was recongnized the device being disconnected |
| 385 | """ |