forked from apache/cloudstack
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtest_rootvolume_resize.py
More file actions
1137 lines (1041 loc) · 49.2 KB
/
test_rootvolume_resize.py
File metadata and controls
1137 lines (1041 loc) · 49.2 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
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# 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.
""" P1 tests for testing resize of root volume functionality
Test Plan: https://cwiki.apache.org/confluence/display/CLOUDSTACK/
Root+Resize+Support
Issue Link: https://issues.apache.org/jira/browse/CLOUDSTACK-9829
"""
# Import Local Modules
from nose.plugins.attrib import attr
from marvin.cloudstackTestCase import cloudstackTestCase
import unittest
from marvin.lib.base import (Account,
ServiceOffering,
VirtualMachine,
Resources,
Domain,
Volume,
Snapshot,
Template,
VmSnapshot,
Host,
Configurations,
StoragePool)
from marvin.lib.common import (get_domain,
get_zone,
get_template,
matchResourceCount,
list_snapshots,
list_hosts,
list_configurations,
list_storage_pools)
from marvin.lib.utils import (cleanup_resources,
validateList)
from marvin.codes import (PASS,
FAIL,
FAILED,
RESOURCE_PRIMARY_STORAGE,
INVALID_INPUT)
from marvin.lib.utils import checkVolumeSize
import time
from marvin.sshClient import SshClient
class TestResizeVolume(cloudstackTestCase):
@classmethod
def setUpClass(cls):
cls.testClient = super(TestResizeVolume, cls).getClsTestClient()
cls.api_client = cls.testClient.getApiClient()
cls.hypervisor = (cls.testClient.getHypervisorInfo()).lower()
cls.storageID = None
# Fill services from the external config file
cls.services = cls.testClient.getParsedTestDataConfig()
# Get Zone, Domain and templates
cls.domain = get_domain(cls.api_client)
cls.zone = get_zone(
cls.api_client,
cls.testClient.getZoneForTests())
cls.services["mode"] = cls.zone.networktype
cls._cleanup = []
cls.unsupportedStorageType = False
cls.unsupportedHypervisorType = False
cls.updateclone = False
if cls.hypervisor not in ['xenserver',"kvm","vmware"]:
cls.unsupportedHypervisorType=True
return
cls.template = get_template(
cls.api_client,
cls.zone.id
)
cls.services["virtual_machine"]["zoneid"] = cls.zone.id
cls.services["virtual_machine"]["template"] = cls.template.id
cls.services["volume"]["zoneid"] = cls.zone.id
try:
cls.parent_domain = Domain.create(cls.api_client,
services=cls.services[
"domain"],
parentdomainid=cls.domain.id)
cls.parentd_admin = Account.create(cls.api_client,
cls.services["account"],
admin=True,
domainid=cls.parent_domain.id)
cls._cleanup.append(cls.parentd_admin)
cls._cleanup.append(cls.parent_domain)
list_pool_resp = list_storage_pools(cls.api_client,
account=cls.parentd_admin.name,domainid=cls.parent_domain.id)
res = validateList(list_pool_resp)
if res[2]== INVALID_INPUT:
raise Exception("Failed to list storage pool-no storagepools found ")
#Identify the storage pool type and set vmware fullclone to true if storage is VMFS
if cls.hypervisor == 'vmware':
for strpool in list_pool_resp:
if strpool.type.lower() == "vmfs" or strpool.type.lower()== "networkfilesystem":
list_config_storage_response = list_configurations(
cls.api_client
, name=
"vmware.create.full.clone",storageid=strpool.id)
res = validateList(list_config_storage_response)
if res[2]== INVALID_INPUT:
raise Exception("Failed to list configurations ")
if list_config_storage_response[0].value == "false":
Configurations.update(cls.api_client,
"vmware.create.full.clone",
value="true",storageid=strpool.id)
cls.updateclone = True
StoragePool.update(cls.api_client,id=strpool.id,tags="scsi")
cls.storageID = strpool.id
cls.unsupportedStorageType = False
break
else:
cls.unsupportedStorageType = True
# Creating service offering with normal config
cls.service_offering = ServiceOffering.create(
cls.api_client,
cls.services["service_offering"])
cls.services_offering_vmware=ServiceOffering.create(
cls.api_client,cls.services["service_offering"],tags="scsi")
cls._cleanup.extend([cls.service_offering,cls.services_offering_vmware])
except Exception as e:
cls.tearDownClass()
return
@classmethod
def tearDownClass(cls):
try:
# Cleanup resources used
if cls.updateclone:
Configurations.update(cls.api_client,
"vmware.create.full.clone",
value="false",storageid=cls.storageID)
cleanup_resources(cls.api_client, cls._cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
def setUp(self):
if self.unsupportedStorageType:
self.skipTest("Tests are Skipped - unsupported Storage type used ")
elif self.unsupportedHypervisorType:
self.skipTest("Tests are Skipped - unsupported Hypervisor type used")
self.apiclient = self.testClient.getApiClient()
self.dbclient = self.testClient.getDbConnection()
self.cleanup = []
return
def tearDown(self):
try:
# Clean up, terminate the created instance, volumes and snapshots
cleanup_resources(self.apiclient, self.cleanup)
pass
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
def updateResourceLimits(self, accountLimit=None, domainLimit=None):
"""Update primary storage limits of the parent domain and its
child domains"""
try:
if domainLimit:
# Update resource limit for domain
Resources.updateLimit(self.apiclient, resourcetype=10,
max=domainLimit,
domainid=self.parent_domain.id)
if accountLimit:
# Update resource limit for domain
Resources.updateLimit(self.apiclient,
resourcetype=10,
max=accountLimit,
account=self.parentd_admin.name,
domainid=self.parent_domain.id)
except Exception as e:
return [FAIL, e]
return [PASS, None]
def setupAccounts(self):
try:
self.parent_domain = Domain.create(self.apiclient,
services=self.services[
"domain"],
parentdomainid=self.domain.id)
self.parentd_admin = Account.create(self.apiclient,
self.services["account"],
admin=True,
domainid=self.parent_domain.id)
# Cleanup the resources created at end of test
self.cleanup.append(self.parent_domain)
self.cleanup.append(self.parentd_admin)
except Exception as e:
return [FAIL, e]
return [PASS, None]
def chk_volume_resize(self, apiclient, vm):
self.assertEqual(
vm.state,
"Running",
msg="VM is not in Running state"
)
# get root vol from created vm, verify its size
list_volume_response = Volume.list(
apiclient,
virtualmachineid=vm.id,
type='ROOT',
listall='True'
)
rootvolume = list_volume_response[0]
if vm.state == "Running" and vm.hypervisor.lower() == "xenserver":
self.virtual_machine.stop(apiclient)
time.sleep(self.services["sleep"])
if vm.hypervisor.lower() == "vmware":
rootdiskcontroller = self.getDiskController(vm)
if rootdiskcontroller!="scsi":
raise Exception("root volume resize only supported on scsi disk ,"
"please check rootdiskcontroller type")
rootvolobj = Volume(rootvolume.__dict__)
newsize = (rootvolume.size >> 30) + 2
success = False
if rootvolume is not None:
try:
rootvolobj.resize(apiclient, size=newsize)
if vm.hypervisor.lower() == "xenserver":
self.virtual_machine.start(apiclient)
time.sleep(self.services["sleep"])
ssh = SshClient(self.virtual_machine.ssh_ip, 22,
"root", "password")
newsizeinbytes = newsize * 1024 * 1024 * 1024
if vm.hypervisor.lower() == "xenserver":
volume_name = "/dev/xvd" + \
chr(ord('a') +
int(
list_volume_response[0].deviceid))
self.debug(" Using XenServer"
" volume_name: %s" % volume_name)
ret = checkVolumeSize(ssh_handle=ssh,
volume_name=volume_name,
size_to_verify=newsizeinbytes)
success = True
elif vm.hypervisor.lower() == "kvm":
volume_name = "/dev/vd" + chr(ord('a') + int
(list_volume_response[0]
.deviceid))
self.debug(" Using KVM volume_name:"
" %s" % volume_name)
ret = checkVolumeSize(ssh_handle=ssh,
volume_name=volume_name,
size_to_verify=newsizeinbytes)
success = True
elif vm.hypervisor.lower() == "vmware":
ret = checkVolumeSize(ssh_handle=ssh,
volume_name="/dev/sdb",
size_to_verify=newsizeinbytes)
success = True
self.debug(" Volume Size Expected %s "
" Actual :%s" % (newsizeinbytes, ret[1]))
except Exception as e:
# need to write the rootdisk controller code.
if vm.hypervisor == "vmware" and rootdiskcontroller == "ide":
assert "Found unsupported root disk " \
"controller :ide" in e.message, \
"able to resize ide root volume Testcase failed"
else:
raise Exception("fail to resize the volume: %s" % e)
else:
self.debug("hypervisor %s unsupported for test "
", verifying it errors properly" % self.hypervisor)
success = False
return success
def getDiskController(self, vm, diskcontroller="ide"):
if vm.hypervisor.lower() == "vmware":
try:
qresultvmuuid = self.dbclient.execute(
"select id from vm_instance where uuid = '%s' ;" %
vm.id
)
self.assertNotEqual(
len(qresultvmuuid),
0,
"Check DB Query result set"
)
vmid = int(qresultvmuuid[0][0])
qresult = self.dbclient.execute(
"select rootDiskController from"
" vm_instance_details where id = '%s';" % vmid
)
self.debug("Query result: %s" % qresult)
diskcontroller = qresult[0][0]
except Exception as e:
raise Exception("Warning: Exception while"
" checking usage event for the "
"root_volume_resize : %s" % e)
return diskcontroller
@attr(tags=["advanced"], required_hardware="true")
def test_01_create__snapshot_new_resized_rootvolume_size(self):
"""Test create snapshot on resized root volume
# Validate the following
# 1. Deploy a VM without any disk offering (only root disk)
# 2. Perform(resize) of the root volume
# 3. Perform snapshot on resized volume
"""
# deploy a vm
try:
if self.updateclone:
self.virtual_machine = VirtualMachine.create(
self.apiclient, self.services["virtual_machine"],
accountid=self.parentd_admin.name,
domainid=self.parent_domain.id,
serviceofferingid=self.services_offering_vmware.id,
mode=self.zone.networktype
)
else:
self.virtual_machine = VirtualMachine.create(
self.apiclient, self.services["virtual_machine"],
accountid=self.parentd_admin.name,
domainid=self.parent_domain.id,
serviceofferingid=self.service_offering.id,
mode=self.zone.networktype
)
# listVirtual machine
list_vms = VirtualMachine.list(self.apiclient,
id=self.virtual_machine.id)
self.debug(
"Verify listVirtualMachines response for virtual machine: %s" %
self.virtual_machine.id
)
res = validateList(list_vms)
self.assertNotEqual(res[2], INVALID_INPUT, "Invalid list response")
vm = list_vms[0]
self.assertEqual(
vm.id,
self.virtual_machine.id,
"Virtual Machine ids do not match"
)
self.assertEqual(
vm.name,
self.virtual_machine.name,
"Virtual Machine names do not match"
)
self.assertEqual(
vm.state,
"Running",
msg="VM is not in Running state"
)
result = self.chk_volume_resize(self.apiclient, vm)
if result:
# get root vol from created vm, verify it is correct size
list_volume_response = Volume.list(
self.apiclient,
virtualmachineid=
self.virtual_machine.id,
type='ROOT',
listall='True'
)
res = validateList(list_volume_response)
self.assertNotEqual(res[2], INVALID_INPUT, "listVolumes returned invalid object in response")
rootvolume = list_volume_response[0]
self.debug("Creating a Snapshot from root volume: "
"%s" % rootvolume.id)
snapshot = Snapshot.create(
self.apiclient,
rootvolume.id,
account=self.parentd_admin.name,
domainid=self.parent_domain.id
)
snapshots = list_snapshots(
self.apiclient,
id=snapshot.id
)
res = validateList(snapshots)
self.assertNotEqual(res[2], INVALID_INPUT, "Invalid list response")
self.assertEqual(
snapshots[0].id,
snapshot.id,
"Check resource id in list resources call"
)
else:
self.debug("Volume resize is failed")
except Exception as e:
raise Exception("Exception while performing"
" the snapshot on resized root volume"
" test case: %s" % e)
self.cleanup.append(self.virtual_machine)
self.cleanup.append(snapshot)
return
@attr(tags=["advanced"], required_hardware="true")
def test_02_create__template_new_resized_rootvolume_size(self):
"""Test create Template resized root volume
# Validate the following
# 1. Deploy a VM without any disk offering (only root disk)
# 2. Perform(resize) of the root volume
# 3. Stop the vm
# 4. Create a template from resized root volume
"""
result = self.setupAccounts()
self.assertEqual(result[0], PASS, result[1])
apiclient = self.testClient.getUserApiClient(
UserName=self.parentd_admin.name,
DomainName=self.parentd_admin.domain)
self.assertNotEqual(apiclient, FAILED, "Failed to get api client\
of account: %s" % self.parentd_admin.name)
# deploy a vm
try:
if self.updateclone:
self.virtual_machine = VirtualMachine.create(
apiclient, self.services["virtual_machine"],
accountid=self.parentd_admin.name,
domainid=self.parent_domain.id,
serviceofferingid=self.services_offering_vmware.id,
mode=self.zone.networktype
)
else:
self.virtual_machine = VirtualMachine.create(
apiclient, self.services["virtual_machine"],
accountid=self.parentd_admin.name,
domainid=self.parent_domain.id,
serviceofferingid=self.service_offering.id,
mode=self.zone.networktype
)
# listVirtual macine
list_vms = VirtualMachine.list(apiclient,
id=self.virtual_machine.id)
self.debug("Verify listVirtualMachines response"
" for virtual machine: %s" % self.virtual_machine.id
)
res = validateList(list_vms)
self.assertNotEqual(res[2], INVALID_INPUT, "Invalid list response")
self.cleanup.append(self.virtual_machine)
vm = list_vms[0]
self.assertEqual(
vm.id,
self.virtual_machine.id,
"Virtual Machine ids do not match"
)
self.assertEqual(
vm.name,
self.virtual_machine.name,
"Virtual Machine names do not match"
)
self.assertEqual(
vm.state,
"Running",
msg="VM is not in Running state"
)
# get root vol from created vm, verify it is correct size
list_volume_response = Volume.list(
apiclient,
virtualmachineid=
self.virtual_machine.id,
type='ROOT',
listall='True'
)
res = validateList(list_volume_response)
self.assertNotEqual(res[2], INVALID_INPUT, "listVolumes returned invalid object in response")
rootvolume = list_volume_response[0]
newsize = (rootvolume.size >> 30) + 2
result = self.chk_volume_resize(apiclient, vm)
if result:
try:
# create a template from stopped VM instances root volume
if vm.state == "Running":
self.virtual_machine.stop(apiclient)
template_from_root = Template.create(
apiclient,
self.services["template"],
volumeid=rootvolume.id,
account=self.parentd_admin.name,
domainid=self.parent_domain.id)
list_template_response = Template.list(
apiclient,
id=template_from_root.id,
templatefilter="all")
res = validateList(list_template_response)
self.assertNotEqual(res[2], INVALID_INPUT, "Check if template exists in ListTemplates")
# Deploy new virtual machine using template
self.virtual_machine2 = VirtualMachine.create(
apiclient,
self.services["virtual_machine"],
templateid=template_from_root.id,
accountid=self.parentd_admin.name,
domainid=self.parent_domain.id,
serviceofferingid=self.service_offering.id,
)
vm_response = VirtualMachine.list(
apiclient,
id=self.virtual_machine2.id,
account=self.parentd_admin.name,
domainid=self.parent_domain.id
)
res = validateList(vm_response)
self.assertNotEqual(res[2], INVALID_INPUT, "Check for list VM response return valid list")
self.cleanup.append(self.virtual_machine2)
self.cleanup.reverse()
vm2 = vm_response[0]
self.assertEqual(
vm2.state,
'Running',
"Check the state of VM created from Template"
)
list_volume_response = Volume.list(
apiclient,
virtualmachineid=vm2.id,
type='ROOT',
listall='True'
)
self.assertEqual(
list_volume_response[0].size,
(newsize * 1024 * 1024 * 1024),
"Check for root volume size not matched with template size"
)
except Exception as e:
raise Exception("Exception while resizing the "
"root volume: %s" % e)
else:
self.debug(" volume resize failed for root volume")
except Exception as e:
raise Exception("Exception while performing"
" template creation from "
"resized_root_volume : %s" % e)
return
# @attr(tags=["advanced"], required_hardware="true")
@attr(tags=["TODO"], required_hardware="true")
def test_03_vmsnapshot__on_resized_rootvolume_vm(self):
"""Test vmsnapshot on resized root volume
# Validate the following
# 1. Deploy a VM without any disk offering (only root disk)
# 2. Perform(resize) of the root volume
# 3. Perform VM snapshot on VM
"""
# deploy a vm
try:
if self.updateclone:
self.virtual_machine = VirtualMachine.create(
self.apiclient, self.services["virtual_machine"],
accountid=self.parentd_admin.name,
domainid=self.parent_domain.id,
serviceofferingid=self.services_offering_vmware.id,
mode=self.zone.networktype
)
else:
self.virtual_machine = VirtualMachine.create(
self.apiclient, self.services["virtual_machine"],
accountid=self.parentd_admin.name,
domainid=self.parent_domain.id,
serviceofferingid=self.service_offering.id,
mode=self.zone.networktype
)
# listVirtual macine
list_vms = VirtualMachine.list(self.apiclient,
id=self.virtual_machine.id)
self.debug(
"Verify listVirtualMachines response for virtual machine: %s" \
% self.virtual_machine.id
)
res = validateList(list_vms)
self.assertNotEqual(res[2], INVALID_INPUT, "Invalid list response")
self.cleanup.append(self.virtual_machine)
vm = list_vms[0]
self.assertEqual(
vm.id,
self.virtual_machine.id,
"Virtual Machine ids do not match"
)
# get root vol from created vm, verify it is correct size
list_volume_response = Volume.list(
self.apiclient,
virtualmachineid=
self.virtual_machine.id,
type='ROOT',
listall='True'
)
res = validateList(list_volume_response)
self.assertNotEqual(res[2], INVALID_INPUT, "listVolumes returned invalid object in response")
rootvolume = list_volume_response[0]
newsize = (rootvolume.size >> 30) + 2
result = self.chk_volume_resize(self.apiclient, vm)
if result:
try:
if 'kvm' in self.hypervisor.lower():
self.virtual_machine.stop(self.apiclient)
virtualmachine_snapshot = VmSnapshot.create \
(self.apiclient, self.virtual_machine.id)
virtulmachine_snapshot_list = VmSnapshot. \
list(self.apiclient,
vmsnapshotid=virtualmachine_snapshot.id)
status = validateList(virtulmachine_snapshot_list)
self.assertEqual(
PASS,
status[0],
"Listing of configuration failed")
self.assertEqual(virtualmachine_snapshot.id,
virtulmachine_snapshot_list[0].id,
"Virtual Machine Snapshot id do not match")
except Exception as e:
raise Exception("Issue CLOUDSTACK-10080: Exception while performing"
" vmsnapshot: %s" % e)
else:
self.debug("volume resize failed for root volume")
except Exception as e:
raise Exception("Exception while performing"
" vmsnapshot on resized volume Test: %s" % e)
@attr(tags=["advanced"], required_hardware="true")
def test_04_vmreset_after_migrate_vm__rootvolume_resized(self):
"""Test migrate vm after root volume resize
# Validate the following
# 1. Deploy a VM without any disk offering (only root disk)
# 2. Perform(resize) of the root volume
# 3. migrate vm from host to another
# 4. perform vm reset after vm migration
"""
try:
if self.updateclone:
self.virtual_machine = VirtualMachine.create(
self.apiclient, self.services["virtual_machine"],
accountid=self.parentd_admin.name,
domainid=self.parent_domain.id,
serviceofferingid=self.services_offering_vmware.id,
mode=self.zone.networktype
)
else:
self.virtual_machine = VirtualMachine.create(
self.apiclient, self.services["virtual_machine"],
accountid=self.parentd_admin.name,
domainid=self.parent_domain.id,
serviceofferingid=self.service_offering.id,
mode=self.zone.networktype
)
# listVirtual macine
list_vms = VirtualMachine.list(self.apiclient,
id=self.virtual_machine.id)
self.debug(
"Verify listVirtualMachines response for virtual machine: %s" \
% self.virtual_machine.id
)
res = validateList(list_vms)
self.assertNotEqual(res[2], INVALID_INPUT, "Invalid list response")
self.cleanup.append(self.virtual_machine)
vm = list_vms[0]
self.assertEqual(
vm.id,
self.virtual_machine.id,
"Virtual Machine ids do not match"
)
# get root vol from created vm, verify it is correct size
list_volume_response = Volume.list(
self.apiclient,
virtualmachineid=
self.virtual_machine.id,
type='ROOT',
listall='True'
)
res = validateList(list_volume_response)
self.assertNotEqual(res[2], INVALID_INPUT, "listVolumes returned invalid object in response")
rootvolume = list_volume_response[0]
result = self.chk_volume_resize(self.apiclient, vm)
if result:
try:
list_host_response = list_hosts(
self.apiclient,
id=self.virtual_machine.hostid
)
res = validateList(list_host_response)
self.assertNotEqual(res[2], INVALID_INPUT, "listHosts returned invalid object in response")
sourcehost = list_host_response[0]
try:
self.list_hosts_suitable = Host.listForMigration \
(self.apiclient,
virtualmachineid=self.virtual_machine.id
)
except Exception as e:
self.debug("Not found suitable host")
raise Exception("Exception while getting hosts"
" list suitable for migration: %s" % e)
self.virtualmachine_migrate_response = \
self.virtual_machine.migrate(
self.apiclient,
self.list_hosts_suitable[0].id)
list_vms = VirtualMachine.list(
self.apiclient,
id=self.virtual_machine.id,
hostid=self.list_hosts_suitable[0].id)
res = validateList(list_vms)
self.assertNotEqual(res[2], INVALID_INPUT, "listVirtualMachines returned "
"invalid object in response")
self.virtual_machine_reset = self.virtual_machine.restore \
(self.apiclient,
self.services["virtual_machine"]["template"])
list_restorevolume_response = Volume.list(
self.apiclient,
virtualmachineid=
self.virtual_machine.id,
type='ROOT',
listall='True'
)
restorerootvolume = list_restorevolume_response[0]
self.assertEqual(rootvolume.size, restorerootvolume.size,
"root volume and restore root"
" volume size differs - CLOUDSTACK-10079")
except Exception as e:
raise Exception("Warning: Exception "
"during VM migration: %s" % e)
except Exception as e:
raise Exception("Warning: Exception during executing"
" the test-migrate_vm_after_rootvolume_resize: %s" % e)
return
@attr(tags=["advanced"], required_hardware="true")
def test_05_vmdeployment_with_size(self):
"""Test vm deployment with new rootdisk size parameter
# Validate the following
# 1. Deploy a VM without any disk offering (only root disk)
# 2. Verify the root disksize after deployment
"""
templateSize = (self.template.size / (1024 ** 3))
newsize = templateSize + 2
# deploy a vm
try:
if self.updateclone:
self.virtual_machine = VirtualMachine.create(
self.apiclient, self.services["virtual_machine"],
accountid=self.parentd_admin.name,
domainid=self.parent_domain.id,
serviceofferingid=self.services_offering_vmware.id,
mode=self.zone.networktype
)
else:
self.virtual_machine = VirtualMachine.create(
self.apiclient, self.services["virtual_machine"],
accountid=self.parentd_admin.name,
domainid=self.parent_domain.id,
serviceofferingid=self.service_offering.id,
mode=self.zone.networktype
)
# listVirtual macine
list_vms = VirtualMachine.list(self.apiclient,
id=self.virtual_machine.id)
self.debug(
"Verify listVirtualMachines response for virtual machine: %s"
% self.virtual_machine.id
)
res = validateList(list_vms)
self.assertNotEqual(res[2], INVALID_INPUT, "Invalid list response")
self.cleanup.append(self.virtual_machine)
vm = list_vms[0]
ssh = SshClient(self.virtual_machine.ssh_ip, 22, "root",
"password")
newsize = newsize * 1024 * 1024 * 1024
list_volume_response = Volume.list(
self.apiclient,
virtualmachineid=
self.virtual_machine.id,
type='ROOT',
listall='True'
)
res = validateList(list_volume_response)
self.assertNotEqual(res[2], INVALID_INPUT, "listVolumes returned invalid object in response")
if vm.hypervisor.lower() == "xenserver":
volume_name = "/dev/xvd" + chr(ord('a') + int(
list_volume_response[0].deviceid))
self.debug(" Using XenServer"
" volume_name: %s" % volume_name)
ret = checkVolumeSize(ssh_handle=ssh,
volume_name=volume_name,
size_to_verify=newsize)
elif vm.hypervisor.lower() == "kvm":
volume_name = "/dev/vd" + chr(ord('a')
+ int(
list_volume_response[0].deviceid))
self.debug(" Using KVM volume_name: %s" % volume_name)
ret = checkVolumeSize(ssh_handle=ssh,
volume_name=volume_name,
size_to_verify=newsize)
elif vm.hypervisor.lower() == "vmware":
ret = checkVolumeSize(ssh_handle=ssh,
volume_name="/dev/sdb",
size_to_verify=newsize)
self.debug(" Volume Size Expected %s"
" Actual :%s" % (newsize, ret[1]))
except Exception as e:
raise Exception("Warning: Exception during"
" VM deployment with new"
" rootdisk parameter : %s" % e)
@attr(tags=["advanced"], required_hardware="true")
def test_06_resized_rootvolume_with_lessvalue(self):
"""Test resize root volume with less than original volume size
# Validate the following
# 1. Deploy a VM without any disk offering (only root disk)
# 2. Perform(resize) of the root volume with less
than current root volume
# 3. Check for proper error message
"""
# deploy a vm
try:
if self.updateclone:
self.virtual_machine = VirtualMachine.create(
self.apiclient, self.services["virtual_machine"],
accountid=self.parentd_admin.name,
domainid=self.parent_domain.id,
serviceofferingid=self.services_offering_vmware.id,
mode=self.zone.networktype
)
else:
self.virtual_machine = VirtualMachine.create(
self.apiclient, self.services["virtual_machine"],
accountid=self.parentd_admin.name,
domainid=self.parent_domain.id,
serviceofferingid=self.service_offering.id,
mode=self.zone.networktype
)
# listVirtual macine
time.sleep(self.services["sleep"])
list_vms = VirtualMachine.list(self.apiclient,
id=self.virtual_machine.id)
self.debug(
"Verify listVirtualMachines response for virtual machine: %s" \
% self.virtual_machine.id
)
res = validateList(list_vms)
self.assertNotEqual(res[2], INVALID_INPUT, "Invalid list response")
self.cleanup.append(self.virtual_machine)
vm = list_vms[0]
self.assertEqual(
vm.id,
self.virtual_machine.id,
"Virtual Machine ids do not match"
)
# get root vol from created vm, verify it is correct size
list_volume_response = Volume.list(
self.apiclient,
virtualmachineid=
self.virtual_machine.id,
type='ROOT',
listall='True'
)
res = validateList(list_volume_response)
self.assertNotEqual(res[2], INVALID_INPUT, "listVolumes returned invalid object in response")
if vm.state == "Running" and vm.hypervisor.lower() == "xenserver":
self.virtual_machine.stop(self.apiclient)
time.sleep(self.services["sleep"])
rootvolume = list_volume_response[0]
# converting json response to Volume Object
rootvol = Volume(rootvolume.__dict__)
newsize = (rootvolume.size >> 30) - 1
success = False
if rootvolume is not None and 'vmware' in vm.hypervisor.lower():
try:
rootvol.resize(self.apiclient, size=newsize)
except Exception as e:
assert "Shrink operation on ROOT volume not supported" \
in e.message, \
"TestCase Failed,able to resize root volume or error message is not matched"
except Exception as e:
raise Exception("Warning: Exception "
"during executing test resize"
" volume with less value : %s" % e)
if rootvol is not None and 'kvm' or 'xenserver' in vm.hypervisor.lower():
rootvol.resize(self.apiclient, size=newsize)
# @attr(tags=["advanced"], required_hrdware="true")
@attr(tags=["TODO"], required_hrdware="true")
def test_07_usage_events_after_rootvolume_resized_(self):
"""Test check usage events after root volume resize
# Validate the following
# 1. Deploy a VM without any disk offering (only root disk)
# 2. Perform(resize) of the root volume
# 3. Check the corresponding usage events
"""
# deploy a vm
try:
if self.updateclone:
self.virtual_machine = VirtualMachine.create(
self.apiclient, self.services["virtual_machine"],
accountid=self.parentd_admin.name,
domainid=self.parent_domain.id,
serviceofferingid=self.services_offering_vmware.id,
mode=self.zone.networktype
)
else:
self.virtual_machine = VirtualMachine.create(
self.apiclient, self.services["virtual_machine"],
accountid=self.parentd_admin.name,
domainid=self.parent_domain.id,
serviceofferingid=self.service_offering.id,
mode=self.zone.networktype
)
# listVirtual macine
time.sleep(self.services["sleep"])
list_vms = VirtualMachine.list(self.apiclient,
id=self.virtual_machine.id)
self.debug(
"Verify listVirtualMachines response for virtual machine: %s"
% self.virtual_machine.id
)
res = validateList(list_vms)
self.assertNotEqual(res[2], INVALID_INPUT, "Invalid list response")
self.cleanup.append(self.virtual_machine)
vm = list_vms[0]
self.assertEqual(
vm.id,
self.virtual_machine.id,
"Virtual Machine ids do not match"
)
# get root vol from created vm, verify it is correct size
list_volume_response = Volume.list(
self.apiclient,
virtualmachineid=
self.virtual_machine.id,
type='ROOT',
listall='True'
)
res = validateList(list_volume_response)
self.assertNotEqual(res[2], INVALID_INPUT, "listVolumes returned invalid object in response")
if vm.state == "Running" and vm.hypervisor.lower() == "xenserver":
self.virtual_machine.stop(self.apiclient)
time.sleep(self.services["sleep"])