Skip to content

Commit 9edae46

Browse files
test fixes
1 parent b85267b commit 9edae46

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.cloud.vm.VirtualMachine;
2323
import org.apache.cloudstack.backup.BackupAnswer;
2424
import org.apache.cloudstack.backup.RestoreBackupCommand;
25+
import org.apache.cloudstack.storage.to.PrimaryDataStoreTO;
2526
import org.junit.Assert;
2627
import org.junit.Before;
2728
import org.junit.Test;
@@ -65,6 +66,8 @@ public void testExecuteWithVmExistsNull() throws Exception {
6566
when(command.getMountOptions()).thenReturn("rw");
6667
when(command.isVmExists()).thenReturn(null);
6768
when(command.getDiskType()).thenReturn("root");
69+
PrimaryDataStoreTO primaryDataStore = Mockito.mock(PrimaryDataStoreTO.class);
70+
when(command.getRestoreVolumePools()).thenReturn(Arrays.asList(primaryDataStore));
6871
when(command.getRestoreVolumePaths()).thenReturn(Arrays.asList("/var/lib/libvirt/images/volume-123"));
6972
when(command.getRestoreVolumeUUID()).thenReturn("volume-123");
7073
when(command.getVmState()).thenReturn(VirtualMachine.State.Running);
@@ -105,6 +108,8 @@ public void testExecuteWithVmExistsTrue() throws Exception {
105108
when(command.getMountOptions()).thenReturn("rw");
106109
when(command.isVmExists()).thenReturn(true);
107110
when(command.getDiskType()).thenReturn("root");
111+
PrimaryDataStoreTO primaryDataStore = Mockito.mock(PrimaryDataStoreTO.class);
112+
when(command.getRestoreVolumePools()).thenReturn(Arrays.asList(primaryDataStore));
108113
when(command.getRestoreVolumePaths()).thenReturn(Arrays.asList("/var/lib/libvirt/images/volume-123"));
109114
when(command.getBackupVolumesUUIDs()).thenReturn(Arrays.asList("volume-123"));
110115
when(command.getMountTimeout()).thenReturn(30);
@@ -141,6 +146,8 @@ public void testExecuteWithVmExistsFalse() throws Exception {
141146
when(command.getMountOptions()).thenReturn("rw");
142147
when(command.isVmExists()).thenReturn(false);
143148
when(command.getDiskType()).thenReturn("root");
149+
PrimaryDataStoreTO primaryDataStore = Mockito.mock(PrimaryDataStoreTO.class);
150+
when(command.getRestoreVolumePools()).thenReturn(Arrays.asList(primaryDataStore));
144151
when(command.getRestoreVolumePaths()).thenReturn(Arrays.asList("/var/lib/libvirt/images/volume-123"));
145152
when(command.getMountTimeout()).thenReturn(30);
146153

@@ -176,6 +183,8 @@ public void testExecuteWithCifsMountType() throws Exception {
176183
when(command.getMountOptions()).thenReturn("username=user,password=pass");
177184
when(command.isVmExists()).thenReturn(null);
178185
when(command.getDiskType()).thenReturn("root");
186+
PrimaryDataStoreTO primaryDataStore = Mockito.mock(PrimaryDataStoreTO.class);
187+
when(command.getRestoreVolumePools()).thenReturn(Arrays.asList(primaryDataStore));
179188
when(command.getRestoreVolumePaths()).thenReturn(Arrays.asList("/var/lib/libvirt/images/volume-123"));
180189
when(command.getRestoreVolumeUUID()).thenReturn("volume-123");
181190
when(command.getVmState()).thenReturn(VirtualMachine.State.Running);
@@ -215,6 +224,8 @@ public void testExecuteWithMountFailure() throws Exception {
215224
lenient().when(command.getMountOptions()).thenReturn("rw");
216225
lenient().when(command.isVmExists()).thenReturn(null);
217226
lenient().when(command.getDiskType()).thenReturn("root");
227+
PrimaryDataStoreTO primaryDataStore = Mockito.mock(PrimaryDataStoreTO.class);
228+
when(command.getRestoreVolumePools()).thenReturn(Arrays.asList(primaryDataStore));
218229
lenient().when(command.getRestoreVolumePaths()).thenReturn(Arrays.asList("/var/lib/libvirt/images/volume-123"));
219230
lenient().when(command.getRestoreVolumeUUID()).thenReturn("volume-123");
220231
lenient().when(command.getVmState()).thenReturn(VirtualMachine.State.Running);
@@ -249,6 +260,8 @@ public void testExecuteWithBackupFileNotFound() throws Exception {
249260
when(command.getMountOptions()).thenReturn("rw");
250261
when(command.isVmExists()).thenReturn(null);
251262
when(command.getDiskType()).thenReturn("root");
263+
PrimaryDataStoreTO primaryDataStore = Mockito.mock(PrimaryDataStoreTO.class);
264+
when(command.getRestoreVolumePools()).thenReturn(Arrays.asList(primaryDataStore));
252265
when(command.getRestoreVolumePaths()).thenReturn(Arrays.asList("/var/lib/libvirt/images/volume-123"));
253266
when(command.getRestoreVolumeUUID()).thenReturn("volume-123");
254267
when(command.getVmState()).thenReturn(VirtualMachine.State.Running);
@@ -293,6 +306,8 @@ public void testExecuteWithCorruptBackupFile() throws Exception {
293306
when(command.getMountOptions()).thenReturn("rw");
294307
when(command.isVmExists()).thenReturn(null);
295308
when(command.getDiskType()).thenReturn("root");
309+
PrimaryDataStoreTO primaryDataStore = Mockito.mock(PrimaryDataStoreTO.class);
310+
when(command.getRestoreVolumePools()).thenReturn(Arrays.asList(primaryDataStore));
296311
when(command.getRestoreVolumePaths()).thenReturn(Arrays.asList("/var/lib/libvirt/images/volume-123"));
297312
when(command.getRestoreVolumeUUID()).thenReturn("volume-123");
298313
when(command.getVmState()).thenReturn(VirtualMachine.State.Running);
@@ -339,6 +354,8 @@ public void testExecuteWithRsyncFailure() throws Exception {
339354
when(command.getMountOptions()).thenReturn("rw");
340355
when(command.isVmExists()).thenReturn(null);
341356
when(command.getDiskType()).thenReturn("root");
357+
PrimaryDataStoreTO primaryDataStore = Mockito.mock(PrimaryDataStoreTO.class);
358+
when(command.getRestoreVolumePools()).thenReturn(Arrays.asList(primaryDataStore));
342359
when(command.getRestoreVolumePaths()).thenReturn(Arrays.asList("/var/lib/libvirt/images/volume-123"));
343360
when(command.getRestoreVolumeUUID()).thenReturn("volume-123");
344361
when(command.getVmState()).thenReturn(VirtualMachine.State.Running);
@@ -387,6 +404,8 @@ public void testExecuteWithAttachVolumeFailure() throws Exception {
387404
when(command.getMountOptions()).thenReturn("rw");
388405
when(command.isVmExists()).thenReturn(null);
389406
when(command.getDiskType()).thenReturn("root");
407+
PrimaryDataStoreTO primaryDataStore = Mockito.mock(PrimaryDataStoreTO.class);
408+
when(command.getRestoreVolumePools()).thenReturn(Arrays.asList(primaryDataStore));
390409
when(command.getRestoreVolumePaths()).thenReturn(Arrays.asList("/var/lib/libvirt/images/volume-123"));
391410
when(command.getRestoreVolumeUUID()).thenReturn("volume-123");
392411
when(command.getVmState()).thenReturn(VirtualMachine.State.Running);
@@ -439,6 +458,8 @@ public void testExecuteWithTempDirectoryCreationFailure() throws Exception {
439458
lenient().when(command.getMountOptions()).thenReturn("rw");
440459
lenient().when(command.isVmExists()).thenReturn(null);
441460
lenient().when(command.getDiskType()).thenReturn("root");
461+
PrimaryDataStoreTO primaryDataStore = Mockito.mock(PrimaryDataStoreTO.class);
462+
when(command.getRestoreVolumePools()).thenReturn(Arrays.asList(primaryDataStore));
442463
lenient().when(command.getRestoreVolumePaths()).thenReturn(Arrays.asList("/var/lib/libvirt/images/volume-123"));
443464
lenient().when(command.getRestoreVolumeUUID()).thenReturn("volume-123");
444465
lenient().when(command.getVmState()).thenReturn(VirtualMachine.State.Running);
@@ -467,6 +488,12 @@ public void testExecuteWithMultipleVolumes() throws Exception {
467488
when(command.getMountOptions()).thenReturn("rw");
468489
when(command.isVmExists()).thenReturn(true);
469490
when(command.getDiskType()).thenReturn("root");
491+
PrimaryDataStoreTO primaryDataStore1 = Mockito.mock(PrimaryDataStoreTO.class);
492+
PrimaryDataStoreTO primaryDataStore2 = Mockito.mock(PrimaryDataStoreTO.class);
493+
when(command.getRestoreVolumePools()).thenReturn(Arrays.asList(
494+
primaryDataStore1,
495+
primaryDataStore2
496+
));
470497
when(command.getRestoreVolumePaths()).thenReturn(Arrays.asList(
471498
"/var/lib/libvirt/images/volume-123",
472499
"/var/lib/libvirt/images/volume-456"

0 commit comments

Comments
 (0)