Skip to content

Commit 750290b

Browse files
Pearl1594abh1sar
andauthored
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>
1 parent 57331ac commit 750290b

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

server/src/main/java/com/cloud/hypervisor/KVMGuru.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ protected void setVmQuotaPercentage(VirtualMachineTO to, VirtualMachineProfile v
132132
VirtualMachine vm = vmProfile.getVirtualMachine();
133133
HostVO host = hostDao.findById(vm.getHostId());
134134
if (host == null) {
135-
throw new CloudRuntimeException("Host with id: " + vm.getHostId() + " not found");
135+
logger.warn("Host is not available. Skipping setting CPU quota percentage for VM: {}", vm);
136+
return;
136137
}
137138
logger.debug("Limiting CPU usage for VM: {} on host: {}", vm, host);
138139
double hostMaxSpeed = getHostCPUSpeed(host);

server/src/test/java/com/cloud/hypervisor/KVMGuruTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import com.cloud.storage.dao.GuestOSDao;
3333
import com.cloud.storage.dao.GuestOSHypervisorDao;
3434
import com.cloud.utils.Pair;
35-
import com.cloud.utils.exception.CloudRuntimeException;
3635
import com.cloud.vm.VirtualMachine;
3736
import com.cloud.vm.VirtualMachineProfile;
3837
import org.apache.cloudstack.api.ApiConstants;
@@ -141,10 +140,11 @@ public void testSetVmQuotaPercentage() {
141140
Mockito.verify(vmTO).setCpuQuotaPercentage(Mockito.anyDouble());
142141
}
143142

144-
@Test(expected = CloudRuntimeException.class)
143+
@Test
145144
public void testSetVmQuotaPercentageNullHost() {
146145
Mockito.when(hostDao.findById(hostId)).thenReturn(null);
147146
guru.setVmQuotaPercentage(vmTO, vmProfile);
147+
Mockito.verify(vmTO, Mockito.never()).setCpuQuotaPercentage(Mockito.anyDouble());
148148
}
149149

150150
@Test

0 commit comments

Comments
 (0)