blob: c9b6ab136502077116960a6f1722eee399c3077e [file] [log] [blame]
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07001"""
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -07002Copyright 2015 Open Networking Foundation ( ONF )
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07003
4Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
5the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
6or 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 Ronquillo23fb2162017-09-15 14:59:57 -070011 ( at your option ) any later version.
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -070012
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 zhangc7635702015-11-03 21:30:20 -080021# This is a basic platform test suite.
22# Additional platform test cases can be added on this test suite where appropriate.
suibin zhangfd266fd2015-10-27 17:06:33 -070023
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070024
suibin zhangfd266fd2015-10-27 17:06:33 -070025class PLATdockertest:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070026
suibin zhangfd266fd2015-10-27 17:06:33 -070027 """
28 This testsuite performs the following tests:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070029 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 zhangfd266fd2015-10-27 17:06:33 -070032
33 Prerequisites:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070034 1 ) docker-engine installed on test station ( localhost );
35 2 ) python docker client ( docker-py ) installed on test station
suibin zhangfd266fd2015-10-27 17:06:33 -070036 """
suibin zhangfd266fd2015-10-27 17:06:33 -070037 def __init__( self ):
38 self.default = ''
Devin Limcde503f2017-09-11 17:23:30 -070039 global DOCKERREPO, DOCKERTAG, INITDOCKERTAG
suibin zhangfd266fd2015-10-27 17:06:33 -070040 global IPlist
41 global CTIDlist
42 global NODElist
43
44 DOCKERREPO = "onosproject/onos"
45 DOCKERTAG = "latest"
46
Pratik Parabcc406452017-02-28 15:15:25 -080047 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 Parabcc406452017-02-28 15:15:25 -080052 import os
53 DOCKERREPO = main.params[ 'DOCKER' ][ 'repo' ]
54 os.system( "docker pull -a " + DOCKERREPO )
55 imageTagList = list()
56 imageTagCounter = 0
Pratik Parab50d53d42017-03-24 14:28:22 -070057 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 Ronquillo23fb2162017-09-15 14:59:57 -070063 utilities.assert_equals( expect=main.TRUE, actual=stepResult,
64 onpass="no duplicate image tags",
65 onfail="duplicate image tags detected!!" )
Pratik Parabcc406452017-02-28 15:15:25 -080066 main.step( "Get a list of image tags" )
67 stepResult = main.FALSE
Pratik Parabcc406452017-02-28 15:15:25 -080068 if imageTagList is not []:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070069 main.log.info( "The Image tag list is: " + str( imageTagList ) )
Pratik Parabcc406452017-02-28 15:15:25 -080070 stepResult = main.TRUE
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070071 utilities.assert_equals( expect=main.TRUE, actual=stepResult,
72 onpass="image tag list pulled successfully",
73 onfail="image tag list not pulled" )
Pratik Parabcc406452017-02-28 15:15:25 -080074
suibin zhangfd266fd2015-10-27 17:06:33 -070075 def CASE1( self, main ):
76 """
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070077 1 ) set up test params;
suibin zhangfd266fd2015-10-27 17:06:33 -070078 """
79 import re
suibin zhang3b067ea2015-11-05 13:55:21 -080080 import time
81 import subprocess
suibin zhangfd266fd2015-10-27 17:06:33 -070082
Pratik Parabcc406452017-02-28 15:15:25 -080083 if imageTagCounter < len( imageTagList ):
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070084 DOCKERTAG = imageTagList[ imageTagCounter ]
Devin Limcde503f2017-09-11 17:23:30 -070085 if not imageTagCounter:
86 INITDOCKERTAG = DOCKERTAG
Pratik Parabcc406452017-02-28 15:15:25 -080087 imageTagCounter += 1
88
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070089 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 zhangfd266fd2015-10-27 17:06:33 -070093 IPlist = list()
Jon Halld74d2952018-03-01 13:26:39 -080094 main.testOnDirectory = re.sub( "(/tests)$", "", main.testsRoot )
suibin zhangfd266fd2015-10-27 17:06:33 -070095 CTIDlist = list()
suibin zhang3b067ea2015-11-05 13:55:21 -080096
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070097 main.log.info( "Check docker status, it not running, try restart it" )
suibin zhang3b067ea2015-11-05 13:55:21 -080098 iter = 0
99 stepResult = main.TRUE
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700100 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 zhang3b067ea2015-11-05 13:55:21 -0800103 iter += 1
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700104 if iter == 3:
105 stepResult = main.FALSE
suibin zhang3b067ea2015-11-05 13:55:21 -0800106
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700107 utilities.assert_equals( expect=main.TRUE, actual=stepResult,
108 onpass="docker is running",
109 onfail="docker is not running" )
suibin zhang3b067ea2015-11-05 13:55:21 -0800110 if stepResult == main.FALSE:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700111 main.log.warn( "docker is not running - exiting test" )
Devin Lim44075962017-08-11 10:56:37 -0700112 main.cleanAndExit()
Pratik Parabcc406452017-02-28 15:15:25 -0800113 if imageTagCounter > len( imageTagList ):
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700114 main.log.info( "All images have been tested" )
You Wang7880b372019-02-27 16:50:47 -0800115 main.cleanAndExit( alarm=False )
suibin zhangfd266fd2015-10-27 17:06:33 -0700116
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700117 def CASE5( self, main ):
suibin zhangfd266fd2015-10-27 17:06:33 -0700118 """
Pratik Parabcc406452017-02-28 15:15:25 -0800119 Pull the specified image
suibin zhangfd266fd2015-10-27 17:06:33 -0700120 """
Pratik Parabcc406452017-02-28 15:15:25 -0800121 main.case( "Pull onos docker image {} from {} - \
122 it may take sometime if this is a first time pulling.".format( DOCKERTAG, DOCKERREPO ) )
suibin zhangfd266fd2015-10-27 17:06:33 -0700123 stepResult = main.FALSE
Pratik Parabcc406452017-02-28 15:15:25 -0800124 main.step( "pull image {} from {}".format( DOCKERTAG, DOCKERREPO ) )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700125 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 zhangfd266fd2015-10-27 17:06:33 -0700131
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 zhang3b067ea2015-11-05 13:55:21 -0800137 createResult = main.TRUE
138 startResult = main.TRUE
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700139 main.case( "Start onos container(s) for onos image {}".format( DOCKERTAG ) )
suibin zhangfd266fd2015-10-27 17:06:33 -0700140 image = DOCKERREPO + ":" + DOCKERTAG
141
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700142 main.step( "Create and (re)start docker container(s) for onos image {} if not already exist".format( DOCKERTAG ) )
143 # stepResult = main.FALSE
suibin zhangfd266fd2015-10-27 17:06:33 -0700144
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700145 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 zhangfd266fd2015-10-27 17:06:33 -0700151 else:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700152 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 zhangfd266fd2015-10-27 17:06:33 -0700154
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700155 utilities.assert_equals( expect=main.TRUE, actual=createResult and startResult,
156 onpass="Container successfully created",
157 onfail="Failed to create the container" )
suibin zhangfd266fd2015-10-27 17:06:33 -0700158
159 main.step( "Get IP address on onos containers" )
160 stepResult = main.FALSE
161
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700162 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 zhangfd266fd2015-10-27 17:06:33 -0700165
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700166 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 zhangfd266fd2015-10-27 17:06:33 -0700171
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700172 def CASE110( self, main ):
suibin zhangfd266fd2015-10-27 17:06:33 -0700173 """
Jeremy Ronquillo29260cd2017-10-13 13:30:54 -0700174 Docker init testing
175
suibin zhangfd266fd2015-10-27 17:06:33 -0700176 Steps:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700177 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 zhangfd266fd2015-10-27 17:06:33 -0700181
182 """
183 import time
184 import json
185
Pratik Parabcc406452017-02-28 15:15:25 -0800186 main.case( "Form onos cluster and check status of onos apps for onos image {}".format( DOCKERTAG ) )
187
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700188 startupSleep = int( main.params[ "SLEEP" ][ "startup" ] )
Jeremy Ronquillo29260cd2017-10-13 13:30:54 -0700189 main.swDPID = main.params[ "CASE110" ][ "swDPID" ]
190 main.debug = main.params[ "CASE110" ][ "debug" ]
suibin zhangfd266fd2015-10-27 17:06:33 -0700191
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700192 appToAct = main.params[ "CASE110" ][ "apps" ]
Jeremy Ronquillo29260cd2017-10-13 13:30:54 -0700193 main.initResult = main.FALSE
suibin zhangfd266fd2015-10-27 17:06:33 -0700194
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700195 main.log.info( "Wait for startup, sleep (sec): " + str( startupSleep ) )
196 time.sleep( startupSleep )
suibin zhangfd266fd2015-10-27 17:06:33 -0700197
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700198 main.step( "Check initial app states from onos1 for onos image {}".format( DOCKERTAG ) )
Jeremy Ronquillo29260cd2017-10-13 13:30:54 -0700199 main.initResult = main.TRUE
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700200 response = main.ONOSbenchRest.apps( ip=IPlist[ 0 ], port=8181 )
201 main.log.debug( "Rest call response is: " + response )
suibin zhangfd266fd2015-10-27 17:06:33 -0700202 if response is not main.FALSE:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700203 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 Ronquillo29260cd2017-10-13 13:30:54 -0700207 main.initResult = main.FALSE
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700208 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 Ronquillo29260cd2017-10-13 13:30:54 -0700211 main.initResult = main.FALSE
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700212 break
Jeremy Ronquillo29260cd2017-10-13 13:30:54 -0700213 utilities.assert_equals( expect=main.TRUE, actual=main.initResult,
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700214 onpass="ONOS successfully started",
215 onfail="Failed to start ONOS correctly" )
Jeremy Ronquillo29260cd2017-10-13 13:30:54 -0700216 if main.initResult is main.FALSE:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700217 main.skipCase()
suibin zhangfd266fd2015-10-27 17:06:33 -0700218
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700219 main.step( "Form onos cluster using 'dependencies/onos-form-cluster' util" )
Jeremy Ronquillo29260cd2017-10-13 13:30:54 -0700220 main.initResult = main.FALSE
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700221 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 zhangfd266fd2015-10-27 17:06:33 -0700230 if status == 200:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700231 jrsp = json.loads( response )
Pratik Parabcc406452017-02-28 15:15:25 -0800232 if DOCKERTAG == "1.2" or DOCKERTAG == "1.3" or DOCKERTAG == "1.4" or DOCKERTAG == "1.5":
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700233 clusterIP = [ item[ "ip" ]for item in jrsp[ "nodes" ] if item[ "status" ] == "ACTIVE" ]
Pratik Parabcc406452017-02-28 15:15:25 -0800234 else:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700235 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 Ronquillo29260cd2017-10-13 13:30:54 -0700239 main.initResult = main.TRUE
suibin zhangfd266fd2015-10-27 17:06:33 -0700240
Jeremy Ronquillo29260cd2017-10-13 13:30:54 -0700241 utilities.assert_equals( expect=main.TRUE, actual=main.initResult,
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700242 onpass="ONOS successfully started",
243 onfail="Failed to start ONOS correctly" )
Jeremy Ronquillo29260cd2017-10-13 13:30:54 -0700244 if main.initResult is main.FALSE:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700245 main.skipCase()
suibin zhangfd266fd2015-10-27 17:06:33 -0700246
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700247 main.step( "Check cluster app status" )
Jeremy Ronquillo29260cd2017-10-13 13:30:54 -0700248 main.initResult = main.TRUE
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700249 response = main.ONOSbenchRest.apps( ip=IPlist[ 0 ], port=8181 )
suibin zhangfd266fd2015-10-27 17:06:33 -0700250 if response is not main.FALSE:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700251 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 Ronquillo29260cd2017-10-13 13:30:54 -0700255 main.initResult = main.FALSE
suibin zhang3b067ea2015-11-05 13:55:21 -0800256 break
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700257 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 Ronquillo29260cd2017-10-13 13:30:54 -0700259 main.initResult = main.FALSE
suibin zhang3b067ea2015-11-05 13:55:21 -0800260 break
Jeremy Ronquillo29260cd2017-10-13 13:30:54 -0700261 utilities.assert_equals( expect=main.TRUE, actual=main.initResult,
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700262 onpass="ONOS successfully started",
263 onfail="Failed to start ONOS correctly" )
Jeremy Ronquillo29260cd2017-10-13 13:30:54 -0700264 if main.initResult is main.FALSE:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700265 main.skipCase()
suibin zhangfd266fd2015-10-27 17:06:33 -0700266
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700267 main.step( " Activate an APP from REST and check APP status" )
suibin zhangfd266fd2015-10-27 17:06:33 -0700268 appResults = list()
Jeremy Ronquillo29260cd2017-10-13 13:30:54 -0700269 main.initResult = main.TRUE
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700270 applist = main.params[ "CASE110" ][ "apps" ].split( "," )
271 main.log.info( "List of apps to activate: " + str( applist ) )
suibin zhangfd266fd2015-10-27 17:06:33 -0700272 for app in applist:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700273 appRslt = main.ONOSbenchRest.activateApp( appName=app, ip=IPlist[ 0 ], port=8181, check=True )
274 time.sleep( 5 )
275 appResults.append( appRslt )
Jeremy Ronquillo29260cd2017-10-13 13:30:54 -0700276 main.initResult = main.initResult and appRslt
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700277 main.log.debug( "Apps activation result for " + ",".join( applist ) + ": " + str( appResults ) )
Jeremy Ronquillo29260cd2017-10-13 13:30:54 -0700278 utilities.assert_equals( expect=main.TRUE, actual=main.initResult,
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700279 onpass="Successfully activated apps",
280 onfail="Failed to activated apps correctly" )
Jeremy Ronquillo29260cd2017-10-13 13:30:54 -0700281
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 Ronquillo23fb2162017-09-15 14:59:57 -0700292 main.skipCase()
suibin zhangfd266fd2015-10-27 17:06:33 -0700293
Jeremy Ronquillo29260cd2017-10-13 13:30:54 -0700294 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 zhangfd266fd2015-10-27 17:06:33 -0700429 appResults = list()
430 stepResult = main.TRUE
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700431 applist = main.params[ "CASE110" ][ "apps" ].split( "," )
432 main.log.info( "Apps to deactivate: " + str( applist ) )
suibin zhangfd266fd2015-10-27 17:06:33 -0700433 for app in applist:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700434 time.sleep( 5 )
435 appRslt = main.ONOSbenchRest.deactivateApp( appName=app, ip=IPlist[ 0 ], port=8181, check=True )
436 appResults.append( appRslt )
suibin zhangfd266fd2015-10-27 17:06:33 -0700437 stepResult = stepResult and appRslt
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700438 main.log.debug( "Apps deactivation result for " + ",".join( applist ) + ": " + str( appResults ) )
439 utilities.assert_equals( expect=main.TRUE, actual=stepResult,
Jeremy Ronquillo29260cd2017-10-13 13:30:54 -0700440 onpass="Successfully deactivated apps",
441 onfail="Failed to deactivated apps correctly" )
suibin zhang3b067ea2015-11-05 13:55:21 -0800442
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700443 def CASE900( self, main ):
suibin zhang3b067ea2015-11-05 13:55:21 -0800444 """
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 Ronquillo23fb2162017-09-15 14:59:57 -0700453 user = main.params[ "DOCKER" ][ "user" ]
454 pwd = main.params[ "DOCKER" ][ "password" ]
suibin zhang3b067ea2015-11-05 13:55:21 -0800455
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700456 main.case( "onos Exceptions check with onos image {}".format( DOCKERTAG ) )
457 main.step( "check onos for any exceptions" )
suibin zhang3b067ea2015-11-05 13:55:21 -0800458
459 for ip in IPlist:
suibin zhang559218e2015-12-08 14:57:12 -0800460 spawncmd = "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p 8101 " + user + "@" + ip
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700461 main.log.info( "log on node using cmd: " + spawncmd )
suibin zhang3b067ea2015-11-05 13:55:21 -0800462 try:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700463 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 zhang3b067ea2015-11-05 13:55:21 -0800475 result = handle.before
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700476 if re.search( "Exception", result ):
477 main.log.info( "onos: " + ip + " Exceptions:" + result )
suibin zhang3b067ea2015-11-05 13:55:21 -0800478 logResult = logResult and main.FALSE
479 else:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700480 main.log.info( "onos: " + ip + " Exceptions: None" )
suibin zhang3b067ea2015-11-05 13:55:21 -0800481 logResult = logResult and main.TRUE
482 except Exception:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700483 main.log.exception( "Uncaught exception when getting log from onos:" + ip )
suibin zhang3b067ea2015-11-05 13:55:21 -0800484 logResult = logResult and main.FALSE
485
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700486 utilities.assert_equals( expect=main.TRUE, actual=logResult,
487 onpass="onos exception check passed",
488 onfail="onos exeption check failed" )
suibin zhangfd266fd2015-10-27 17:06:33 -0700489
490 def CASE1000( self, main ):
suibin zhangfd266fd2015-10-27 17:06:33 -0700491 """
Pratik Parabcc406452017-02-28 15:15:25 -0800492 Cleanup after tests - stop and delete the containers created; delete the image
suibin zhangfd266fd2015-10-27 17:06:33 -0700493 """
494 import time
495
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700496 main.case( "Clean up images (ex. none:none tagged) and containers" )
497 main.step( "Stop onos containers" )
suibin zhangfd266fd2015-10-27 17:06:33 -0700498 stepResult = main.TRUE
499 for ctname in NODElist:
Pratik Parabcc406452017-02-28 15:15:25 -0800500 if main.ONOSbenchDocker.dockerCheckCTName( ctName="/" + ctname ):
501 main.log.info( "stopping docker container: /" + ctname )
502 stopResult = main.ONOSbenchDocker.dockerStopCT( ctName="/" + ctname )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700503 time.sleep( 10 )
Pratik Parabcc406452017-02-28 15:15:25 -0800504 rmResult = main.ONOSbenchDocker.dockerRemoveCT( ctName="/" + ctname )
suibin zhangfd266fd2015-10-27 17:06:33 -0700505 stepResult = stepResult and stopResult and rmResult
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700506 utilities.assert_equals( expect=main.TRUE, actual=stepResult,
507 onpass="Container successfully stopped",
508 onfail="Failed to stopped the container" )
suibin zhangfd266fd2015-10-27 17:06:33 -0700509
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700510 # main.step( "remove exiting onosproject/onos images" )
511 # stepResult = main.ONOSbenchDocker.dockerRemoveImage( image=DOCKERREPO + ":" + DOCKERTAG )
512 main.step( "remove dangling 'none:none' images" )
Pratik Parabcc406452017-02-28 15:15:25 -0800513 stepResult = main.ONOSbenchDocker.dockerRemoveImage()
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700514 utilities.assert_equals( expect=main.TRUE, actual=stepResult,
515 onpass="Succeeded in cleaning up images",
516 onfail="Failed in cleaning up images" )
suibin zhangfd266fd2015-10-27 17:06:33 -0700517
Pratik Parab8d884d12017-03-16 12:14:32 -0700518 def CASE1001( self, main ):
Pratik Parab8d884d12017-03-16 12:14:32 -0700519 """
520 Create a file for publishing results on wiki in tabular form
521 """
Pratik Parab8d884d12017-03-16 12:14:32 -0700522 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 Ronquillo23fb2162017-09-15 14:59:57 -0700532 main.wikiTableFile = open( main.tableFileName, "a+" )
533 main.wikiFileHandle = open( main.WikiFileName, "r" )
Pratik Parab8d884d12017-03-16 12:14:32 -0700534 for imageTag in imageTagList:
535 resultDictionary[ imageTag ] = []
536 for line in main.wikiFileHandle:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700537 matchObj = re.search( "(?!.*Case 0).*<h3>(.+?)<\/h3>", line )
Pratik Parab8d884d12017-03-16 12:14:32 -0700538 if testCaseCounter < totalNumOfTestCases:
539 if matchObj:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700540 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 Parab8d884d12017-03-16 12:14:32 -0700544 testCaseCounter += 1
545 if matchObj:
546 if "- PASS" in line:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700547 resultDictionary[ imageTagList[ imageTagCounter ] ].append( "PASS" )
Pratik Parab8d884d12017-03-16 12:14:32 -0700548 if "- FAIL" in line:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700549 resultDictionary[ imageTagList[ imageTagCounter ] ].append( "FAIL" )
Pratik Parab8d884d12017-03-16 12:14:32 -0700550 if "- No Result" in line:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700551 resultDictionary[ imageTagList[ imageTagCounter ] ].append( "No Result" )
Pratik Parab8d884d12017-03-16 12:14:32 -0700552 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 Ronquillo23fb2162017-09-15 14:59:57 -0700581 utilities.assert_equals( expect=main.TRUE, actual=logResult,
582 onpass="onos exception check passed",
583 onfail="onos exception check failed" )