diff --git a/test/integration/plugins/storpool/sp_util.py b/test/integration/plugins/storpool/sp_util.py index 084a57ee954e..ac0bc15a067f 100644 --- a/test/integration/plugins/storpool/sp_util.py +++ b/test/integration/plugins/storpool/sp_util.py @@ -88,6 +88,7 @@ class TestData(): diskOfferingMedium = "diskOfferingMedium" diskOfferingLarge = "diskOfferingLarge" diskOfferingCustom = "diskOfferingCustom" + diskOfferingCustomAdditionalZone = "diskOfferingCustomAdditionalZone" domainId = "domainId" hypervisor = "hypervisor" login = "login" @@ -121,11 +122,13 @@ class TestData(): zoneId = "zoneId" sp_template_1 = 'sp_template_1' sp_template_2 = 'sp_template_2' + sp_template_4 = 'sp_template_4' def __init__(self): sp_template_1 = 'ssd' sp_template_2 = 'ssd2' sp_template_3 = 'test-primary' + sp_template_4 = 'ssd-b' self.testdata = { TestData.primaryStorage: { "name": sp_template_1, @@ -374,6 +377,14 @@ def __init__(self): TestData.tags: sp_template_1, "storagetype": "shared" }, + TestData.diskOfferingCustomAdditionalZone: { + "name": "Test-Custom-Zone-B", + "displaytext": "Custom Disk Offering", + "custom": True, + "hypervisorsnapshotreserve": 200, + TestData.tags: sp_template_4, + "storagetype": "shared" + }, TestData.volume_1: { TestData.diskName: "test-volume-1", }, @@ -970,9 +981,11 @@ def verify_snapshot_copies(cls, userapiclient, snapshot_id, zone_ids): if obj.zoneid not in snapshots: new_list.append(obj) snapshots.add(obj.zoneid) - + logging.debug("new list %s" % new_list) + logging.debug("zone IDs %s" % zone_ids) + logging.debug("snapshot entries %s" % snapshot_entries) if len(new_list) != len(zone_ids): - cls.fail("Undesired list snapshot size for multiple zones") + raise Exception("Undesired list snapshot size for multiple zones") for zone_id in zone_ids: zone_found = False for entry in new_list: @@ -980,4 +993,4 @@ def verify_snapshot_copies(cls, userapiclient, snapshot_id, zone_ids): zone_found = True break if zone_found == False: - cls.fail("Unable to find snapshot entry for the zone ID: %s" % zone_id) + raise Exception("Unable to find snapshot entry for the zone ID: %s" % zone_id) diff --git a/test/integration/plugins/storpool/test_snapshot_copy_on_primary_storage.py b/test/integration/plugins/storpool/test_snapshot_copy_on_primary_storage.py index 4e627a58f3b7..8bd5191a7a57 100644 --- a/test/integration/plugins/storpool/test_snapshot_copy_on_primary_storage.py +++ b/test/integration/plugins/storpool/test_snapshot_copy_on_primary_storage.py @@ -38,13 +38,15 @@ StoragePool) from marvin.lib.common import (get_domain, get_zone, - get_template) + get_template, + list_disk_offering) from marvin.lib.decoratorGenerators import skipTestIf from marvin.codes import FAILED, PASS from nose.plugins.attrib import attr import logging from sp_util import (TestData, StorPoolHelper) import math +import uuid class TestSnapshotCopy(cloudstackTestCase): @@ -108,9 +110,11 @@ def setUpClass(cls): domainid=cls.domain.id) cls._cleanup.append(cls.account) - cls.helper = StorPoolHelper() - compute_offering_service = cls.services["service_offerings"]["tiny"].copy() + td = TestData() + cls.testdata = td.testdata + cls.helper = StorPoolHelper() + cls.disk_offerings = cls.create_do_if_not_exists(cls.testdata[TestData.diskOfferingCustomAdditionalZone]) cls.service_offering = ServiceOffering.create( cls.apiclient, compute_offering_service) @@ -158,10 +162,9 @@ def test_01_take_snapshot_multi_zone(self): """ snapshot = Snapshot.create(self.userapiclient, volume_id=self.volume.id, zoneids=[str(self.additional_zone.id)], usestoragereplication=True) + self._cleanup.append(snapshot) self.snapshot_id = snapshot.id self.helper.verify_snapshot_copies(self.userapiclient, self.snapshot_id, [self.zone.id, self.additional_zone.id]) - time.sleep(420) - Snapshot.delete(snapshot, self.userapiclient) return @skipTestIf("testsNotSupported") @@ -171,11 +174,11 @@ def test_02_copy_snapshot_multi_pools(self): """ snapshot = Snapshot.create(self.userapiclient, volume_id=self.volume.id) + self._cleanup.append(snapshot) self.snapshot_id = snapshot.id Snapshot.copy(self.userapiclient, self.snapshot_id, zone_ids=[str(self.additional_zone.id)], source_zone_id=self.zone.id, usestoragereplication=True) self.helper.verify_snapshot_copies(self.userapiclient, self.snapshot_id, [self.zone.id, self.additional_zone.id]) - time.sleep(420) - Snapshot.delete(snapshot, self.userapiclient) + return @skipTestIf("testsNotSupported") @@ -190,7 +193,7 @@ def test_03_take_snapshot_multi_pools_delete_single_zone(self): time.sleep(420) Snapshot.delete(snapshot, self.userapiclient, self.zone.id) self.helper.verify_snapshot_copies(self.userapiclient, self.snapshot_id, [self.additional_zone.id]) - self.cleanup.append(snapshot) + self._cleanup.append(snapshot) return @skipTestIf("testsNotSupported") @@ -217,6 +220,7 @@ def test_05_take_snapshot_multi_zone_create_volume_additional_zone(self): """ snapshot = Snapshot.create(self.userapiclient,volume_id=self.volume.id, zoneids=[str(self.additional_zone.id)], usestoragereplication=True) + self._cleanup.append(snapshot) self.snapshot_id = snapshot.id self.helper.verify_snapshot_copies(self.userapiclient, self.snapshot_id, [self.zone.id, self.additional_zone.id]) disk_offering_id = None @@ -227,13 +231,11 @@ def test_05_take_snapshot_multi_zone_create_volume_additional_zone(self): self.apiclient, service ) - self.cleanup.append(self.disk_offering) + self._cleanup.append(self.disk_offering) disk_offering_id = self.disk_offering.id self.volume = Volume.create(self.userapiclient, {"diskname":"StorPoolDisk-1" }, snapshotid=self.snapshot_id, zoneid=self.zone.id, diskofferingid=disk_offering_id) self.cleanup.append(self.volume) - time.sleep(420) - Snapshot.delete(snapshot, self.userapiclient) if self.zone.id != self.volume.zoneid: self.fail("Volume from snapshot not created in the additional zone") return @@ -244,12 +246,101 @@ def test_06_take_snapshot_multi_zone_create_template_additional_zone(self): """Test to take volume snapshot in multiple StorPool primary storages in diff zones and create a volume in one of the additional zones """ snapshot = Snapshot.create(self.userapiclient, volume_id=self.volume.id, zoneids=[str(self.additional_zone.id)], usestoragereplication=True) + self._cleanup.append(snapshot) self.snapshot_id = snapshot.id self.helper.verify_snapshot_copies(self.userapiclient, self.snapshot_id, [self.zone.id, self.additional_zone.id]) self.template = self.helper.create_snapshot_template(self.userapiclient, self.services, self.snapshot_id, self.additional_zone.id) + self.cleanup.append(self.template) if self.additional_zone.id != self.template.zoneid: self.fail("Template from snapshot not created in the additional zone") + return + + @skipTestIf("testsNotSupported") + @attr(tags=["devcloud", "advanced", "advancedns", "smoke", "basic", "sg"], required_hardware="false") + def test_07_take_snapshot_multi_zone_deploy_vm_additional_zone(self): + """Test to take volume snapshot in multiple StorPool primary storages in diff zones and deploy a VM from snapshot in one of the additional zones + """ + snapshot = Snapshot.create(self.userapiclient, volume_id=self.volume.id, zoneids=[str(self.additional_zone.id)], usestoragereplication=True) + self._cleanup.append(snapshot) + self.snapshot_id = snapshot.id + self.helper.verify_snapshot_copies(self.userapiclient, self.snapshot_id, [self.zone.id, self.additional_zone.id]) + vm = self.deploy_vm_from_snapshot(snapshot, self.additional_zone.id) + if self.additional_zone.id != vm.zoneid: + self.fail("VM from snapshot not created in the additional zone") + return + + + @skipTestIf("testsNotSupported") + @attr(tags=["devcloud", "advanced", "advancedns", "smoke", "basic", "sg"], required_hardware="false") + def test_08_take_snapshot_multi_zone_create_volume_additional_zone_deploy_vm(self): + """Test to take volume snapshot in multiple StorPool primary storages in diff zones + create a volume from the snapshot in the additional zone + and deploy a VM from the volume in one of the additional zones + """ + snapshot = Snapshot.create(self.userapiclient, volume_id=self.volume.id, zoneids=[str(self.additional_zone.id)], usestoragereplication=True) + self.cleanup.append(snapshot) + self.snapshot_id = snapshot.id + self.helper.verify_snapshot_copies(self.userapiclient, self.snapshot_id, [self.zone.id, self.additional_zone.id]) + vm = self.create_volume_from_snapshot_deploy_vm(snapshotid=self.snapshot_id, zoneid=self.additional_zone.id) time.sleep(420) - Snapshot.delete(snapshot, self.userapiclient) - self.cleanup.append(self.template) + if self.additional_zone.id != vm.zoneid: + self.fail("VM from snapshot not created in the additional zone") return + + def create_volume_from_snapshot_deploy_vm(self, snapshotid, zoneid=None): + volume = Volume.create_from_snapshot( + self.apiclient, + snapshot_id=snapshotid, + services=self.services, + disk_offering=self.disk_offerings.id, + size=8, + account=self.account.name, + domainid=self.account.domainid, + zoneid=zoneid, + ) + virtual_machine = VirtualMachine.create(self.apiclient, + {"name": "Test-%s" % uuid.uuid4()}, + accountid=self.account.name, + domainid=self.account.domainid, + zoneid=zoneid, + serviceofferingid=self.service_offering.id, + volumeid=volume.id, + mode="basic", + ) + self.cleanup.append(virtual_machine) + try: + virtual_machine.get_ssh_client() + except Exception as e: + self.fail("SSH failed for virtual machine: %s - %s" % + (virtual_machine.ipaddress, e)) + return virtual_machine + + def deploy_vm_from_snapshot(self, snapshot, zoneid=None): + virtual_machine = VirtualMachine.create(self.apiclient, + {"name": "Test-%s" % uuid.uuid4()}, + accountid=self.account.name, + domainid=self.account.domainid, + zoneid=zoneid, + serviceofferingid=self.service_offering.id, + snapshotid=snapshot.id, + mode="basic", + ) + self.cleanup.append(virtual_machine) + try: + virtual_machine.get_ssh_client() + except Exception as e: + self.fail("SSH failed for virtual machine: %s - %s" % + (virtual_machine.ipaddress, e)) + return virtual_machine + + @classmethod + def create_do_if_not_exists(cls, data): + disk_offerings = list_disk_offering( + cls.apiclient, + name=data["name"] + ) + if disk_offerings is None: + disk_offerings = DiskOffering.create(cls.apiclient, services=data, custom=True) + else: + disk_offerings = disk_offerings[0] + return disk_offerings diff --git a/test/integration/smoke/test_vm_lifecycle_with_snapshot_or_volume.py b/test/integration/smoke/test_vm_lifecycle_with_snapshot_or_volume.py index 871cf25a4021..f424da912f38 100644 --- a/test/integration/smoke/test_vm_lifecycle_with_snapshot_or_volume.py +++ b/test/integration/smoke/test_vm_lifecycle_with_snapshot_or_volume.py @@ -82,25 +82,22 @@ def setUpClass(cls): storage_pools_response = list_storage_pools(cls.apiclient, zoneid=cls.zone.id, - scope="ZONE") + scope="ZONE", + status="Up") if storage_pools_response: cls.zone_wide_storage = storage_pools_response[0] + storage_tag = None + if cls.zone_wide_storage.tags: + storage_tag = cls.zone_wide_storage.tags cls.debug( "zone wide storage id is %s" % cls.zone_wide_storage.id) - update1 = StoragePool.update(cls.apiclient, - id=cls.zone_wide_storage.id, - tags="test-vm" - ) - cls.debug( - "Storage %s pool tag%s" % - (cls.zone_wide_storage.id, update1.tags)) cls.service_offering = ServiceOffering.create( cls.apiclient, cls.services["service_offerings"]["small"], - tags="test-vm" + tags=storage_tag ) cls._cleanup.append(cls.service_offering) @@ -108,7 +105,7 @@ def setUpClass(cls): "name": "do-tags", "displaytext": "Disk offering with tags", "disksize":8, - "tags": "test-vm" + "tags": storage_tag } cls.disk_offering = DiskOffering.create( cls.apiclient, @@ -186,7 +183,7 @@ def test_03_deploy_vm_with_existing_volume_deleted_template(self): mode="basic", ) try: - ssh_client = virtual_machine.get_ssh_client() + virtual_machine.get_ssh_client() except Exception as e: self.fail("SSH failed for virtual machine: %s - %s" % (virtual_machine.ipaddress, e)) @@ -224,7 +221,7 @@ def test_04_deploy_vm_with_existing_snapshot_deleted_template(self): mode="basic", ) try: - ssh_client = virtual_machine.get_ssh_client() + virtual_machine.get_ssh_client() except Exception as e: self.fail("SSH failed for virtual machine: %s - %s" % (virtual_machine.ipaddress, e)) @@ -277,7 +274,7 @@ def test_05_deploy_vm_with_existing_snapshot_deleted_volume(self): self.deploy_vm_from_snapshot(snapshot) def deploy_vm_from_snapshot(self, snapshot): - virtual_machine = VirtualMachine.create(self.apiclient, + self.virtual_machine = VirtualMachine.create(self.apiclient, {"name": "Test-%s" % uuid.uuid4()}, accountid=self.account.name, domainid=self.account.domainid, @@ -286,11 +283,12 @@ def deploy_vm_from_snapshot(self, snapshot): snapshotid=snapshot.id, mode="basic", ) + self.cleanup.append(self.virtual_machine) try: - ssh_client = virtual_machine.get_ssh_client() + ssh_client = self.virtual_machine.get_ssh_client() except Exception as e: self.fail("SSH failed for virtual machine: %s - %s" % - (virtual_machine.ipaddress, e)) + (self.virtual_machine.ipaddress, e)) def create_volume_from_snapshot_deploy_vm(self, snapshotid): volume = Volume.create_from_snapshot( @@ -302,7 +300,7 @@ def create_volume_from_snapshot_deploy_vm(self, snapshotid): domainid=self.account.domainid, zoneid=self.zone.id, ) - virtual_machine = VirtualMachine.create(self.apiclient, + self.virtual_machine = VirtualMachine.create(self.apiclient, {"name": "Test-%s" % uuid.uuid4()}, accountid=self.account.name, domainid=self.account.domainid, @@ -311,8 +309,9 @@ def create_volume_from_snapshot_deploy_vm(self, snapshotid): volumeid=volume.id, mode="basic", ) + self.cleanup.append(self.virtual_machine) try: - ssh_client = virtual_machine.get_ssh_client() + ssh_client = self.virtual_machine.get_ssh_client() except Exception as e: self.fail("SSH failed for virtual machine: %s - %s" % - (virtual_machine.ipaddress, e)) + (self.virtual_machine.ipaddress, e))