|
22 | 22 | import com.cloud.vm.VirtualMachine; |
23 | 23 | import org.apache.cloudstack.backup.BackupAnswer; |
24 | 24 | import org.apache.cloudstack.backup.RestoreBackupCommand; |
| 25 | +import org.apache.cloudstack.storage.to.PrimaryDataStoreTO; |
25 | 26 | import org.junit.Assert; |
26 | 27 | import org.junit.Before; |
27 | 28 | import org.junit.Test; |
@@ -65,6 +66,8 @@ public void testExecuteWithVmExistsNull() throws Exception { |
65 | 66 | when(command.getMountOptions()).thenReturn("rw"); |
66 | 67 | when(command.isVmExists()).thenReturn(null); |
67 | 68 | when(command.getDiskType()).thenReturn("root"); |
| 69 | + PrimaryDataStoreTO primaryDataStore = Mockito.mock(PrimaryDataStoreTO.class); |
| 70 | + when(command.getRestoreVolumePools()).thenReturn(Arrays.asList(primaryDataStore)); |
68 | 71 | when(command.getRestoreVolumePaths()).thenReturn(Arrays.asList("/var/lib/libvirt/images/volume-123")); |
69 | 72 | when(command.getRestoreVolumeUUID()).thenReturn("volume-123"); |
70 | 73 | when(command.getVmState()).thenReturn(VirtualMachine.State.Running); |
@@ -105,6 +108,8 @@ public void testExecuteWithVmExistsTrue() throws Exception { |
105 | 108 | when(command.getMountOptions()).thenReturn("rw"); |
106 | 109 | when(command.isVmExists()).thenReturn(true); |
107 | 110 | when(command.getDiskType()).thenReturn("root"); |
| 111 | + PrimaryDataStoreTO primaryDataStore = Mockito.mock(PrimaryDataStoreTO.class); |
| 112 | + when(command.getRestoreVolumePools()).thenReturn(Arrays.asList(primaryDataStore)); |
108 | 113 | when(command.getRestoreVolumePaths()).thenReturn(Arrays.asList("/var/lib/libvirt/images/volume-123")); |
109 | 114 | when(command.getBackupVolumesUUIDs()).thenReturn(Arrays.asList("volume-123")); |
110 | 115 | when(command.getMountTimeout()).thenReturn(30); |
@@ -141,6 +146,8 @@ public void testExecuteWithVmExistsFalse() throws Exception { |
141 | 146 | when(command.getMountOptions()).thenReturn("rw"); |
142 | 147 | when(command.isVmExists()).thenReturn(false); |
143 | 148 | when(command.getDiskType()).thenReturn("root"); |
| 149 | + PrimaryDataStoreTO primaryDataStore = Mockito.mock(PrimaryDataStoreTO.class); |
| 150 | + when(command.getRestoreVolumePools()).thenReturn(Arrays.asList(primaryDataStore)); |
144 | 151 | when(command.getRestoreVolumePaths()).thenReturn(Arrays.asList("/var/lib/libvirt/images/volume-123")); |
145 | 152 | when(command.getMountTimeout()).thenReturn(30); |
146 | 153 |
|
@@ -176,6 +183,8 @@ public void testExecuteWithCifsMountType() throws Exception { |
176 | 183 | when(command.getMountOptions()).thenReturn("username=user,password=pass"); |
177 | 184 | when(command.isVmExists()).thenReturn(null); |
178 | 185 | when(command.getDiskType()).thenReturn("root"); |
| 186 | + PrimaryDataStoreTO primaryDataStore = Mockito.mock(PrimaryDataStoreTO.class); |
| 187 | + when(command.getRestoreVolumePools()).thenReturn(Arrays.asList(primaryDataStore)); |
179 | 188 | when(command.getRestoreVolumePaths()).thenReturn(Arrays.asList("/var/lib/libvirt/images/volume-123")); |
180 | 189 | when(command.getRestoreVolumeUUID()).thenReturn("volume-123"); |
181 | 190 | when(command.getVmState()).thenReturn(VirtualMachine.State.Running); |
@@ -215,6 +224,8 @@ public void testExecuteWithMountFailure() throws Exception { |
215 | 224 | lenient().when(command.getMountOptions()).thenReturn("rw"); |
216 | 225 | lenient().when(command.isVmExists()).thenReturn(null); |
217 | 226 | lenient().when(command.getDiskType()).thenReturn("root"); |
| 227 | + PrimaryDataStoreTO primaryDataStore = Mockito.mock(PrimaryDataStoreTO.class); |
| 228 | + when(command.getRestoreVolumePools()).thenReturn(Arrays.asList(primaryDataStore)); |
218 | 229 | lenient().when(command.getRestoreVolumePaths()).thenReturn(Arrays.asList("/var/lib/libvirt/images/volume-123")); |
219 | 230 | lenient().when(command.getRestoreVolumeUUID()).thenReturn("volume-123"); |
220 | 231 | lenient().when(command.getVmState()).thenReturn(VirtualMachine.State.Running); |
@@ -249,6 +260,8 @@ public void testExecuteWithBackupFileNotFound() throws Exception { |
249 | 260 | when(command.getMountOptions()).thenReturn("rw"); |
250 | 261 | when(command.isVmExists()).thenReturn(null); |
251 | 262 | when(command.getDiskType()).thenReturn("root"); |
| 263 | + PrimaryDataStoreTO primaryDataStore = Mockito.mock(PrimaryDataStoreTO.class); |
| 264 | + when(command.getRestoreVolumePools()).thenReturn(Arrays.asList(primaryDataStore)); |
252 | 265 | when(command.getRestoreVolumePaths()).thenReturn(Arrays.asList("/var/lib/libvirt/images/volume-123")); |
253 | 266 | when(command.getRestoreVolumeUUID()).thenReturn("volume-123"); |
254 | 267 | when(command.getVmState()).thenReturn(VirtualMachine.State.Running); |
@@ -293,6 +306,8 @@ public void testExecuteWithCorruptBackupFile() throws Exception { |
293 | 306 | when(command.getMountOptions()).thenReturn("rw"); |
294 | 307 | when(command.isVmExists()).thenReturn(null); |
295 | 308 | when(command.getDiskType()).thenReturn("root"); |
| 309 | + PrimaryDataStoreTO primaryDataStore = Mockito.mock(PrimaryDataStoreTO.class); |
| 310 | + when(command.getRestoreVolumePools()).thenReturn(Arrays.asList(primaryDataStore)); |
296 | 311 | when(command.getRestoreVolumePaths()).thenReturn(Arrays.asList("/var/lib/libvirt/images/volume-123")); |
297 | 312 | when(command.getRestoreVolumeUUID()).thenReturn("volume-123"); |
298 | 313 | when(command.getVmState()).thenReturn(VirtualMachine.State.Running); |
@@ -339,6 +354,8 @@ public void testExecuteWithRsyncFailure() throws Exception { |
339 | 354 | when(command.getMountOptions()).thenReturn("rw"); |
340 | 355 | when(command.isVmExists()).thenReturn(null); |
341 | 356 | when(command.getDiskType()).thenReturn("root"); |
| 357 | + PrimaryDataStoreTO primaryDataStore = Mockito.mock(PrimaryDataStoreTO.class); |
| 358 | + when(command.getRestoreVolumePools()).thenReturn(Arrays.asList(primaryDataStore)); |
342 | 359 | when(command.getRestoreVolumePaths()).thenReturn(Arrays.asList("/var/lib/libvirt/images/volume-123")); |
343 | 360 | when(command.getRestoreVolumeUUID()).thenReturn("volume-123"); |
344 | 361 | when(command.getVmState()).thenReturn(VirtualMachine.State.Running); |
@@ -387,6 +404,8 @@ public void testExecuteWithAttachVolumeFailure() throws Exception { |
387 | 404 | when(command.getMountOptions()).thenReturn("rw"); |
388 | 405 | when(command.isVmExists()).thenReturn(null); |
389 | 406 | when(command.getDiskType()).thenReturn("root"); |
| 407 | + PrimaryDataStoreTO primaryDataStore = Mockito.mock(PrimaryDataStoreTO.class); |
| 408 | + when(command.getRestoreVolumePools()).thenReturn(Arrays.asList(primaryDataStore)); |
390 | 409 | when(command.getRestoreVolumePaths()).thenReturn(Arrays.asList("/var/lib/libvirt/images/volume-123")); |
391 | 410 | when(command.getRestoreVolumeUUID()).thenReturn("volume-123"); |
392 | 411 | when(command.getVmState()).thenReturn(VirtualMachine.State.Running); |
@@ -439,6 +458,8 @@ public void testExecuteWithTempDirectoryCreationFailure() throws Exception { |
439 | 458 | lenient().when(command.getMountOptions()).thenReturn("rw"); |
440 | 459 | lenient().when(command.isVmExists()).thenReturn(null); |
441 | 460 | lenient().when(command.getDiskType()).thenReturn("root"); |
| 461 | + PrimaryDataStoreTO primaryDataStore = Mockito.mock(PrimaryDataStoreTO.class); |
| 462 | + when(command.getRestoreVolumePools()).thenReturn(Arrays.asList(primaryDataStore)); |
442 | 463 | lenient().when(command.getRestoreVolumePaths()).thenReturn(Arrays.asList("/var/lib/libvirt/images/volume-123")); |
443 | 464 | lenient().when(command.getRestoreVolumeUUID()).thenReturn("volume-123"); |
444 | 465 | lenient().when(command.getVmState()).thenReturn(VirtualMachine.State.Running); |
@@ -467,6 +488,12 @@ public void testExecuteWithMultipleVolumes() throws Exception { |
467 | 488 | when(command.getMountOptions()).thenReturn("rw"); |
468 | 489 | when(command.isVmExists()).thenReturn(true); |
469 | 490 | 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 | + )); |
470 | 497 | when(command.getRestoreVolumePaths()).thenReturn(Arrays.asList( |
471 | 498 | "/var/lib/libvirt/images/volume-123", |
472 | 499 | "/var/lib/libvirt/images/volume-456" |
|
0 commit comments