Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion test/integration/plugins/storpool/sp_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class TestData():
diskOfferingMedium = "diskOfferingMedium"
diskOfferingLarge = "diskOfferingLarge"
diskOfferingCustom = "diskOfferingCustom"
diskOfferingCustomAdditionalZone = "diskOfferingCustomAdditionalZone"
domainId = "domainId"
hypervisor = "hypervisor"
login = "login"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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",
},
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Comment on lines 167 to +169
Copy link
Contributor

Choose a reason for hiding this comment

The 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])
time.sleep(420)
Snapshot.delete(snapshot, self.userapiclient)
self._cleanup.append(snapshot)
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])

return

@skipTestIf("testsNotSupported")
Expand All @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should move to just below the create .
also, is the copy a separate entity and should it be in the cleanup list as well?

return

@skipTestIf("testsNotSupported")
Expand All @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn’t the snapshot to be removed from the cleanup list here?

return

@skipTestIf("testsNotSupported")
Expand Down Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this added at this point?

if self.zone.id != self.volume.zoneid:
self.fail("Volume from snapshot not created in the additional zone")
return
Expand All @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should move up a couple of lines to be just below the matching create

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
Original file line number Diff line number Diff line change
Expand Up @@ -82,33 +82,27 @@ 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]

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)

do = {
"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,
Expand Down Expand Up @@ -286,6 +280,7 @@ def deploy_vm_from_snapshot(self, snapshot):
snapshotid=snapshot.id,
mode="basic",
)
self._cleanup.append(virtual_machine)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self._cleanup.append(virtual_machine)
self.cleanup.append(virtual_machine)

maybe?

try:
ssh_client = virtual_machine.get_ssh_client()
except Exception as e:
Expand All @@ -311,6 +306,7 @@ def create_volume_from_snapshot_deploy_vm(self, snapshotid):
volumeid=volume.id,
mode="basic",
)
self._cleanup.append(virtual_machine)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self._cleanup.append(virtual_machine)
self.cleanup.append(virtual_machine)

?
(as it is an operation on self and not on cls)

try:
ssh_client = virtual_machine.get_ssh_client()
except Exception as e:
Expand Down
Loading