CLOUDSTACK-8014: Fix NPE searching including removed templates

Steps to reproduce if you have this issue:
- Create a VM's volume snapshot
- Remove VM's template and mark the template as removed with timestamp in DB
- Restart mgmt server and create a volume out of snapshot you should get NPE

Fix: In `storagePoolHasEnoughSpace`, we're only searching for a VM's volume's
snapshot's template by Id and not including removed templates. This is a corner
case and NPE hits when template has been marked removed for a VM's volume's
template so we should search including removed templates.

Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
(cherry picked from commit f189c105d8dde5491697b171b969e757f8f15858)
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
Rohit Yadav 2014-12-10 19:08:26 +05:30
parent ec478c49a6
commit fdb782ffcb

View File

@ -1576,8 +1576,8 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
long totalAskingSize = 0;
for (Volume volume : volumes) {
if (volume.getTemplateId() != null) {
VMTemplateVO tmpl = _templateDao.findById(volume.getTemplateId());
if (tmpl.getFormat() != ImageFormat.ISO) {
VMTemplateVO tmpl = _templateDao.findByIdIncludingRemoved(volume.getTemplateId());
if (tmpl != null && tmpl.getFormat() != ImageFormat.ISO) {
allocatedSizeWithtemplate = _capacityMgr.getAllocatedPoolCapacity(poolVO, tmpl);
}
}