-
Notifications
You must be signed in to change notification settings - Fork 1.3k
refactoring a few smoke tests #11748
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 4.22
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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() | ||||||
|
slavkap marked this conversation as resolved.
|
||||||
| 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) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @DaanHoogland, the cleanup is left on purpose for the class because there is a required time.sleep() and I don't want to delay the tests execution with invoking it in each test case
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but the creation does need to happen in the test?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. btw, if it is really needed please leave a don’t-do-this-at-home warning with it? |
||||||
| 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) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| 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) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isn’t the snapshot to be removed from the cleanup list here?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @slavkap per test items should go in the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @DaanHoogland, the cleanup is left on purpose for the class because there is a required time.sleep() and I don't want to delay the tests execution with invoking it in each test case
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry for the late reply @slavkap , I got it, but can you add an explicit warning/comment on why you are adding those in the "wrong" place?
slavkap marked this conversation as resolved.
|
||||||
| 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) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| 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) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| 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) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| 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_deply_vm_additional_zone(self): | ||||||
|
||||||
| def test_07_take_snapshot_multi_zone_deply_vm_additional_zone(self): | |
| def test_07_take_snapshot_multi_zone_deploy_vm_additional_zone(self): |
Copilot
AI
Jan 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This helper appends the created VM to self._cleanup (class-level), so it won't be deleted until tearDownClass. Since this test class already uses self.cleanup + tearDown() for per-test cleanup, consider adding the VM to self.cleanup instead to avoid accumulating running VMs across tests (unless you intentionally need the VM to persist across multiple test cases).
Copilot
AI
Jan 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This helper adds the created VM to self._cleanup (class-level), which defers deletion until tearDownClass. Given this class already uses self.cleanup in tearDown() for test-scoped resources, consider using self.cleanup here too so each test cleans up its own VM and doesn't leave extra VMs around for subsequent tests in the same class.
Copilot
AI
Jan 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variable ssh_client is not used.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -82,33 +82,30 @@ 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) | ||
|
|
||
| do = { | ||
| "name": "do-tags", | ||
| "displaytext": "Disk offering with tags", | ||
| "disksize":8, | ||
| "tags": "test-vm" | ||
| "tags": storage_tag | ||
| } | ||
| cls.disk_offering = DiskOffering.create( | ||
| cls.apiclient, | ||
|
|
@@ -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)) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
StorPoolHelper.verify_snapshot_copiesnow raises exceptions for some failure cases, but it still callscls.fail(...)earlier in the method whenSnapshot.listdoesn't return a list. SinceStorPoolHelperis not aunittest.TestCase,cls.failis not defined and that path will raiseAttributeErrorinstead of a clear test failure. Replace that remainingcls.failusage with an exception/AssertionError for consistency and correct error reporting.