Jeremy | fc567ca | 2016-02-16 15:08:25 -0800 | [diff] [blame] | 1 | # Testing the NETCONF protocol within ONOS |
| 2 | |
| 3 | class FUNCnetconf: |
| 4 | |
| 5 | def __init__( self ): |
| 6 | self.default = '' |
| 7 | |
| 8 | def CASE1( self, main ): |
| 9 | import time |
| 10 | import imp |
| 11 | import re |
| 12 | |
| 13 | """ |
| 14 | - Construct tests variables |
| 15 | - GIT ( optional ) |
| 16 | - Checkout ONOS master branch |
| 17 | - Pull latest ONOS code |
| 18 | - Building ONOS ( optional ) |
| 19 | - Install ONOS package |
| 20 | - Build ONOS package |
| 21 | """ |
| 22 | |
| 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' ] |
Jeremy Songster | 17147f2 | 2016-05-31 18:30:52 -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' ] |
| 61 | main.cellData = {} # for creating cell file |
| 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 |
| 72 | for i in range( 1, main.maxNodes + 1 ): |
| 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, |
| 83 | main.dependencyPath + |
| 84 | wrapperFile2 + |
| 85 | ".py" ) |
| 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: |
| 105 | main.log.exception(e) |
| 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 | |
| 115 | if gitPull == 'True': |
| 116 | main.step( "Building ONOS in " + gitBranch + " branch" ) |
| 117 | onosBuildResult = main.startUp.onosBuild( main, gitBranch ) |
| 118 | stepResult = onosBuildResult |
| 119 | utilities.assert_equals( expect=main.TRUE, |
| 120 | actual=stepResult, |
| 121 | onpass="Successfully compiled " + |
| 122 | "latest ONOS", |
| 123 | onfail="Failed to compile " + |
| 124 | "latest ONOS" ) |
| 125 | else: |
| 126 | main.log.warn( "Did not pull new code so skipping mvn " + |
| 127 | "clean install" ) |
| 128 | main.ONOSbench.getVersion( report=True ) |
| 129 | |
| 130 | def CASE2( self, main ): |
| 131 | """ |
| 132 | - Set up cell |
| 133 | - Create cell file |
| 134 | - Set cell file |
| 135 | - Verify cell file |
| 136 | - Kill ONOS process |
| 137 | - Uninstall ONOS cluster |
| 138 | - Verify ONOS start up |
| 139 | - Install ONOS cluster |
| 140 | - Connect to cli |
| 141 | """ |
| 142 | |
Jeremy Songster | 17147f2 | 2016-05-31 18:30:52 -0700 | [diff] [blame] | 143 | main.cycle += 1 |
| 144 | |
Jeremy | fc567ca | 2016-02-16 15:08:25 -0800 | [diff] [blame] | 145 | # main.scale[ 0 ] determines the current number of ONOS controller |
| 146 | main.numCtrls = int( main.scale[ 0 ] ) |
| 147 | |
| 148 | main.case( "Starting up " + str( main.numCtrls ) + |
| 149 | " node(s) ONOS cluster" ) |
| 150 | main.caseExplanation = "Set up ONOS with " + str( main.numCtrls ) +\ |
| 151 | " node(s) ONOS cluster" |
| 152 | |
| 153 | |
| 154 | |
| 155 | #kill off all onos processes |
| 156 | main.log.info( "Safety check, killing all ONOS processes" + |
| 157 | " before initiating environment setup" ) |
| 158 | |
| 159 | |
| 160 | |
| 161 | time.sleep( main.startUpSleep ) |
| 162 | main.step( "Uninstalling ONOS package" ) |
| 163 | onosUninstallResult = main.TRUE |
| 164 | for ip in main.ONOSip: |
| 165 | onosUninstallResult = onosUninstallResult and \ |
| 166 | main.ONOSbench.onosUninstall( nodeIp=ip ) |
| 167 | stepResult = onosUninstallResult |
| 168 | utilities.assert_equals( expect=main.TRUE, |
| 169 | actual=stepResult, |
| 170 | onpass="Successfully uninstalled ONOS package", |
| 171 | onfail="Failed to uninstall ONOS package" ) |
| 172 | |
| 173 | for i in range( main.maxNodes ): |
| 174 | main.ONOSbench.onosDie( main.ONOSip[ i ] ) |
| 175 | |
| 176 | main.log.info( "NODE COUNT = " + str( main.numCtrls ) ) |
| 177 | |
| 178 | tempOnosIp = [] |
| 179 | for i in range( main.numCtrls ): |
| 180 | tempOnosIp.append( main.ONOSip[i] ) |
| 181 | |
| 182 | main.ONOSbench.createCellFile( main.ONOSbench.ip_address, |
| 183 | "temp", main.Mininet1.ip_address, |
| 184 | main.apps, tempOnosIp ) |
| 185 | |
| 186 | main.step( "Apply cell to environment" ) |
| 187 | cellResult = main.ONOSbench.setCell( "temp" ) |
| 188 | verifyResult = main.ONOSbench.verifyCell() |
| 189 | stepResult = cellResult and verifyResult |
| 190 | utilities.assert_equals( expect=main.TRUE, |
| 191 | actual=stepResult, |
| 192 | onpass="Successfully applied cell to " + \ |
| 193 | "environment", |
| 194 | onfail="Failed to apply cell to environment " ) |
| 195 | |
| 196 | main.step( "Creating ONOS package" ) |
| 197 | packageResult = main.ONOSbench.onosPackage() |
| 198 | stepResult = packageResult |
| 199 | utilities.assert_equals( expect=main.TRUE, |
| 200 | actual=stepResult, |
| 201 | onpass="Successfully created ONOS package", |
| 202 | onfail="Failed to create ONOS package" ) |
| 203 | |
| 204 | time.sleep( main.startUpSleep ) |
| 205 | main.step( "Installing ONOS package" ) |
| 206 | onosInstallResult = main.TRUE |
| 207 | for i in range( main.numCtrls ): |
| 208 | onosInstallResult = onosInstallResult and \ |
| 209 | main.ONOSbench.onosInstall( node=main.ONOSip[ i ], options="" ) |
| 210 | stepResult = onosInstallResult |
| 211 | |
| 212 | utilities.assert_equals( expect=main.TRUE, |
| 213 | actual=stepResult, |
| 214 | onpass="Successfully installed ONOS package", |
| 215 | onfail="Failed to install ONOS package" ) |
| 216 | |
| 217 | time.sleep( main.startUpSleep ) |
| 218 | main.step( "Starting ONOS service" ) |
| 219 | stopResult = main.TRUE |
| 220 | startResult = main.TRUE |
| 221 | onosIsUp = main.TRUE |
| 222 | |
| 223 | for i in range( main.numCtrls ): |
| 224 | onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] ) |
| 225 | if onosIsUp == main.TRUE: |
| 226 | main.log.report( "ONOS instance is up and ready" ) |
| 227 | else: |
| 228 | main.log.report( "ONOS instance may not be up, stop and " + |
| 229 | "start ONOS again " ) |
| 230 | for i in range( main.numCtrls ): |
| 231 | stopResult = stopResult and \ |
| 232 | main.ONOSbench.onosStop( main.ONOSip[ i ] ) |
| 233 | for i in range( main.numCtrls ): |
| 234 | startResult = startResult and \ |
| 235 | main.ONOSbench.onosStart( main.ONOSip[ i ] ) |
| 236 | stepResult = onosIsUp and stopResult and startResult |
| 237 | utilities.assert_equals( expect=main.TRUE, |
| 238 | actual=stepResult, |
| 239 | onpass="ONOS service is ready", |
| 240 | onfail="ONOS service did not start properly" ) |
| 241 | |
| 242 | # Start an ONOS cli to provide functionality that is not currently |
| 243 | # supported by the Rest API remove this when Leader Checking is supported |
| 244 | # by the REST API |
| 245 | |
| 246 | main.step( "Start ONOS cli" ) |
| 247 | cliResult = main.TRUE |
| 248 | for i in range( main.numCtrls ): |
| 249 | cliResult = cliResult and \ |
| 250 | main.CLIs2[ i ].startOnosCli( main.ONOSip[ i ] ) |
| 251 | stepResult = cliResult |
| 252 | utilities.assert_equals( expect=main.TRUE, |
| 253 | actual=stepResult, |
| 254 | onpass="Successfully start ONOS cli", |
| 255 | onfail="Failed to start ONOS cli" ) |
| 256 | |
| 257 | # Remove the first element in main.scale list |
| 258 | main.scale.remove( main.scale[ 0 ] ) |
| 259 | |
Jeremy Songster | 17147f2 | 2016-05-31 18:30:52 -0700 | [diff] [blame] | 260 | def CASE19( self, main ): |
| 261 | """ |
| 262 | Copy the karaf.log files after each testcase cycle |
| 263 | """ |
| 264 | main.log.report( "Copy karaf logs" ) |
| 265 | main.case( "Copy karaf logs" ) |
| 266 | main.caseExplanation = "Copying the karaf logs to preserve them through" +\ |
| 267 | "reinstalling ONOS" |
| 268 | main.step( "Copying karaf logs" ) |
Jeremy Songster | 31aad31 | 2016-06-13 16:32:11 -0700 | [diff] [blame] | 269 | stepResult = main.TRUE |
| 270 | scpResult = main.TRUE |
| 271 | copyResult = main.TRUE |
Jeremy Songster | 17147f2 | 2016-05-31 18:30:52 -0700 | [diff] [blame] | 272 | i = 0 |
Jeremy Songster | dd8999d | 2016-06-10 11:27:20 -0700 | [diff] [blame] | 273 | for cli in main.CLIs2: |
Jeremy Songster | 17147f2 | 2016-05-31 18:30:52 -0700 | [diff] [blame] | 274 | main.node = cli |
| 275 | ip = main.ONOSip[ i ] |
| 276 | main.node.ip_address = ip |
Jeremy Songster | 31aad31 | 2016-06-13 16:32:11 -0700 | [diff] [blame] | 277 | scpResult = scpResult and main.ONOSbench.scp( main.node , |
| 278 | "/opt/onos/log/karaf.log", |
| 279 | "/tmp/karaf.log", |
| 280 | direction="from" ) |
| 281 | copyResult = copyResult and main.ONOSbench.cpLogsToDir( "/tmp/karaf.log", main.logdir, |
| 282 | copyFileName=( "karaf.log.node{0}.cycle{1}".format( str( i + 1 ), str( main.cycle ) ) ) ) |
| 283 | if scpResult and copyResult: |
| 284 | stepResult = main.TRUE and stepResult |
| 285 | else: |
| 286 | stepResult = main.FALSE and stepResult |
Jeremy Songster | 17147f2 | 2016-05-31 18:30:52 -0700 | [diff] [blame] | 287 | i += 1 |
Jeremy Songster | 72a4703 | 2016-06-14 14:35:51 -0700 | [diff] [blame^] | 288 | if main.numCtrls == 1: |
| 289 | break |
Jeremy Songster | 31aad31 | 2016-06-13 16:32:11 -0700 | [diff] [blame] | 290 | utilities.assert_equals( expect=main.TRUE, |
| 291 | actual=stepResult, |
| 292 | onpass="Successfully copied remote ONOS logs", |
| 293 | onfail="Failed to copy remote ONOS logs" ) |
Jeremy Songster | 17147f2 | 2016-05-31 18:30:52 -0700 | [diff] [blame] | 294 | |
Jeremy | fc567ca | 2016-02-16 15:08:25 -0800 | [diff] [blame] | 295 | def CASE100( self, main ): |
| 296 | """ |
| 297 | Start NETCONF app and OFC-Server or make sure that they are already running |
| 298 | """ |
| 299 | assert main, "There is no main" |
| 300 | assert main.CLIs, "There is no main.CLIs" |
| 301 | assert main.numCtrls, "Placed the total number of switch topology in \ |
| 302 | main.numCtrls" |
| 303 | |
| 304 | testResult = main.FALSE |
| 305 | main.testName = "Start up NETCONF app in all nodes" |
| 306 | main.case( main.testName + " Test - " + str( main.numCtrls ) + |
| 307 | " NODE(S)" ) |
| 308 | main.step( "Starting NETCONF app" ) |
| 309 | main.assertReturnString = "Assertion result for starting NETCONF app" |
| 310 | testResult = main.netconfFunction.startApp( main ) |
| 311 | |
| 312 | utilities.assert_equals( expect=main.TRUE, |
| 313 | actual=testResult, |
| 314 | onpass=main.assertReturnString, |
| 315 | onfail=main.assertReturnString ) |
| 316 | |
| 317 | main.step( "Starting OFC-Server" ) |
| 318 | main.assertReturnString = "Assertion result for starting OFC-Server" |
| 319 | testResult = main.netconfFunction.startOFC( main ) |
| 320 | |
| 321 | utilities.assert_equals( expect=main.TRUE, |
| 322 | actual=testResult, |
| 323 | onpass=main.assertReturnString, |
| 324 | onfail=main.assertReturnString ) |
| 325 | time.sleep( main.startUpSleep ) |
| 326 | |
| 327 | def CASE200( self, main ): |
| 328 | """ |
| 329 | Create or modify a Configuration file |
| 330 | -The file is built from information loaded from the .params file |
| 331 | """ |
| 332 | assert main, "There is no main" |
| 333 | assert main.CLIs, "There is no main.CLIs" |
| 334 | assert main.numCtrls, "Placed the total number of switch topology in \ |
| 335 | main.numCtrls" |
| 336 | |
| 337 | main.testName = "Assemble the configuration" |
| 338 | main.case( main.testName + " Test - " + str( main.numCtrls ) + |
| 339 | " NODES(S)" ) |
| 340 | main.step( "Assembling configuration file" ) |
| 341 | main.assertReturnString = "Assertion result for assembling configuration file" |
| 342 | testResult = main.FALSE |
| 343 | testResult = main.netconfFunction.createConfig( main ) |
| 344 | |
| 345 | utilities.assert_equals( expect=main.TRUE, |
| 346 | actual=testResult, |
| 347 | onpass=main.assertReturnString, |
| 348 | onfail=main.assertReturnString ) |
| 349 | time.sleep( main.startUpSleep ) |
| 350 | |
| 351 | def CASE300( self, main ): |
| 352 | """ |
| 353 | Push a configuration and bring up a switch |
| 354 | """ |
| 355 | assert main, "There is no main" |
| 356 | assert main.CLIs, "There is no main.CLIs" |
| 357 | assert main.numCtrls, "Placed the total number of switch topology in \ |
| 358 | main.numCtrls" |
| 359 | |
| 360 | main.testName = "Uploading the configuration" |
| 361 | main.case( main.testName + " Test - " + str( main.numCtrls ) + |
| 362 | " NODES(S)" ) |
| 363 | main.step( "Sending the configuration file") |
| 364 | main.assertReturnString = "Assertion result for sending the configuration file" |
| 365 | testResult = main.FALSE |
| 366 | |
| 367 | testResult = main.netconfFunction.sendConfig( main ) |
| 368 | |
| 369 | utilities.assert_equals( expect=main.TRUE, |
| 370 | actual=testResult, |
| 371 | onpass=main.assertReturnString, |
| 372 | onfail=main.assertReturnString ) |
| 373 | |
| 374 | time.sleep( main.switchSleep ) |
| 375 | |
| 376 | main.step( "Confirming the device was configured" ) |
| 377 | main.assertReturnString = "Assertion result for confirming a configuration." |
| 378 | testResult = main.FALSE |
| 379 | |
| 380 | testResult = main.netconfFunction.devices( main ) |
| 381 | |
| 382 | utilities.assert_equals( expect=main.TRUE, |
| 383 | actual=testResult, |
| 384 | onpass=main.assertReturnString, |
| 385 | onfail=main.assertReturnString ) |
| 386 | |
| 387 | def CASE400( self, main ): |
| 388 | """ |
| 389 | Bring down a switch |
| 390 | This test case is not yet possible, but the functionality needed to |
| 391 | perform it is planned to be added |
| 392 | There is a message that is sent "Device () has closed session" |
| 393 | when the device disconnects from onos for some reason. |
| 394 | Because of the triggers for this message are not practical |
| 395 | to activate this will likely not be used to implement the test |
| 396 | case at this time |
| 397 | Possible ways to do this may include bringing down mininet then checking |
| 398 | ONOS to see if it was recongnized the device being disconnected |
| 399 | """ |