From f564597e9246d1cc28ce02e1ebbe55f4afec1a1b Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Mon, 6 Sep 2021 18:28:32 +0530 Subject: [PATCH] api, ui: fix NPE with deployVirtualMachine when null boottype (#5387) * api: fix NPE with deployVirtualMachine when null boottype Signed-off-by: Abhishek Kumar * throw exception for empty bootmode Signed-off-by: Abhishek Kumar * fix Signed-off-by: Abhishek Kumar * ui: fix boot options Signed-off-by: Abhishek Kumar * check Signed-off-by: Abhishek Kumar --- .../api/command/user/vm/DeployVMCmd.java | 21 +++++--- ui/src/views/compute/DeployVM.vue | 51 +++++++------------ 2 files changed, 31 insertions(+), 41 deletions(-) diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java index 6d7cc9c81c2..801e025eed5 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java @@ -27,8 +27,6 @@ import java.util.Map; import javax.annotation.Nonnull; -import com.cloud.utils.StringUtils; - import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.affinity.AffinityGroupResponse; import org.apache.cloudstack.api.ACL; @@ -70,6 +68,7 @@ import com.cloud.network.Network.IpAddresses; import com.cloud.offering.DiskOffering; import com.cloud.template.VirtualMachineTemplate; import com.cloud.uservm.UserVm; +import com.cloud.utils.StringUtils; import com.cloud.utils.net.Dhcp; import com.cloud.utils.net.NetUtils; import com.cloud.vm.VirtualMachine; @@ -265,7 +264,7 @@ public class DeployVMCmd extends BaseAsyncCreateCustomIdCmd implements SecurityG return domainId; } - public ApiConstants.BootType getBootType() { + public ApiConstants.BootType getBootType() { if (StringUtils.isNotBlank(bootType)) { try { String type = bootType.trim().toUpperCase(); @@ -310,11 +309,17 @@ public class DeployVMCmd extends BaseAsyncCreateCustomIdCmd implements SecurityG String mode = bootMode.trim().toUpperCase(); return ApiConstants.BootMode.valueOf(mode); } catch (IllegalArgumentException e) { - String errMesg = "Invalid bootMode " + bootMode + "Specified for vm " + getName() - + " Valid values are: "+ Arrays.toString(ApiConstants.BootMode.values()); - s_logger.warn(errMesg); - throw new InvalidParameterValueException(errMesg); - } + String msg = String.format("Invalid %s: %s specified for VM: %s. Valid values are: %s", + ApiConstants.BOOT_MODE, bootMode, getName(), Arrays.toString(ApiConstants.BootMode.values())); + s_logger.error(msg); + throw new InvalidParameterValueException(msg); + } + } + if (ApiConstants.BootType.UEFI.equals(getBootType())) { + String msg = String.format("%s must be specified for the VM with boot type: %s. Valid values are: %s", + ApiConstants.BOOT_MODE, getBootType(), Arrays.toString(ApiConstants.BootMode.values())); + s_logger.error(msg); + throw new InvalidParameterValueException(msg); } return null; } diff --git a/ui/src/views/compute/DeployVM.vue b/ui/src/views/compute/DeployVM.vue index 2b415ef95bc..6578a87c081 100644 --- a/ui/src/views/compute/DeployVM.vue +++ b/ui/src/views/compute/DeployVM.vue @@ -487,16 +487,15 @@