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