From 2d9e488d0c999cac734ab97c1f272dc21ddac0f5 Mon Sep 17 00:00:00 2001 From: Brad House Date: Sun, 22 Nov 2026 20:33:59 +0000 Subject: [PATCH] Fix two lines changed by mistake in the 4.22 merge The merge 82bfa9fb3f left these on main; neither parent had them. - ApiResponseHelper.getDataStoreRole: Boolean.getBoolean(value) reads a JVM system property, so it was always false and snapshots on storage with storage-system snapshot support got the Image role. Use Boolean.parseBoolean(value), same as main had (new Boolean). - VolumeApiServiceImpl.uploadVolume: restore UseHttpsToUpload.valueIn(zoneId) from #11539; the zone value was ignored for volume uploads. - VolumeApiServiceImpl: fix {code}...{code} Javadoc to {@code ...}. - Add getDataStoreRole tests in ApiResponseHelperTest. Signed-off-by: Brad House --- .../java/com/cloud/api/ApiResponseHelper.java | 2 +- .../cloud/storage/VolumeApiServiceImpl.java | 10 +++--- .../com/cloud/api/ApiResponseHelperTest.java | 35 +++++++++++++++++++ 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/server/src/main/java/com/cloud/api/ApiResponseHelper.java b/server/src/main/java/com/cloud/api/ApiResponseHelper.java index 1464f4444891..4ad71e6d414d 100644 --- a/server/src/main/java/com/cloud/api/ApiResponseHelper.java +++ b/server/src/main/java/com/cloud/api/ApiResponseHelper.java @@ -840,7 +840,7 @@ public static DataStoreRole getDataStoreRole(Snapshot snapshot, SnapshotDataStor if (mapCapabilities != null) { String value = mapCapabilities.get(DataStoreCapabilities.STORAGE_SYSTEM_SNAPSHOT.toString()); - boolean supportsStorageSystemSnapshots = Boolean.getBoolean(value); + boolean supportsStorageSystemSnapshots = Boolean.parseBoolean(value); if (supportsStorageSystemSnapshots) { return DataStoreRole.Primary; diff --git a/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java b/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java index 11b24a9beef6..174339169e33 100644 --- a/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java +++ b/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java @@ -531,7 +531,7 @@ public GetUploadParamsResponse doInTransaction(TransactionStatus status) throws GetUploadParamsResponse response = new GetUploadParamsResponse(); String ssvmUrlDomain = _configDao.getValue(Config.SecStorageSecureCopyCert.key()); - String protocol = UseHttpsToUpload.value() ? "https" : "http"; + String protocol = UseHttpsToUpload.valueIn(zoneId) ? "https" : "http"; String url = ImageStoreUtil.generatePostUploadUrl(ssvmUrlDomain, ep.getPublicAddr(), vol.getUuid(), protocol); response.setPostURL(new URL(url)); @@ -1819,10 +1819,10 @@ protected VolumeVO retrieveAndValidateVolume(long volumeId, Account caller) { * * A volume can be destroyed if it is not in any of the following states. * * * The volume is destroyed via {@link VolumeService#destroyVolume(long)} method. diff --git a/server/src/test/java/com/cloud/api/ApiResponseHelperTest.java b/server/src/test/java/com/cloud/api/ApiResponseHelperTest.java index bbd7afcdd113..c81ecf47bd9b 100644 --- a/server/src/test/java/com/cloud/api/ApiResponseHelperTest.java +++ b/server/src/test/java/com/cloud/api/ApiResponseHelperTest.java @@ -58,6 +58,12 @@ import org.apache.cloudstack.api.response.UsageRecordResponse; import org.apache.cloudstack.api.response.TrafficTypeResponse; import org.apache.cloudstack.context.CallContext; +import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; +import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreCapabilities; +import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreDriver; +import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager; +import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreDao; +import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO; import org.apache.cloudstack.usage.UsageService; import org.apache.cloudstack.vm.UnmanagedInstanceTO; @@ -84,7 +90,9 @@ import com.cloud.server.ResourceIcon; import com.cloud.server.ResourceIconManager; import com.cloud.server.ResourceTag; +import com.cloud.storage.DataStoreRole; import com.cloud.storage.GuestOsCategory; +import com.cloud.storage.Snapshot; import com.cloud.storage.VMTemplateVO; import com.cloud.usage.UsageVO; import com.cloud.user.Account; @@ -850,4 +858,31 @@ public void showVmInfoForSharedNetworksTestRouterPlaceholderOnly() { verify(ipResponse, Mockito.never()).setVirtualMachineId(Mockito.anyString()); } } + + private DataStoreRole getDataStoreRoleForStorageSystemSnapshotCapability(String capability) { + Snapshot snapshot = Mockito.mock(Snapshot.class); + when(snapshot.getId()).thenReturn(1L); + SnapshotDataStoreVO snapshotStore = Mockito.mock(SnapshotDataStoreVO.class); + when(snapshotStore.getDataStoreId()).thenReturn(2L); + SnapshotDataStoreDao snapshotStoreDao = Mockito.mock(SnapshotDataStoreDao.class); + when(snapshotStoreDao.findOneBySnapshotAndDatastoreRole(1L, DataStoreRole.Primary)).thenReturn(snapshotStore); + DataStoreDriver driver = Mockito.mock(DataStoreDriver.class); + when(driver.getCapabilities()).thenReturn(Map.of(DataStoreCapabilities.STORAGE_SYSTEM_SNAPSHOT.toString(), capability)); + DataStore dataStore = Mockito.mock(DataStore.class); + when(dataStore.getDriver()).thenReturn(driver); + DataStoreManager dataStoreMgr = Mockito.mock(DataStoreManager.class); + when(dataStoreMgr.getDataStore(2L, DataStoreRole.Primary)).thenReturn(dataStore); + + return ApiResponseHelper.getDataStoreRole(snapshot, snapshotStoreDao, dataStoreMgr); + } + + @Test + public void getDataStoreRoleTestStorageSystemSnapshotSupported() { + assertEquals(DataStoreRole.Primary, getDataStoreRoleForStorageSystemSnapshotCapability("true")); + } + + @Test + public void getDataStoreRoleTestStorageSystemSnapshotNotSupported() { + assertEquals(DataStoreRole.Image, getDataStoreRoleForStorageSystemSnapshotCapability("false")); + } }