mirror of https://github.com/apache/cloudstack.git
Prevent NPE when removing NIC from a stopped VM using service offering with CPU cap set (#12232)
This PR fixes: #12225 --------- Co-authored-by: Abhisar Sinha <63767682+abh1sar@users.noreply.github.com>
This commit is contained in:
parent
57331aca2f
commit
750290b8ae
|
|
@ -132,7 +132,8 @@ public class KVMGuru extends HypervisorGuruBase implements HypervisorGuru {
|
||||||
VirtualMachine vm = vmProfile.getVirtualMachine();
|
VirtualMachine vm = vmProfile.getVirtualMachine();
|
||||||
HostVO host = hostDao.findById(vm.getHostId());
|
HostVO host = hostDao.findById(vm.getHostId());
|
||||||
if (host == null) {
|
if (host == null) {
|
||||||
throw new CloudRuntimeException("Host with id: " + vm.getHostId() + " not found");
|
logger.warn("Host is not available. Skipping setting CPU quota percentage for VM: {}", vm);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
logger.debug("Limiting CPU usage for VM: {} on host: {}", vm, host);
|
logger.debug("Limiting CPU usage for VM: {} on host: {}", vm, host);
|
||||||
double hostMaxSpeed = getHostCPUSpeed(host);
|
double hostMaxSpeed = getHostCPUSpeed(host);
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,6 @@ import com.cloud.storage.GuestOSVO;
|
||||||
import com.cloud.storage.dao.GuestOSDao;
|
import com.cloud.storage.dao.GuestOSDao;
|
||||||
import com.cloud.storage.dao.GuestOSHypervisorDao;
|
import com.cloud.storage.dao.GuestOSHypervisorDao;
|
||||||
import com.cloud.utils.Pair;
|
import com.cloud.utils.Pair;
|
||||||
import com.cloud.utils.exception.CloudRuntimeException;
|
|
||||||
import com.cloud.vm.VirtualMachine;
|
import com.cloud.vm.VirtualMachine;
|
||||||
import com.cloud.vm.VirtualMachineProfile;
|
import com.cloud.vm.VirtualMachineProfile;
|
||||||
import org.apache.cloudstack.api.ApiConstants;
|
import org.apache.cloudstack.api.ApiConstants;
|
||||||
|
|
@ -141,10 +140,11 @@ public class KVMGuruTest {
|
||||||
Mockito.verify(vmTO).setCpuQuotaPercentage(Mockito.anyDouble());
|
Mockito.verify(vmTO).setCpuQuotaPercentage(Mockito.anyDouble());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = CloudRuntimeException.class)
|
@Test
|
||||||
public void testSetVmQuotaPercentageNullHost() {
|
public void testSetVmQuotaPercentageNullHost() {
|
||||||
Mockito.when(hostDao.findById(hostId)).thenReturn(null);
|
Mockito.when(hostDao.findById(hostId)).thenReturn(null);
|
||||||
guru.setVmQuotaPercentage(vmTO, vmProfile);
|
guru.setVmQuotaPercentage(vmTO, vmProfile);
|
||||||
|
Mockito.verify(vmTO, Mockito.never()).setCpuQuotaPercentage(Mockito.anyDouble());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue