mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-03 04:12:31 +01:00
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
This commit is contained in:
parent
d5414d26b4
commit
f6e162afe4
@ -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();
|
||||
|
||||
@ -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());
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user