Skip to content

Commit 540c7b8

Browse files
authored
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 <[email protected]>
1 parent 0183e25 commit 540c7b8

File tree

1 file changed

+156
-0
lines changed

1 file changed

+156
-0
lines changed

test/integration/smoke/test_snapshots.py

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,3 +374,159 @@ def test_02_list_snapshots_with_removed_data_store(self):
374374
)
375375

376376
return
377+
378+
379+
class TestSnapshotStandaloneBackup(cloudstackTestCase):
380+
381+
@classmethod
382+
def setUpClass(cls):
383+
testClient = super(TestSnapshotStandaloneBackup, cls).getClsTestClient()
384+
cls.apiclient = testClient.getApiClient()
385+
cls.services = testClient.getParsedTestDataConfig()
386+
387+
# Get Zone, Domain and templates
388+
cls.domain = get_domain(cls.apiclient)
389+
cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())
390+
cls.services['mode'] = cls.zone.networktype
391+
392+
cls.hypervisorNotSupported = False
393+
cls.hypervisor = cls.testClient.getHypervisorInfo()
394+
if cls.hypervisor.lower() in ['hyperv', 'lxc'] or 'kvm-centos6' in cls.testClient.getZoneForTests():
395+
cls.hypervisorNotSupported = True
396+
397+
cls._cleanup = []
398+
if not cls.hypervisorNotSupported:
399+
cls.services["domainid"] = cls.domain.id
400+
cls.services["small"]["zoneid"] = cls.zone.id
401+
cls.services["zoneid"] = cls.zone.id
402+
403+
# Create VMs, NAT Rules etc
404+
cls.account = Account.create(
405+
cls.apiclient,
406+
cls.services["account"],
407+
domainid=cls.domain.id
408+
)
409+
cls._cleanup.append(cls.account)
410+
cls.service_offering = ServiceOffering.create(
411+
cls.apiclient,
412+
cls.services["service_offerings"]["tiny"]
413+
)
414+
cls._cleanup.append(cls.service_offering)
415+
cls.userapiclient = cls.testClient.getUserApiClient(
416+
UserName=cls.account.name,
417+
DomainName=cls.account.domain
418+
)
419+
cls.template = Template.register(
420+
cls.userapiclient,
421+
cls.services["test_templates"][cls.hypervisor.lower()],
422+
zoneid=cls.zone.id,
423+
hypervisor=cls.hypervisor
424+
)
425+
cls._cleanup.append(cls.template)
426+
cls.template.download(cls.apiclient)
427+
cls.ostypeid = cls.template.ostypeid
428+
cls.virtual_machine = VirtualMachine.create(
429+
cls.userapiclient,
430+
cls.services["small"],
431+
templateid=cls.template.id,
432+
accountid=cls.account.name,
433+
domainid=cls.account.domainid,
434+
zoneid=cls.zone.id,
435+
serviceofferingid=cls.service_offering.id,
436+
mode=cls.services["mode"]
437+
)
438+
cls._cleanup.append(cls.virtual_machine)
439+
440+
volumes =Volume.list(
441+
cls.userapiclient,
442+
virtualmachineid=cls.virtual_machine.id,
443+
type='ROOT',
444+
listall=True
445+
)
446+
cls.snapshot = Snapshot.create(
447+
cls.userapiclient,
448+
volumes[0].id,
449+
account=cls.account.name,
450+
domainid=cls.account.domainid
451+
)
452+
cls._cleanup.append(cls.snapshot)
453+
454+
cls.virtual_machine.delete(cls.apiclient, expunge=True)
455+
cls._cleanup.remove(cls.virtual_machine)
456+
cls.template.delete(cls.userapiclient)
457+
cls._cleanup.remove(cls.template)
458+
459+
return
460+
461+
@classmethod
462+
def tearDownClass(cls):
463+
super(TestSnapshotStandaloneBackup, cls).tearDownClass()
464+
465+
def setUp(self):
466+
self.cleanup = []
467+
return
468+
469+
def tearDown(self):
470+
super(TestSnapshotStandaloneBackup, self).tearDown()
471+
472+
@skipTestIf("hypervisorNotSupported")
473+
@attr(tags=["advanced", "advancedns", "smoke"], required_hardware="true")
474+
def test_01_snapshot_to_volume(self):
475+
"""Test creating volume from snapshot
476+
"""
477+
self.services['volume_from_snapshot']['zoneid'] = self.zone.id
478+
self.volume_from_snap = Volume.create_from_snapshot(
479+
self.userapiclient,
480+
snapshot_id=self.snapshot.id,
481+
services=self.services["volume_from_snapshot"],
482+
account=self.account.name,
483+
domainid=self.account.domainid
484+
)
485+
self.cleanup.append(self.volume_from_snap)
486+
487+
self.assertEqual(
488+
self.volume_from_snap.state,
489+
'Ready',
490+
"Check state of the volume created from snapshot"
491+
)
492+
493+
@skipTestIf("hypervisorNotSupported")
494+
@attr(tags=["advanced", "advancedns", "smoke"], required_hardware="true")
495+
def test_02_snapshot_to_template(self):
496+
"""Test creating volume from snapshot
497+
"""
498+
499+
500+
services = {"displaytext": "Template-1", "name": "Template-1-name", "ostypeid": self.ostypeid, "ispublic": "true"}
501+
self.template_from_snap = Template.create_from_snapshot(
502+
self.userapiclient,
503+
self.snapshot,
504+
services
505+
)
506+
self.cleanup.append(self.template_from_snap)
507+
508+
self.assertEqual(
509+
self.template_from_snap.isready,
510+
True,
511+
"Check state of the template created from snapshot"
512+
)
513+
514+
self.virtual_machine1 = VirtualMachine.create(
515+
self.userapiclient,
516+
self.services["small"],
517+
templateid=self.template_from_snap.id,
518+
accountid=self.account.name,
519+
domainid=self.account.domainid,
520+
zoneid=self.zone.id,
521+
serviceofferingid=self.service_offering.id,
522+
mode=self.services["mode"]
523+
)
524+
self.cleanup.append(self.virtual_machine1)
525+
526+
self.assertEqual(
527+
self.virtual_machine1.state,
528+
'Running',
529+
"Check state of the VM deployed using the template created from snapshot"
530+
)
531+
532+
return

0 commit comments

Comments
 (0)