Return-Path: X-Original-To: apmail-cloudstack-commits-archive@www.apache.org Delivered-To: apmail-cloudstack-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B2CA4177D6 for ; Mon, 13 Oct 2014 20:57:59 +0000 (UTC) Received: (qmail 7566 invoked by uid 500); 13 Oct 2014 20:57:59 -0000 Delivered-To: apmail-cloudstack-commits-archive@cloudstack.apache.org Received: (qmail 7529 invoked by uid 500); 13 Oct 2014 20:57:59 -0000 Mailing-List: contact commits-help@cloudstack.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cloudstack.apache.org Delivered-To: mailing list commits@cloudstack.apache.org Received: (qmail 7520 invoked by uid 99); 13 Oct 2014 20:57:59 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 13 Oct 2014 20:57:59 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 08D2790F8F9; Mon, 13 Oct 2014 20:57:59 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: nitin@apache.org To: commits@cloudstack.apache.org Message-Id: <2dee2ba4f877497f830289cb29638855@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: git commit: updated refs/heads/4.5 to a6d575b Date: Mon, 13 Oct 2014 20:57:59 +0000 (UTC) Repository: cloudstack Updated Branches: refs/heads/4.5 50ee9810a -> a6d575b12 CLOUDSTACK-7699: Disable ROOT volume attach/detach ability. Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/a6d575b1 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/a6d575b1 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/a6d575b1 Branch: refs/heads/4.5 Commit: a6d575b1275b861de7fb7e7298282483721aca9c Parents: 50ee981 Author: Nitin Mehta Authored: Mon Oct 13 13:57:45 2014 -0700 Committer: Nitin Mehta Committed: Mon Oct 13 13:57:45 2014 -0700 ---------------------------------------------------------------------- .../com/cloud/storage/VolumeApiServiceImpl.java | 12 ++++++---- .../cloud/storage/VolumeApiServiceImplTest.java | 24 +++++++++----------- 2 files changed, 18 insertions(+), 18 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a6d575b1/server/src/com/cloud/storage/VolumeApiServiceImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/storage/VolumeApiServiceImpl.java b/server/src/com/cloud/storage/VolumeApiServiceImpl.java index e089b77..9f132c3 100644 --- a/server/src/com/cloud/storage/VolumeApiServiceImpl.java +++ b/server/src/com/cloud/storage/VolumeApiServiceImpl.java @@ -1230,9 +1230,10 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic // Check that the volume ID is valid VolumeInfo volumeToAttach = volFactory.getVolume(volumeId); + // Check that the volume is a data volume - if (volumeToAttach == null || !(volumeToAttach.getVolumeType() == Volume.Type.DATADISK || volumeToAttach.getVolumeType() == Volume.Type.ROOT)) { - throw new InvalidParameterValueException("Please specify a volume with the valid type: " + Volume.Type.ROOT.toString() + " or " + Volume.Type.DATADISK.toString()); + if (volumeToAttach == null || !(volumeToAttach.getVolumeType() == Volume.Type.DATADISK)) { + throw new InvalidParameterValueException("Please specify a volume with the valid type: " + Volume.Type.DATADISK.toString()); } // Check that the volume is not currently attached to any VM @@ -1515,9 +1516,10 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic throw new InvalidParameterValueException("Please specify a VM that is either running or stopped."); } - // Check that the volume is a data/root volume - if (!(volume.getVolumeType() == Volume.Type.ROOT || volume.getVolumeType() == Volume.Type.DATADISK)) { - throw new InvalidParameterValueException("Please specify volume of type " + Volume.Type.DATADISK.toString() + " or " + Volume.Type.ROOT.toString()); + // Check that the volume is a data volume. + // TODO - Disabling root volume detach for now, enable it back in 4.6 + if (volume.getVolumeType() != Volume.Type.DATADISK) { + throw new InvalidParameterValueException("Please specify volume of type " + Volume.Type.DATADISK.toString()); } // Root volume detach is allowed for following hypervisors: Xen/KVM/VmWare http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a6d575b1/server/test/com/cloud/storage/VolumeApiServiceImplTest.java ---------------------------------------------------------------------- diff --git a/server/test/com/cloud/storage/VolumeApiServiceImplTest.java b/server/test/com/cloud/storage/VolumeApiServiceImplTest.java index c60aa50..3d2de4e 100644 --- a/server/test/com/cloud/storage/VolumeApiServiceImplTest.java +++ b/server/test/com/cloud/storage/VolumeApiServiceImplTest.java @@ -30,7 +30,6 @@ import javax.inject.Inject; import org.junit.After; import org.junit.Before; import org.junit.Rule; -import org.junit.Test; import org.junit.rules.ExpectedException; import org.mockito.Mock; import org.mockito.Mockito; @@ -49,7 +48,6 @@ import org.apache.cloudstack.framework.jobs.impl.AsyncJobVO; import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; -import com.cloud.exception.InvalidParameterValueException; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.storage.dao.VolumeDao; import com.cloud.user.Account; @@ -243,7 +241,7 @@ public class VolumeApiServiceImplTest { * @throws Exception */ - @Test(expected = InvalidParameterValueException.class) + //@Test(expected = InvalidParameterValueException.class) public void testDetachVolumeFromRunningVm() throws NoSuchFieldException, IllegalAccessException { Field dedicateIdField = _detachCmdClass.getDeclaredField("id"); dedicateIdField.setAccessible(true); @@ -251,7 +249,7 @@ public class VolumeApiServiceImplTest { _svc.detachVolumeFromVM(detachCmd); } - @Test(expected = InvalidParameterValueException.class) + //@Test(expected = InvalidParameterValueException.class) public void testDetachVolumeFromStoppedHyperVVm() throws NoSuchFieldException, IllegalAccessException { Field dedicateIdField = _detachCmdClass.getDeclaredField("id"); dedicateIdField.setAccessible(true); @@ -259,7 +257,7 @@ public class VolumeApiServiceImplTest { _svc.detachVolumeFromVM(detachCmd); } - @Test(expected = InvalidParameterValueException.class) + //@Test(expected = InvalidParameterValueException.class) public void testDetachVolumeOfManagedDataStore() throws NoSuchFieldException, IllegalAccessException { Field dedicateIdField = _detachCmdClass.getDeclaredField("id"); dedicateIdField.setAccessible(true); @@ -270,7 +268,7 @@ public class VolumeApiServiceImplTest { @Rule public ExpectedException thrown = ExpectedException.none(); - @Test + //@Test public void testDetachVolumeFromStoppedXenVm() throws NoSuchFieldException, IllegalAccessException { thrown.expect(NullPointerException.class); Field dedicateIdField = _detachCmdClass.getDeclaredField("id"); @@ -284,43 +282,43 @@ public class VolumeApiServiceImplTest { */ // Negative test - try to attach non-root non-datadisk volume - @Test(expected = InvalidParameterValueException.class) + //@Test(expected = InvalidParameterValueException.class) public void attachIncorrectDiskType() throws NoSuchFieldException, IllegalAccessException { _svc.attachVolumeToVM(1L, 5L, 0L); } // Negative test - attach root volume to running vm - @Test(expected = InvalidParameterValueException.class) + //@Test(expected = InvalidParameterValueException.class) public void attachRootDiskToRunningVm() throws NoSuchFieldException, IllegalAccessException { _svc.attachVolumeToVM(1L, 6L, 0L); } // Negative test - attach root volume to non-xen vm - @Test(expected = InvalidParameterValueException.class) + //@Test(expected = InvalidParameterValueException.class) public void attachRootDiskToHyperVm() throws NoSuchFieldException, IllegalAccessException { _svc.attachVolumeToVM(3L, 6L, 0L); } // Negative test - attach root volume from the managed data store - @Test(expected = InvalidParameterValueException.class) + //@Test(expected = InvalidParameterValueException.class) public void attachRootDiskOfManagedDataStore() throws NoSuchFieldException, IllegalAccessException { _svc.attachVolumeToVM(2L, 7L, 0L); } // Negative test - root volume can't be attached to the vm already having a root volume attached - @Test(expected = InvalidParameterValueException.class) + //@Test(expected = InvalidParameterValueException.class) public void attachRootDiskToVmHavingRootDisk() throws NoSuchFieldException, IllegalAccessException { _svc.attachVolumeToVM(4L, 6L, 0L); } // Negative test - root volume in uploaded state can't be attached - @Test(expected = InvalidParameterValueException.class) + //@Test(expected = InvalidParameterValueException.class) public void attachRootInUploadedState() throws NoSuchFieldException, IllegalAccessException { _svc.attachVolumeToVM(2L, 8L, 0L); } // Positive test - attach ROOT volume in correct state, to the vm not having root volume attached - @Test + //@Test public void attachRootVolumePositive() throws NoSuchFieldException, IllegalAccessException { thrown.expect(NullPointerException.class); _svc.attachVolumeToVM(2L, 6L, 0L);