Gustavo Frederico Temple Pedrosa has uploaded a new change for review. Change subject: engine: Vnic interface validation ......................................................................
engine: Vnic interface validation This change displays an error if the network interface type is not compatible with the selected operating system. Change-Id: I0a5879c61d79e69a11e71584aaadba66951cbc2d Signed-off-by: Gustavo Pedrosa <[email protected]> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/template/AddVmTemplateInterfaceCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/template/UpdateVmTemplateInterfaceCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/AddVmInterfaceCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/UpdateVmInterfaceCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/VmNicValidator.java M backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/VmNicValidatorTest.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java M backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties M frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java M frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties M frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties 11 files changed, 103 insertions(+), 9 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/88/18288/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/template/AddVmTemplateInterfaceCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/template/AddVmTemplateInterfaceCommand.java index ffd932b..d92ace2 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/template/AddVmTemplateInterfaceCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/template/AddVmTemplateInterfaceCommand.java @@ -68,9 +68,11 @@ } Version clusterCompatibilityVersion = getVdsGroup().getcompatibility_version(); - VmNicValidator nicValidator = new VmNicValidator(getParameters().getInterface(), clusterCompatibilityVersion); + VmNicValidator nicValidator = new VmNicValidator(getParameters().getInterface(), clusterCompatibilityVersion, getVmTemplate().getOsId()); - if (!validate(nicValidator.linkedCorrectly()) || !validate(nicValidator.emptyNetworkValid())) { + if (!validate(nicValidator.linkedCorrectly()) + || !validate(nicValidator.isCompatibleWithOs()) + || !validate(nicValidator.emptyNetworkValid())) { return false; } diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/template/UpdateVmTemplateInterfaceCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/template/UpdateVmTemplateInterfaceCommand.java index 3eec8d7..b2426e8 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/template/UpdateVmTemplateInterfaceCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/template/UpdateVmTemplateInterfaceCommand.java @@ -62,9 +62,11 @@ }); Version clusterCompatibilityVersion = getVdsGroup().getcompatibility_version(); - VmNicValidator nicValidator = new VmNicValidator(getParameters().getInterface(), clusterCompatibilityVersion); + VmNicValidator nicValidator = new VmNicValidator(getParameters().getInterface(), clusterCompatibilityVersion, getVmTemplate().getOsId()); - if (!validate(nicValidator.linkedCorrectly()) || !validate(nicValidator.emptyNetworkValid())) { + if (!validate(nicValidator.linkedCorrectly()) + || !validate(nicValidator.isCompatibleWithOs()) + || !validate(nicValidator.emptyNetworkValid())) { return false; } diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/AddVmInterfaceCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/AddVmInterfaceCommand.java index adf0429..383ad90 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/AddVmInterfaceCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/AddVmInterfaceCommand.java @@ -131,9 +131,11 @@ } Version compatibilityVersion = getVm().getVdsGroupCompatibilityVersion(); - VmNicValidator nicValidator = new VmNicValidator(getInterface(), compatibilityVersion); + VmNicValidator nicValidator = new VmNicValidator(getInterface(), compatibilityVersion, getVm().getOs()); - if (!validate(nicValidator.linkedCorrectly()) || !validate(nicValidator.emptyNetworkValid())) { + if (!validate(nicValidator.linkedCorrectly()) + || !validate(nicValidator.isCompatibleWithOs()) + || !validate(nicValidator.emptyNetworkValid())) { return false; } diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/UpdateVmInterfaceCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/UpdateVmInterfaceCommand.java index f1de649..6e5c249 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/UpdateVmInterfaceCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/UpdateVmInterfaceCommand.java @@ -184,9 +184,10 @@ } UpdateVmNicValidator nicValidator = - new UpdateVmNicValidator(getInterface(), getVm().getVdsGroupCompatibilityVersion()); + new UpdateVmNicValidator(getInterface(), getVm().getVdsGroupCompatibilityVersion(), getVm().getOs()); if (!validate(nicValidator.unplugPlugNotRequired()) || !validate(nicValidator.linkedCorrectly()) + || !validate(nicValidator.isCompatibleWithOs()) || !validate(nicValidator.emptyNetworkValid()) || !validate(nicValidator.hotUpdatePossible())) { return false; @@ -296,8 +297,8 @@ */ private class UpdateVmNicValidator extends VmNicValidator { - public UpdateVmNicValidator(VmNic nic, Version version) { - super(nic, version); + public UpdateVmNicValidator(VmNic nic, Version version, int osId) { + super(nic, version, osId); } /** diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/VmNicValidator.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/VmNicValidator.java index 3e7a2c9..8a943bc 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/VmNicValidator.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/VmNicValidator.java @@ -1,9 +1,15 @@ package org.ovirt.engine.core.bll.validator; +import java.util.ArrayList; +import java.util.List; + import org.ovirt.engine.core.bll.ValidationResult; import org.ovirt.engine.core.common.FeatureSupported; +import org.ovirt.engine.core.common.businessentities.network.VmInterfaceType; import org.ovirt.engine.core.common.businessentities.network.VmNic; import org.ovirt.engine.core.common.errors.VdcBllMessages; +import org.ovirt.engine.core.common.osinfo.OsRepository; +import org.ovirt.engine.core.common.utils.SimpleDependecyInjector; import org.ovirt.engine.core.compat.Version; /** @@ -17,9 +23,17 @@ protected Version version; + protected int osId; + public VmNicValidator(VmNic nic, Version version) { this.nic = nic; this.version = version; + } + + public VmNicValidator(VmNic nic, Version version, int osId) { + this.nic = nic; + this.version = version; + this.osId = osId; } /** @@ -43,4 +57,27 @@ protected String clusterVersion() { return String.format(CLUSTER_VERSION_REPLACEMENT_FORMAT, version.getValue()); } + + /** + * @return An error if the network interface type is not compatible with the selected operating + * system. + */ + public ValidationResult isCompatibleWithOs() { + + OsRepository osRepository = SimpleDependecyInjector.getInstance().get(OsRepository.class); + + List<String> networkDevices = osRepository.getNetworkDevices(osId, version); + + List<VmInterfaceType> interfaceTypes = new ArrayList<VmInterfaceType>(); + + for (String networkDevice : networkDevices) { + interfaceTypes.add(VmInterfaceType.valueOf(networkDevice)); + } + + return (!interfaceTypes.contains(VmInterfaceType.forValue(nic.getType()))) + ? new ValidationResult(VdcBllMessages.VM_INTERFACE_TYPE_IS_NOT_SUPPORTED_BY_OS) + : ValidationResult.VALID; + + } + } diff --git a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/VmNicValidatorTest.java b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/VmNicValidatorTest.java index b10f9bb..6167899 100644 --- a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/VmNicValidatorTest.java +++ b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/VmNicValidatorTest.java @@ -4,9 +4,14 @@ import static org.junit.matchers.JUnitMatchers.both; import static org.junit.matchers.JUnitMatchers.hasItem; import static org.mockito.Mockito.when; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; import static org.ovirt.engine.core.bll.validator.ValidationResultMatchers.failsWith; import static org.ovirt.engine.core.bll.validator.ValidationResultMatchers.isValid; import static org.ovirt.engine.core.bll.validator.ValidationResultMatchers.replacements; + +import java.util.ArrayList; +import java.util.Arrays; import org.hamcrest.Matcher; import org.junit.Before; @@ -16,9 +21,12 @@ import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import org.ovirt.engine.core.bll.ValidationResult; +import org.ovirt.engine.core.common.businessentities.network.VmInterfaceType; import org.ovirt.engine.core.common.businessentities.network.VmNic; import org.ovirt.engine.core.common.config.ConfigValues; import org.ovirt.engine.core.common.errors.VdcBllMessages; +import org.ovirt.engine.core.common.osinfo.OsRepository; +import org.ovirt.engine.core.common.utils.SimpleDependecyInjector; import org.ovirt.engine.core.compat.Guid; import org.ovirt.engine.core.compat.Version; import org.ovirt.engine.core.utils.MockConfigRule; @@ -28,6 +36,8 @@ private static final Guid VNIC_PROFILE_ID = Guid.newGuid(); private static final String CLUSTER_VERSION = "7"; + private static final ArrayList<String> NETWORK_DEVICES = new ArrayList<String>( + Arrays.asList("rtl8139", "pv")); private static final String CLUSTER_VERSION_REPLACEMENT = String.format(VmNicValidator.CLUSTER_VERSION_REPLACEMENT_FORMAT, CLUSTER_VERSION); @@ -42,12 +52,22 @@ private Version version; private VmNicValidator validator; + private VmNicValidator validatorType; + + @Mock + OsRepository osRepository; @Before public void setup() { when(version.getValue()).thenReturn(CLUSTER_VERSION); + when(osRepository.getNetworkDevices(eq(0), any(Version.class))).thenReturn(NETWORK_DEVICES); + + // init the injector with the osRepository instance + SimpleDependecyInjector.getInstance().bind(OsRepository.class, osRepository); + validator = new VmNicValidator(nic, version); + validatorType = new VmNicValidator(nic, version, 0); } @Test @@ -96,6 +116,23 @@ vnicProfileTest(isValid(), true, VNIC_PROFILE_ID); } + @Test + public void e1000VmInterfaceTypeWhenNotIsCompatibleWithOs() throws Exception { + isCompatibleWithOsTest(both(failsWith(VdcBllMessages.VM_INTERFACE_TYPE_IS_NOT_SUPPORTED_BY_OS)), + VmInterfaceType.e1000.getValue()); + } + + @Test + public void pvVmInterfaceTypeWhenIsCompatibleWithOs() throws Exception { + isCompatibleWithOsTest(isValid(), VmInterfaceType.pv.getValue()); + } + + @Test + public void rtl8139VmInterfaceTypeWhenIsCompatibleWithOs() throws Exception { + isCompatibleWithOsTest(isValid(), VmInterfaceType.rtl8139.getValue()); + } + + private void unlinkingTest(Matcher<ValidationResult> matcher, boolean networkLinkingSupported, boolean nicLinked) { mockConfigRule.mockConfigValue(ConfigValues.NetworkLinkingSupported, version, networkLinkingSupported); when(nic.isLinked()).thenReturn(nicLinked); @@ -110,4 +147,10 @@ assertThat(validator.emptyNetworkValid(), matcher); } + private void isCompatibleWithOsTest(Matcher<ValidationResult> matcher, int vmInterfaceType) { + when(nic.getType()).thenReturn(vmInterfaceType); + + assertThat(validatorType.isCompatibleWithOs(), matcher); + } + } diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java index 639b2e6..cc6ffea 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java @@ -624,6 +624,7 @@ UNLINKING_IS_NOT_SUPPORTED(ErrorType.NOT_SUPPORTED), NULL_NETWORK_IS_NOT_SUPPORTED(ErrorType.NOT_SUPPORTED), HOT_VM_INTERFACE_UPDATE_IS_NOT_SUPPORTED(ErrorType.NOT_SUPPORTED), + VM_INTERFACE_TYPE_IS_NOT_SUPPORTED_BY_OS(ErrorType.INCOMPATIBLE_VERSION), CANNOT_PERFOM_HOT_UPDATE(ErrorType.CONFLICT), CANNOT_PERFOM_HOT_UPDATE_WITH_PORT_MIRRORING(ErrorType.CONFLICT), PORT_MIRRORING_REQUIRES_NETWORK(ErrorType.BAD_PARAMETERS), diff --git a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties index 393146b..08764b9 100644 --- a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties +++ b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties @@ -809,6 +809,7 @@ UNLINKING_IS_NOT_SUPPORTED=Cannot ${action} ${type}. Link state is set to 'Down' on the virtual machine's interface, this is not supported for clusters of version ${clusterVersion}. NULL_NETWORK_IS_NOT_SUPPORTED=Cannot ${action} ${type}. There is no network on the virtual machine's interface, this is not supported for clusters of version ${clusterVersion}. HOT_VM_INTERFACE_UPDATE_IS_NOT_SUPPORTED=Cannot ${action} ${type}. Updating the virtual machine interface while the virtual machine is running is not supported for clusters of version ${clusterVersion}. +VM_INTERFACE_TYPE_IS_NOT_SUPPORTED_BY_OS=Cannot ${action} ${type}. The network interface type is not compatible with the selected operating system. CANNOT_PERFOM_HOT_UPDATE=Cannot ${action} ${type}. Updating some of the properties is not supported while the interface is plugged into a running virtual machine. Please un-plug the interface, update the properties, and then plug it back. CANNOT_PERFOM_HOT_UPDATE_WITH_PORT_MIRRORING=Cannot ${action} ${type}. Update is not possible when 'Port Mirroring' is set on the interface of a running virtual machine. PORT_MIRRORING_REQUIRES_NETWORK=Cannot ${action} ${type}. 'Port Mirroring' setting requires a network. diff --git a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java index fdfffb5..4ddba33 100644 --- a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java +++ b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java @@ -2185,6 +2185,9 @@ @DefaultStringValue("Cannot ${action} ${type}. Updating the virtual machine interface while the virtual machine is running is not supported for clusters of version ${clusterVersion}.") String HOT_VM_INTERFACE_UPDATE_IS_NOT_SUPPORTED(); + @DefaultStringValue("Cannot ${action} ${type}. The network interface type is not compatible with the selected operating system.") + String VM_INTERFACE_TYPE_IS_NOT_SUPPORTED_BY_OS(); + @DefaultStringValue("Cannot ${action} ${type}. Updating some of the properties is not supported while the interface is plugged into a running virtual machine. Please un-plug the interface, update the properties, and then plug it back.") String CANNOT_PERFOM_HOT_UPDATE(); diff --git a/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties b/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties index faa0147..30d8374 100644 --- a/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties +++ b/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties @@ -790,6 +790,7 @@ UNLINKING_IS_NOT_SUPPORTED=Cannot ${action} ${type}. Link state is set to 'Down' on the virtual machine's interface, this is not supported for clusters of version ${clusterVersion}. NULL_NETWORK_IS_NOT_SUPPORTED=Cannot ${action} ${type}. There is no network on the virtual machine's interface, this is not supported for clusters of version ${clusterVersion}. HOT_VM_INTERFACE_UPDATE_IS_NOT_SUPPORTED=Cannot ${action} ${type}. Updating the virtual machine interface while the virtual machine is running is not supported for clusters of version ${clusterVersion}. +VM_INTERFACE_TYPE_IS_NOT_SUPPORTED_BY_OS=Cannot ${action} ${type}. The network interface type is not compatible with the selected operating system. CANNOT_PERFOM_HOT_UPDATE=Cannot ${action} ${type}. Updating some of the properties is not supported while the interface is plugged into a running virtual machine. Please un-plug the interface, update the properties, and then plug it back. CANNOT_PERFOM_HOT_UPDATE_WITH_PORT_MIRRORING=Cannot ${action} ${type}. Update is not possible when 'Port Mirroring' is set on the interface of a running virtual machine. PORT_MIRRORING_REQUIRES_NETWORK=Cannot ${action} ${type}. 'Port Mirroring' setting requires a network. diff --git a/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties b/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties index 031d8b2..af34924 100644 --- a/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties +++ b/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties @@ -811,6 +811,7 @@ UNLINKING_IS_NOT_SUPPORTED=Cannot ${action} ${type}. Link state is set to 'Down' on the virtual machine's interface, this is not supported for clusters of version ${clusterVersion}. NULL_NETWORK_IS_NOT_SUPPORTED=Cannot ${action} ${type}. There is no network on the virtual machine's interface, this is not supported for clusters of version ${clusterVersion}. HOT_VM_INTERFACE_UPDATE_IS_NOT_SUPPORTED=Cannot ${action} ${type}. Updating the virtual machine interface while the virtual machine is running is not supported for clusters of version ${clusterVersion}. +VM_INTERFACE_TYPE_IS_NOT_SUPPORTED_BY_OS=Cannot ${action} ${type}. The network interface type is not compatible with the selected operating system. CANNOT_PERFOM_HOT_UPDATE=Cannot ${action} ${type}. Updating some of the properties is not supported while the interface is plugged into a running virtual machine. Please un-plug the interface, update the properties, and then plug it back. CANNOT_PERFOM_HOT_UPDATE_WITH_PORT_MIRRORING=Cannot ${action} ${type}. Update is not possible when 'Port Mirroring' is set on the interface of a running virtual machine. PORT_MIRRORING_REQUIRES_NETWORK=Cannot ${action} ${type}. 'Port Mirroring' setting requires a network. -- To view, visit http://gerrit.ovirt.org/18288 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I0a5879c61d79e69a11e71584aaadba66951cbc2d Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Gustavo Frederico Temple Pedrosa <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
