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'.
This commit is contained in:
Koushik Das 2015-07-20 14:48:40 +05:30
parent b631da2542
commit 3be278ed5e
4 changed files with 60 additions and 4 deletions

View File

@ -54,8 +54,12 @@ public interface VMTemplateDao extends GenericDao<VMTemplateVO, Long>, StateDao<
public List<VMTemplateVO> listAllInZone(long dataCenterId);
public List<VMTemplateVO> listInZoneByState(long dataCenterId, VirtualMachineTemplate.State... states);
public List<VMTemplateVO> listAllActive();
public List<VMTemplateVO> listByState(VirtualMachineTemplate.State... states);
public List<VMTemplateVO> listByHypervisorType(List<HypervisorType> hyperTypes);
public List<VMTemplateVO> publicIsoSearch(Boolean bootable, boolean listRemoved, Map<String, String> tags);

View File

@ -372,7 +372,7 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
tmpltZoneSearch.and("zoneId", tmpltZoneSearch.entity().getZoneId(), SearchCriteria.Op.EQ);
TmpltsInZoneSearch = createSearchBuilder();
TmpltsInZoneSearch.and("state", TmpltsInZoneSearch.entity().getState(), SearchCriteria.Op.EQ);
TmpltsInZoneSearch.and("state", TmpltsInZoneSearch.entity().getState(), SearchCriteria.Op.IN);
TmpltsInZoneSearch.and().op("avoidtype", TmpltsInZoneSearch.entity().getTemplateType(), SearchCriteria.Op.NEQ);
TmpltsInZoneSearch.or("templateType", TmpltsInZoneSearch.entity().getTemplateType(), SearchCriteria.Op.NULL);
TmpltsInZoneSearch.cp();
@ -381,7 +381,7 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
TmpltsInZoneSearch.done();
ActiveTmpltSearch = createSearchBuilder();
ActiveTmpltSearch.and("state", ActiveTmpltSearch.entity().getState(), SearchCriteria.Op.EQ);
ActiveTmpltSearch.and("state", ActiveTmpltSearch.entity().getState(), SearchCriteria.Op.IN);
CountTemplatesByAccount = createSearchBuilder(Long.class);
CountTemplatesByAccount.select(null, Func.COUNT, null);
@ -792,6 +792,15 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
return listBy(sc);
}
@Override
public List<VMTemplateVO> listInZoneByState(long dataCenterId, VirtualMachineTemplate.State... states) {
SearchCriteria<VMTemplateVO> sc = TmpltsInZoneSearch.create();
sc.setParameters("avoidtype", TemplateType.PERHOST.toString());
sc.setParameters("state", (Object[])states);
sc.setJoinParameters("tmpltzone", "zoneId", dataCenterId);
return listBy(sc);
}
@Override
public List<VMTemplateVO> listAllActive() {
SearchCriteria<VMTemplateVO> sc = ActiveTmpltSearch.create();
@ -799,6 +808,13 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
return listBy(sc);
}
@Override
public List<VMTemplateVO> listByState(VirtualMachineTemplate.State... states) {
SearchCriteria<VMTemplateVO> sc = ActiveTmpltSearch.create();
sc.setParameters("state", (Object[])states);
return listBy(sc);
}
@Override
public List<VMTemplateVO> listDefaultBuiltinTemplates() {
SearchCriteria<VMTemplateVO> sc = tmpltTypeSearch.create();

View File

@ -291,10 +291,10 @@ public class TemplateServiceImpl implements TemplateService {
List<VMTemplateVO> allTemplates = null;
if (zoneId == null) {
// region wide store
allTemplates = _templateDao.listAllActive();
allTemplates = _templateDao.listByState(VirtualMachineTemplate.State.Active, VirtualMachineTemplate.State.NotUploaded, VirtualMachineTemplate.State.UploadInProgress);
} else {
// zone wide store
allTemplates = _templateDao.listAllInZone(zoneId);
allTemplates = _templateDao.listInZoneByState(zoneId, VirtualMachineTemplate.State.Active, VirtualMachineTemplate.State.NotUploaded, VirtualMachineTemplate.State.UploadInProgress);
}
List<VMTemplateVO> rtngTmplts = _templateDao.listAllSystemVMTemplates();
List<VMTemplateVO> defaultBuiltin = _templateDao.listDefaultBuiltinTemplates();

View File

@ -1674,6 +1674,42 @@ class TestBrowseUploadVolume(cloudstackTestCase):
return
@attr(tags = ["advanced", "advancedns", "smoke", "basic"], required_hardware="false")
def test_browser_upload_template_incomplete(self):
"""
Test browser based incomplete template upload, followed by SSVM destroy. Template should go to UploadAbandoned state and get cleaned up.
"""
try:
self.debug("========================= Test browser based incomplete template upload ========================")
#Only register template, without uploading
cmd = getUploadParamsForTemplate.getUploadParamsForTemplateCmd()
cmd.zoneid = self.zone.id
cmd.format = self.uploadtemplateformat
cmd.name=self.templatename+self.account.name+(random.choice(string.ascii_uppercase))
cmd.account=self.account.name
cmd.domainid=self.domain.id
cmd.displaytext=cmd.name
cmd.hypervisor=self.templatehypervisor
cmd.ostypeid=self.templateostypeid
template_response=self.apiclient.getUploadParamsForTemplate(cmd)
#Destroy SSVM, and wait for new one to start
self.destroy_ssvm()
#Verify that the template is cleaned up as part of sync-up during new SSVM start
list_template_response=Template.list(
self.apiclient,
id=template_response.id,
templatefilter="all",
zoneid=self.zone.id)
self.assertEqual(list_template_response, None, "Template is not cleaned up, some issue with template sync-up")
except Exception as e:
self.fail("Exceptione occurred : %s" % e)
return
@classmethod
def tearDownClass(self):
try: