Skip to content

Commit 70c00fe

Browse files
committed
Fix restore VM
1 parent 48073b3 commit 70c00fe

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

server/src/main/java/com/cloud/vm/UserVmManagerImpl.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2352,11 +2352,6 @@ public UserVm recoverVirtualMachine(RecoverVMCmd cmd) throws ResourceAllocationE
23522352
throw new InvalidParameterValueException("Vm with id " + vm.getUuid() + " is not in the right state");
23532353
}
23542354

2355-
if (isVMPartOfAnyCKSCluster(vm)) {
2356-
throw new UnsupportedServiceException("Cannot recover VM with id = " + vm.getUuid() +
2357-
" as it belongs to a CKS cluster. Please remove the VM from the CKS cluster before recovering.");
2358-
}
2359-
23602355
if (logger.isDebugEnabled()) {
23612356
logger.debug("Recovering vm {}", vm);
23622357
}
@@ -8765,6 +8760,10 @@ public UserVm restoreVM(RestoreVMCmd cmd) throws InsufficientCapacityException,
87658760
throw new InvalidParameterValueException(String.format("Operation not supported for instance: %s",
87668761
vm.getName()));
87678762
}
8763+
if (isVMPartOfAnyCKSCluster(vm)) {
8764+
throw new UnsupportedServiceException("Cannot restore VM with id = " + vm.getUuid() +
8765+
" as it belongs to a CKS cluster. Please remove the VM from the CKS cluster before restoring.");
8766+
}
87688767
_accountMgr.checkAccess(caller, null, true, vm);
87698768

87708769
VMTemplateVO template;

server/src/test/java/com/cloud/vm/UserVmManagerImplTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
import java.util.TimeZone;
6060
import java.util.UUID;
6161

62+
import com.cloud.kubernetes.cluster.KubernetesServiceHelper;
6263
import com.cloud.storage.dao.SnapshotPolicyDao;
6364
import org.apache.cloudstack.acl.ControlledEntity;
6465
import org.apache.cloudstack.acl.SecurityChecker;
@@ -1475,6 +1476,9 @@ public void testRestoreVMWithVolumeSnapshots() throws ResourceUnavailableExcepti
14751476
when(cmd.getVmId()).thenReturn(vmId);
14761477
when(cmd.getTemplateId()).thenReturn(2L);
14771478
when(userVmDao.findById(vmId)).thenReturn(userVmVoMock);
1479+
KubernetesServiceHelper helper = mock(KubernetesServiceHelper.class);
1480+
when(helper.findByVmId(anyLong())).thenReturn(null);
1481+
userVmManagerImpl.setKubernetesServiceHelpers(Collections.singletonList(helper));
14781482

14791483
userVmManagerImpl.restoreVM(cmd);
14801484
}

0 commit comments

Comments
 (0)