Skip to content

Commit 07d555d

Browse files
author
Prasanna Santhanam
committed
Summary: secondary storage tests refactored
Detail: The secondary storage tests are now simplified. Since before running tests we already ensure the health checks - template, builtin, system vms are ready. there is no need to add additonal wait/sleep here. Signed-off-by: Prasanna Santhanam <tsp@apache.org> 1351595163 +0530
1 parent 843e140 commit 07d555d

1 file changed

Lines changed: 69 additions & 229 deletions

File tree

‎test/integration/smoke/test_secondary_storage.py‎

Lines changed: 69 additions & 229 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
# to you under the Apache License, Version 2.0 (the
66
# "License"); you may not use this file except in compliance
77
# with the License. You may obtain a copy of the License at
8-
#
8+
#
99
# http://www.apache.org/licenses/LICENSE-2.0
10-
#
10+
#
1111
# Unless required by applicable law or agreed to in writing,
1212
# software distributed under the License is distributed on an
1313
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -28,35 +28,14 @@
2828
#Import System modules
2929
import time
3030

31-
class Services:
32-
"""Test secondary storage Services
33-
"""
34-
35-
def __init__(self):
36-
self.services = {
37-
"storage": {
38-
"url": "nfs://192.168.100.131/SecStorage"
39-
# Format: File_System_Type/Location/Path
40-
},
41-
"hypervisors": {
42-
0: {
43-
"hypervisor": "XenServer",
44-
"templatefilter": "self",
45-
},
46-
},
47-
"sleep": 60,
48-
"timeout": 5,
49-
}
50-
5131
class TestSecStorageServices(cloudstackTestCase):
52-
32+
5333
@classmethod
5434
def setUpClass(cls):
5535
cls.api_client = super(TestSecStorageServices, cls).getClsTestClient().getApiClient()
56-
cls.services = Services().services
5736
cls._cleanup = []
5837
return
59-
38+
6039
@classmethod
6140
def tearDownClass(cls):
6241
try:
@@ -65,16 +44,32 @@ def tearDownClass(cls):
6544
except Exception as e:
6645
raise Exception("Warning: Exception during cleanup : %s" % e)
6746
return
68-
69-
def setUp(self):
7047

48+
def setUp(self):
7149
self.apiclient = self.testClient.getApiClient()
7250
self.cleanup = []
73-
self.services = Services().services
7451
# Get Zone and pod
75-
self.domain = get_domain(self.apiclient, self.services)
76-
self.zone = get_zone(self.apiclient, self.services)
77-
self.pod = get_pod(self.apiclient, self.zone.id)
52+
self.zones = []
53+
self.pods = []
54+
for zone in self.config.zones:
55+
cmd = listZones.listZonesCmd()
56+
cmd.name = zone.name
57+
z = self.apiclient.listZones(cmd)
58+
if isinstance(z, list) and len(z) > 0:
59+
self.zones.append(z[0].id)
60+
for pod in zone.pods:
61+
podcmd = listPods.listPodsCmd()
62+
podcmd.zoneid = z[0].id
63+
p = self.apiclient.listPods(podcmd)
64+
if isinstance(p, list) and len(p) >0:
65+
self.pods.append(p[0].id)
66+
67+
self.domains = []
68+
dcmd = listDomains.listDomainsCmd()
69+
domains = self.apiclient.listDomains(dcmd)
70+
assert isinstance(domains, list) and len(domains) > 0
71+
for domain in domains:
72+
self.domains.append(domain.id)
7873
return
7974

8075
def tearDown(self):
@@ -85,62 +80,8 @@ def tearDown(self):
8580
raise Exception("Warning: Exception during cleanup : %s" % e)
8681
return
8782

88-
@unittest.skip("skipped - do not add secondary storage")
89-
def test_01_add_sec_storage(self):
90-
"""Test secondary storage
91-
"""
92-
93-
# Validate the following:
94-
# 1. secondary storage should be added to the zone.
95-
# 2. Verify with listHosts and type secondarystorage
96-
97-
cmd = addSecondaryStorage.addSecondaryStorageCmd()
98-
cmd.zoneid = self.zone.id
99-
cmd.url = self.services["storage"]["url"]
100-
sec_storage = self.apiclient.addSecondaryStorage(cmd)
101-
102-
self.debug("Added secondary storage to zone: %s" % self.zone.id)
103-
# Cleanup at the end
104-
self._cleanup.append(sec_storage)
105-
106-
self.assertEqual(
107-
sec_storage.zoneid,
108-
self.zone.id,
109-
"Check zoneid where sec storage is added"
110-
)
111-
112-
list_hosts_response = list_hosts(
113-
self.apiclient,
114-
type='SecondaryStorage',
115-
id=sec_storage.id
116-
)
117-
self.assertEqual(
118-
isinstance(list_hosts_response, list),
119-
True,
120-
"Check list response returns a valid list"
121-
)
122-
self.assertNotEqual(
123-
len(list_hosts_response),
124-
0,
125-
"Check list Hosts response"
126-
)
127-
128-
host_response = list_hosts_response[0]
129-
#Check if host is Up and running
130-
self.assertEqual(
131-
host_response.id,
132-
sec_storage.id,
133-
"Check ID of secondary storage"
134-
)
135-
self.assertEqual(
136-
sec_storage.type,
137-
host_response.type,
138-
"Check type of host from list hosts response"
139-
)
140-
return
141-
14283
@attr(tags = ["advanced", "advancedns", "smoke", "basic", "eip", "sg"])
143-
def test_02_sys_vm_start(self):
84+
def test_01_sys_vm_start(self):
14485
"""Test system VM start
14586
"""
14687

@@ -152,8 +93,6 @@ def test_02_sys_vm_start(self):
15293
list_hosts_response = list_hosts(
15394
self.apiclient,
15495
type='Routing',
155-
zoneid=self.zone.id,
156-
podid=self.pod.id
15796
)
15897
self.assertEqual(
15998
isinstance(list_hosts_response, list),
@@ -176,8 +115,6 @@ def test_02_sys_vm_start(self):
176115
# ListStoragePools shows all primary storage pools in UP state
177116
list_storage_response = list_storage_pools(
178117
self.apiclient,
179-
zoneid=self.zone.id,
180-
podid=self.pod.id
181118
)
182119
self.assertEqual(
183120
isinstance(list_storage_response, list),
@@ -197,58 +134,11 @@ def test_02_sys_vm_start(self):
197134
"Check state of primary storage pools is Up or not"
198135
)
199136

200-
# Secondary storage is added successfully
201-
timeout = self.services["timeout"]
202-
while True:
203-
list_hosts_response = list_hosts(
204-
self.apiclient,
205-
type='SecondaryStorageVM',
206-
zoneid=self.zone.id,
207-
)
208-
209-
if not isinstance(list_hosts_response, list):
210-
# Sleep to ensure Secondary storage is Up
211-
time.sleep(int(self.services["sleep"]))
212-
timeout = timeout - 1
213-
elif timeout == 0 or isinstance(list_hosts_response, list):
214-
break
215-
216-
self.assertEqual(
217-
isinstance(list_hosts_response, list),
218-
True,
219-
"Check list response returns a valid list"
220-
)
221-
222-
self.assertNotEqual(
223-
len(list_hosts_response),
224-
0,
225-
"Check list Hosts response"
226-
)
227-
228-
host_response = list_hosts_response[0]
229-
#Check if host is Up and running
230-
self.assertEqual(
231-
host_response.state,
232-
'Up',
233-
"Check state of secondary storage"
234-
)
235-
self.debug("Checking SSVM status in zone: %s" % self.zone.id)
236-
237-
timeout = self.services["timeout"]
137+
list_ssvm_response = list_ssvms(
138+
self.apiclient,
139+
systemvmtype='secondarystoragevm',
140+
)
238141

239-
while True:
240-
list_ssvm_response = list_ssvms(
241-
self.apiclient,
242-
systemvmtype='secondarystoragevm',
243-
zoneid=self.zone.id,
244-
)
245-
if not isinstance(list_ssvm_response, list):
246-
# Sleep to ensure SSVMs are Up and Running
247-
time.sleep(int(self.services["sleep"]))
248-
timeout = timeout - 1
249-
elif timeout == 0 or isinstance(list_ssvm_response, list):
250-
break
251-
252142
self.assertEqual(
253143
isinstance(list_ssvm_response, list),
254144
True,
@@ -270,7 +160,7 @@ def test_02_sys_vm_start(self):
270160
return
271161

272162
@attr(tags = ["advanced", "advancedns", "smoke", "basic", "eip", "sg"])
273-
def test_03_sys_template_ready(self):
163+
def test_02_sys_template_ready(self):
274164
"""Test system templates are ready
275165
"""
276166

@@ -279,100 +169,50 @@ def test_03_sys_template_ready(self):
279169
# 1. wait for listTemplates to show all builtin templates downloaded and
280170
# in Ready state
281171

282-
for k, v in self.services["hypervisors"].items():
172+
hypervisors = {}
173+
for zone in self.config.zones:
174+
for pod in zone.pods:
175+
for cluster in pod.clusters:
176+
hypervisors[cluster.hypervisor] = "self"
283177

284-
self.debug("Downloading BUILTIN templates in zone: %s" %
285-
self.zone.id)
286-
287-
list_template_response = list_templates(
288-
self.apiclient,
289-
hypervisor=v["hypervisor"],
290-
zoneid=self.zone.id,
291-
templatefilter=v["templatefilter"],
292-
listall=True,
293-
account='system',
294-
domainid=self.domain.id
295-
)
178+
for zid in self.zones:
179+
for k, v in hypervisors.items():
180+
self.debug("Checking BUILTIN templates in zone: %s" %zid)
181+
list_template_response = list_templates(
182+
self.apiclient,
183+
hypervisor=k,
184+
zoneid=zid,
185+
templatefilter=v,
186+
listall=True,
187+
account='system'
188+
)
296189

297-
# Ensure all BUILTIN templates are downloaded
298-
templateid = None
299-
for template in list_template_response:
300-
if template.templatetype == "BUILTIN":
301-
templateid = template.id
190+
# Ensure all BUILTIN templates are downloaded
191+
templateid = None
192+
for template in list_template_response:
193+
if template.templatetype == "BUILTIN":
194+
templateid = template.id
302195

303-
# Wait to start a downloading of template
304-
time.sleep(self.services["sleep"])
305-
306-
while True and (templateid != None):
307-
308-
timeout = self.services["timeout"]
309-
while True:
310196
template_response = list_templates(
311197
self.apiclient,
312198
id=templateid,
313-
zoneid=self.zone.id,
314-
templatefilter=v["templatefilter"],
199+
zoneid=zid,
200+
templatefilter=v,
315201
listall=True,
316-
account='system',
317-
domainid=self.domain.id
202+
account='system'
318203
)
319-
320204
if isinstance(template_response, list):
321205
template = template_response[0]
322-
break
323-
324-
elif timeout == 0:
325-
raise Exception("List template API call failed.")
326-
327-
time.sleep(1)
328-
timeout = timeout - 1
329-
330-
# If template is ready,
331-
# template.status = Download Complete
332-
# Downloading - x% Downloaded
333-
# Error - Any other string
334-
if template.status == 'Download Complete' :
335-
break
336-
elif 'Downloaded' not in template.status.split():
337-
raise Exception
338-
elif 'Downloaded' in template.status.split():
339-
time.sleep(self.services["sleep"])
340-
341-
#Ensuring the template is in ready state
342-
time.sleep(self.services["sleep"])
343-
344-
timeout = self.services["timeout"]
345-
while True:
346-
template_response = list_templates(
347-
self.apiclient,
348-
id=templateid,
349-
zoneid=self.zone.id,
350-
templatefilter=v["templatefilter"],
351-
listall=True,
352-
account='system',
353-
domainid=self.domain.id
354-
)
355-
356-
if isinstance(template_response, list):
357-
template = template_response[0]
358-
break
359-
360-
elif timeout == 0:
361-
raise Exception("List template API call failed.")
362-
363-
time.sleep(1)
364-
timeout = timeout - 1
365-
366-
self.assertEqual(
367-
isinstance(template_response, list),
368-
True,
369-
"Check list response returns a valid list"
370-
)
371-
template = template_response[0]
372-
373-
self.assertEqual(
374-
template.isready,
375-
True,
376-
"Check whether state of template is ready or not"
377-
)
378-
return
206+
else:
207+
raise Exception("ListTemplate API returned invalid list")
208+
209+
if template.status == 'Download Complete':
210+
self.debug("Template %s is ready in zone %s"%(template.templatetype, zid))
211+
elif 'Downloaded' not in template.status.split():
212+
self.debug("templates status is %s"%template.status)
213+
214+
self.assertEqual(
215+
template.isready,
216+
True,
217+
"Builtin template is not ready %s in zone %s"%(template.status, zid)
218+
)

0 commit comments

Comments
 (0)