@@ -218,6 +218,19 @@ def setUpCloudStack(cls):
218
218
hypervisor = cls .hypervisor ,
219
219
rootdisksize = 10
220
220
)
221
+ cls .virtual_machine3 = VirtualMachine .create (
222
+ cls .apiclient ,
223
+ {"name" :"StorPool-%s" % uuid .uuid4 () },
224
+ zoneid = cls .zone .id ,
225
+ templateid = template .id ,
226
+ accountid = cls .account .name ,
227
+ domainid = cls .account .domainid ,
228
+ serviceofferingid = cls .service_offering .id ,
229
+ hypervisor = cls .hypervisor ,
230
+ diskofferingid = cls .disk_offerings .id ,
231
+ size = 2 ,
232
+ rootdisksize = 10
233
+ )
221
234
cls .template = template
222
235
cls .random_data_0 = random_gen (size = 100 )
223
236
cls .test_dir = "/tmp"
@@ -270,7 +283,7 @@ def test_01_set_vcpolicy_tag_to_vm_with_attached_disks(self):
270
283
virtualmachineid = self .virtual_machine .id , listall = True
271
284
)
272
285
273
- self .vc_policy_tags (volumes , vm_tags , vm )
286
+ self .vc_policy_tags (volumes , vm_tags , vm , True )
274
287
275
288
276
289
@attr (tags = ["advanced" , "advancedns" , "smoke" ], required_hardware = "true" )
@@ -310,7 +323,7 @@ def test_03_create_vm_snapshot_vc_policy_tag(self):
310
323
vm = list_virtual_machines (self .apiclient ,id = self .virtual_machine .id , listall = True )
311
324
vm_tags = vm [0 ].tags
312
325
313
- self .vc_policy_tags (volumes , vm_tags , vm )
326
+ self .vc_policy_tags (volumes , vm_tags , vm , True )
314
327
315
328
316
329
self .assertEqual (volume_attached .id , self .volume .id , "Is not the same volume " )
@@ -442,7 +455,7 @@ def test_04_revert_vm_snapshots_vc_policy_tag(self):
442
455
vm = list_virtual_machines (self .apiclient ,id = self .virtual_machine .id , listall = True )
443
456
vm_tags = vm [0 ].tags
444
457
445
- self .vc_policy_tags (volumes , vm_tags , vm )
458
+ self .vc_policy_tags (volumes , vm_tags , vm , True )
446
459
447
460
self .assertEqual (
448
461
self .random_data_0 ,
@@ -490,18 +503,17 @@ def test_05_delete_vm_snapshots(self):
490
503
def test_06_remove_vcpolicy_tag_when_disk_detached (self ):
491
504
""" Test remove vc-policy tag to disk detached from VM"""
492
505
time .sleep (60 )
493
- volume_detached = self .virtual_machine .detach_volume (
494
- self .apiclient ,
495
- self .volume_2
496
- )
497
506
vm = list_virtual_machines (self .apiclient ,id = self .virtual_machine .id , listall = True )
498
507
vm_tags = vm [0 ].tags
499
508
volumes = list_volumes (
500
509
self .apiclient ,
501
- virtualmachineid = self .virtual_machine .id , listall = True
510
+ id = self .volume_2 .id , listall = True ,
502
511
)
503
-
504
- self .vc_policy_tags ( volumes , vm_tags , vm )
512
+ volume_detached = self .virtual_machine .detach_volume (
513
+ self .apiclient ,
514
+ self .volume_2
515
+ )
516
+ self .vc_policy_tags ( volumes , vm_tags , vm , False )
505
517
506
518
@attr (tags = ["advanced" , "advancedns" , "smoke" ], required_hardware = "true" )
507
519
def test_07_delete_vcpolicy_tag (self ):
@@ -538,7 +550,7 @@ def test_08_vcpolicy_tag_to_reverted_disk(self):
538
550
virtualmachineid = self .virtual_machine2 .id , listall = True ,
539
551
type = "ROOT"
540
552
)
541
- self .vc_policy_tags (volume , vm_tags , vm )
553
+ self .vc_policy_tags (volume , vm_tags , vm , True )
542
554
543
555
snapshot = Snapshot .create (
544
556
self .apiclient ,
@@ -560,21 +572,52 @@ def test_08_vcpolicy_tag_to_reverted_disk(self):
560
572
vm_tags = vm [0 ].tags
561
573
562
574
vol = list_volumes (self .apiclient , id = snapshot .volumeid , listall = True )
563
- self .vc_policy_tags (vol , vm_tags , vm )
575
+ self .vc_policy_tags (vol , vm_tags , vm , True )
576
+
577
+ @attr (tags = ["advanced" , "advancedns" , "smoke" ], required_hardware = "true" )
578
+ def test_09_remove_vm_tags_on_datadisks_attached_to_destroyed_vm (self ):
579
+ tag = Tag .create (
580
+ self .apiclient ,
581
+ resourceIds = self .virtual_machine3 .id ,
582
+ resourceType = 'UserVm' ,
583
+ tags = {'vc-policy' : 'testing_vc-policy' }
584
+ )
585
+ vm = list_virtual_machines (self .apiclient ,id = self .virtual_machine3 .id , listall = True )
586
+ vm_tags = vm [0 ].tags
587
+ volumes = list_volumes (
588
+ self .apiclient ,
589
+ virtualmachineid = self .virtual_machine3 .id , listall = True
590
+ )
564
591
592
+ self .vc_policy_tags (volumes , vm_tags , vm , True )
565
593
566
- def vc_policy_tags (self , volumes , vm_tags , vm ):
567
- flag = False
594
+ volumes = list_volumes (
595
+ self .apiclient ,
596
+ virtualmachineid = self .virtual_machine3 .id , listall = True , type = "DATADISK"
597
+ )
598
+ self .virtual_machine3 .delete (self .apiclient , expunge = True )
599
+
600
+ self .vc_policy_tags (volumes , vm_tags , vm , False )
601
+
602
+ def vc_policy_tags (self , volumes , vm_tags , vm , should_tags_exists = None ):
603
+ vcPolicyTag = False
604
+ cvmTag = False
568
605
for v in volumes :
569
606
name = v .path .split ("/" )[3 ]
570
607
spvolume = self .spapi .volumeList (volumeName = "~" + name )
571
608
tags = spvolume [0 ].tags
572
609
for t in tags :
573
610
for vm_tag in vm_tags :
574
611
if t == vm_tag .key :
575
- flag = True
612
+ vcPolicyTag = True
576
613
self .assertEqual (tags [t ], vm_tag .value , "Tags are not equal" )
577
614
if t == 'cvm' :
615
+ cvmTag = True
578
616
self .assertEqual (tags [t ], vm [0 ].id , "CVM tag is not the same as vm UUID" )
579
617
#self.assertEqual(tag.tags., second, msg)
580
- self .assertTrue (flag , "There aren't volumes with vm tags" )
618
+ if should_tags_exists :
619
+ self .assertTrue (vcPolicyTag , "There aren't volumes with vm tags" )
620
+ self .assertTrue (cvmTag , "There aren't volumes with vm tags" )
621
+ else :
622
+ self .assertFalse (vcPolicyTag , "The tags should be removed" )
623
+ self .assertFalse (cvmTag , "The tags should be removed" )
0 commit comments