Skip to content

Commit f493d99

Browse files
authored
sharedfs: skip hypervisors without system templates (#13830)
1 parent c860e0c commit f493d99

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

plugins/storage/sharedfs/storagevm/src/main/java/org/apache/cloudstack/storage/sharedfs/lifecycle/StorageVmSharedFSLifeCycle.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,10 @@ private UserVm deploySharedFSVM(Long zoneId, Account owner, List<Long> networkId
180180
for (final Iterator<Hypervisor.HypervisorType> iter = hypervisors.iterator(); iter.hasNext();) {
181181
final Hypervisor.HypervisorType hypervisor = iter.next();
182182
VMTemplateVO template = templateDao.findSystemVMReadyTemplate(zoneId, hypervisor, preferredArchitecture);
183-
if (template == null && !iter.hasNext()) {
183+
if (template == null) {
184+
if (iter.hasNext()) {
185+
continue;
186+
}
184187
throw new CloudRuntimeException(String.format("Unable to find the systemvm template for %s or it was not downloaded in %s.", hypervisor.toString(), zone.toString()));
185188
}
186189

plugins/storage/sharedfs/storagevm/src/test/java/org/apache/cloudstack/storage/sharedfs/lifecycle/StorageVmSharedFSLifeCycleTest.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import com.cloud.vm.dao.NicDao;
5454
import com.cloud.vm.dao.UserVmDao;
5555
import java.io.IOException;
56+
import java.util.ArrayList;
5657
import java.util.List;
5758
import java.util.Optional;
5859
import org.apache.cloudstack.api.ApiCommandResourceType;
@@ -273,6 +274,46 @@ public void testDeploySharedFS() throws ResourceUnavailableException, Insufficie
273274
Assert.assertEquals(Optional.ofNullable(result.second()), Optional.ofNullable(s_vmId));
274275
}
275276

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+
276317
@Test(expected = CloudRuntimeException.class)
277318
public void testDeploySharedFSHypervisorNotFound() throws ResourceUnavailableException, InsufficientCapacityException, ResourceAllocationException, IOException, OperationTimedoutException {
278319
SharedFS sharedFS = mock(SharedFS.class);

0 commit comments

Comments
 (0)