Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -468,14 +468,26 @@ private void avoidDifferentArchResources(VirtualMachineProfile vmProfile, DataCe
}
}

/**
* Whether to try the VM's last host before running the planner.
* Not for a migration plan, i.e. a VM moved off a host that is being evacuated (host maintenance, HA): each
* migration records its source host as the VM's last host, so preferring it sends VMs back to the hosts
* evacuated earlier, for example during a rolling maintenance, and skips the planner and the VM allocation
* algorithm.
*/
protected boolean shouldConsiderLastHost(VirtualMachineProfile vmProfile, DeploymentPlan plan, VirtualMachine vm) {
if (vm.getLastHostId() == null || plan.isMigrationPlan()) {
return false;
}
String considerLastHostStr = (String)vmProfile.getParameter(VirtualMachineProfile.Param.ConsiderLastHost);
String haVmTag = (String)vmProfile.getParameter(VirtualMachineProfile.Param.HaTag);
return haVmTag == null && !(Boolean.FALSE.toString().equalsIgnoreCase(considerLastHostStr));
}

private DeployDestination deployInVmLastHost(VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoids,
DeploymentPlanner planner, VirtualMachine vm, DataCenter dc, ServiceOffering offering, int cpuRequested, long ramRequested,
boolean volumesRequireEncryption) throws InsufficientServerCapacityException {
String considerLastHostStr = (String)vmProfile.getParameter(VirtualMachineProfile.Param.ConsiderLastHost);
String haVmTag = (String)vmProfile.getParameter(VirtualMachineProfile.Param.HaTag);
boolean considerLastHost = vm.getLastHostId() != null && haVmTag == null &&
!(Boolean.FALSE.toString().equalsIgnoreCase(considerLastHostStr));
if (!considerLastHost) {
if (!shouldConsiderLastHost(vmProfile, plan, vm)) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1281,4 +1281,31 @@ public void avoidOtherClustersForDeploymentIfMigrationDisabledValid() {
Assert.assertEquals(allClusters.size() - 1, avoidedClusters.size());
Assert.assertFalse(avoidedClusters.contains(allClusters.get(0)));
}

private boolean shouldConsiderLastHost(Long lastHostId, boolean migrationPlan, Map<VirtualMachineProfile.Param, Object> params) {
VMInstanceVO lastHostVm = Mockito.mock(VMInstanceVO.class);
Mockito.when(lastHostVm.getLastHostId()).thenReturn(lastHostId);
Mockito.lenient().when(lastHostVm.getType()).thenReturn(Type.User);
DataCenterDeployment deployment = new DataCenterDeployment(1L, 1L, 1L, null, null, null);
deployment.setMigrationPlan(migrationPlan);
return _dpm.shouldConsiderLastHost(new VirtualMachineProfileImpl(lastHostVm, null, null, null, params), deployment, lastHostVm);
}

@Test
public void shouldConsiderLastHostForAStart() {
Assert.assertTrue(shouldConsiderLastHost(5L, false, null));
}

@Test
public void shouldNotConsiderLastHostForAMigrationPlan() {
Assert.assertFalse(shouldConsiderLastHost(5L, true, null));
Assert.assertFalse(shouldConsiderLastHost(5L, true, new HashMap<>(Map.of(VirtualMachineProfile.Param.ConsiderLastHost, Boolean.TRUE.toString()))));
}

@Test
public void shouldNotConsiderLastHostWithoutOneOrWhenTurnedOff() {
Assert.assertFalse(shouldConsiderLastHost(null, false, null));
Assert.assertFalse(shouldConsiderLastHost(5L, false, new HashMap<>(Map.of(VirtualMachineProfile.Param.ConsiderLastHost, Boolean.FALSE.toString()))));
Assert.assertFalse(shouldConsiderLastHost(5L, false, new HashMap<>(Map.of(VirtualMachineProfile.Param.HaTag, "ha"))));
}
}
Loading