blob: f62998ba6da52f0f949addf771b84c39d77adddf [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
32
33 main.case("Set case test params")
34 main.step("Initialize test params")
35 NODElist = main.params["SCALE"]["nodelist"].split(',')
36 main.log.info("onos container names are: " + ",".join(NODElist) )
37 IPlist = list()
38 main.testOnDirectory = re.sub( "(/tests)$", "", main.testDir )
39 DOCKERREPO = main.params[ 'DOCKER' ][ 'repo' ]
40 DOCKERTAG = main.params[ 'DOCKER' ][ 'tag' ]
41 CTIDlist = list()
42 utilities.assert_equals( expect = main.TRUE, actual = main.TRUE,
43 onpass = "Params set",
44 onfail = "Failed to set params")
45
46 def CASE5(self, main):
47 """
48 Pull (default) "onosproject/onos:latest" image
49 """
50
51 main.case( "Pull latest onos docker image from onosproject/onos - \
52 it may take sometime if this is a first time pulling." )
53 stepResult = main.FALSE
54 main.step( "pull latest image from onosproject/onos")
55 stepResult = main.ONOSbenchDocker.dockerPull( onosRepo = DOCKERREPO, onosTag = DOCKERTAG )
56 utilities.assert_equals( expect = main.TRUE, actual = stepResult,
57 onpass = "Succeeded in pulling " + DOCKERREPO + ":" + DOCKERTAG,
58 onfail = "Failed to pull " + DOCKERREPO + ":" + DOCKERTAG )
59
60 def CASE10( self, main ):
61 """
62 Start docker containers for list of onos nodes, only if not already existed
63 """
64 import re
65
66 main.case( "Start onos container(s)")
67 image = DOCKERREPO + ":" + DOCKERTAG
68
69 main.step( "Create and (re)start docker container(s) if not already exist")
70 #stepResult = main.FALSE
71
72 for ct in xrange(0, len(NODElist)):
73 if not main.ONOSbenchDocker.dockerCheckCTName( ctName = NODElist[ct] ):
74 main.log.info( "Create new container for onos" + str(ct + 1) )
75 createResult, ctid = main.ONOSbenchDocker.dockerCreateCT( onosImage = image, onosNode = NODElist[ct])
76 CTIDlist.append(ctid)
77 startResult = main.ONOSbenchDocker.dockerStartCT( ctID = ctid )
78 else:
79 main.log.info("Container exists for node onos" + str(ct + 1) + "; restart container with latest image" )
80 startResult = main.ONOSbenchDocker.dockerRestartCT( ctName = NODElist[ct ] )
81
82 utilities.assert_equals( expect = main.TRUE, actual = createResult and startResult,
83 onpass = "Container successfully created",
84 onfail = "Failed to create the container" )
85
86 main.step( "Get IP address on onos containers" )
87 stepResult = main.FALSE
88
89 for ct in xrange(0,len(NODElist)):
90 IPlist.append(main.ONOSbenchDocker.dockerIP( ctName = NODElist[ct] ))
91 main.log.info("Container IPs are: " + ', '.join( IPlist ))
92
93 if IPlist is not []:stepResult = main.TRUE
94 utilities.assert_equals( expect = main.TRUE, actual = stepResult,
95 onpass = "Container successfully started",
96 onfail = "Failed to start the container" )
97
98 def CASE110(self,main):
99 """
100 Steps:
101 1) check default startup standalone onos applications status;
102 2) form onos cluster with all nodes;
103 3) check onos applications status;
104 4) activate apps per params and check app status;
105 5) deactivate apps and check app status
106
107 """
108 import time
109 import json
110
111 startupSleep = int(main.params["SLEEP"]["startup"])
112
113 appToAct = main.params["CASE110"]["apps"]
114 stepResult = main.FALSE
115
116 main.log.info( "Wait for startup, sleep (sec): " + str(startupSleep))
117 time.sleep(startupSleep)
118
119 main.step( "Check initial app states from onos1")
120 stepResult = main.TRUE
121 response = main.ONOSbenchRest.apps( ip=IPlist[0], port = 8181 )
122 main.log.debug("Rest call response is: " + response)
123 if response is not main.FALSE:
124 for item in json.loads(response):
125 if item["state"] not in ["ACTIVE", "INSTALLED"]:
126 main.log.info("Some bundles are not in correct state. ")
127 main.log.info("App states are: " + response)
128 stepResult = main.FALSE
129 break;
130 if (item["description"] == "Builtin device drivers") and (item["state"] != "ACTIVE"):
131 main.log.info("Driver app is not in 'ACTIVE' state, but in: " + item["state"])
132 stepResult = main.FALSE
133 break;
134 utilities.assert_equals( expect = main.TRUE, actual = stepResult,
135 onpass = "ONOS successfully started",
136 onfail = "Failed to start ONOS correctly" )
137 if stepResult is main.FALSE: main.skipCase
138
139 main.step( "Form onos cluster using 'Dependency/onos-form-cluster' util")
140 stepResult = main.FALSE
141 clcmdpath = main.params["CASE110"]["clustercmdpath"]
142 main.log.info("onos-form-cluster cmd path is: " + clcmdpath)
143 dkruser = main.params["DOCKER"]["user"]
144 dkrpasswd = main.params["DOCKER"]["password"]
145 main.ONOSbenchDocker.onosFormCluster(cmdPath = clcmdpath, onosIPs=IPlist, user=dkruser, passwd = dkrpasswd)
146 main.log.info("Wait for cluster to form with sleep time of " + str(startupSleep))
147 time.sleep(startupSleep)
148 status, response = main.ONOSbenchRest.send(ip=IPlist[0],port=8181, url="/cluster")
149 main.log.debug("Rest call response: " + str(status) + " - " + response)
150 if status == 200:
151 jrsp = json.loads(response)
152 clusterIP = [item["ip"]for item in jrsp["nodes"] if item["status"]== "ACTIVE"]
153 if set(IPlist) == set(clusterIP): stepResult = main.TRUE
154
155 utilities.assert_equals( expect = main.TRUE, actual = stepResult,
156 onpass = "ONOS successfully started",
157 onfail = "Failed to start ONOS correctly" )
158 if stepResult is main.FALSE: main.skipCase
159
160 main.step( "Check cluster app status")
161 stepResult = main.TRUE
162 response = main.ONOSbenchRest.apps( ip=IPlist[0], port = 8181 )
163 if response is not main.FALSE:
164 for item in json.loads(response):
165 if item["state"] not in ["ACTIVE", "INSTALLED"]:
166 main.log.info("Some bundles are not in correct state. ")
167 main.log.info("App states are: " + response)
168 stepResult = main.FALSE
169 break;
170 if (item["description"] == "Builtin device drivers") and (item["state"] != "ACTIVE"):
171 main.log.info("Driver app is not in 'ACTIVE' state, but in: " + item["state"])
172 stepResult = main.FALSE
173 break;
174 utilities.assert_equals( expect = main.TRUE, actual = stepResult,
175 onpass = "ONOS successfully started",
176 onfail = "Failed to start ONOS correctly" )
177 if stepResult is main.FALSE: main.skipCase
178
179 main.step(" Activate an APP from REST and check APP status")
180 appResults = list()
181 stepResult = main.TRUE
182 applist = main.params["CASE110"]["apps"].split(",")
183 main.log.info("List of apps to activate: " + str(applist) )
184 for app in applist:
185 time.sleep(5)
186 appRslt = main.ONOSbenchRest.activateApp(appName=app, ip=IPlist[0], port=8181, check=True)
187 appResults.append(appRslt)
188 stepResult = stepResult and appRslt
189 main.log.debug("Apps activation result for " + ",".join(applist) + ": " + str(appResults) )
190 utilities.assert_equals( expect = main.TRUE, actual = stepResult,
191 onpass = "Successfully activate apps",
192 onfail = "Failed to activate apps correctly" )
193 if stepResult is main.FALSE: main.skipCase
194
195 main.step(" Deactivate an APP from REST and check APP status")
196 appResults = list()
197 stepResult = main.TRUE
198 applist = main.params["CASE110"]["apps"].split(",")
199 main.log.info("Apps to activae: " + str(applist) )
200 for app in applist:
201 time.sleep(5)
202 appRslt = main.ONOSbenchRest.deactivateApp(appName=app, ip=IPlist[0], port=8181, check=True)
203 appResults.append(appRslt)
204 stepResult = stepResult and appRslt
205 main.log.debug("Apps deactivation result for " + ",".join(applist) + ": " + str(appResults) )
206 utilities.assert_equals( expect = main.TRUE, actual = stepResult,
207 onpass = "Successfully deactivate apps",
208 onfail = "Failed to deactivate apps correctly" )
209 if stepResult is main.FALSE: main.skipCase
210
211 def CASE1000( self, main ):
212
213 """
214 Cleanup after tests - stop and delete the containers created; delete "onosproject/onos:latest image
215 """
216 import time
217
218 main.step("Stop onos containers")
219 stepResult = main.TRUE
220 for ctname in NODElist:
221 if main.ONOSbenchDocker.dockerCheckCTName(ctName = "/" + ctname):
222 main.log.info( "stopping docker container: /" + ctname)
223 stopResult = main.ONOSbenchDocker.dockerStopCT( ctName = "/" + ctname )
224 time.sleep(10)
225 rmResult = main.ONOSbenchDocker.dockerRemoveCT( ctName = "/" + ctname)
226 stepResult = stepResult and stopResult and rmResult
227 utilities.assert_equals( expect = main.TRUE, actual = stepResult,
228 onpass = "Container successfully stopped",
229 onfail = "Failed to stopped the container" )
230
231 #main.step( "remove exiting onosproject/onos images")
232 #stepResult = main.ONOSbenchDocker.dockerRemoveImage( image = DOCKERREPO + ":" + DOCKERTAG )
233 main.step( "remove exiting '<none>:<none>' images")
234 stepResult = main.ONOSbenchDocker.dockerRemoveImage( image = "<none>:<none>" )
235 utilities.assert_equals( expect = main.TRUE, actual = stepResult,
236 onpass = "Succeeded in deleting image " + "<none>:<none>",
237 onfail = "Failed to delete image " + "<none>:<none>" )
238