cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e...@apache.org
Subject [5/8] git commit: updated refs/heads/master to 096d1b9
Date Sun, 05 Apr 2015 11:25:12 GMT
Refactoring the MigrateWithStorageCompleteCommand wrapper in order to cope with new design
   - Unit tests added: 50% coverage
   - It's a bit difficult to test the Xen API classes due to their static nature


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/f6e162af
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/f6e162af
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/f6e162af

Branch: refs/heads/master
Commit: f6e162afe437eb1aed9dad74e5abebed9225f5d8
Parents: d5414d2
Author: wilderrodrigues <wrodrigues@schubergphilis.com>
Authored: Fri Apr 3 16:29:08 2015 +0200
Committer: wilderrodrigues <wrodrigues@schubergphilis.com>
Committed: Sun Apr 5 09:23:10 2015 +0200

----------------------------------------------------------------------
 .../resource/XenServer610Resource.java          | 36 +-------------------
 .../wrapper/XenServer610WrapperTest.java        | 27 +++++++++++++++
 2 files changed, 28 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f6e162af/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XenServer610Resource.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XenServer610Resource.java
b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XenServer610Resource.java
index 261ace0..212b41b 100644
--- a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XenServer610Resource.java
+++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XenServer610Resource.java
@@ -30,18 +30,14 @@ import org.apache.xmlrpc.XmlRpcException;
 
 import com.cloud.agent.api.Answer;
 import com.cloud.agent.api.Command;
-import com.cloud.agent.api.MigrateWithStorageCompleteAnswer;
-import com.cloud.agent.api.MigrateWithStorageCompleteCommand;
 import com.cloud.agent.api.storage.MigrateVolumeAnswer;
 import com.cloud.agent.api.storage.MigrateVolumeCommand;
 import com.cloud.agent.api.to.DiskTO;
 import com.cloud.agent.api.to.StorageFilerTO;
-import com.cloud.agent.api.to.VirtualMachineTO;
 import com.cloud.resource.ServerResource;
 import com.cloud.storage.Volume;
 import com.cloud.utils.exception.CloudRuntimeException;
 import com.xensource.xenapi.Connection;
-import com.xensource.xenapi.Host;
 import com.xensource.xenapi.SR;
 import com.xensource.xenapi.Task;
 import com.xensource.xenapi.Types;
@@ -58,9 +54,7 @@ public class XenServer610Resource extends XenServer600Resource {
 
     @Override
     public Answer executeRequest(final Command cmd) {
-        if (cmd instanceof MigrateWithStorageCompleteCommand) {
-            return execute((MigrateWithStorageCompleteCommand)cmd);
-        } else if (cmd instanceof MigrateVolumeCommand) {
+        if (cmd instanceof MigrateVolumeCommand) {
             return execute((MigrateVolumeCommand)cmd);
         } else {
             return super.executeRequest(cmd);
@@ -102,34 +96,6 @@ public class XenServer610Resource extends XenServer600Resource {
         return volumeToList;
     }
 
-    protected MigrateWithStorageCompleteAnswer execute(final MigrateWithStorageCompleteCommand
cmd) {
-        final Connection connection = getConnection();
-        final VirtualMachineTO vmSpec = cmd.getVirtualMachine();
-
-        try {
-            final Host host = Host.getByUuid(connection, _host.getUuid());
-            final Set<VM> vms = VM.getByNameLabel(connection, vmSpec.getName());
-            final VM migratedVm = vms.iterator().next();
-
-            // Check the vm is present on the new host.
-            if (migratedVm == null) {
-                throw new CloudRuntimeException("Couldn't find the migrated vm " + vmSpec.getName()
+ " on the destination host.");
-            }
-
-            // Volume paths would have changed. Return that information.
-            final List<VolumeObjectTO> volumeToSet = getUpdatedVolumePathsOfMigratedVm(connection,
migratedVm, vmSpec.getDisks());
-            migratedVm.setAffinity(connection, host);
-
-            return new MigrateWithStorageCompleteAnswer(cmd, volumeToSet);
-        } catch (final CloudRuntimeException e) {
-            s_logger.error("Migration of vm " + vmSpec.getName() + " with storage failed
due to " + e.toString(), e);
-            return new MigrateWithStorageCompleteAnswer(cmd, e);
-        } catch (final Exception e) {
-            s_logger.error("Migration of vm " + vmSpec.getName() + " with storage failed
due to " + e.toString(), e);
-            return new MigrateWithStorageCompleteAnswer(cmd, e);
-        }
-    }
-
     protected MigrateVolumeAnswer execute(final MigrateVolumeCommand cmd) {
         final Connection connection = getConnection();
         final String volumeUUID = cmd.getVolumePath();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f6e162af/plugins/hypervisors/xenserver/test/com/cloud/hypervisor/xenserver/resource/wrapper/XenServer610WrapperTest.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xenserver/test/com/cloud/hypervisor/xenserver/resource/wrapper/XenServer610WrapperTest.java
b/plugins/hypervisors/xenserver/test/com/cloud/hypervisor/xenserver/resource/wrapper/XenServer610WrapperTest.java
index 7f17ed4..3e04782 100644
--- a/plugins/hypervisors/xenserver/test/com/cloud/hypervisor/xenserver/resource/wrapper/XenServer610WrapperTest.java
+++ b/plugins/hypervisors/xenserver/test/com/cloud/hypervisor/xenserver/resource/wrapper/XenServer610WrapperTest.java
@@ -39,6 +39,7 @@ import org.powermock.modules.junit4.PowerMockRunner;
 import com.cloud.agent.api.Answer;
 import com.cloud.agent.api.CheckNetworkCommand;
 import com.cloud.agent.api.MigrateWithStorageCommand;
+import com.cloud.agent.api.MigrateWithStorageCompleteCommand;
 import com.cloud.agent.api.MigrateWithStorageReceiveCommand;
 import com.cloud.agent.api.MigrateWithStorageSendCommand;
 import com.cloud.agent.api.SetupCommand;
@@ -433,4 +434,30 @@ public class XenServer610WrapperTest {
 
         assertFalse(answer.getResult());
     }
+
+    @Test
+    public void testMigrateWithStorageCompleteCommand() {
+        final String vmName = "small";
+        final String uuid = "206b21a7-c6ec-40e2-b5e2-f861b9612f04";
+
+        final Connection conn = Mockito.mock(Connection.class);
+        final XsHost xsHost = Mockito.mock(XsHost.class);
+
+        final VirtualMachineTO vm = Mockito.mock(VirtualMachineTO.class);
+
+        final MigrateWithStorageCompleteCommand createStorageCommand = new MigrateWithStorageCompleteCommand(vm);
+
+        final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
+        assertNotNull(wrapper);
+
+        when(xenServer610Resource.getConnection()).thenReturn(conn);
+        when(vm.getName()).thenReturn(vmName);
+        when(xenServer610Resource.getHost()).thenReturn(xsHost);
+        when(xsHost.getUuid()).thenReturn(uuid);
+
+        final Answer answer = wrapper.execute(createStorageCommand, xenServer610Resource);
+        verify(xenServer610Resource, times(1)).getConnection();
+
+        assertFalse(answer.getResult());
+    }
 }
\ No newline at end of file


Mime
View raw message