mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
test: add test for standalone snapshot (#8104)
Fixes #8034 Adds the following test for a backed-up snapshot (original template and VM deleted beforehand): - Create volume from snapshot - Create a template from the snapshot and deploy a VM using it Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
This commit is contained in:
parent
0183e25279
commit
540c7b802f
@ -374,3 +374,159 @@ class TestSnapshotRootDisk(cloudstackTestCase):
|
||||
)
|
||||
|
||||
return
|
||||
|
||||
|
||||
class TestSnapshotStandaloneBackup(cloudstackTestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
testClient = super(TestSnapshotStandaloneBackup, cls).getClsTestClient()
|
||||
cls.apiclient = testClient.getApiClient()
|
||||
cls.services = testClient.getParsedTestDataConfig()
|
||||
|
||||
# Get Zone, Domain and templates
|
||||
cls.domain = get_domain(cls.apiclient)
|
||||
cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())
|
||||
cls.services['mode'] = cls.zone.networktype
|
||||
|
||||
cls.hypervisorNotSupported = False
|
||||
cls.hypervisor = cls.testClient.getHypervisorInfo()
|
||||
if cls.hypervisor.lower() in ['hyperv', 'lxc'] or 'kvm-centos6' in cls.testClient.getZoneForTests():
|
||||
cls.hypervisorNotSupported = True
|
||||
|
||||
cls._cleanup = []
|
||||
if not cls.hypervisorNotSupported:
|
||||
cls.services["domainid"] = cls.domain.id
|
||||
cls.services["small"]["zoneid"] = cls.zone.id
|
||||
cls.services["zoneid"] = cls.zone.id
|
||||
|
||||
# Create VMs, NAT Rules etc
|
||||
cls.account = Account.create(
|
||||
cls.apiclient,
|
||||
cls.services["account"],
|
||||
domainid=cls.domain.id
|
||||
)
|
||||
cls._cleanup.append(cls.account)
|
||||
cls.service_offering = ServiceOffering.create(
|
||||
cls.apiclient,
|
||||
cls.services["service_offerings"]["tiny"]
|
||||
)
|
||||
cls._cleanup.append(cls.service_offering)
|
||||
cls.userapiclient = cls.testClient.getUserApiClient(
|
||||
UserName=cls.account.name,
|
||||
DomainName=cls.account.domain
|
||||
)
|
||||
cls.template = Template.register(
|
||||
cls.userapiclient,
|
||||
cls.services["test_templates"][cls.hypervisor.lower()],
|
||||
zoneid=cls.zone.id,
|
||||
hypervisor=cls.hypervisor
|
||||
)
|
||||
cls._cleanup.append(cls.template)
|
||||
cls.template.download(cls.apiclient)
|
||||
cls.ostypeid = cls.template.ostypeid
|
||||
cls.virtual_machine = VirtualMachine.create(
|
||||
cls.userapiclient,
|
||||
cls.services["small"],
|
||||
templateid=cls.template.id,
|
||||
accountid=cls.account.name,
|
||||
domainid=cls.account.domainid,
|
||||
zoneid=cls.zone.id,
|
||||
serviceofferingid=cls.service_offering.id,
|
||||
mode=cls.services["mode"]
|
||||
)
|
||||
cls._cleanup.append(cls.virtual_machine)
|
||||
|
||||
volumes =Volume.list(
|
||||
cls.userapiclient,
|
||||
virtualmachineid=cls.virtual_machine.id,
|
||||
type='ROOT',
|
||||
listall=True
|
||||
)
|
||||
cls.snapshot = Snapshot.create(
|
||||
cls.userapiclient,
|
||||
volumes[0].id,
|
||||
account=cls.account.name,
|
||||
domainid=cls.account.domainid
|
||||
)
|
||||
cls._cleanup.append(cls.snapshot)
|
||||
|
||||
cls.virtual_machine.delete(cls.apiclient, expunge=True)
|
||||
cls._cleanup.remove(cls.virtual_machine)
|
||||
cls.template.delete(cls.userapiclient)
|
||||
cls._cleanup.remove(cls.template)
|
||||
|
||||
return
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
super(TestSnapshotStandaloneBackup, cls).tearDownClass()
|
||||
|
||||
def setUp(self):
|
||||
self.cleanup = []
|
||||
return
|
||||
|
||||
def tearDown(self):
|
||||
super(TestSnapshotStandaloneBackup, self).tearDown()
|
||||
|
||||
@skipTestIf("hypervisorNotSupported")
|
||||
@attr(tags=["advanced", "advancedns", "smoke"], required_hardware="true")
|
||||
def test_01_snapshot_to_volume(self):
|
||||
"""Test creating volume from snapshot
|
||||
"""
|
||||
self.services['volume_from_snapshot']['zoneid'] = self.zone.id
|
||||
self.volume_from_snap = Volume.create_from_snapshot(
|
||||
self.userapiclient,
|
||||
snapshot_id=self.snapshot.id,
|
||||
services=self.services["volume_from_snapshot"],
|
||||
account=self.account.name,
|
||||
domainid=self.account.domainid
|
||||
)
|
||||
self.cleanup.append(self.volume_from_snap)
|
||||
|
||||
self.assertEqual(
|
||||
self.volume_from_snap.state,
|
||||
'Ready',
|
||||
"Check state of the volume created from snapshot"
|
||||
)
|
||||
|
||||
@skipTestIf("hypervisorNotSupported")
|
||||
@attr(tags=["advanced", "advancedns", "smoke"], required_hardware="true")
|
||||
def test_02_snapshot_to_template(self):
|
||||
"""Test creating volume from snapshot
|
||||
"""
|
||||
|
||||
|
||||
services = {"displaytext": "Template-1", "name": "Template-1-name", "ostypeid": self.ostypeid, "ispublic": "true"}
|
||||
self.template_from_snap = Template.create_from_snapshot(
|
||||
self.userapiclient,
|
||||
self.snapshot,
|
||||
services
|
||||
)
|
||||
self.cleanup.append(self.template_from_snap)
|
||||
|
||||
self.assertEqual(
|
||||
self.template_from_snap.isready,
|
||||
True,
|
||||
"Check state of the template created from snapshot"
|
||||
)
|
||||
|
||||
self.virtual_machine1 = VirtualMachine.create(
|
||||
self.userapiclient,
|
||||
self.services["small"],
|
||||
templateid=self.template_from_snap.id,
|
||||
accountid=self.account.name,
|
||||
domainid=self.account.domainid,
|
||||
zoneid=self.zone.id,
|
||||
serviceofferingid=self.service_offering.id,
|
||||
mode=self.services["mode"]
|
||||
)
|
||||
self.cleanup.append(self.virtual_machine1)
|
||||
|
||||
self.assertEqual(
|
||||
self.virtual_machine1.state,
|
||||
'Running',
|
||||
"Check state of the VM deployed using the template created from snapshot"
|
||||
)
|
||||
|
||||
return
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user