Moti Asayag has uploaded a new change for review. Change subject: engine: Prevent adding vnic profiles to non vm network ......................................................................
engine: Prevent adding vnic profiles to non vm network The patch prevent adding a vnic profiles to a non vm network since the profiles are relevant only in the context of vms. Change-Id: I9ca90d31a44038846b04bf23b3c9215d9560907d Signed-off-by: Moti Asayag <[email protected]> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/AddVnicProfileCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/VnicProfileValidator.java M backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/VnicProfileValidatorTest.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 8 files changed, 29 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/30/17030/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/AddVnicProfileCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/AddVnicProfileCommand.java index d9dd717..094a714 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/AddVnicProfileCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/AddVnicProfileCommand.java @@ -24,6 +24,7 @@ VnicProfileValidator validator = new VnicProfileValidator(getVnicProfile()); return validate(validator.vnicProfileIsSet()) && validate(validator.networkExists()) + && validate(validator.vnicProfileForVmNetworkOnly()) && validate(validator.vnicProfileNameNotUsed()); } diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/VnicProfileValidator.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/VnicProfileValidator.java index bbe0312..f20c31c 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/VnicProfileValidator.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/VnicProfileValidator.java @@ -74,6 +74,11 @@ VdcBllMessages.VAR__ENTITIES__VM_TEMPLATES); } + public ValidationResult vnicProfileForVmNetworkOnly() { + return getNetwork().isVmNetwork() ? ValidationResult.VALID + : new ValidationResult(VdcBllMessages.CANNOT_ADD_VNIC_PROFILE_TO_NON_VM_NETWORK); + } + protected ValidationResult vnicProfileNotUsed(List<? extends Nameable> entities, VdcBllMessages entitiesReplacement) { if (entities.isEmpty()) { return ValidationResult.VALID; diff --git a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/VnicProfileValidatorTest.java b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/VnicProfileValidatorTest.java index 7c2123f..3901206 100644 --- a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/VnicProfileValidatorTest.java +++ b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/VnicProfileValidatorTest.java @@ -216,4 +216,20 @@ vnicProfileNotUsedByTemplatesTest(failsWithVnicProfileInUse(), Collections.singletonList(template)); } + + @Test + public void vnicProfileForVmNetwork() { + vnicProfileForVmNetworkTest(true, isValid()); + } + + @Test + public void vnicProfileForNonVmNetwork() { + vnicProfileForVmNetworkTest(false, failsWith(VdcBllMessages.CANNOT_ADD_VNIC_PROFILE_TO_NON_VM_NETWORK)); + } + + private void vnicProfileForVmNetworkTest(boolean vmNetwork, Matcher<ValidationResult> matcher) { + when(network.isVmNetwork()).thenReturn(vmNetwork); + when(networkDao.get(any(Guid.class))).thenReturn(network); + assertThat(validator.vnicProfileForVmNetworkOnly(), 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 808f56b..2f54d27 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 @@ -429,6 +429,7 @@ VNIC_PROFILE_NAME_IN_USE(ErrorType.CONFLICT), VNIC_PROFILE_IN_USE(ErrorType.CONFLICT), CANNOT_CHANGE_VNIC_PROFILE_NETWORK(ErrorType.BAD_PARAMETERS), + CANNOT_ADD_VNIC_PROFILE_TO_NON_VM_NETWORK(ErrorType.BAD_PARAMETERS), ACTION_TYPE_FAILED_MIGRATION_NETWORK_IS_NOT_SUPPORTED(ErrorType.NOT_SUPPORTED), ACTION_TYPE_FAILED_PROVIDER_DOESNT_EXIST(ErrorType.BAD_PARAMETERS), ACTION_TYPE_FAILED_MANAGEMENT_NETWORK_REQUIRED(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 04fc342..df967a2 100644 --- a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties +++ b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties @@ -363,6 +363,7 @@ VNIC_PROFILE_NAME_IN_USE=Cannot ${action} ${type}. The VM network interface profile's name is already used by an existing profile in the same data-center.\n-Please choose a different name. VNIC_PROFILE_IN_USE=Cannot ${action} ${type}. Several ${entities} (${ENTITIES_USING_VNIC_PROFILE_COUNTER}) are using this VM network interface profile:\n${ENTITIES_USING_VNIC_PROFILE}\n - Please remove it from all ${entities} that are using it and try again. CANNOT_CHANGE_VNIC_PROFILE_NETWORK=Cannot ${action} ${type}. VM network interface profile's network cannot be changed. +CANNOT_ADD_VNIC_PROFILE_TO_NON_VM_NETWORK=Cannot ${action} ${type}. VM network interface profiles can be added to a VM network only. ACTION_TYPE_FAILED_NAME_ALREADY_USED=Cannot ${action} ${type}. The ${type} name is already in use, please choose a unique name and try again. ACTION_TYPE_FAILED_URL_INVALID=Cannot ${action} ${type}. The URL is not valid, please enter a valid URL and try again. ACTION_TYPE_FAILED_STORAGE_CONNECTION_NOT_EXIST=Cannot ${action} ${type}. Storage connection doesn't exist. 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 f67c502..5c1f047 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 @@ -1150,6 +1150,9 @@ @DefaultStringValue("Cannot ${action} ${type}. VM network interface profile's network cannot be changed.") String CANNOT_CHANGE_VNIC_PROFILE_NETWORK(); + @DefaultStringValue("Cannot ${action} ${type}. VM network interface profiles can be added to a VM network only.") + String CANNOT_ADD_VNIC_PROFILE_TO_NON_VM_NETWORK(); + @DefaultStringValue("The specified external network cannot be configured on the host's interface.") String EXTERNAL_NETWORK_CANNOT_BE_PROVISIONED(); 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 07122a5..235d11f 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 @@ -404,6 +404,7 @@ VNIC_PROFILE_NAME_IN_USE=Cannot ${action} ${type}. The VM network interface profile's name is already used by an existing profile in the same data-center.\n-Please choose a different name. VNIC_PROFILE_IN_USE=Cannot ${action} ${type}. Several ${entities} (${ENTITIES_USING_VNIC_PROFILE_COUNTER}) are using this VM network interface profile:\n${ENTITIES_USING_VNIC_PROFILE}\n - Please remove it from all ${entities} that are using it and try again. CANNOT_CHANGE_VNIC_PROFILE_NETWORK=Cannot ${action} ${type}. VM network interface profile's network cannot be changed. +CANNOT_ADD_VNIC_PROFILE_TO_NON_VM_NETWORK=Cannot ${action} ${type}. VM network interface profiles can be added to a VM network only. EXTERNAL_NETWORK_CANNOT_BE_PROVISIONED=The specified external network cannot be configured on the host's interface. ILLEGAL_VNIC_PROFILE_NAME=Virtual machine network interface profile name must be 1-50 long and can contain only 'A-Z', 'a-z', '0-9', '_' characters. ERROR_CANNOT_RECOVERY_STORAGE_POOL_THERE_IS_ACTIVE_DATA_DOMAINS=Cannot recover Data Center with active Data Storage Domain in Data Center. 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 c6cb0f7..70c0632 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 @@ -367,6 +367,7 @@ VNIC_PROFILE_NAME_IN_USE=Cannot ${action} ${type}. The VM network interface profile's name is already used by an existing profile in the same data-center.\n-Please choose a different name. VNIC_PROFILE_IN_USE=Cannot ${action} ${type}. Several ${entities} (${ENTITIES_USING_VNIC_PROFILE_COUNTER}) are using this VM network interface profile:\n${ENTITIES_USING_VNIC_PROFILE}\n - Please remove it from all ${entities} that are using it and try again. CANNOT_CHANGE_VNIC_PROFILE_NETWORK=Cannot ${action} ${type}. VM network interface profile's network cannot be changed. +CANNOT_ADD_VNIC_PROFILE_TO_NON_VM_NETWORK=Cannot ${action} ${type}. VM network interface profiles can be added to a VM network only. ACTION_TYPE_FAILED_NAME_ALREADY_USED=Cannot ${action} ${type}. The ${type} name is already in use, please choose a unique name and try again. VALIDATION_VDS_CONSOLEADDRESSS_HOSTNAME_OR_IP=Console address must be a FQDN or a valid IP address ACTION_TYPE_FAILED_URL_INVALID=Cannot ${action} ${type}. The URL is not valid, please enter a valid URL and try again. -- To view, visit http://gerrit.ovirt.org/17030 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I9ca90d31a44038846b04bf23b3c9215d9560907d Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Moti Asayag <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
