Merge remote-tracking branch 'apache/4.18' into main

This commit is contained in:
Abhishek Kumar 2023-10-19 10:39:40 +05:30
commit 20046ffe61
2 changed files with 156 additions and 2 deletions

View File

@ -419,7 +419,6 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long> implements Vol
TotalVMSnapshotSizeByPoolSearch.and("poolId", TotalVMSnapshotSizeByPoolSearch.entity().getPoolId(), Op.EQ);
TotalVMSnapshotSizeByPoolSearch.and("removed", TotalVMSnapshotSizeByPoolSearch.entity().getRemoved(), Op.NULL);
TotalVMSnapshotSizeByPoolSearch.and("state", TotalVMSnapshotSizeByPoolSearch.entity().getState(), Op.NEQ);
TotalVMSnapshotSizeByPoolSearch.and("vType", TotalVMSnapshotSizeByPoolSearch.entity().getVolumeType(), Op.EQ);
TotalVMSnapshotSizeByPoolSearch.and("instanceId", TotalVMSnapshotSizeByPoolSearch.entity().getInstanceId(), Op.NNULL);
TotalVMSnapshotSizeByPoolSearch.done();
@ -661,7 +660,6 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long> implements Vol
SearchCriteria<SumCount> sc = TotalVMSnapshotSizeByPoolSearch.create();
sc.setParameters("poolId", poolId);
sc.setParameters("state", State.Destroy);
sc.setParameters("vType", Volume.Type.ROOT.toString());
List<SumCount> results = customSearch(sc, null);
if (results != null) {
return results.get(0).sum;

View File

@ -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