Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 1 | """ |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 2 | Copyright 2015 Open Networking Foundation ( ONF ) |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 3 | |
| 4 | Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 5 | the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 6 | or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg> |
| 7 | |
| 8 | TestON is free software: you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation, either version 2 of the License, or |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 11 | ( at your option ) any later version. |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 12 | |
| 13 | TestON is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with TestON. If not, see <http://www.gnu.org/licenses/>. |
| 20 | """ |
suibin zhang | c763570 | 2015-11-03 21:30:20 -0800 | [diff] [blame] | 21 | # This is a basic platform test suite. |
| 22 | # Additional platform test cases can be added on this test suite where appropriate. |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 23 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 24 | |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 25 | class PLATdockertest: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 26 | |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 27 | """ |
| 28 | This testsuite performs the following tests: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 29 | 1 ) checkout onos docker image; |
| 30 | 2 ) test image start up in single and clustered mode; |
| 31 | 3 ) test onos app activation and deactivation; |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 32 | |
| 33 | Prerequisites: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 34 | 1 ) docker-engine installed on test station ( localhost ); |
| 35 | 2 ) python docker client ( docker-py ) installed on test station |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 36 | """ |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 37 | def __init__( self ): |
| 38 | self.default = '' |
Devin Lim | cde503f | 2017-09-11 17:23:30 -0700 | [diff] [blame] | 39 | global DOCKERREPO, DOCKERTAG, INITDOCKERTAG |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 40 | global IPlist |
| 41 | global CTIDlist |
| 42 | global NODElist |
| 43 | |
| 44 | DOCKERREPO = "onosproject/onos" |
| 45 | DOCKERTAG = "latest" |
| 46 | |
Pratik Parab | cc40645 | 2017-02-28 15:15:25 -0800 | [diff] [blame] | 47 | def CASE0( self, main ): |
| 48 | """ |
| 49 | Pull all docker images and get a list of image tags |
| 50 | """ |
| 51 | main.case( "Pull all docker images and get a list of image tags" ) |
Pratik Parab | cc40645 | 2017-02-28 15:15:25 -0800 | [diff] [blame] | 52 | import os |
| 53 | DOCKERREPO = main.params[ 'DOCKER' ][ 'repo' ] |
| 54 | os.system( "docker pull -a " + DOCKERREPO ) |
| 55 | imageTagList = list() |
| 56 | imageTagCounter = 0 |
Pratik Parab | 50d53d4 | 2017-03-24 14:28:22 -0700 | [diff] [blame] | 57 | duplicateTagDetected = 0 |
| 58 | imageTagList, duplicateTagDetected = main.ONOSbenchDocker.getListOfImages( DOCKERREPO ) |
| 59 | stepResult = main.FALSE |
| 60 | main.step( "Check for duplicate Tags for a given image" ) |
| 61 | if not duplicateTagDetected: |
| 62 | stepResult = main.TRUE |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 63 | utilities.assert_equals( expect=main.TRUE, actual=stepResult, |
| 64 | onpass="no duplicate image tags", |
| 65 | onfail="duplicate image tags detected!!" ) |
Pratik Parab | cc40645 | 2017-02-28 15:15:25 -0800 | [diff] [blame] | 66 | main.step( "Get a list of image tags" ) |
| 67 | stepResult = main.FALSE |
Pratik Parab | cc40645 | 2017-02-28 15:15:25 -0800 | [diff] [blame] | 68 | if imageTagList is not []: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 69 | main.log.info( "The Image tag list is: " + str( imageTagList ) ) |
Pratik Parab | cc40645 | 2017-02-28 15:15:25 -0800 | [diff] [blame] | 70 | stepResult = main.TRUE |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 71 | utilities.assert_equals( expect=main.TRUE, actual=stepResult, |
| 72 | onpass="image tag list pulled successfully", |
| 73 | onfail="image tag list not pulled" ) |
Pratik Parab | cc40645 | 2017-02-28 15:15:25 -0800 | [diff] [blame] | 74 | |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 75 | def CASE1( self, main ): |
| 76 | """ |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 77 | 1 ) set up test params; |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 78 | """ |
| 79 | import re |
suibin zhang | 3b067ea | 2015-11-05 13:55:21 -0800 | [diff] [blame] | 80 | import time |
| 81 | import subprocess |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 82 | |
Pratik Parab | cc40645 | 2017-02-28 15:15:25 -0800 | [diff] [blame] | 83 | if imageTagCounter < len( imageTagList ): |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 84 | DOCKERTAG = imageTagList[ imageTagCounter ] |
Devin Lim | cde503f | 2017-09-11 17:23:30 -0700 | [diff] [blame] | 85 | if not imageTagCounter: |
| 86 | INITDOCKERTAG = DOCKERTAG |
Pratik Parab | cc40645 | 2017-02-28 15:15:25 -0800 | [diff] [blame] | 87 | imageTagCounter += 1 |
| 88 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 89 | main.case( "Set case test params for onos image {}".format( DOCKERTAG ) ) |
| 90 | main.step( "Initialize test params" ) |
| 91 | NODElist = main.params[ "SCALE" ][ "nodelist" ].split( ',' ) |
| 92 | main.log.info( "onos container names are: " + ",".join( NODElist ) ) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 93 | IPlist = list() |
| 94 | main.testOnDirectory = re.sub( "(/tests)$", "", main.testDir ) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 95 | CTIDlist = list() |
suibin zhang | 3b067ea | 2015-11-05 13:55:21 -0800 | [diff] [blame] | 96 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 97 | main.log.info( "Check docker status, it not running, try restart it" ) |
suibin zhang | 3b067ea | 2015-11-05 13:55:21 -0800 | [diff] [blame] | 98 | iter = 0 |
| 99 | stepResult = main.TRUE |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 100 | while subprocess.call( "sudo service docker status", shell=True ) and iter <= 3: |
| 101 | subprocess.call( "sudo service docker restart", shell=True ) |
| 102 | time.sleep( 5 ) |
suibin zhang | 3b067ea | 2015-11-05 13:55:21 -0800 | [diff] [blame] | 103 | iter += 1 |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 104 | if iter == 3: |
| 105 | stepResult = main.FALSE |
suibin zhang | 3b067ea | 2015-11-05 13:55:21 -0800 | [diff] [blame] | 106 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 107 | utilities.assert_equals( expect=main.TRUE, actual=stepResult, |
| 108 | onpass="docker is running", |
| 109 | onfail="docker is not running" ) |
suibin zhang | 3b067ea | 2015-11-05 13:55:21 -0800 | [diff] [blame] | 110 | if stepResult == main.FALSE: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 111 | main.log.warn( "docker is not running - exiting test" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 112 | main.cleanAndExit() |
Pratik Parab | cc40645 | 2017-02-28 15:15:25 -0800 | [diff] [blame] | 113 | if imageTagCounter > len( imageTagList ): |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 114 | main.log.info( "All images have been tested" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 115 | main.cleanAndExit() |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 116 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 117 | def CASE5( self, main ): |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 118 | """ |
Pratik Parab | cc40645 | 2017-02-28 15:15:25 -0800 | [diff] [blame] | 119 | Pull the specified image |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 120 | """ |
Pratik Parab | cc40645 | 2017-02-28 15:15:25 -0800 | [diff] [blame] | 121 | main.case( "Pull onos docker image {} from {} - \ |
| 122 | it may take sometime if this is a first time pulling.".format( DOCKERTAG, DOCKERREPO ) ) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 123 | stepResult = main.FALSE |
Pratik Parab | cc40645 | 2017-02-28 15:15:25 -0800 | [diff] [blame] | 124 | main.step( "pull image {} from {}".format( DOCKERTAG, DOCKERREPO ) ) |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 125 | stepResult = main.ONOSbenchDocker.dockerPull( onosRepo=DOCKERREPO, onosTag=DOCKERTAG ) |
| 126 | utilities.assert_equals( expect=main.TRUE, actual=stepResult, |
| 127 | onpass="Succeeded in pulling " + DOCKERREPO + ":" + DOCKERTAG, |
| 128 | onfail="Failed to pull " + DOCKERREPO + ":" + DOCKERTAG ) |
| 129 | if stepResult == main.FALSE: |
| 130 | main.skipCase() |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 131 | |
| 132 | def CASE10( self, main ): |
| 133 | """ |
| 134 | Start docker containers for list of onos nodes, only if not already existed |
| 135 | """ |
| 136 | import re |
suibin zhang | 3b067ea | 2015-11-05 13:55:21 -0800 | [diff] [blame] | 137 | createResult = main.TRUE |
| 138 | startResult = main.TRUE |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 139 | main.case( "Start onos container(s) for onos image {}".format( DOCKERTAG ) ) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 140 | image = DOCKERREPO + ":" + DOCKERTAG |
| 141 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 142 | main.step( "Create and (re)start docker container(s) for onos image {} if not already exist".format( DOCKERTAG ) ) |
| 143 | # stepResult = main.FALSE |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 144 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 145 | for ct in xrange( 0, len( NODElist ) ): |
| 146 | if not main.ONOSbenchDocker.dockerCheckCTName( ctName=NODElist[ ct ] ): |
| 147 | main.log.info( "Create new container for onos" + str( ct + 1 ) ) |
| 148 | createResult, ctid = main.ONOSbenchDocker.dockerCreateCT( onosImage=image, onosNode=NODElist[ ct ] ) |
| 149 | CTIDlist.append( ctid ) |
| 150 | startResult = main.ONOSbenchDocker.dockerStartCT( ctID=ctid ) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 151 | else: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 152 | main.log.info( "Container exists for node onos" + str( ct + 1 ) + "; restart container with {} image".format( DOCKERTAG ) ) |
| 153 | startResult = main.ONOSbenchDocker.dockerRestartCT( ctName=NODElist[ ct ] ) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 154 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 155 | utilities.assert_equals( expect=main.TRUE, actual=createResult and startResult, |
| 156 | onpass="Container successfully created", |
| 157 | onfail="Failed to create the container" ) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 158 | |
| 159 | main.step( "Get IP address on onos containers" ) |
| 160 | stepResult = main.FALSE |
| 161 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 162 | for ct in xrange( 0, len( NODElist ) ): |
| 163 | IPlist.append( main.ONOSbenchDocker.dockerIP( ctName=NODElist[ ct ] ) ) |
| 164 | main.log.info( "Container IPs are: " + ', '.join( IPlist ) ) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 165 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 166 | if IPlist is not []: |
| 167 | stepResult = main.TRUE |
| 168 | utilities.assert_equals( expect=main.TRUE, actual=stepResult, |
| 169 | onpass="Container successfully started", |
| 170 | onfail="Failed to start the container" ) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 171 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 172 | def CASE110( self, main ): |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 173 | """ |
| 174 | Steps: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 175 | 1 ) check default startup standalone onos applications status; |
| 176 | 2 ) form onos cluster with all nodes; |
| 177 | 3 ) check onos applications status; |
| 178 | 4 ) activate apps per params and check app status; |
| 179 | 5 ) deactivate apps and check app status |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 180 | |
| 181 | """ |
| 182 | import time |
| 183 | import json |
| 184 | |
Pratik Parab | cc40645 | 2017-02-28 15:15:25 -0800 | [diff] [blame] | 185 | main.case( "Form onos cluster and check status of onos apps for onos image {}".format( DOCKERTAG ) ) |
| 186 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 187 | startupSleep = int( main.params[ "SLEEP" ][ "startup" ] ) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 188 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 189 | appToAct = main.params[ "CASE110" ][ "apps" ] |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 190 | stepResult = main.FALSE |
| 191 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 192 | main.log.info( "Wait for startup, sleep (sec): " + str( startupSleep ) ) |
| 193 | time.sleep( startupSleep ) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 194 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 195 | main.step( "Check initial app states from onos1 for onos image {}".format( DOCKERTAG ) ) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 196 | stepResult = main.TRUE |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 197 | response = main.ONOSbenchRest.apps( ip=IPlist[ 0 ], port=8181 ) |
| 198 | main.log.debug( "Rest call response is: " + response ) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 199 | if response is not main.FALSE: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 200 | for item in json.loads( response ): |
| 201 | if item[ "state" ] not in [ "ACTIVE", "INSTALLED" ]: |
| 202 | main.log.info( "Some bundles are not in correct state. " ) |
| 203 | main.log.info( "App states are: " + response ) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 204 | stepResult = main.FALSE |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 205 | break |
| 206 | if ( item[ "description" ] == "Builtin device drivers" ) and ( item[ "state" ] != "ACTIVE" ): |
| 207 | main.log.info( "Driver app is not in 'ACTIVE' state, but in: " + item[ "state" ] ) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 208 | stepResult = main.FALSE |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 209 | break |
| 210 | utilities.assert_equals( expect=main.TRUE, actual=stepResult, |
| 211 | onpass="ONOS successfully started", |
| 212 | onfail="Failed to start ONOS correctly" ) |
| 213 | if stepResult is main.FALSE: |
| 214 | main.skipCase() |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 215 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 216 | main.step( "Form onos cluster using 'dependencies/onos-form-cluster' util" ) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 217 | stepResult = main.FALSE |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 218 | clcmdpath = main.params[ "CASE110" ][ "clustercmdpath" ] |
| 219 | main.log.info( "onos-form-cluster cmd path is: " + clcmdpath ) |
| 220 | dkruser = main.params[ "DOCKER" ][ "user" ] |
| 221 | dkrpasswd = main.params[ "DOCKER" ][ "password" ] |
| 222 | main.ONOSbenchDocker.onosFormCluster( cmdPath=clcmdpath, onosIPs=IPlist, user=dkruser, passwd=dkrpasswd ) |
| 223 | main.log.info( "Wait for cluster to form with sleep time of " + str( startupSleep ) ) |
| 224 | time.sleep( startupSleep ) |
| 225 | status, response = main.ONOSbenchRest.send( ip=IPlist[ 0 ], port=8181, url="/cluster" ) |
| 226 | main.log.debug( "Rest call response: " + str( status ) + " - " + response ) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 227 | if status == 200: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 228 | jrsp = json.loads( response ) |
Pratik Parab | cc40645 | 2017-02-28 15:15:25 -0800 | [diff] [blame] | 229 | if DOCKERTAG == "1.2" or DOCKERTAG == "1.3" or DOCKERTAG == "1.4" or DOCKERTAG == "1.5": |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 230 | clusterIP = [ item[ "ip" ]for item in jrsp[ "nodes" ] if item[ "status" ] == "ACTIVE" ] |
Pratik Parab | cc40645 | 2017-02-28 15:15:25 -0800 | [diff] [blame] | 231 | else: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 232 | clusterIP = [ item[ "ip" ]for item in jrsp[ "nodes" ] if item[ "status" ] == "READY" ] |
| 233 | main.log.debug( " IPlist is:" + ",".join( IPlist ) ) |
| 234 | main.log.debug( " cluster IP is" + ",".join( clusterIP ) ) |
| 235 | if set( IPlist ) == set( clusterIP ): |
| 236 | stepResult = main.TRUE |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 237 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 238 | utilities.assert_equals( expect=main.TRUE, actual=stepResult, |
| 239 | onpass="ONOS successfully started", |
| 240 | onfail="Failed to start ONOS correctly" ) |
| 241 | if stepResult is main.FALSE: |
| 242 | main.skipCase() |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 243 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 244 | main.step( "Check cluster app status" ) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 245 | stepResult = main.TRUE |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 246 | response = main.ONOSbenchRest.apps( ip=IPlist[ 0 ], port=8181 ) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 247 | if response is not main.FALSE: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 248 | for item in json.loads( response ): |
| 249 | if item[ "state" ] not in [ "ACTIVE", "INSTALLED" ]: |
| 250 | main.log.info( "Some bundles are not in correct state. " ) |
| 251 | main.log.info( "App states are: " + response ) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 252 | stepResult = main.FALSE |
suibin zhang | 3b067ea | 2015-11-05 13:55:21 -0800 | [diff] [blame] | 253 | break |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 254 | if ( item[ "description" ] == "Builtin device drivers" ) and ( item[ "state" ] != "ACTIVE" ): |
| 255 | main.log.info( "Driver app is not in 'ACTIVE' state, but in: " + item[ "state" ] ) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 256 | stepResult = main.FALSE |
suibin zhang | 3b067ea | 2015-11-05 13:55:21 -0800 | [diff] [blame] | 257 | break |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 258 | utilities.assert_equals( expect=main.TRUE, actual=stepResult, |
| 259 | onpass="ONOS successfully started", |
| 260 | onfail="Failed to start ONOS correctly" ) |
| 261 | if stepResult is main.FALSE: |
| 262 | main.skipCase() |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 263 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 264 | main.step( " Activate an APP from REST and check APP status" ) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 265 | appResults = list() |
| 266 | stepResult = main.TRUE |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 267 | applist = main.params[ "CASE110" ][ "apps" ].split( "," ) |
| 268 | main.log.info( "List of apps to activate: " + str( applist ) ) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 269 | for app in applist: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 270 | appRslt = main.ONOSbenchRest.activateApp( appName=app, ip=IPlist[ 0 ], port=8181, check=True ) |
| 271 | time.sleep( 5 ) |
| 272 | appResults.append( appRslt ) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 273 | stepResult = stepResult and appRslt |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 274 | main.log.debug( "Apps activation result for " + ",".join( applist ) + ": " + str( appResults ) ) |
| 275 | utilities.assert_equals( expect=main.TRUE, actual=stepResult, |
| 276 | onpass="Successfully activated apps", |
| 277 | onfail="Failed to activated apps correctly" ) |
| 278 | if stepResult is main.FALSE: |
| 279 | main.skipCase() |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 280 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 281 | main.step( " Deactivate an APP from REST and check APP status" ) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 282 | appResults = list() |
| 283 | stepResult = main.TRUE |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 284 | applist = main.params[ "CASE110" ][ "apps" ].split( "," ) |
| 285 | main.log.info( "Apps to deactivate: " + str( applist ) ) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 286 | for app in applist: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 287 | time.sleep( 5 ) |
| 288 | appRslt = main.ONOSbenchRest.deactivateApp( appName=app, ip=IPlist[ 0 ], port=8181, check=True ) |
| 289 | appResults.append( appRslt ) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 290 | stepResult = stepResult and appRslt |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 291 | main.log.debug( "Apps deactivation result for " + ",".join( applist ) + ": " + str( appResults ) ) |
| 292 | utilities.assert_equals( expect=main.TRUE, actual=stepResult, |
| 293 | onpass="Successfully deactivated apps", |
| 294 | onfail="Failed to deactivated apps correctly" ) |
| 295 | if stepResult is main.FALSE: |
| 296 | main.skipCase() |
suibin zhang | 3b067ea | 2015-11-05 13:55:21 -0800 | [diff] [blame] | 297 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 298 | def CASE900( self, main ): |
suibin zhang | 3b067ea | 2015-11-05 13:55:21 -0800 | [diff] [blame] | 299 | """ |
| 300 | Check onos logs for exceptions after tests |
| 301 | """ |
| 302 | import pexpect |
| 303 | import time |
| 304 | import re |
| 305 | |
| 306 | logResult = main.TRUE |
| 307 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 308 | user = main.params[ "DOCKER" ][ "user" ] |
| 309 | pwd = main.params[ "DOCKER" ][ "password" ] |
suibin zhang | 3b067ea | 2015-11-05 13:55:21 -0800 | [diff] [blame] | 310 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 311 | main.case( "onos Exceptions check with onos image {}".format( DOCKERTAG ) ) |
| 312 | main.step( "check onos for any exceptions" ) |
suibin zhang | 3b067ea | 2015-11-05 13:55:21 -0800 | [diff] [blame] | 313 | |
| 314 | for ip in IPlist: |
suibin zhang | 559218e | 2015-12-08 14:57:12 -0800 | [diff] [blame] | 315 | spawncmd = "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p 8101 " + user + "@" + ip |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 316 | main.log.info( "log on node using cmd: " + spawncmd ) |
suibin zhang | 3b067ea | 2015-11-05 13:55:21 -0800 | [diff] [blame] | 317 | try: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 318 | handle = pexpect.spawn( spawncmd ) |
| 319 | # handle.expect( "yes/no" ) |
| 320 | # handle.sendline( "yes" ) |
| 321 | # print( "yes is sent" ) |
| 322 | # this extra statement is sent to get around some |
| 323 | # pexpect issue of not seeing the next expected string |
| 324 | handle.expect( "Password:" ) |
| 325 | handle.sendline( pwd ) |
| 326 | time.sleep( 5 ) |
| 327 | handle.expect( "onos>" ) |
| 328 | handle.sendline( "log:exception-display" ) |
| 329 | handle.expect( "onos>" ) |
suibin zhang | 3b067ea | 2015-11-05 13:55:21 -0800 | [diff] [blame] | 330 | result = handle.before |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 331 | if re.search( "Exception", result ): |
| 332 | main.log.info( "onos: " + ip + " Exceptions:" + result ) |
suibin zhang | 3b067ea | 2015-11-05 13:55:21 -0800 | [diff] [blame] | 333 | logResult = logResult and main.FALSE |
| 334 | else: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 335 | main.log.info( "onos: " + ip + " Exceptions: None" ) |
suibin zhang | 3b067ea | 2015-11-05 13:55:21 -0800 | [diff] [blame] | 336 | logResult = logResult and main.TRUE |
| 337 | except Exception: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 338 | main.log.exception( "Uncaught exception when getting log from onos:" + ip ) |
suibin zhang | 3b067ea | 2015-11-05 13:55:21 -0800 | [diff] [blame] | 339 | logResult = logResult and main.FALSE |
| 340 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 341 | utilities.assert_equals( expect=main.TRUE, actual=logResult, |
| 342 | onpass="onos exception check passed", |
| 343 | onfail="onos exeption check failed" ) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 344 | |
| 345 | def CASE1000( self, main ): |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 346 | """ |
Pratik Parab | cc40645 | 2017-02-28 15:15:25 -0800 | [diff] [blame] | 347 | Cleanup after tests - stop and delete the containers created; delete the image |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 348 | """ |
| 349 | import time |
| 350 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 351 | main.case( "Clean up images (ex. none:none tagged) and containers" ) |
| 352 | main.step( "Stop onos containers" ) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 353 | stepResult = main.TRUE |
| 354 | for ctname in NODElist: |
Pratik Parab | cc40645 | 2017-02-28 15:15:25 -0800 | [diff] [blame] | 355 | if main.ONOSbenchDocker.dockerCheckCTName( ctName="/" + ctname ): |
| 356 | main.log.info( "stopping docker container: /" + ctname ) |
| 357 | stopResult = main.ONOSbenchDocker.dockerStopCT( ctName="/" + ctname ) |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 358 | time.sleep( 10 ) |
Pratik Parab | cc40645 | 2017-02-28 15:15:25 -0800 | [diff] [blame] | 359 | rmResult = main.ONOSbenchDocker.dockerRemoveCT( ctName="/" + ctname ) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 360 | stepResult = stepResult and stopResult and rmResult |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 361 | utilities.assert_equals( expect=main.TRUE, actual=stepResult, |
| 362 | onpass="Container successfully stopped", |
| 363 | onfail="Failed to stopped the container" ) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 364 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 365 | # main.step( "remove exiting onosproject/onos images" ) |
| 366 | # stepResult = main.ONOSbenchDocker.dockerRemoveImage( image=DOCKERREPO + ":" + DOCKERTAG ) |
| 367 | main.step( "remove dangling 'none:none' images" ) |
Pratik Parab | cc40645 | 2017-02-28 15:15:25 -0800 | [diff] [blame] | 368 | stepResult = main.ONOSbenchDocker.dockerRemoveImage() |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 369 | utilities.assert_equals( expect=main.TRUE, actual=stepResult, |
| 370 | onpass="Succeeded in cleaning up images", |
| 371 | onfail="Failed in cleaning up images" ) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 372 | |
Pratik Parab | 8d884d1 | 2017-03-16 12:14:32 -0700 | [diff] [blame] | 373 | def CASE1001( self, main ): |
Pratik Parab | 8d884d1 | 2017-03-16 12:14:32 -0700 | [diff] [blame] | 374 | """ |
| 375 | Create a file for publishing results on wiki in tabular form |
| 376 | """ |
Pratik Parab | 8d884d1 | 2017-03-16 12:14:32 -0700 | [diff] [blame] | 377 | main.case( "Create a file for publishing on wiki in tabular form" ) |
| 378 | import re |
| 379 | imageTagCounter = 0 |
| 380 | testCaseCounter = 0 |
| 381 | resultCounter = 0 |
| 382 | resultDictionary = {} |
| 383 | testCaseList = [] |
| 384 | totalNumOfTestCases = 6 |
| 385 | try: |
| 386 | main.tableFileName = main.logdir + "/" + main.TEST + "TableWiki.txt" |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 387 | main.wikiTableFile = open( main.tableFileName, "a+" ) |
| 388 | main.wikiFileHandle = open( main.WikiFileName, "r" ) |
Pratik Parab | 8d884d1 | 2017-03-16 12:14:32 -0700 | [diff] [blame] | 389 | for imageTag in imageTagList: |
| 390 | resultDictionary[ imageTag ] = [] |
| 391 | for line in main.wikiFileHandle: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 392 | matchObj = re.search( "(?!.*Case 0).*<h3>(.+?)<\/h3>", line ) |
Pratik Parab | 8d884d1 | 2017-03-16 12:14:32 -0700 | [diff] [blame] | 393 | if testCaseCounter < totalNumOfTestCases: |
| 394 | if matchObj: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 395 | wordsToRemove = re.compile( "latest|- PASS|- FAIL|- No Result" ) |
| 396 | testCaseName = wordsToRemove.sub( "", matchObj.group( 1 ) ) |
| 397 | testCaseName = testCaseName.replace( INITDOCKERTAG, '' ) |
| 398 | testCaseList.append( testCaseName ) |
Pratik Parab | 8d884d1 | 2017-03-16 12:14:32 -0700 | [diff] [blame] | 399 | testCaseCounter += 1 |
| 400 | if matchObj: |
| 401 | if "- PASS" in line: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 402 | resultDictionary[ imageTagList[ imageTagCounter ] ].append( "PASS" ) |
Pratik Parab | 8d884d1 | 2017-03-16 12:14:32 -0700 | [diff] [blame] | 403 | if "- FAIL" in line: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 404 | resultDictionary[ imageTagList[ imageTagCounter ] ].append( "FAIL" ) |
Pratik Parab | 8d884d1 | 2017-03-16 12:14:32 -0700 | [diff] [blame] | 405 | if "- No Result" in line: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 406 | resultDictionary[ imageTagList[ imageTagCounter ] ].append( "No Result" ) |
Pratik Parab | 8d884d1 | 2017-03-16 12:14:32 -0700 | [diff] [blame] | 407 | resultCounter += 1 |
| 408 | if resultCounter == totalNumOfTestCases: |
| 409 | imageTagCounter += 1 |
| 410 | resultCounter = 0 |
| 411 | main.wikiTableFile.write( "<table style=\"width:100%\">\n" ) |
| 412 | main.wikiTableFile.write( "<tr>\n" ) |
| 413 | main.wikiTableFile.write( "<th>ONOS Version</th>\n" ) |
| 414 | for testCaseName in testCaseList: |
| 415 | main.wikiTableFile.write( "<th>" + testCaseName + "</th>\n" ) |
| 416 | main.wikiTableFile.write( "</tr>\n" ) |
| 417 | for imageTag in imageTagList: |
| 418 | main.wikiTableFile.write( "<tr>\n" ) |
| 419 | main.wikiTableFile.write( "<td>" + imageTag + "</td>\n" ) |
| 420 | for resultValue in resultDictionary[ imageTag ]: |
| 421 | if resultValue == "PASS": |
| 422 | emoticonValue = "\"tick\"" |
| 423 | if resultValue == "FAIL": |
| 424 | emoticonValue = "\"cross\"" |
| 425 | if resultValue == "No Result": |
| 426 | emoticonValue = "\"warning\"" |
| 427 | main.wikiTableFile.write( "<td>" + resultValue + " <ac:emoticon ac:name=" + emoticonValue + " /></td>\n" ) |
| 428 | main.wikiTableFile.write( "</tr>\n" ) |
| 429 | main.wikiTableFile.write( "</table>\n" ) |
| 430 | main.wikiTableFile.close() |
| 431 | main.wikiFileHandle.close() |
| 432 | logResult = main.TRUE |
| 433 | except Exception: |
| 434 | main.log.exception( "Exception while writing to the table file" ) |
| 435 | logResult = main.FALSE |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 436 | utilities.assert_equals( expect=main.TRUE, actual=logResult, |
| 437 | onpass="onos exception check passed", |
| 438 | onfail="onos exception check failed" ) |