blob: 753151161e94f63221c16da5b54b1dc6a87c7294 [file] [log] [blame]
suibin zhangfd266fd2015-10-27 17:06:33 -07001
suibin zhangc7635702015-11-03 21:30:20 -08002# This is a basic platform test suite.
3# Additional platform test cases can be added on this test suite where appropriate.
suibin zhangfd266fd2015-10-27 17:06:33 -07004
5class PLATdockertest:
6 """
7 This testsuite performs the following tests:
8 1) checkout onos docker image;
9 2) test image start up in single and clustered mode;
10 3) test onos app activation and deactivation;
11
12 Prerequisites:
13 1) docker-engine installed on test station (localhost);
14 2) python docker client (docker-py) installed on test station
15 """
16
17 def __init__( self ):
18 self.default = ''
19 global DOCKERREPO, DOCKERTAG
20 global IPlist
21 global CTIDlist
22 global NODElist
23
24 DOCKERREPO = "onosproject/onos"
25 DOCKERTAG = "latest"
26
27 def CASE1( self, main ):
28 """
29 1) set up test params;
30 """
31 import re
suibin zhang3b067ea2015-11-05 13:55:21 -080032 import time
33 import subprocess
suibin zhangfd266fd2015-10-27 17:06:33 -070034
35 main.case("Set case test params")
36 main.step("Initialize test params")
37 NODElist = main.params["SCALE"]["nodelist"].split(',')
38 main.log.info("onos container names are: " + ",".join(NODElist) )
39 IPlist = list()
40 main.testOnDirectory = re.sub( "(/tests)$", "", main.testDir )
41 DOCKERREPO = main.params[ 'DOCKER' ][ 'repo' ]
42 DOCKERTAG = main.params[ 'DOCKER' ][ 'tag' ]
43 CTIDlist = list()
suibin zhang3b067ea2015-11-05 13:55:21 -080044
45 main.log.info("Check docker status, it not running, try restart it")
46 iter = 0
47 stepResult = main.TRUE
48 while subprocess.call("sudo service docker status", shell=True) and iter <= 3:
49 subprocess.call("sudo service docker restart", shell=True)
50 time.sleep(5)
51 iter += 1
52 if iter == 3: stepResult = main.FALSE
53
54 utilities.assert_equals( expect = main.TRUE, actual = stepResult,
55 onpass = "docker is running",
56 onfail = "docker is not running")
57 if stepResult == main.FALSE:
58 main.log.warn("docker is not running - exiting test")
59 main.exit()
60 main.cleanup()
suibin zhangfd266fd2015-10-27 17:06:33 -070061
62 def CASE5(self, main):
63 """
64 Pull (default) "onosproject/onos:latest" image
65 """
66
67 main.case( "Pull latest onos docker image from onosproject/onos - \
68 it may take sometime if this is a first time pulling." )
69 stepResult = main.FALSE
70 main.step( "pull latest image from onosproject/onos")
71 stepResult = main.ONOSbenchDocker.dockerPull( onosRepo = DOCKERREPO, onosTag = DOCKERTAG )
72 utilities.assert_equals( expect = main.TRUE, actual = stepResult,
73 onpass = "Succeeded in pulling " + DOCKERREPO + ":" + DOCKERTAG,
74 onfail = "Failed to pull " + DOCKERREPO + ":" + DOCKERTAG )
suibin zhang3b067ea2015-11-05 13:55:21 -080075 if stepResult == main.FALSE: main.skipCase()
suibin zhangfd266fd2015-10-27 17:06:33 -070076
77 def CASE10( self, main ):
78 """
79 Start docker containers for list of onos nodes, only if not already existed
80 """
81 import re
suibin zhang3b067ea2015-11-05 13:55:21 -080082 createResult = main.TRUE
83 startResult = main.TRUE
suibin zhangfd266fd2015-10-27 17:06:33 -070084 main.case( "Start onos container(s)")
85 image = DOCKERREPO + ":" + DOCKERTAG
86
87 main.step( "Create and (re)start docker container(s) if not already exist")
88 #stepResult = main.FALSE
89
90 for ct in xrange(0, len(NODElist)):
91 if not main.ONOSbenchDocker.dockerCheckCTName( ctName = NODElist[ct] ):
92 main.log.info( "Create new container for onos" + str(ct + 1) )
93 createResult, ctid = main.ONOSbenchDocker.dockerCreateCT( onosImage = image, onosNode = NODElist[ct])
94 CTIDlist.append(ctid)
95 startResult = main.ONOSbenchDocker.dockerStartCT( ctID = ctid )
96 else:
97 main.log.info("Container exists for node onos" + str(ct + 1) + "; restart container with latest image" )
98 startResult = main.ONOSbenchDocker.dockerRestartCT( ctName = NODElist[ct ] )
99
100 utilities.assert_equals( expect = main.TRUE, actual = createResult and startResult,
101 onpass = "Container successfully created",
102 onfail = "Failed to create the container" )
103
104 main.step( "Get IP address on onos containers" )
105 stepResult = main.FALSE
106
107 for ct in xrange(0,len(NODElist)):
108 IPlist.append(main.ONOSbenchDocker.dockerIP( ctName = NODElist[ct] ))
109 main.log.info("Container IPs are: " + ', '.join( IPlist ))
110
111 if IPlist is not []:stepResult = main.TRUE
112 utilities.assert_equals( expect = main.TRUE, actual = stepResult,
113 onpass = "Container successfully started",
114 onfail = "Failed to start the container" )
115
116 def CASE110(self,main):
117 """
118 Steps:
119 1) check default startup standalone onos applications status;
120 2) form onos cluster with all nodes;
121 3) check onos applications status;
122 4) activate apps per params and check app status;
123 5) deactivate apps and check app status
124
125 """
126 import time
127 import json
128
129 startupSleep = int(main.params["SLEEP"]["startup"])
130
131 appToAct = main.params["CASE110"]["apps"]
132 stepResult = main.FALSE
133
134 main.log.info( "Wait for startup, sleep (sec): " + str(startupSleep))
135 time.sleep(startupSleep)
136
137 main.step( "Check initial app states from onos1")
138 stepResult = main.TRUE
139 response = main.ONOSbenchRest.apps( ip=IPlist[0], port = 8181 )
140 main.log.debug("Rest call response is: " + response)
141 if response is not main.FALSE:
142 for item in json.loads(response):
143 if item["state"] not in ["ACTIVE", "INSTALLED"]:
144 main.log.info("Some bundles are not in correct state. ")
145 main.log.info("App states are: " + response)
146 stepResult = main.FALSE
147 break;
148 if (item["description"] == "Builtin device drivers") and (item["state"] != "ACTIVE"):
149 main.log.info("Driver app is not in 'ACTIVE' state, but in: " + item["state"])
150 stepResult = main.FALSE
151 break;
152 utilities.assert_equals( expect = main.TRUE, actual = stepResult,
153 onpass = "ONOS successfully started",
154 onfail = "Failed to start ONOS correctly" )
suibin zhang3b067ea2015-11-05 13:55:21 -0800155 if stepResult is main.FALSE: main.skipCase()
suibin zhangfd266fd2015-10-27 17:06:33 -0700156
157 main.step( "Form onos cluster using 'Dependency/onos-form-cluster' util")
158 stepResult = main.FALSE
159 clcmdpath = main.params["CASE110"]["clustercmdpath"]
160 main.log.info("onos-form-cluster cmd path is: " + clcmdpath)
161 dkruser = main.params["DOCKER"]["user"]
162 dkrpasswd = main.params["DOCKER"]["password"]
163 main.ONOSbenchDocker.onosFormCluster(cmdPath = clcmdpath, onosIPs=IPlist, user=dkruser, passwd = dkrpasswd)
164 main.log.info("Wait for cluster to form with sleep time of " + str(startupSleep))
165 time.sleep(startupSleep)
166 status, response = main.ONOSbenchRest.send(ip=IPlist[0],port=8181, url="/cluster")
167 main.log.debug("Rest call response: " + str(status) + " - " + response)
168 if status == 200:
169 jrsp = json.loads(response)
170 clusterIP = [item["ip"]for item in jrsp["nodes"] if item["status"]== "ACTIVE"]
suibin zhang3b067ea2015-11-05 13:55:21 -0800171 main.log.debug(" IPlist is:" + ",".join(IPlist))
172 main.log.debug("cluster IP is" + ",".join(clusterIP) )
suibin zhangfd266fd2015-10-27 17:06:33 -0700173 if set(IPlist) == set(clusterIP): stepResult = main.TRUE
174
175 utilities.assert_equals( expect = main.TRUE, actual = stepResult,
176 onpass = "ONOS successfully started",
177 onfail = "Failed to start ONOS correctly" )
suibin zhang3b067ea2015-11-05 13:55:21 -0800178 if stepResult is main.FALSE: main.skipCase()
suibin zhangfd266fd2015-10-27 17:06:33 -0700179
180 main.step( "Check cluster app status")
181 stepResult = main.TRUE
182 response = main.ONOSbenchRest.apps( ip=IPlist[0], port = 8181 )
183 if response is not main.FALSE:
184 for item in json.loads(response):
185 if item["state"] not in ["ACTIVE", "INSTALLED"]:
186 main.log.info("Some bundles are not in correct state. ")
187 main.log.info("App states are: " + response)
188 stepResult = main.FALSE
suibin zhang3b067ea2015-11-05 13:55:21 -0800189 break
suibin zhangfd266fd2015-10-27 17:06:33 -0700190 if (item["description"] == "Builtin device drivers") and (item["state"] != "ACTIVE"):
191 main.log.info("Driver app is not in 'ACTIVE' state, but in: " + item["state"])
192 stepResult = main.FALSE
suibin zhang3b067ea2015-11-05 13:55:21 -0800193 break
suibin zhangfd266fd2015-10-27 17:06:33 -0700194 utilities.assert_equals( expect = main.TRUE, actual = stepResult,
195 onpass = "ONOS successfully started",
196 onfail = "Failed to start ONOS correctly" )
suibin zhang3b067ea2015-11-05 13:55:21 -0800197 if stepResult is main.FALSE: main.skipCase()
suibin zhangfd266fd2015-10-27 17:06:33 -0700198
199 main.step(" Activate an APP from REST and check APP status")
200 appResults = list()
201 stepResult = main.TRUE
202 applist = main.params["CASE110"]["apps"].split(",")
203 main.log.info("List of apps to activate: " + str(applist) )
204 for app in applist:
suibin zhangfd266fd2015-10-27 17:06:33 -0700205 appRslt = main.ONOSbenchRest.activateApp(appName=app, ip=IPlist[0], port=8181, check=True)
suibin zhang5ae25332015-11-04 13:56:28 -0800206 time.sleep(5)
suibin zhangfd266fd2015-10-27 17:06:33 -0700207 appResults.append(appRslt)
208 stepResult = stepResult and appRslt
209 main.log.debug("Apps activation result for " + ",".join(applist) + ": " + str(appResults) )
210 utilities.assert_equals( expect = main.TRUE, actual = stepResult,
suibin zhang1a291692015-11-04 12:14:31 -0800211 onpass = "Successfully activated apps",
212 onfail = "Failed to activated apps correctly" )
suibin zhang3b067ea2015-11-05 13:55:21 -0800213 if stepResult is main.FALSE: main.skipCase()
suibin zhangfd266fd2015-10-27 17:06:33 -0700214
215 main.step(" Deactivate an APP from REST and check APP status")
216 appResults = list()
217 stepResult = main.TRUE
218 applist = main.params["CASE110"]["apps"].split(",")
suibin zhang5ae25332015-11-04 13:56:28 -0800219 main.log.info("Apps to deactivate: " + str(applist) )
suibin zhangfd266fd2015-10-27 17:06:33 -0700220 for app in applist:
221 time.sleep(5)
222 appRslt = main.ONOSbenchRest.deactivateApp(appName=app, ip=IPlist[0], port=8181, check=True)
223 appResults.append(appRslt)
224 stepResult = stepResult and appRslt
225 main.log.debug("Apps deactivation result for " + ",".join(applist) + ": " + str(appResults) )
226 utilities.assert_equals( expect = main.TRUE, actual = stepResult,
suibin zhang1a291692015-11-04 12:14:31 -0800227 onpass = "Successfully deactivated apps",
228 onfail = "Failed to deactivated apps correctly" )
suibin zhang3b067ea2015-11-05 13:55:21 -0800229 if stepResult is main.FALSE: main.skipCase()
230
231 def CASE900(self,main):
232 """
233 Check onos logs for exceptions after tests
234 """
235 import pexpect
236 import time
237 import re
238
239 logResult = main.TRUE
240
241 user = main.params["DOCKER"]["user"]
242 pwd = main.params["DOCKER"]["password"]
243
244 main.case("onos Exceptions check")
245 main.step("check onos for any exceptions")
246
247 for ip in IPlist:
248 spawncmd = "ssh -p 8101 " + user + "@" + ip
249 main.log.info("log on node using cmd: " + spawncmd)
250 try:
251 handle = pexpect.spawn(spawncmd)
252 handle.expect("yes/no")
253 handle.sendline("yes")
254 handle.expect("Password:")
255 handle.sendline(pwd)
256 time.sleep(5)
257 handle.expect("onos>")
258 handle.sendline("log:exception-display")
259 handle.expect("onos>")
260 result = handle.before
261 if re.search("Exception", result):
262 main.log.info("onos: " + ip + " Exceptions:" + result)
263 logResult = logResult and main.FALSE
264 else:
265 main.log.info("onos: " + ip + " Exceptions: None")
266 logResult = logResult and main.TRUE
267 except Exception:
268 main.log.exception("Uncaught exception when getting log from onos:" + ip)
269 logResult = logResult and main.FALSE
270
271 utilities.assert_equals( expect = main.TRUE, actual = logResult,
272 onpass = "onos exception check passed",
273 onfail = "onos exeption check failed" )
suibin zhangfd266fd2015-10-27 17:06:33 -0700274
275 def CASE1000( self, main ):
276
277 """
278 Cleanup after tests - stop and delete the containers created; delete "onosproject/onos:latest image
279 """
280 import time
281
suibin zhang3b067ea2015-11-05 13:55:21 -0800282 main.case("Clean up images (ex. none:none tagged) and containers")
suibin zhangfd266fd2015-10-27 17:06:33 -0700283 main.step("Stop onos containers")
284 stepResult = main.TRUE
285 for ctname in NODElist:
286 if main.ONOSbenchDocker.dockerCheckCTName(ctName = "/" + ctname):
287 main.log.info( "stopping docker container: /" + ctname)
288 stopResult = main.ONOSbenchDocker.dockerStopCT( ctName = "/" + ctname )
289 time.sleep(10)
290 rmResult = main.ONOSbenchDocker.dockerRemoveCT( ctName = "/" + ctname)
291 stepResult = stepResult and stopResult and rmResult
292 utilities.assert_equals( expect = main.TRUE, actual = stepResult,
293 onpass = "Container successfully stopped",
294 onfail = "Failed to stopped the container" )
295
296 #main.step( "remove exiting onosproject/onos images")
297 #stepResult = main.ONOSbenchDocker.dockerRemoveImage( image = DOCKERREPO + ":" + DOCKERTAG )
suibin zhang3b067ea2015-11-05 13:55:21 -0800298 main.step( "remove dangling 'none:none' images")
suibin zhangfd266fd2015-10-27 17:06:33 -0700299 stepResult = main.ONOSbenchDocker.dockerRemoveImage( image = "<none>:<none>" )
300 utilities.assert_equals( expect = main.TRUE, actual = stepResult,
suibin zhang3b067ea2015-11-05 13:55:21 -0800301 onpass = "Succeeded in cleaning up images",
302 onfail = "Failed in cleaning up images" )
suibin zhangfd266fd2015-10-27 17:06:33 -0700303