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() |
Jon Hall | d74d295 | 2018-03-01 13:26:39 -0800 | [diff] [blame] | 94 | main.testOnDirectory = re.sub( "(/tests)$", "", main.testsRoot ) |
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" ) |
You Wang | 7880b37 | 2019-02-27 16:50:47 -0800 | [diff] [blame] | 115 | main.cleanAndExit( alarm=False ) |
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 | """ |
Jeremy Ronquillo | 29260cd | 2017-10-13 13:30:54 -0700 | [diff] [blame] | 174 | Docker init testing |
| 175 | |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 176 | Steps: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 177 | 1 ) check default startup standalone onos applications status; |
| 178 | 2 ) form onos cluster with all nodes; |
| 179 | 3 ) check onos applications status; |
| 180 | 4 ) activate apps per params and check app status; |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 181 | |
| 182 | """ |
| 183 | import time |
| 184 | import json |
| 185 | |
Pratik Parab | cc40645 | 2017-02-28 15:15:25 -0800 | [diff] [blame] | 186 | main.case( "Form onos cluster and check status of onos apps for onos image {}".format( DOCKERTAG ) ) |
| 187 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 188 | startupSleep = int( main.params[ "SLEEP" ][ "startup" ] ) |
Jeremy Ronquillo | 29260cd | 2017-10-13 13:30:54 -0700 | [diff] [blame] | 189 | main.swDPID = main.params[ "CASE110" ][ "swDPID" ] |
| 190 | main.debug = main.params[ "CASE110" ][ "debug" ] |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 191 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 192 | appToAct = main.params[ "CASE110" ][ "apps" ] |
Jeremy Ronquillo | 29260cd | 2017-10-13 13:30:54 -0700 | [diff] [blame] | 193 | main.initResult = main.FALSE |
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.log.info( "Wait for startup, sleep (sec): " + str( startupSleep ) ) |
| 196 | time.sleep( startupSleep ) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 197 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 198 | main.step( "Check initial app states from onos1 for onos image {}".format( DOCKERTAG ) ) |
Jeremy Ronquillo | 29260cd | 2017-10-13 13:30:54 -0700 | [diff] [blame] | 199 | main.initResult = main.TRUE |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 200 | response = main.ONOSbenchRest.apps( ip=IPlist[ 0 ], port=8181 ) |
| 201 | main.log.debug( "Rest call response is: " + response ) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 202 | if response is not main.FALSE: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 203 | for item in json.loads( response ): |
| 204 | if item[ "state" ] not in [ "ACTIVE", "INSTALLED" ]: |
| 205 | main.log.info( "Some bundles are not in correct state. " ) |
| 206 | main.log.info( "App states are: " + response ) |
Jeremy Ronquillo | 29260cd | 2017-10-13 13:30:54 -0700 | [diff] [blame] | 207 | main.initResult = main.FALSE |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 208 | break |
| 209 | if ( item[ "description" ] == "Builtin device drivers" ) and ( item[ "state" ] != "ACTIVE" ): |
| 210 | main.log.info( "Driver app is not in 'ACTIVE' state, but in: " + item[ "state" ] ) |
Jeremy Ronquillo | 29260cd | 2017-10-13 13:30:54 -0700 | [diff] [blame] | 211 | main.initResult = main.FALSE |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 212 | break |
Jeremy Ronquillo | 29260cd | 2017-10-13 13:30:54 -0700 | [diff] [blame] | 213 | utilities.assert_equals( expect=main.TRUE, actual=main.initResult, |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 214 | onpass="ONOS successfully started", |
| 215 | onfail="Failed to start ONOS correctly" ) |
Jeremy Ronquillo | 29260cd | 2017-10-13 13:30:54 -0700 | [diff] [blame] | 216 | if main.initResult is main.FALSE: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 217 | main.skipCase() |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 218 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 219 | main.step( "Form onos cluster using 'dependencies/onos-form-cluster' util" ) |
Jeremy Ronquillo | 29260cd | 2017-10-13 13:30:54 -0700 | [diff] [blame] | 220 | main.initResult = main.FALSE |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 221 | clcmdpath = main.params[ "CASE110" ][ "clustercmdpath" ] |
| 222 | main.log.info( "onos-form-cluster cmd path is: " + clcmdpath ) |
| 223 | dkruser = main.params[ "DOCKER" ][ "user" ] |
| 224 | dkrpasswd = main.params[ "DOCKER" ][ "password" ] |
| 225 | main.ONOSbenchDocker.onosFormCluster( cmdPath=clcmdpath, onosIPs=IPlist, user=dkruser, passwd=dkrpasswd ) |
| 226 | main.log.info( "Wait for cluster to form with sleep time of " + str( startupSleep ) ) |
| 227 | time.sleep( startupSleep ) |
| 228 | status, response = main.ONOSbenchRest.send( ip=IPlist[ 0 ], port=8181, url="/cluster" ) |
| 229 | main.log.debug( "Rest call response: " + str( status ) + " - " + response ) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 230 | if status == 200: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 231 | jrsp = json.loads( response ) |
Pratik Parab | cc40645 | 2017-02-28 15:15:25 -0800 | [diff] [blame] | 232 | 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] | 233 | clusterIP = [ item[ "ip" ]for item in jrsp[ "nodes" ] if item[ "status" ] == "ACTIVE" ] |
Pratik Parab | cc40645 | 2017-02-28 15:15:25 -0800 | [diff] [blame] | 234 | else: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 235 | clusterIP = [ item[ "ip" ]for item in jrsp[ "nodes" ] if item[ "status" ] == "READY" ] |
| 236 | main.log.debug( " IPlist is:" + ",".join( IPlist ) ) |
| 237 | main.log.debug( " cluster IP is" + ",".join( clusterIP ) ) |
| 238 | if set( IPlist ) == set( clusterIP ): |
Jeremy Ronquillo | 29260cd | 2017-10-13 13:30:54 -0700 | [diff] [blame] | 239 | main.initResult = main.TRUE |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 240 | |
Jeremy Ronquillo | 29260cd | 2017-10-13 13:30:54 -0700 | [diff] [blame] | 241 | utilities.assert_equals( expect=main.TRUE, actual=main.initResult, |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 242 | onpass="ONOS successfully started", |
| 243 | onfail="Failed to start ONOS correctly" ) |
Jeremy Ronquillo | 29260cd | 2017-10-13 13:30:54 -0700 | [diff] [blame] | 244 | if main.initResult is main.FALSE: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 245 | main.skipCase() |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 246 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 247 | main.step( "Check cluster app status" ) |
Jeremy Ronquillo | 29260cd | 2017-10-13 13:30:54 -0700 | [diff] [blame] | 248 | main.initResult = main.TRUE |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 249 | response = main.ONOSbenchRest.apps( ip=IPlist[ 0 ], port=8181 ) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 250 | if response is not main.FALSE: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 251 | for item in json.loads( response ): |
| 252 | if item[ "state" ] not in [ "ACTIVE", "INSTALLED" ]: |
| 253 | main.log.info( "Some bundles are not in correct state. " ) |
| 254 | main.log.info( "App states are: " + response ) |
Jeremy Ronquillo | 29260cd | 2017-10-13 13:30:54 -0700 | [diff] [blame] | 255 | main.initResult = main.FALSE |
suibin zhang | 3b067ea | 2015-11-05 13:55:21 -0800 | [diff] [blame] | 256 | break |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 257 | if ( item[ "description" ] == "Builtin device drivers" ) and ( item[ "state" ] != "ACTIVE" ): |
| 258 | main.log.info( "Driver app is not in 'ACTIVE' state, but in: " + item[ "state" ] ) |
Jeremy Ronquillo | 29260cd | 2017-10-13 13:30:54 -0700 | [diff] [blame] | 259 | main.initResult = main.FALSE |
suibin zhang | 3b067ea | 2015-11-05 13:55:21 -0800 | [diff] [blame] | 260 | break |
Jeremy Ronquillo | 29260cd | 2017-10-13 13:30:54 -0700 | [diff] [blame] | 261 | utilities.assert_equals( expect=main.TRUE, actual=main.initResult, |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 262 | onpass="ONOS successfully started", |
| 263 | onfail="Failed to start ONOS correctly" ) |
Jeremy Ronquillo | 29260cd | 2017-10-13 13:30:54 -0700 | [diff] [blame] | 264 | if main.initResult is main.FALSE: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 265 | main.skipCase() |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 266 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 267 | main.step( " Activate an APP from REST and check APP status" ) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 268 | appResults = list() |
Jeremy Ronquillo | 29260cd | 2017-10-13 13:30:54 -0700 | [diff] [blame] | 269 | main.initResult = main.TRUE |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 270 | applist = main.params[ "CASE110" ][ "apps" ].split( "," ) |
| 271 | main.log.info( "List of apps to activate: " + str( applist ) ) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 272 | for app in applist: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 273 | appRslt = main.ONOSbenchRest.activateApp( appName=app, ip=IPlist[ 0 ], port=8181, check=True ) |
| 274 | time.sleep( 5 ) |
| 275 | appResults.append( appRslt ) |
Jeremy Ronquillo | 29260cd | 2017-10-13 13:30:54 -0700 | [diff] [blame] | 276 | main.initResult = main.initResult and appRslt |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 277 | main.log.debug( "Apps activation result for " + ",".join( applist ) + ": " + str( appResults ) ) |
Jeremy Ronquillo | 29260cd | 2017-10-13 13:30:54 -0700 | [diff] [blame] | 278 | utilities.assert_equals( expect=main.TRUE, actual=main.initResult, |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 279 | onpass="Successfully activated apps", |
| 280 | onfail="Failed to activated apps correctly" ) |
Jeremy Ronquillo | 29260cd | 2017-10-13 13:30:54 -0700 | [diff] [blame] | 281 | |
| 282 | def CASE120( self, main ): |
| 283 | """ |
| 284 | Docker Mininet testing |
| 285 | """ |
| 286 | import time |
| 287 | import json |
| 288 | from operator import itemgetter |
| 289 | |
| 290 | if main.initResult is main.FALSE: |
| 291 | main.mininetResult = main.FALSE |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 292 | main.skipCase() |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 293 | |
Jeremy Ronquillo | 29260cd | 2017-10-13 13:30:54 -0700 | [diff] [blame] | 294 | main.step( "Loading Mininet Topology." ) |
| 295 | |
| 296 | mnCmd = main.params[ "CASE110" ][ "mnCmd" ] |
| 297 | main.mininetResult = main.Mininet1.startNet( mnCmd=mnCmd + IPlist[ 0 ] ) |
| 298 | utilities.assert_equals( expect=main.TRUE, |
| 299 | actual=main.mininetResult, |
| 300 | onpass="Successfully loaded topology.", |
| 301 | onfail="Failed to load topology" ) |
| 302 | |
| 303 | if main.mininetResult is main.FALSE: |
| 304 | main.skipCase() |
| 305 | |
| 306 | main.mininetResult = utilities.retry( f=main.Mininet1.pingall, |
| 307 | retValue=main.FALSE, |
| 308 | attempts=3, |
| 309 | sleep=5 ) |
| 310 | |
| 311 | utilities.assert_equals( expect=main.TRUE, |
| 312 | actual=main.mininetResult, |
| 313 | onpass="Successfully loaded topology.", |
| 314 | onfail="Failed to load topology" ) |
| 315 | |
| 316 | def CASE130( self, main ): |
| 317 | """ |
| 318 | Docker Intents testing |
| 319 | """ |
| 320 | import time |
| 321 | import json |
| 322 | from operator import itemgetter |
| 323 | |
| 324 | if main.initResult is main.FALSE or main.mininetResult is main.FALSE: |
| 325 | main.intentResult = False |
| 326 | main.skipCase() |
| 327 | |
| 328 | main.hosts = sorted( json.loads( main.ONOSbenchRest.hosts( ip=IPlist[ 0 ] ) ), key=itemgetter( "ipAddresses" ) ) |
| 329 | main.ONOSbenchRest.addHostIntent( main.hosts[ 0 ][ "id" ], main.hosts[ -1 ][ "id" ], ip=IPlist[ 0 ] ) |
| 330 | main.ONOSbenchRest.addHostIntent( main.hosts[ 1 ][ "id" ], main.hosts[ -2 ][ "id" ], ip=IPlist[ 0 ] ) |
| 331 | |
| 332 | main.log.info( "Sleeping for 5 seconds to avoid potential race condition..." ) |
| 333 | time.sleep( 5 ) |
| 334 | |
| 335 | main.step( "Get the intents from each controller" ) |
| 336 | main.ONOSIntents = main.ONOSbenchRest.intents( IPlist[ 0 ] ) |
| 337 | main.intentResult = True |
| 338 | for i in range( 0, len( IPlist ) ): |
| 339 | node = str( IPlist[ i ] ) |
| 340 | if not main.ONOSIntents[ i ] or "Error" in main.ONOSIntents[ i ]: |
| 341 | main.log.error( "Error in getting " + node + " intents" ) |
| 342 | main.log.warn( node + " intents response: " + |
| 343 | repr( main.ONOSIntents[ i ] ) ) |
| 344 | main.intentResult = False |
| 345 | |
| 346 | utilities.assert_equals( expect=True, |
| 347 | actual=main.intentResult, |
| 348 | onpass="No error in reading intents output", |
| 349 | onfail="Error in reading intents from ONOS" ) |
| 350 | |
| 351 | if not main.intentResult: |
| 352 | main.skipCase() |
| 353 | |
| 354 | main.step( "Checking intent state" ) |
| 355 | |
| 356 | main.intentResult = json.loads( main.ONOSIntents )[ 0 ][ "state" ] == "INSTALLED" |
| 357 | |
| 358 | utilities.assert_equals( expect=True, |
| 359 | actual=main.intentResult, |
| 360 | onpass="Intent check successful.", |
| 361 | onfail="Intent check failed." ) |
| 362 | |
| 363 | def CASE140( self, main ): |
| 364 | """ |
| 365 | Docker Flows testing |
| 366 | """ |
| 367 | import time |
| 368 | import json |
| 369 | |
| 370 | if main.initResult is main.FALSE or not main.intentResult: |
| 371 | main.skipCase() |
| 372 | |
| 373 | main.step( "Adding flows." ) |
| 374 | |
| 375 | ingress = 1 |
| 376 | egress = 2 |
| 377 | |
| 378 | main.log.info( "Add flow with MAC selectors." ) |
| 379 | main.flowResult = main.ONOSbenchRest.addFlow( deviceId=main.swDPID, |
| 380 | egressPort=egress, |
| 381 | ingressPort=ingress, |
| 382 | ethSrc=main.hosts[ 0 ][ 'mac' ], |
| 383 | ethDst=main.hosts[ 1 ][ 'mac' ], |
| 384 | debug=main.debug, |
| 385 | ip=IPlist[ 0 ] ) |
| 386 | |
| 387 | main.log.info( "Sleeping for 10 seconds..." ) |
| 388 | time.sleep( 10 ) |
| 389 | |
| 390 | utilities.assert_equals( expect=main.TRUE, |
| 391 | actual=main.flowResult, |
| 392 | onpass="Successfully added flows", |
| 393 | onfail="Failed to add flows" ) |
| 394 | |
| 395 | def CASE299( self, main ): |
| 396 | """ |
| 397 | Cleanup Docker testing |
| 398 | """ |
| 399 | import time |
| 400 | import json |
| 401 | |
| 402 | if main.initResult is main.FALSE: |
| 403 | main.skipCase() |
| 404 | |
| 405 | if main.flowResult is main.TRUE: |
| 406 | main.step( "Remove flow." ) |
| 407 | |
| 408 | prevFlow = json.loads( main.ONOSbenchRest.getFlows( main.swDPID, ip=IPlist[ 0 ] ) )[ -1 ] |
| 409 | stepResult = main.ONOSbenchRest.removeFlow( main.swDPID, prevFlow[ 'id' ], ip=IPlist[ 0 ] ) |
| 410 | utilities.assert_equals( expect=main.TRUE, actual=stepResult, |
| 411 | onpass="Successfully removed flow.", |
| 412 | onfail="Failed to remove flow." ) |
| 413 | |
| 414 | if main.intentResult: |
| 415 | main.step( "Remove intents." ) |
| 416 | results = [] |
| 417 | for i in range( 0, len( json.loads( main.ONOSIntents ) ) ): |
| 418 | intentID = json.loads( main.ONOSbenchRest.intents( IPlist[ 0 ] ) )[ 0 ][ 'id' ] |
| 419 | results.append( main.ONOSbenchRest.removeIntent( intentID, ip=IPlist[ 0 ] ) == main.TRUE ) |
| 420 | |
| 421 | utilities.assert_equals( expect=True, actual=all( results ), |
| 422 | onpass="Successfully removed intents.", |
| 423 | onfail="Failed to remove intents." ) |
| 424 | |
| 425 | if main.mininetResult is main.TRUE: |
| 426 | main.Mininet1.stopNet() |
| 427 | |
| 428 | main.step( "Deactivate an APP from REST and check APP status" ) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 429 | appResults = list() |
| 430 | stepResult = main.TRUE |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 431 | applist = main.params[ "CASE110" ][ "apps" ].split( "," ) |
| 432 | main.log.info( "Apps to deactivate: " + str( applist ) ) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 433 | for app in applist: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 434 | time.sleep( 5 ) |
| 435 | appRslt = main.ONOSbenchRest.deactivateApp( appName=app, ip=IPlist[ 0 ], port=8181, check=True ) |
| 436 | appResults.append( appRslt ) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 437 | stepResult = stepResult and appRslt |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 438 | main.log.debug( "Apps deactivation result for " + ",".join( applist ) + ": " + str( appResults ) ) |
| 439 | utilities.assert_equals( expect=main.TRUE, actual=stepResult, |
Jeremy Ronquillo | 29260cd | 2017-10-13 13:30:54 -0700 | [diff] [blame] | 440 | onpass="Successfully deactivated apps", |
| 441 | onfail="Failed to deactivated apps correctly" ) |
suibin zhang | 3b067ea | 2015-11-05 13:55:21 -0800 | [diff] [blame] | 442 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 443 | def CASE900( self, main ): |
suibin zhang | 3b067ea | 2015-11-05 13:55:21 -0800 | [diff] [blame] | 444 | """ |
| 445 | Check onos logs for exceptions after tests |
| 446 | """ |
| 447 | import pexpect |
| 448 | import time |
| 449 | import re |
| 450 | |
| 451 | logResult = main.TRUE |
| 452 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 453 | user = main.params[ "DOCKER" ][ "user" ] |
| 454 | pwd = main.params[ "DOCKER" ][ "password" ] |
suibin zhang | 3b067ea | 2015-11-05 13:55:21 -0800 | [diff] [blame] | 455 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 456 | main.case( "onos Exceptions check with onos image {}".format( DOCKERTAG ) ) |
| 457 | main.step( "check onos for any exceptions" ) |
suibin zhang | 3b067ea | 2015-11-05 13:55:21 -0800 | [diff] [blame] | 458 | |
| 459 | for ip in IPlist: |
suibin zhang | 559218e | 2015-12-08 14:57:12 -0800 | [diff] [blame] | 460 | 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] | 461 | main.log.info( "log on node using cmd: " + spawncmd ) |
suibin zhang | 3b067ea | 2015-11-05 13:55:21 -0800 | [diff] [blame] | 462 | try: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 463 | handle = pexpect.spawn( spawncmd ) |
| 464 | # handle.expect( "yes/no" ) |
| 465 | # handle.sendline( "yes" ) |
| 466 | # print( "yes is sent" ) |
| 467 | # this extra statement is sent to get around some |
| 468 | # pexpect issue of not seeing the next expected string |
| 469 | handle.expect( "Password:" ) |
| 470 | handle.sendline( pwd ) |
| 471 | time.sleep( 5 ) |
| 472 | handle.expect( "onos>" ) |
| 473 | handle.sendline( "log:exception-display" ) |
| 474 | handle.expect( "onos>" ) |
suibin zhang | 3b067ea | 2015-11-05 13:55:21 -0800 | [diff] [blame] | 475 | result = handle.before |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 476 | if re.search( "Exception", result ): |
| 477 | main.log.info( "onos: " + ip + " Exceptions:" + result ) |
suibin zhang | 3b067ea | 2015-11-05 13:55:21 -0800 | [diff] [blame] | 478 | logResult = logResult and main.FALSE |
| 479 | else: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 480 | main.log.info( "onos: " + ip + " Exceptions: None" ) |
suibin zhang | 3b067ea | 2015-11-05 13:55:21 -0800 | [diff] [blame] | 481 | logResult = logResult and main.TRUE |
| 482 | except Exception: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 483 | main.log.exception( "Uncaught exception when getting log from onos:" + ip ) |
suibin zhang | 3b067ea | 2015-11-05 13:55:21 -0800 | [diff] [blame] | 484 | logResult = logResult and main.FALSE |
| 485 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 486 | utilities.assert_equals( expect=main.TRUE, actual=logResult, |
| 487 | onpass="onos exception check passed", |
| 488 | onfail="onos exeption check failed" ) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 489 | |
| 490 | def CASE1000( self, main ): |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 491 | """ |
Pratik Parab | cc40645 | 2017-02-28 15:15:25 -0800 | [diff] [blame] | 492 | Cleanup after tests - stop and delete the containers created; delete the image |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 493 | """ |
| 494 | import time |
| 495 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 496 | main.case( "Clean up images (ex. none:none tagged) and containers" ) |
| 497 | main.step( "Stop onos containers" ) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 498 | stepResult = main.TRUE |
| 499 | for ctname in NODElist: |
Pratik Parab | cc40645 | 2017-02-28 15:15:25 -0800 | [diff] [blame] | 500 | if main.ONOSbenchDocker.dockerCheckCTName( ctName="/" + ctname ): |
| 501 | main.log.info( "stopping docker container: /" + ctname ) |
| 502 | stopResult = main.ONOSbenchDocker.dockerStopCT( ctName="/" + ctname ) |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 503 | time.sleep( 10 ) |
Pratik Parab | cc40645 | 2017-02-28 15:15:25 -0800 | [diff] [blame] | 504 | rmResult = main.ONOSbenchDocker.dockerRemoveCT( ctName="/" + ctname ) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 505 | stepResult = stepResult and stopResult and rmResult |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 506 | utilities.assert_equals( expect=main.TRUE, actual=stepResult, |
| 507 | onpass="Container successfully stopped", |
| 508 | onfail="Failed to stopped the container" ) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 509 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 510 | # main.step( "remove exiting onosproject/onos images" ) |
| 511 | # stepResult = main.ONOSbenchDocker.dockerRemoveImage( image=DOCKERREPO + ":" + DOCKERTAG ) |
| 512 | main.step( "remove dangling 'none:none' images" ) |
Pratik Parab | cc40645 | 2017-02-28 15:15:25 -0800 | [diff] [blame] | 513 | stepResult = main.ONOSbenchDocker.dockerRemoveImage() |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 514 | utilities.assert_equals( expect=main.TRUE, actual=stepResult, |
| 515 | onpass="Succeeded in cleaning up images", |
| 516 | onfail="Failed in cleaning up images" ) |
suibin zhang | fd266fd | 2015-10-27 17:06:33 -0700 | [diff] [blame] | 517 | |
Pratik Parab | 8d884d1 | 2017-03-16 12:14:32 -0700 | [diff] [blame] | 518 | def CASE1001( self, main ): |
Pratik Parab | 8d884d1 | 2017-03-16 12:14:32 -0700 | [diff] [blame] | 519 | """ |
| 520 | Create a file for publishing results on wiki in tabular form |
| 521 | """ |
Pratik Parab | 8d884d1 | 2017-03-16 12:14:32 -0700 | [diff] [blame] | 522 | main.case( "Create a file for publishing on wiki in tabular form" ) |
| 523 | import re |
| 524 | imageTagCounter = 0 |
| 525 | testCaseCounter = 0 |
| 526 | resultCounter = 0 |
| 527 | resultDictionary = {} |
| 528 | testCaseList = [] |
| 529 | totalNumOfTestCases = 6 |
| 530 | try: |
| 531 | main.tableFileName = main.logdir + "/" + main.TEST + "TableWiki.txt" |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 532 | main.wikiTableFile = open( main.tableFileName, "a+" ) |
| 533 | main.wikiFileHandle = open( main.WikiFileName, "r" ) |
Pratik Parab | 8d884d1 | 2017-03-16 12:14:32 -0700 | [diff] [blame] | 534 | for imageTag in imageTagList: |
| 535 | resultDictionary[ imageTag ] = [] |
| 536 | for line in main.wikiFileHandle: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 537 | matchObj = re.search( "(?!.*Case 0).*<h3>(.+?)<\/h3>", line ) |
Pratik Parab | 8d884d1 | 2017-03-16 12:14:32 -0700 | [diff] [blame] | 538 | if testCaseCounter < totalNumOfTestCases: |
| 539 | if matchObj: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 540 | wordsToRemove = re.compile( "latest|- PASS|- FAIL|- No Result" ) |
| 541 | testCaseName = wordsToRemove.sub( "", matchObj.group( 1 ) ) |
| 542 | testCaseName = testCaseName.replace( INITDOCKERTAG, '' ) |
| 543 | testCaseList.append( testCaseName ) |
Pratik Parab | 8d884d1 | 2017-03-16 12:14:32 -0700 | [diff] [blame] | 544 | testCaseCounter += 1 |
| 545 | if matchObj: |
| 546 | if "- PASS" in line: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 547 | resultDictionary[ imageTagList[ imageTagCounter ] ].append( "PASS" ) |
Pratik Parab | 8d884d1 | 2017-03-16 12:14:32 -0700 | [diff] [blame] | 548 | if "- FAIL" in line: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 549 | resultDictionary[ imageTagList[ imageTagCounter ] ].append( "FAIL" ) |
Pratik Parab | 8d884d1 | 2017-03-16 12:14:32 -0700 | [diff] [blame] | 550 | if "- No Result" in line: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 551 | resultDictionary[ imageTagList[ imageTagCounter ] ].append( "No Result" ) |
Pratik Parab | 8d884d1 | 2017-03-16 12:14:32 -0700 | [diff] [blame] | 552 | resultCounter += 1 |
| 553 | if resultCounter == totalNumOfTestCases: |
| 554 | imageTagCounter += 1 |
| 555 | resultCounter = 0 |
| 556 | main.wikiTableFile.write( "<table style=\"width:100%\">\n" ) |
| 557 | main.wikiTableFile.write( "<tr>\n" ) |
| 558 | main.wikiTableFile.write( "<th>ONOS Version</th>\n" ) |
| 559 | for testCaseName in testCaseList: |
| 560 | main.wikiTableFile.write( "<th>" + testCaseName + "</th>\n" ) |
| 561 | main.wikiTableFile.write( "</tr>\n" ) |
| 562 | for imageTag in imageTagList: |
| 563 | main.wikiTableFile.write( "<tr>\n" ) |
| 564 | main.wikiTableFile.write( "<td>" + imageTag + "</td>\n" ) |
| 565 | for resultValue in resultDictionary[ imageTag ]: |
| 566 | if resultValue == "PASS": |
| 567 | emoticonValue = "\"tick\"" |
| 568 | if resultValue == "FAIL": |
| 569 | emoticonValue = "\"cross\"" |
| 570 | if resultValue == "No Result": |
| 571 | emoticonValue = "\"warning\"" |
| 572 | main.wikiTableFile.write( "<td>" + resultValue + " <ac:emoticon ac:name=" + emoticonValue + " /></td>\n" ) |
| 573 | main.wikiTableFile.write( "</tr>\n" ) |
| 574 | main.wikiTableFile.write( "</table>\n" ) |
| 575 | main.wikiTableFile.close() |
| 576 | main.wikiFileHandle.close() |
| 577 | logResult = main.TRUE |
| 578 | except Exception: |
| 579 | main.log.exception( "Exception while writing to the table file" ) |
| 580 | logResult = main.FALSE |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 581 | utilities.assert_equals( expect=main.TRUE, actual=logResult, |
| 582 | onpass="onos exception check passed", |
| 583 | onfail="onos exception check failed" ) |