ofri masad has uploaded a new change for review. Change subject: core: Quota Dependency Test + RemoveSnapshot fix ......................................................................
core: Quota Dependency Test + RemoveSnapshot fix Added a test that checks that is VdcActionType is defined quota dependent - the correlating command is implementing the correct interface. RemoveSnapshotCommand did not implement QuotaStorageDependent. Fixed: implementation added. Change-Id: Ifd9e215abaa5de0fc03dae0609d9dc3ffc957f55 Signed-off-by: Ofri Masad <oma...@redhat.com> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveSnapshotCommand.java A backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/quota/QuotaDependencyTest.java 2 files changed, 81 insertions(+), 1 deletion(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/13/9413/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveSnapshotCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveSnapshotCommand.java index 319b9d5..39fb533 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveSnapshotCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveSnapshotCommand.java @@ -1,11 +1,15 @@ package org.ovirt.engine.core.bll; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; import org.apache.commons.lang.StringUtils; import org.ovirt.engine.core.bll.job.ExecutionHandler; +import org.ovirt.engine.core.bll.quota.QuotaConsumptionParameter; +import org.ovirt.engine.core.bll.quota.QuotaManager; +import org.ovirt.engine.core.bll.quota.QuotaStorageDependent; import org.ovirt.engine.core.bll.snapshots.SnapshotsValidator; import org.ovirt.engine.core.common.AuditLogType; import org.ovirt.engine.core.common.VdcObjectType; @@ -28,7 +32,8 @@ @DisableInPrepareMode @LockIdNameAttribute -public class RemoveSnapshotCommand<T extends RemoveSnapshotParameters> extends VmCommand<T> { +public class RemoveSnapshotCommand<T extends RemoveSnapshotParameters> extends VmCommand<T> + implements QuotaStorageDependent { private static final long serialVersionUID = 3162100352844371734L; private List<DiskImage> _sourceImages = null; @@ -121,6 +126,8 @@ if (vdcReturnValue != null && vdcReturnValue.getInternalTaskIdList() != null) { getReturnValue().getTaskIdList().addAll(vdcReturnValue.getInternalTaskIdList()); } + QuotaManager.getInstance().removeQuotaFromCache(getStoragePoolId().getValue(), source.getQuotaId()); + QuotaManager.getInstance().removeQuotaFromCache(getStoragePoolId().getValue(), dest.getQuotaId()); } setSucceeded(true); } @@ -255,4 +262,10 @@ protected SnapshotDao getSnapshotDao() { return getDbFacade().getSnapshotDao(); } + + @Override + public List<QuotaConsumptionParameter> getQuotaStorageConsumptionParameters() { + //return empty list - the command only release quota so it could never fail the quota check + return new ArrayList<QuotaConsumptionParameter>(); + } } diff --git a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/quota/QuotaDependencyTest.java b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/quota/QuotaDependencyTest.java new file mode 100644 index 0000000..8b18cd3 --- /dev/null +++ b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/quota/QuotaDependencyTest.java @@ -0,0 +1,67 @@ +package org.ovirt.engine.core.bll.quota; + +import org.junit.Test; +import org.ovirt.engine.core.bll.CommandBase; +import org.ovirt.engine.core.bll.CommandsFactory; +import org.ovirt.engine.core.bll.InternalCommandAttribute; +import org.ovirt.engine.core.common.action.VdcActionType; + +import java.util.Arrays; + +import static org.junit.Assert.assertTrue; + +public class QuotaDependencyTest { + + @Test + public void quotaDependencyTest() { + + for (VdcActionType vdcActionType : VdcActionType.values()) { + + if (vdcActionType.getQuotaDependency() != VdcActionType.QuotaDependency.NONE) { + Class commandClass = CommandsFactory.getCommandClass(vdcActionType.name()); + + // if command is deprecated or internal - skip it + if (commandClass.getAnnotation(Deprecated.class) != null + || commandClass.getAnnotation(InternalCommandAttribute.class) != null) { + continue; + } + + switch (vdcActionType.getQuotaDependency()) { + case VDS_GROUP: + assertCommandIsQuotaVdsDependent(commandClass); + break; + case STORAGE: + assertCommandIsQuotaStorageDependent(commandClass); + break; + case BOTH: + assertCommandIsQuotaVdsDependent(commandClass); + assertCommandIsQuotaStorageDependent(commandClass); + break; + default: + break; + } + } + } + } + + private void assertCommandIsQuotaStorageDependent(Class commandClass) { + assertTrue(String.format("The command %s was expected to implement QuotaStorageDependent interface", + commandClass.getName()), + isImplementingRecursive(commandClass, QuotaStorageDependent.class)); + } + + private void assertCommandIsQuotaVdsDependent(Class commandClass) { + assertTrue(String.format("The command %s was expected to implement QuotaVdsDependent interface", + commandClass.getName()), + isImplementingRecursive(commandClass, QuotaVdsDependent.class)); + } + + private boolean isImplementingRecursive(Class commandClass, Class interfaceClass) { + if (Arrays.asList(commandClass.getInterfaces()).contains(interfaceClass)) { + return true; + } else { + return commandClass.getSuperclass() != CommandBase.class + && isImplementingRecursive(commandClass.getSuperclass(), interfaceClass); + } + } +} -- To view, visit http://gerrit.ovirt.org/9413 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ifd9e215abaa5de0fc03dae0609d9dc3ffc957f55 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: ofri masad <oma...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches