Skip to content
Draft
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
3 changes: 2 additions & 1 deletion server/src/main/java/com/cloud/hypervisor/KVMGuru.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ protected void setVmQuotaPercentage(VirtualMachineTO to, VirtualMachineProfile v
VirtualMachine vm = vmProfile.getVirtualMachine();
HostVO host = hostDao.findById(vm.getHostId());
if (host == null) {
throw new CloudRuntimeException("Host with id: " + vm.getHostId() + " not found");
logger.warn("Host is not available. Skipping CPU quota calculation for VM: {}", vm);
return;
}
logger.debug("Limiting CPU usage for VM: {} on host: {}", vm, host);
double hostMaxSpeed = getHostCPUSpeed(host);
Expand Down
4 changes: 2 additions & 2 deletions server/src/test/java/com/cloud/hypervisor/KVMGuruTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import com.cloud.storage.dao.GuestOSDao;
import com.cloud.storage.dao.GuestOSHypervisorDao;
import com.cloud.utils.Pair;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile;
import org.apache.cloudstack.api.ApiConstants;
Expand Down Expand Up @@ -141,10 +140,11 @@ public void testSetVmQuotaPercentage() {
Mockito.verify(vmTO).setCpuQuotaPercentage(Mockito.anyDouble());
}

@Test(expected = CloudRuntimeException.class)
@Test
public void testSetVmQuotaPercentageNullHost() {
Mockito.when(hostDao.findById(hostId)).thenReturn(null);
guru.setVmQuotaPercentage(vmTO, vmProfile);
Mockito.verify(vmTO, Mockito.never()).setCpuQuotaPercentage(Mockito.anyDouble());
}

@Test
Expand Down
Loading