-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathtest_secondary_storage.py
More file actions
405 lines (350 loc) · 16.8 KB
/
test_secondary_storage.py
File metadata and controls
405 lines (350 loc) · 16.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
""" BVT tests for Secondary Storage
"""
#Import Local Modules
import marvin
from marvin.cloudstackTestCase import *
from marvin.cloudstackAPI import *
from marvin.lib.utils import *
from marvin.lib.base import *
from marvin.lib.common import *
from nose.plugins.attrib import attr
from marvin.cloudstackAPI import (listImageStores)
from marvin.cloudstackAPI import (updateImageStore)
#Import System modules
import time
_multiprocess_shared_ = True
class TestSecStorageServices(cloudstackTestCase):
@classmethod
def setUpClass(cls):
cls.apiclient = super(TestSecStorageServices, cls).getClsTestClient().getApiClient()
cls._cleanup = []
return
@classmethod
def tearDownClass(cls):
try:
#Cleanup resources used
cleanup_resources(cls.apiclient, cls._cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
def setUp(self):
self.apiclient = self.testClient.getApiClient()
self.cleanup = []
# Get Zone and pod
self.zones = []
self.pods = []
for zone in self.config.zones:
cmd = listZones.listZonesCmd()
cmd.name = zone.name
z = self.apiclient.listZones(cmd)
if isinstance(z, list) and len(z) > 0:
self.zones.append(z[0].id)
for pod in zone.pods:
podcmd = listPods.listPodsCmd()
podcmd.zoneid = z[0].id
p = self.apiclient.listPods(podcmd)
if isinstance(p, list) and len(p) >0:
self.pods.append(p[0].id)
self.domains = []
dcmd = listDomains.listDomainsCmd()
domains = self.apiclient.listDomains(dcmd)
assert isinstance(domains, list) and len(domains) > 0
for domain in domains:
self.domains.append(domain.id)
return
def tearDown(self):
try:
#Clean up, terminate the created templates
cleanup_resources(self.apiclient, self.cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@attr(tags = ["advanced", "advancedns", "smoke", "basic", "eip", "sg"], required_hardware="false")
def test_01_sys_vm_start(self):
"""Test system VM start
"""
# 1. verify listHosts has all 'routing' hosts in UP state
# 2. verify listStoragePools shows all primary storage pools
# in UP state
# 3. verify that secondary storage was added successfully
list_hosts_response = list_hosts(
self.apiclient,
type='Routing',
)
self.assertEqual(
isinstance(list_hosts_response, list),
True,
"Check list response returns a valid list"
)
# ListHosts has all 'routing' hosts in UP state
self.assertNotEqual(
len(list_hosts_response),
0,
"Check list host response"
)
for host in list_hosts_response:
self.assertEqual(
host.state,
'Up',
"Check state of routing hosts is Up or not"
)
# ListStoragePools shows all primary storage pools in UP state
list_storage_response = list_storage_pools(
self.apiclient,
)
self.assertEqual(
isinstance(list_storage_response, list),
True,
"Check list response returns a valid list"
)
self.assertNotEqual(
len(list_storage_response),
0,
"Check list storage pools response"
)
for primary_storage in list_hosts_response:
self.assertEqual(
primary_storage.state,
'Up',
"Check state of primary storage pools is Up or not"
)
# Poll until all SSVMs are Running, or timeout after 3 minutes
timeout = 180
interval = 15
list_ssvm_response = []
while timeout > 0:
list_ssvm_response = list_ssvms(
self.apiclient,
systemvmtype='secondarystoragevm',
)
self.assertEqual(
isinstance(list_ssvm_response, list),
True,
"Check list response returns a valid list"
)
#Verify SSVM response
self.assertNotEqual(
len(list_ssvm_response),
0,
"Check list System VMs response"
)
if all(ssvm.state == 'Running' for ssvm in list_ssvm_response):
break
time.sleep(interval)
timeout -= interval
for ssvm in list_ssvm_response:
self.assertEqual(
ssvm.state,
'Running',
"Check whether state of SSVM is running"
)
return
@attr(tags = ["advanced", "advancedns", "smoke", "basic", "eip", "sg"], required_hardware="false")
def test_02_sys_template_ready(self):
"""Test system templates are ready
"""
# Validate the following
# If SSVM is in UP state and running
# 1. wait for listTemplates to show all builtin templates downloaded and
# in Ready state
hypervisors = {}
for zone in self.config.zones:
for pod in zone.pods:
for cluster in pod.clusters:
hypervisors[cluster.hypervisor] = "self"
for zid in self.zones:
for k, v in list(hypervisors.items()):
self.debug("Checking BUILTIN templates in zone: %s" %zid)
list_template_response = list_templates(
self.apiclient,
hypervisor=k,
zoneid=zid,
templatefilter=v,
listall=True,
account='system'
)
self.assertEqual(validateList(list_template_response)[0], PASS,\
"templates list validation failed")
# Ensure all BUILTIN templates are downloaded
templateid = None
for template in list_template_response:
if template.templatetype == "BUILTIN":
templateid = template.id
template_response = list_templates(
self.apiclient,
id=templateid,
zoneid=zid,
templatefilter=v,
listall=True,
account='system'
)
if isinstance(template_response, list):
template = template_response[0]
else:
raise Exception("ListTemplate API returned invalid list")
if template.status == 'Download Complete':
self.debug("Template %s is ready in zone %s"%(template.templatetype, zid))
elif 'Downloaded' not in template.status.split():
self.debug("templates status is %s"%template.status)
self.assertEqual(
template.isready,
True,
"Builtin template is not ready %s in zone %s"%(template.status, zid)
)
@attr(tags = ["advanced", "advancedns", "smoke", "basic", "eip", "sg"], required_hardware="false")
def test_03_check_read_only_flag(self):
"""Test the secondary storage read-only flag
"""
# Validate the following
# It is possible to enable/disable the read-only flag on a secondary storage and filter by it
# 1. Make the first secondary storage as read-only and verify its state has been changed
# 2. Search for the read-only storages and make sure ours is in the list
# 3. Make it again read/write and verify it has been set properly
first_storage = self.list_secondary_storages(self.apiclient)[0]
first_storage_id = first_storage['id']
# Step 1
self.update_secondary_storage(self.apiclient, first_storage_id, True)
updated_storage = self.list_secondary_storages(self.apiclient, first_storage_id)[0]
self.assertEqual(
updated_storage['readonly'],
True,
"Check if the secondary storage status has been set to read-only"
)
# Step 2
readonly_storages = self.list_secondary_storages(self.apiclient, readonly=True)
self.assertEqual(
isinstance(readonly_storages, list),
True,
"Check list response returns a valid list"
)
result = any(d['id'] == first_storage_id for d in readonly_storages)
self.assertEqual(
result,
True,
"Check if we are able to list storages by their read-only status"
)
# Step 3
self.update_secondary_storage(self.apiclient, first_storage_id, False)
updated_storage = self.list_secondary_storages(self.apiclient, first_storage_id)[0]
self.assertEqual(
updated_storage['readonly'],
False,
"Check if the secondary storage status has been set back to read-write"
)
@attr(tags = ["advanced", "advancedns", "smoke", "basic", "eip", "sg"], required_hardware="false")
def test_04_migrate_to_read_only_storage(self):
"""Test migrations to a read-only secondary storage
"""
# Validate the following
# It is not possible to migrate a storage to a read-only one
# NOTE: This test requires more than one secondary storage in the system
# 1. Make the first storage read-only
# 2. Try complete migration from the second to the first storage - it should fail
# 3. Try balanced migration from the second to the first storage - it should fail
# 4. Make the first storage read-write again
storages = self.list_secondary_storages(self.apiclient)
if (len(storages)) < 2:
self.skipTest(
"This test requires more than one secondary storage")
first_storage = self.list_secondary_storages(self.apiclient)[0]
first_storage_id = first_storage['id']
second_storage = self.list_secondary_storages(self.apiclient)[1]
second_storage_id = second_storage['id']
# Set the first storage to read-only
self.update_secondary_storage(self.apiclient, first_storage_id, True)
# Try complete migration from second to the first storage
success = False
try:
self.migrate_secondary_storage(self.apiclient, second_storage_id, first_storage_id, "complete")
except Exception as ex:
if re.search("No destination valid store\(s\) available to migrate.", str(ex)):
success = True
else:
self.debug("Secondary storage complete migration to a read-only one\
did not fail appropriately. Error was actually : " + str(ex));
self.assertEqual(success, True, "Check if a complete migration to a read-only storage one fails appropriately")
# Try balanced migration from second to the first storage
success = False
try:
self.migrate_secondary_storage(self.apiclient, second_storage_id, first_storage_id, "balance")
except Exception as ex:
if re.search("No destination valid store\(s\) available to migrate.", str(ex)):
success = True
else:
self.debug("Secondary storage balanced migration to a read-only one\
did not fail appropriately. Error was actually : " + str(ex))
self.assertEqual(success, True, "Check if a balanced migration to a read-only storage one fails appropriately")
# Set the first storage back to read-write
self.update_secondary_storage(self.apiclient, first_storage_id, False)
@attr(tags = ["advanced", "advancedns", "smoke", "basic", "eip", "sg"], required_hardware="false")
def test_05_migrate_to_less_free_space(self):
"""Test migrations when the destination storage has less space
"""
# Validate the following
# Migration to a secondary storage with less space should be refused
# NOTE: This test requires more than one secondary storage in the system
# 1. Try complete migration from a storage with more (or equal) free space - migration should be refused
storages = self.list_secondary_storages(self.apiclient)
if (len(storages)) < 2 or (storages[0]['zoneid'] != storages[1]['zoneid']):
self.skipTest(
"This test requires more than one secondary storage")
first_storage = self.list_secondary_storages(self.apiclient)[0]
first_storage_disksizeused = first_storage['disksizeused']
first_storage_disksizetotal = first_storage['disksizetotal']
second_storage = self.list_secondary_storages(self.apiclient)[1]
second_storage_disksizeused = second_storage['disksizeused']
second_storage_disksizetotal = second_storage['disksizetotal']
first_storage_freespace = first_storage_disksizetotal - first_storage_disksizeused
second_storage_freespace = second_storage_disksizetotal - second_storage_disksizeused
if first_storage_freespace == second_storage_freespace:
self.skipTest(
"This test requires two secondary storages with different free space")
# Setting the storage with more free space as source storage
if first_storage_freespace > second_storage_freespace:
src_storage = first_storage['id']
dst_storage = second_storage['id']
else:
src_storage = second_storage['id']
dst_storage = first_storage['id']
response = self.migrate_secondary_storage(self.apiclient, src_storage, dst_storage, "complete")
success = False
if re.search("has equal or more free space than destination", str(response)):
success = True
else:
self.debug("Secondary storage complete migration to a storage \
with less space was not refused. Here is the command output : " + str(response))
self.assertEqual(success, True, "Secondary storage complete migration to a storage\
with less space was properly refused.")
def list_secondary_storages(self, apiclient, id=None, readonly=None):
cmd = listImageStores.listImageStoresCmd()
cmd.id = id
cmd.readonly = readonly
return apiclient.listImageStores(cmd)
def update_secondary_storage(self, apiclient, id, readonly):
cmd = updateImageStore.updateImageStoreCmd()
cmd.id = id
cmd.readonly = readonly
apiclient.updateImageStore(cmd)
def migrate_secondary_storage(self, apiclient, first_id, second_id, type):
cmd = migrateSecondaryStorageData.migrateSecondaryStorageDataCmd()
cmd.srcpool = first_id
cmd.destpools = second_id
cmd.migrationtype = type
response = apiclient.migrateSecondaryStorageData(cmd)
return response