|
53 | 53 | import com.cloud.vm.dao.NicDao; |
54 | 54 | import com.cloud.vm.dao.UserVmDao; |
55 | 55 | import java.io.IOException; |
| 56 | +import java.util.ArrayList; |
56 | 57 | import java.util.List; |
57 | 58 | import java.util.Optional; |
58 | 59 | import org.apache.cloudstack.api.ApiCommandResourceType; |
@@ -273,6 +274,46 @@ public void testDeploySharedFS() throws ResourceUnavailableException, Insufficie |
273 | 274 | Assert.assertEquals(Optional.ofNullable(result.second()), Optional.ofNullable(s_vmId)); |
274 | 275 | } |
275 | 276 |
|
| 277 | + @Test |
| 278 | + public void testDeploySharedFSContinuesWhenTemplateIsMissingForNonLastHypervisor() throws ResourceUnavailableException, InsufficientCapacityException, ResourceAllocationException, IOException, OperationTimedoutException { |
| 279 | + SharedFS sharedFS = prepareDeploySharedFS(); |
| 280 | + when(resourceMgr.getSupportedHypervisorTypes(s_zoneId, false, null)).thenReturn(new ArrayList<>(List.of(Hypervisor.HypervisorType.External, Hypervisor.HypervisorType.KVM)) { |
| 281 | + @Override |
| 282 | + public Hypervisor.HypervisorType set(int index, Hypervisor.HypervisorType element) { |
| 283 | + // Keep the test order stable while exercising the production shuffle call. |
| 284 | + return get(index); |
| 285 | + } |
| 286 | + }); |
| 287 | + when(templateDao.findSystemVMReadyTemplate(s_zoneId, Hypervisor.HypervisorType.External, ResourceManager.SystemVmPreferredArchitecture.defaultValue())).thenReturn(null); |
| 288 | + |
| 289 | + Account owner = mock(Account.class); |
| 290 | + when(owner.getId()).thenReturn(s_ownerId); |
| 291 | + when(accountMgr.getActiveAccountById(s_ownerId)).thenReturn(owner); |
| 292 | + |
| 293 | + UserVm vm = mock(UserVm.class); |
| 294 | + when(vm.getId()).thenReturn(s_vmId); |
| 295 | + when(userVmService.createAdvancedVirtualMachine( |
| 296 | + any(DataCenter.class), any(ServiceOffering.class), any(VirtualMachineTemplate.class), anyList(), any(Account.class), anyString(), |
| 297 | + anyString(), anyLong(), anyLong(), any(), isNull(), any(Hypervisor.HypervisorType.class), any(BaseCmd.HTTPMethod.class), anyString(), |
| 298 | + isNull(), isNull(), anyList(), isNull(), any(Network.IpAddresses.class), isNull(), isNull(), isNull(), |
| 299 | + anyMap(), isNull(), isNull(), isNull(), isNull(), |
| 300 | + anyBoolean(), anyString(), isNull(), isNull(), isNull())).thenReturn(vm); |
| 301 | + |
| 302 | + VolumeVO rootVol = mock(VolumeVO.class); |
| 303 | + when(rootVol.getVolumeType()).thenReturn(Volume.Type.ROOT); |
| 304 | + when(rootVol.getName()).thenReturn("ROOT-1"); |
| 305 | + VolumeVO dataVol = mock(VolumeVO.class); |
| 306 | + when(dataVol.getId()).thenReturn(s_volumeId); |
| 307 | + when(dataVol.getName()).thenReturn("DATA-1"); |
| 308 | + when(dataVol.getVolumeType()).thenReturn(Volume.Type.DATADISK); |
| 309 | + when(volumeDao.findByInstance(s_vmId)).thenReturn(List.of(rootVol, dataVol)); |
| 310 | + |
| 311 | + Pair<Long, Long> result = lifeCycle.deploySharedFS(sharedFS, s_networkId, s_diskOfferingId, s_size, s_minIops, s_maxIops); |
| 312 | + |
| 313 | + Assert.assertEquals(Optional.ofNullable(result.first()), Optional.ofNullable(s_volumeId)); |
| 314 | + Assert.assertEquals(Optional.ofNullable(result.second()), Optional.ofNullable(s_vmId)); |
| 315 | + } |
| 316 | + |
276 | 317 | @Test(expected = CloudRuntimeException.class) |
277 | 318 | public void testDeploySharedFSHypervisorNotFound() throws ResourceUnavailableException, InsufficientCapacityException, ResourceAllocationException, IOException, OperationTimedoutException { |
278 | 319 | SharedFS sharedFS = mock(SharedFS.class); |
|
0 commit comments