From c90c4b886ce5368cb908f8eb54baf3f8d7c38545 Mon Sep 17 00:00:00 2001 From: Slavka Peleva Date: Wed, 24 Sep 2025 12:54:24 +0300 Subject: [PATCH] refactor smoke tests --- test/integration/plugins/storpool/sp_util.py | 15 ++- .../test_snapshot_copy_on_primary_storage.py | 117 ++++++++++++++++-- ...st_vm_lifecycle_with_snapshot_or_volume.py | 16 +-- 3 files changed, 125 insertions(+), 23 deletions(-) diff --git a/test/integration/plugins/storpool/sp_util.py b/test/integration/plugins/storpool/sp_util.py index 084a57ee954e..826f6b46b772 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,7 +981,9 @@ 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) + logging.debug(zone_ids) + logging.debug(snapshot_entries) if len(new_list) != len(zone_ids): cls.fail("Undesired list snapshot size for multiple zones") for zone_id in zone_ids: 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..ac748276aaa3 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): @@ -111,6 +113,10 @@ def setUpClass(cls): 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) @@ -160,8 +166,7 @@ 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.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) + self._cleanup.append(snapshot) return @skipTestIf("testsNotSupported") @@ -174,8 +179,8 @@ def test_02_copy_snapshot_multi_pools(self): 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) + + self._cleanup.append(snapshot) return @skipTestIf("testsNotSupported") @@ -190,7 +195,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") @@ -227,13 +232,12 @@ 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) + self._cleanup.append(self.volume) + self._cleanup.append(snapshot) if self.zone.id != self.volume.zoneid: self.fail("Volume from snapshot not created in the additional zone") return @@ -249,7 +253,96 @@ def test_06_take_snapshot_multi_zone_create_template_additional_zone(self): self.template = self.helper.create_snapshot_template(self.userapiclient, self.services, self.snapshot_id, self.additional_zone.id) if self.additional_zone.id != self.template.zoneid: self.fail("Template from snapshot not created in the additional zone") + self._cleanup.append(snapshot) + self._cleanup.append(self.template) + return + + @skipTestIf("testsNotSupported") + @attr(tags=["devcloud", "advanced", "advancedns", "smoke", "basic", "sg"], required_hardware="false") + def test_07_take_snapshot_multi_zone_deply_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: + ssh_client = 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: + ssh_client = 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..b448b70ec4a5 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,7 +82,8 @@ 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] @@ -90,17 +91,10 @@ def setUpClass(cls): 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=cls.zone_wide_storage.tags ) cls._cleanup.append(cls.service_offering) @@ -108,7 +102,7 @@ def setUpClass(cls): "name": "do-tags", "displaytext": "Disk offering with tags", "disksize":8, - "tags": "test-vm" + "tags": cls.zone_wide_storage.tags } cls.disk_offering = DiskOffering.create( cls.apiclient, @@ -286,6 +280,7 @@ def deploy_vm_from_snapshot(self, snapshot): snapshotid=snapshot.id, mode="basic", ) + self._cleanup.append(virtual_machine) try: ssh_client = virtual_machine.get_ssh_client() except Exception as e: @@ -311,6 +306,7 @@ def create_volume_from_snapshot_deploy_vm(self, snapshotid): volumeid=volume.id, mode="basic", ) + self._cleanup.append(virtual_machine) try: ssh_client = virtual_machine.get_ssh_client() except Exception as e: