@@ -283,7 +283,7 @@ def test_01_set_vcpolicy_tag_to_vm_with_attached_disks(self):
283
283
virtualmachineid = self .virtual_machine .id , listall = True
284
284
)
285
285
286
- self .vc_policy_tags (volumes , vm_tags , vm , True )
286
+ self .vc_policy_tags (volumes , vm_tags , vm , should_tags_exists = True )
287
287
288
288
289
289
@attr (tags = ["advanced" , "advancedns" , "smoke" ], required_hardware = "true" )
@@ -323,7 +323,7 @@ def test_03_create_vm_snapshot_vc_policy_tag(self):
323
323
vm = list_virtual_machines (self .apiclient ,id = self .virtual_machine .id , listall = True )
324
324
vm_tags = vm [0 ].tags
325
325
326
- self .vc_policy_tags (volumes , vm_tags , vm , True )
326
+ self .vc_policy_tags (volumes , vm_tags , vm , should_tags_exists = True )
327
327
328
328
329
329
self .assertEqual (volume_attached .id , self .volume .id , "Is not the same volume " )
@@ -455,7 +455,7 @@ def test_04_revert_vm_snapshots_vc_policy_tag(self):
455
455
vm = list_virtual_machines (self .apiclient ,id = self .virtual_machine .id , listall = True )
456
456
vm_tags = vm [0 ].tags
457
457
458
- self .vc_policy_tags (volumes , vm_tags , vm , True )
458
+ self .vc_policy_tags (volumes , vm_tags , vm , should_tags_exists = True )
459
459
460
460
self .assertEqual (
461
461
self .random_data_0 ,
@@ -491,14 +491,12 @@ def test_05_delete_vm_snapshots(self):
491
491
492
492
list_snapshot_response = VmSnapshot .list (
493
493
self .apiclient ,
494
- #vmid=self.virtual_machine.id,
495
494
virtualmachineid = self .virtual_machine .id ,
496
495
listall = False )
497
496
self .debug ('list_snapshot_response -------------------- %s' % list_snapshot_response )
498
497
499
498
self .assertIsNone (list_snapshot_response , "snapshot is already deleted" )
500
499
501
-
502
500
@attr (tags = ["advanced" , "advancedns" , "smoke" ], required_hardware = "true" )
503
501
def test_06_remove_vcpolicy_tag_when_disk_detached (self ):
504
502
""" Test remove vc-policy tag to disk detached from VM"""
@@ -513,7 +511,7 @@ def test_06_remove_vcpolicy_tag_when_disk_detached(self):
513
511
self .apiclient ,
514
512
self .volume_2
515
513
)
516
- self .vc_policy_tags ( volumes , vm_tags , vm , False )
514
+ self .vc_policy_tags ( volumes , vm_tags , vm , should_tags_exists = False )
517
515
518
516
@attr (tags = ["advanced" , "advancedns" , "smoke" ], required_hardware = "true" )
519
517
def test_07_delete_vcpolicy_tag (self ):
@@ -550,7 +548,7 @@ def test_08_vcpolicy_tag_to_reverted_disk(self):
550
548
virtualmachineid = self .virtual_machine2 .id , listall = True ,
551
549
type = "ROOT"
552
550
)
553
- self .vc_policy_tags (volume , vm_tags , vm , True )
551
+ self .vc_policy_tags (volume , vm_tags , vm , should_tags_exists = True )
554
552
555
553
snapshot = Snapshot .create (
556
554
self .apiclient ,
@@ -571,8 +569,8 @@ def test_08_vcpolicy_tag_to_reverted_disk(self):
571
569
vm = list_virtual_machines (self .apiclient ,id = self .virtual_machine2 .id )
572
570
vm_tags = vm [0 ].tags
573
571
574
- vol = list_volumes (self .apiclient , id = snapshot .volumeid , listall = True )
575
- self .vc_policy_tags (vol , vm_tags , vm , True )
572
+ vol = list_volumes (self .apiclient , id = snapshot .volumeid , listall = True )
573
+ self .vc_policy_tags (vol , vm_tags , vm , should_tags_exists = True )
576
574
577
575
@attr (tags = ["advanced" , "advancedns" , "smoke" ], required_hardware = "true" )
578
576
def test_09_remove_vm_tags_on_datadisks_attached_to_destroyed_vm (self ):
@@ -586,38 +584,82 @@ def test_09_remove_vm_tags_on_datadisks_attached_to_destroyed_vm(self):
586
584
vm_tags = vm [0 ].tags
587
585
volumes = list_volumes (
588
586
self .apiclient ,
589
- virtualmachineid = self .virtual_machine3 .id , listall = True
587
+ virtualmachineid = self .virtual_machine3 .id , listall = True
590
588
)
591
589
592
- self .vc_policy_tags (volumes , vm_tags , vm , True )
590
+ self .vc_policy_tags (volumes , vm_tags , vm , should_tags_exists = True )
593
591
594
592
volumes = list_volumes (
595
593
self .apiclient ,
596
- virtualmachineid = self .virtual_machine3 .id , listall = True , type = "DATADISK"
594
+ virtualmachineid = self .virtual_machine3 .id , listall = True , type = "DATADISK"
597
595
)
598
596
self .virtual_machine3 .delete (self .apiclient , expunge = True )
599
597
600
- self .vc_policy_tags (volumes , vm_tags , vm , False )
598
+ self .vc_policy_tags (volumes , vm_tags , vm , should_tags_exists = False )
601
599
602
- def vc_policy_tags (self , volumes , vm_tags , vm , should_tags_exists = None ):
603
- vcPolicyTag = False
604
- cvmTag = False
600
+ @attr (tags = ["advanced" , "advancedns" , "smoke" ], required_hardware = "true" )
601
+ def test_10_check_tags_on_deployed_vm_with_data_disk (self ):
602
+ """
603
+ Check disk and cvm tags are set on all volumes when VM is deployed with additional DATA disk
604
+ Detach the DATA disk
605
+ """
606
+ vm = VirtualMachine .create (
607
+ self .apiclient ,
608
+ {"name" :"StorPool-%s" % uuid .uuid4 () },
609
+ zoneid = self .zone .id ,
610
+ templateid = self .template .id ,
611
+ accountid = self .account .name ,
612
+ domainid = self .account .domainid ,
613
+ serviceofferingid = self .service_offering .id ,
614
+ hypervisor = self .hypervisor ,
615
+ diskofferingid = self .disk_offerings .id ,
616
+ size = 2 ,
617
+ rootdisksize = 10
618
+ )
619
+ volumes = list_volumes (
620
+ self .apiclient ,
621
+ virtualmachineid = vm .id , listall = True
622
+ )
623
+ vm1 = list_virtual_machines (self .apiclient ,id = vm .id , listall = True )
624
+ vm_tags = vm1 [0 ].tags
625
+ self .vc_policy_tags (volumes , vm_tags , vm1 , False , True )
626
+ vm .stop (self .apiclient , forced = True )
627
+ volumes = list_volumes (
628
+ self .apiclient ,
629
+ virtualmachineid = vm .id , listall = True , type = "DATADISK"
630
+ )
631
+
632
+ self .debug ("detaching volume %s" % volumes )
633
+ VirtualMachine .detach_volume (vm , self .apiclient , volumes [0 ])
634
+ self .vc_policy_tags (volumes , vm_tags , vm1 , False , False )
635
+
636
+ def vc_policy_tags (self , volumes , vm_tags , vm , tag_check = True , should_tags_exists = None ,):
637
+ vc_policy_tag = False
638
+ cvm_tag = False
639
+ disk_id_tag = False
605
640
for v in volumes :
606
641
name = v .path .split ("/" )[3 ]
607
- spvolume = self .spapi .volumeList (volumeName = "~" + name )
608
- tags = spvolume [0 ].tags
642
+ volume = self .spapi .volumeList (volumeName = "~" + name )
643
+ tags = volume [0 ].tags
644
+ self .debug ("Tags %s" % tags )
609
645
for t in tags :
610
646
for vm_tag in vm_tags :
611
647
if t == vm_tag .key :
612
- vcPolicyTag = True
648
+ vc_policy_tag = True
613
649
self .assertEqual (tags [t ], vm_tag .value , "Tags are not equal" )
614
- if t == 'cvm' :
615
- cvmTag = True
616
- self .assertEqual (tags [t ], vm [0 ].id , "CVM tag is not the same as vm UUID" )
617
- #self.assertEqual(tag.tags., second, msg)
650
+ if t == 'cvm' :
651
+ cvm_tag = True
652
+ self .assertEqual (tags [t ], vm [0 ].id , "CVM tag is not the same as vm UUID" )
653
+ if t == 'disk' :
654
+ disk_id_tag = True
655
+ self .assertEqual (tags [t ], str (v .deviceid ), "Disk tag is not equal to the device ID" )
618
656
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" )
657
+ if tag_check :
658
+ self .assertTrue (vc_policy_tag , "There aren't volumes with vc policy tags" )
659
+ self .assertTrue (cvm_tag , "There aren't volumes with vm UUID tags" )
660
+ self .assertTrue (disk_id_tag , "There aren't volumes with vm disk tag" )
621
661
else :
622
- self .assertFalse (vcPolicyTag , "The tags should be removed" )
623
- self .assertFalse (cvmTag , "The tags should be removed" )
662
+ if tag_check :
663
+ self .assertFalse (vc_policy_tag , "The vc policy tag should be removed" )
664
+ self .assertFalse (cvm_tag , "The cvm tag should be removed" )
665
+ self .assertFalse (disk_id_tag , "The disk tag should be removed" )
0 commit comments