Skip to content

Commit c4f3b78

Browse files
CSTACKEX-259: downloaded state check is not required
1 parent 38de128 commit c4f3b78

2 files changed

Lines changed: 7 additions & 14 deletions

File tree

plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/driver/OntapPrimaryDatastoreDriver.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import com.cloud.storage.ScopeType;
3636
import com.cloud.storage.SnapshotVO;
3737
import com.cloud.storage.VMTemplateStoragePoolVO;
38-
import com.cloud.storage.VMTemplateStorageResourceAssoc;
3938
import com.cloud.storage.dao.SnapshotDao;
4039
import com.cloud.storage.dao.SnapshotDetailsDao;
4140
import com.cloud.storage.dao.SnapshotDetailsVO;
@@ -950,8 +949,8 @@ public long getBytesRequiredForTemplate(TemplateInfo templateInfo, StoragePool s
950949
if (templateInfo == null || storagePool == null) {
951950
return 0;
952951
}
953-
// template_spool_ref is inserted in Allocated/NOT_DOWNLOADED before the cache exists;
954-
// only skip reservation when the template is truly cached on this pool.
952+
// template_spool_ref is inserted in Allocated before the cache exists;
953+
// only skip reservation when the template is Ready and has a backend identity.
955954
VMTemplateStoragePoolVO templatePoolRef =
956955
vmTemplatePoolDao.findByPoolTemplate(storagePool.getId(), templateInfo.getId(), null);
957956
Map<String, String> details = storagePoolDetailsDao.listDetailsKeyPairs(storagePool.getId());
@@ -963,15 +962,13 @@ public long getBytesRequiredForTemplate(TemplateInfo templateInfo, StoragePool s
963962

964963
/**
965964
* Returns true when the primary template cache is present and usable for clone/deploy.
966-
* A spool_ref row alone is not enough: CloudStack creates it before the LUN/file exists.
965+
* A spool_ref row alone is not enough: CloudStack creates it in Allocated before the LUN/file exists.
966+
* Ready is sufficient; downloadState is set alongside Ready on the managed-cache success path.
967967
*/
968968
private boolean isTemplateCachedOnPool(VMTemplateStoragePoolVO templatePoolRef, Map<String, String> details) {
969969
if (templatePoolRef == null) {
970970
return false;
971971
}
972-
if (templatePoolRef.getDownloadState() != VMTemplateStorageResourceAssoc.Status.DOWNLOADED) {
973-
return false;
974-
}
975972
if (templatePoolRef.getState() != ObjectInDataStoreStateMachine.State.Ready) {
976973
return false;
977974
}

plugins/storage/volume/ontap/src/test/java/org/apache/cloudstack/storage/driver/OntapPrimaryDatastoreDriverTest.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import com.cloud.storage.ScopeType;
2626
import com.cloud.storage.Storage;
2727
import com.cloud.storage.VMTemplateStoragePoolVO;
28-
import com.cloud.storage.VMTemplateStorageResourceAssoc;
2928
import com.cloud.storage.VolumeVO;
3029
import com.cloud.storage.VolumeDetailVO;
3130
import com.cloud.storage.dao.VMTemplatePoolDao;
@@ -681,7 +680,6 @@ void testGetBytesRequiredForTemplate_AlreadyCached_ReturnsZero() {
681680
when(templateInfo.getId()).thenReturn(50L);
682681
when(storagePoolDetailsDao.listDetailsKeyPairs(1L)).thenReturn(storagePoolDetails);
683682
when(vmTemplatePoolDao.findByPoolTemplate(1L, 50L, null)).thenReturn(templatePoolRef);
684-
when(templatePoolRef.getDownloadState()).thenReturn(VMTemplateStorageResourceAssoc.Status.DOWNLOADED);
685683
when(templatePoolRef.getState()).thenReturn(ObjectInDataStoreStateMachine.State.Ready);
686684
when(templatePoolRef.getLocalDownloadPath()).thenReturn("template-lun-uuid");
687685

@@ -700,25 +698,24 @@ void testGetBytesRequiredForTemplate_NotCached_ReturnsVirtualSize() {
700698
}
701699

702700
@Test
703-
void testGetBytesRequiredForTemplate_SpoolRefNotDownloaded_ReturnsVirtualSize() {
701+
void testGetBytesRequiredForTemplate_SpoolRefNotReady_ReturnsVirtualSize() {
704702
when(storagePool.getId()).thenReturn(1L);
705703
when(templateInfo.getId()).thenReturn(50L);
706704
when(templateInfo.getSize()).thenReturn(5368709120L);
707705
when(storagePoolDetailsDao.listDetailsKeyPairs(1L)).thenReturn(storagePoolDetails);
708706
when(vmTemplatePoolDao.findByPoolTemplate(1L, 50L, null)).thenReturn(templatePoolRef);
709-
when(templatePoolRef.getDownloadState()).thenReturn(VMTemplateStorageResourceAssoc.Status.NOT_DOWNLOADED);
707+
when(templatePoolRef.getState()).thenReturn(ObjectInDataStoreStateMachine.State.Allocated);
710708

711709
assertEquals(5368709120L, driver.getBytesRequiredForTemplate(templateInfo, storagePool));
712710
}
713711

714712
@Test
715-
void testGetBytesRequiredForTemplate_DownloadedWithoutBackendIdentity_ReturnsVirtualSize() {
713+
void testGetBytesRequiredForTemplate_ReadyWithoutBackendIdentity_ReturnsVirtualSize() {
716714
when(storagePool.getId()).thenReturn(1L);
717715
when(templateInfo.getId()).thenReturn(50L);
718716
when(templateInfo.getSize()).thenReturn(5368709120L);
719717
when(storagePoolDetailsDao.listDetailsKeyPairs(1L)).thenReturn(storagePoolDetails);
720718
when(vmTemplatePoolDao.findByPoolTemplate(1L, 50L, null)).thenReturn(templatePoolRef);
721-
when(templatePoolRef.getDownloadState()).thenReturn(VMTemplateStorageResourceAssoc.Status.DOWNLOADED);
722719
when(templatePoolRef.getState()).thenReturn(ObjectInDataStoreStateMachine.State.Ready);
723720
when(templatePoolRef.getLocalDownloadPath()).thenReturn(null);
724721

@@ -732,7 +729,6 @@ void testGetBytesRequiredForTemplate_NfsCached_ReturnsZero() {
732729
when(templateInfo.getId()).thenReturn(50L);
733730
when(storagePoolDetailsDao.listDetailsKeyPairs(1L)).thenReturn(storagePoolDetails);
734731
when(vmTemplatePoolDao.findByPoolTemplate(1L, 50L, null)).thenReturn(templatePoolRef);
735-
when(templatePoolRef.getDownloadState()).thenReturn(VMTemplateStorageResourceAssoc.Status.DOWNLOADED);
736732
when(templatePoolRef.getState()).thenReturn(ObjectInDataStoreStateMachine.State.Ready);
737733
when(templatePoolRef.getInstallPath()).thenReturn("/mnt/pool/template-uuid");
738734

0 commit comments

Comments
 (0)