Skip to content

Commit 3be278e

Browse files
committed
CLOUDSTACK-8651: [Browser Based Upload Template] Partially uploaded templates doesn't get cleaned up after the SSVM handling it is destroyed
Fixed template sync code to include templates in 'NotUploaded' and 'UploadInProgress' states along with 'Active'.
1 parent b631da2 commit 3be278e

4 files changed

Lines changed: 60 additions & 4 deletions

File tree

‎engine/schema/src/com/cloud/storage/dao/VMTemplateDao.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,12 @@ public interface VMTemplateDao extends GenericDao<VMTemplateVO, Long>, StateDao<
5454

5555
public List<VMTemplateVO> listAllInZone(long dataCenterId);
5656

57+
public List<VMTemplateVO> listInZoneByState(long dataCenterId, VirtualMachineTemplate.State... states);
58+
5759
public List<VMTemplateVO> listAllActive();
5860

61+
public List<VMTemplateVO> listByState(VirtualMachineTemplate.State... states);
62+
5963
public List<VMTemplateVO> listByHypervisorType(List<HypervisorType> hyperTypes);
6064

6165
public List<VMTemplateVO> publicIsoSearch(Boolean bootable, boolean listRemoved, Map<String, String> tags);

‎engine/schema/src/com/cloud/storage/dao/VMTemplateDaoImpl.java‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
372372
tmpltZoneSearch.and("zoneId", tmpltZoneSearch.entity().getZoneId(), SearchCriteria.Op.EQ);
373373

374374
TmpltsInZoneSearch = createSearchBuilder();
375-
TmpltsInZoneSearch.and("state", TmpltsInZoneSearch.entity().getState(), SearchCriteria.Op.EQ);
375+
TmpltsInZoneSearch.and("state", TmpltsInZoneSearch.entity().getState(), SearchCriteria.Op.IN);
376376
TmpltsInZoneSearch.and().op("avoidtype", TmpltsInZoneSearch.entity().getTemplateType(), SearchCriteria.Op.NEQ);
377377
TmpltsInZoneSearch.or("templateType", TmpltsInZoneSearch.entity().getTemplateType(), SearchCriteria.Op.NULL);
378378
TmpltsInZoneSearch.cp();
@@ -381,7 +381,7 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
381381
TmpltsInZoneSearch.done();
382382

383383
ActiveTmpltSearch = createSearchBuilder();
384-
ActiveTmpltSearch.and("state", ActiveTmpltSearch.entity().getState(), SearchCriteria.Op.EQ);
384+
ActiveTmpltSearch.and("state", ActiveTmpltSearch.entity().getState(), SearchCriteria.Op.IN);
385385

386386
CountTemplatesByAccount = createSearchBuilder(Long.class);
387387
CountTemplatesByAccount.select(null, Func.COUNT, null);
@@ -792,13 +792,29 @@ public List<VMTemplateVO> listAllInZone(long dataCenterId) {
792792
return listBy(sc);
793793
}
794794

795+
@Override
796+
public List<VMTemplateVO> listInZoneByState(long dataCenterId, VirtualMachineTemplate.State... states) {
797+
SearchCriteria<VMTemplateVO> sc = TmpltsInZoneSearch.create();
798+
sc.setParameters("avoidtype", TemplateType.PERHOST.toString());
799+
sc.setParameters("state", (Object[])states);
800+
sc.setJoinParameters("tmpltzone", "zoneId", dataCenterId);
801+
return listBy(sc);
802+
}
803+
795804
@Override
796805
public List<VMTemplateVO> listAllActive() {
797806
SearchCriteria<VMTemplateVO> sc = ActiveTmpltSearch.create();
798807
sc.setParameters("state", VirtualMachineTemplate.State.Active.toString());
799808
return listBy(sc);
800809
}
801810

811+
@Override
812+
public List<VMTemplateVO> listByState(VirtualMachineTemplate.State... states) {
813+
SearchCriteria<VMTemplateVO> sc = ActiveTmpltSearch.create();
814+
sc.setParameters("state", (Object[])states);
815+
return listBy(sc);
816+
}
817+
802818
@Override
803819
public List<VMTemplateVO> listDefaultBuiltinTemplates() {
804820
SearchCriteria<VMTemplateVO> sc = tmpltTypeSearch.create();

‎engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateServiceImpl.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,10 @@ public void handleTemplateSync(DataStore store) {
291291
List<VMTemplateVO> allTemplates = null;
292292
if (zoneId == null) {
293293
// region wide store
294-
allTemplates = _templateDao.listAllActive();
294+
allTemplates = _templateDao.listByState(VirtualMachineTemplate.State.Active, VirtualMachineTemplate.State.NotUploaded, VirtualMachineTemplate.State.UploadInProgress);
295295
} else {
296296
// zone wide store
297-
allTemplates = _templateDao.listAllInZone(zoneId);
297+
allTemplates = _templateDao.listInZoneByState(zoneId, VirtualMachineTemplate.State.Active, VirtualMachineTemplate.State.NotUploaded, VirtualMachineTemplate.State.UploadInProgress);
298298
}
299299
List<VMTemplateVO> rtngTmplts = _templateDao.listAllSystemVMTemplates();
300300
List<VMTemplateVO> defaultBuiltin = _templateDao.listDefaultBuiltinTemplates();

‎test/integration/component/test_browse_templates.py‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1674,6 +1674,42 @@ def test_09_Browser_Upload_Volume_secondary_storage_resource_limits_after_deleti
16741674
return
16751675

16761676

1677+
@attr(tags = ["advanced", "advancedns", "smoke", "basic"], required_hardware="false")
1678+
def test_browser_upload_template_incomplete(self):
1679+
"""
1680+
Test browser based incomplete template upload, followed by SSVM destroy. Template should go to UploadAbandoned state and get cleaned up.
1681+
"""
1682+
try:
1683+
self.debug("========================= Test browser based incomplete template upload ========================")
1684+
1685+
#Only register template, without uploading
1686+
cmd = getUploadParamsForTemplate.getUploadParamsForTemplateCmd()
1687+
cmd.zoneid = self.zone.id
1688+
cmd.format = self.uploadtemplateformat
1689+
cmd.name=self.templatename+self.account.name+(random.choice(string.ascii_uppercase))
1690+
cmd.account=self.account.name
1691+
cmd.domainid=self.domain.id
1692+
cmd.displaytext=cmd.name
1693+
cmd.hypervisor=self.templatehypervisor
1694+
cmd.ostypeid=self.templateostypeid
1695+
template_response=self.apiclient.getUploadParamsForTemplate(cmd)
1696+
1697+
#Destroy SSVM, and wait for new one to start
1698+
self.destroy_ssvm()
1699+
1700+
#Verify that the template is cleaned up as part of sync-up during new SSVM start
1701+
list_template_response=Template.list(
1702+
self.apiclient,
1703+
id=template_response.id,
1704+
templatefilter="all",
1705+
zoneid=self.zone.id)
1706+
self.assertEqual(list_template_response, None, "Template is not cleaned up, some issue with template sync-up")
1707+
1708+
except Exception as e:
1709+
self.fail("Exceptione occurred : %s" % e)
1710+
return
1711+
1712+
16771713
@classmethod
16781714
def tearDownClass(self):
16791715
try:

0 commit comments

Comments
 (0)