Skip to content

Commit c17b6b9

Browse files
DaanHooglandwinterhazelabh1sar
authored
Apply suggestions from code review
Co-authored-by: Fabricio Duarte <fabricio.duarte.jr@gmail.com> Co-authored-by: Abhisar Sinha <63767682+abh1sar@users.noreply.github.com>
1 parent bb09201 commit c17b6b9

3 files changed

Lines changed: 18 additions & 8 deletions

File tree

framework/quota/src/test/java/org/apache/cloudstack/quota/activationrule/presetvariables/PresetVariableHelperTest.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,14 +215,14 @@ private Value getValueForTests() {
215215
value.setTags(Collections.singletonMap("tag1", "value1"));
216216
value.setTemplate(getGenericPresetVariableForTests());
217217
value.setDiskOffering(getDiskOfferingForTests());
218-
value.setProvisioningType(ProvisioningType.THIN);
218+
value.setProvisioningType(ProvisioningType.THIN.toString());
219219
value.setStorage(getStorageForTests());
220220
value.setSize(ByteScaleUtils.GiB);
221221
value.setSnapshotType(Snapshot.Type.HOURLY.toString());
222222
value.setTag("tag_test");
223223
value.setVmSnapshotType(VMSnapshot.Type.Disk.toString());
224224
value.setComputingResources(getComputingResourcesForTests());
225-
value.setVolumeType(Volume.Type.DATADISK);
225+
value.setVolumeType(Volume.Type.DATADISK.toString());
226226
return value;
227227
}
228228

@@ -743,8 +743,8 @@ public void loadPresetVariableValueForVolumeTestRecordIsVolumeAndHasStorageSetFi
743743
Mockito.doReturn(expected.getId()).when(volumeVoMock).getUuid();
744744
Mockito.doReturn(expected.getName()).when(volumeVoMock).getName();
745745
Mockito.doReturn(expected.getDiskOffering()).when(presetVariableHelperSpy).getPresetVariableValueDiskOffering(Mockito.anyLong());
746-
Mockito.doReturn(expected.getVolumeType()).when(volumeVoMock).getVolumeType();
747-
Mockito.doReturn(expected.getProvisioningType()).when(volumeVoMock).getProvisioningType();
746+
Mockito.doReturn(Volume.Type.valueOf(expected.getVolumeType())).when(volumeVoMock).getVolumeType();
747+
Mockito.doReturn(ProvisioningType.getProvisioningType(expected.getProvisioningType())).when(volumeVoMock).getProvisioningType();
748748
Mockito.doReturn(expected.getStorage()).when(presetVariableHelperSpy).getPresetVariableValueStorage(Mockito.anyLong(), Mockito.anyInt());
749749
Mockito.doReturn(expected.getTags()).when(presetVariableHelperSpy).getPresetVariableValueResourceTags(Mockito.anyLong(), Mockito.any(ResourceObjectType.class));
750750
Mockito.doReturn(expected.getSize()).when(volumeVoMock).getSize();
@@ -785,8 +785,9 @@ public void loadPresetVariableValueForVolumeTestRecordIsVolumeAndDoesNotHaveStor
785785
Mockito.doReturn(expected.getId()).when(volumeVoMock).getUuid();
786786
Mockito.doReturn(expected.getName()).when(volumeVoMock).getName();
787787
Mockito.doReturn(expected.getDiskOffering()).when(presetVariableHelperSpy).getPresetVariableValueDiskOffering(Mockito.anyLong());
788-
Mockito.doReturn(expected.getVolumeType()).when(volumeVoMock).getVolumeType();
789-
Mockito.doReturn(expected.getProvisioningType()).when(volumeVoMock).getProvisioningType();
788+
Mockito.doReturn(Volume.Type.valueOf(expected.getVolumeType())).when(volumeVoMock).getVolumeType();
789+
790+
Mockito.doReturn(ProvisioningType.getProvisioningType(expected.getProvisioningType())).when(volumeVoMock).getProvisioningType();
790791
Mockito.doReturn(expected.getTags()).when(presetVariableHelperSpy).getPresetVariableValueResourceTags(Mockito.anyLong(), Mockito.any(ResourceObjectType.class));
791792
Mockito.doReturn(expected.getSize()).when(volumeVoMock).getSize();
792793
Mockito.doReturn(imageFormat).when(volumeVoMock).getFormat();

plugins/backup/nas/src/main/java/org/apache/cloudstack/backup/NASBackupProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ public Pair<Boolean, String> restoreBackedUpVolume(Backup backup, Backup.VolumeI
379379
if (matchingVolume == null) {
380380
throw new CloudRuntimeException(String.format("Unable to find volume %s in the list of backed up volumes for backup %s, cannot proceed with restore", volume.getUuid(), backup));
381381
}
382-
382+
Long backedUpVolumeSize = matchingVolume.getSize();
383383
LOG.debug("Restoring vm volume {} from backup {} on the NAS Backup Provider", volume, backup);
384384
BackupRepository backupRepository = getBackupRepository(backup);
385385

@@ -398,7 +398,7 @@ public Pair<Boolean, String> restoreBackedUpVolume(Backup backup, Backup.VolumeI
398398
restoredVolume.setPoolType(pool.getPoolType());
399399
restoredVolume.setPath(restoredVolume.getUuid());
400400
restoredVolume.setState(Volume.State.Copying);
401-
restoredVolume.setSize(backupVolumeInfo.getSize());
401+
restoredVolume.setSize(backedUpVolumeSize);
402402
restoredVolume.setDiskOfferingId(diskOffering.getId());
403403
if (pool.getPoolType() != Storage.StoragePoolType.RBD) {
404404
restoredVolume.setFormat(Storage.ImageFormat.QCOW2);

plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRestoreBackupCommandWrapperTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ public void testExecuteWithVmExistsTrue() throws Exception {
113113
when(command.getRestoreVolumePools()).thenReturn(Arrays.asList(primaryDataStore));
114114
when(command.getRestoreVolumePaths()).thenReturn(Arrays.asList("/var/lib/libvirt/images/volume-123"));
115115
when(command.getBackupVolumesUUIDs()).thenReturn(Arrays.asList("volume-123"));
116+
when(command.getBackupFiles()).thenReturn(Arrays.asList("volume-123"));
116117
when(command.getMountTimeout()).thenReturn(30);
117118

118119
try (MockedStatic<Files> filesMock = mockStatic(Files.class)) {
@@ -150,6 +151,7 @@ public void testExecuteWithVmExistsFalse() throws Exception {
150151
PrimaryDataStoreTO primaryDataStore = Mockito.mock(PrimaryDataStoreTO.class);
151152
when(command.getRestoreVolumePools()).thenReturn(Arrays.asList(primaryDataStore));
152153
when(command.getRestoreVolumePaths()).thenReturn(Arrays.asList("/var/lib/libvirt/images/volume-123"));
154+
when(command.getBackupFiles()).thenReturn(Arrays.asList("volume-123"));
153155
when(command.getMountTimeout()).thenReturn(30);
154156

155157
try (MockedStatic<Files> filesMock = mockStatic(Files.class)) {
@@ -188,6 +190,7 @@ public void testExecuteWithCifsMountType() throws Exception {
188190
when(command.getRestoreVolumePools()).thenReturn(Arrays.asList(primaryDataStore));
189191
when(command.getRestoreVolumePaths()).thenReturn(Arrays.asList("/var/lib/libvirt/images/volume-123"));
190192
when(command.getBackupVolumesUUIDs()).thenReturn(Collections.singletonList("volume-123"));
193+
when(command.getBackupFiles()).thenReturn(Arrays.asList("volume-123"));
191194
when(command.getVmState()).thenReturn(VirtualMachine.State.Running);
192195
when(command.getMountTimeout()).thenReturn(30);
193196

@@ -229,6 +232,7 @@ public void testExecuteWithMountFailure() throws Exception {
229232
when(command.getRestoreVolumePools()).thenReturn(Arrays.asList(primaryDataStore));
230233
lenient().when(command.getRestoreVolumePaths()).thenReturn(Arrays.asList("/var/lib/libvirt/images/volume-123"));
231234
lenient().when(command.getBackupVolumesUUIDs()).thenReturn(Collections.singletonList("volume-123"));
235+
when(command.getBackupFiles()).thenReturn(Arrays.asList("volume-123"));
232236
lenient().when(command.getVmState()).thenReturn(VirtualMachine.State.Running);
233237
lenient().when(command.getMountTimeout()).thenReturn(30);
234238

@@ -265,6 +269,7 @@ public void testExecuteWithBackupFileNotFound() throws Exception {
265269
when(command.getRestoreVolumePools()).thenReturn(Arrays.asList(primaryDataStore));
266270
when(command.getRestoreVolumePaths()).thenReturn(Arrays.asList("/var/lib/libvirt/images/volume-123"));
267271
when(command.getBackupVolumesUUIDs()).thenReturn(Collections.singletonList("volume-123"));
272+
when(command.getBackupFiles()).thenReturn(Arrays.asList("volume-123"));
268273
when(command.getVmState()).thenReturn(VirtualMachine.State.Running);
269274
when(command.getMountTimeout()).thenReturn(30);
270275

@@ -311,6 +316,7 @@ public void testExecuteWithCorruptBackupFile() throws Exception {
311316
when(command.getRestoreVolumePools()).thenReturn(Arrays.asList(primaryDataStore));
312317
when(command.getRestoreVolumePaths()).thenReturn(Arrays.asList("/var/lib/libvirt/images/volume-123"));
313318
when(command.getBackupVolumesUUIDs()).thenReturn(Collections.singletonList("volume-123"));
319+
when(command.getBackupFiles()).thenReturn(Arrays.asList("volume-123"));
314320
when(command.getVmState()).thenReturn(VirtualMachine.State.Running);
315321
when(command.getMountTimeout()).thenReturn(30);
316322

@@ -359,6 +365,7 @@ public void testExecuteWithRsyncFailure() throws Exception {
359365
when(command.getRestoreVolumePools()).thenReturn(Arrays.asList(primaryDataStore));
360366
when(command.getRestoreVolumePaths()).thenReturn(Arrays.asList("/var/lib/libvirt/images/volume-123"));
361367
when(command.getBackupVolumesUUIDs()).thenReturn(Collections.singletonList("volume-123"));
368+
when(command.getBackupFiles()).thenReturn(Arrays.asList("volume-123"));
362369
when(command.getVmState()).thenReturn(VirtualMachine.State.Running);
363370
when(command.getMountTimeout()).thenReturn(30);
364371

@@ -409,6 +416,7 @@ public void testExecuteWithAttachVolumeFailure() throws Exception {
409416
when(command.getRestoreVolumePools()).thenReturn(Arrays.asList(primaryDataStore));
410417
when(command.getRestoreVolumePaths()).thenReturn(Arrays.asList("/var/lib/libvirt/images/volume-123"));
411418
when(command.getBackupVolumesUUIDs()).thenReturn(Collections.singletonList("volume-123"));
419+
when(command.getBackupFiles()).thenReturn(Arrays.asList("volume-123"));
412420
when(command.getVmState()).thenReturn(VirtualMachine.State.Running);
413421
when(command.getMountTimeout()).thenReturn(30);
414422

@@ -463,6 +471,7 @@ public void testExecuteWithTempDirectoryCreationFailure() throws Exception {
463471
when(command.getRestoreVolumePools()).thenReturn(Arrays.asList(primaryDataStore));
464472
lenient().when(command.getRestoreVolumePaths()).thenReturn(Arrays.asList("/var/lib/libvirt/images/volume-123"));
465473
lenient().when(command.getBackupVolumesUUIDs()).thenReturn(Collections.singletonList("volume-123"));
474+
when(command.getBackupFiles()).thenReturn(Arrays.asList("volume-123"));
466475
lenient().when(command.getVmState()).thenReturn(VirtualMachine.State.Running);
467476
lenient().when(command.getMountTimeout()).thenReturn(30);
468477

0 commit comments

Comments
 (0)