use of com.cloud.agent.api.to.VirtualMachineTO in project cloudstack by apache.
the class XenServer610WrapperTest method testMigrateWithStorageCommand.
@Test
public void testMigrateWithStorageCommand() {
final String vmName = "small";
final String uuid = "206b21a7-c6ec-40e2-b5e2-f861b9612f04";
final String path = "/";
final Connection conn = Mockito.mock(Connection.class);
final VirtualMachineTO vmSpec = Mockito.mock(VirtualMachineTO.class);
final VolumeTO vol1 = Mockito.mock(VolumeTO.class);
final VolumeTO vol2 = Mockito.mock(VolumeTO.class);
final StorageFilerTO storage1 = Mockito.mock(StorageFilerTO.class);
final StorageFilerTO storage2 = Mockito.mock(StorageFilerTO.class);
final Map<VolumeTO, StorageFilerTO> volumeToFiler = new HashMap<VolumeTO, StorageFilerTO>();
volumeToFiler.put(vol1, storage1);
volumeToFiler.put(vol2, storage2);
final NicTO nicTO1 = Mockito.mock(NicTO.class);
final NicTO nicTO2 = Mockito.mock(NicTO.class);
final NicTO nicTO3 = Mockito.mock(NicTO.class);
final NicTO[] nicTOs = { nicTO1, nicTO2, nicTO3 };
final XsLocalNetwork nativeNetworkForTraffic = Mockito.mock(XsLocalNetwork.class);
final Network networkForSm = Mockito.mock(Network.class);
final XsHost xsHost = Mockito.mock(XsHost.class);
final SR sr1 = Mockito.mock(SR.class);
final SR sr2 = Mockito.mock(SR.class);
final VDI vdi1 = Mockito.mock(VDI.class);
final VDI vdi2 = Mockito.mock(VDI.class);
final MigrateWithStorageCommand migrateStorageCommand = new MigrateWithStorageCommand(vmSpec, volumeToFiler);
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
assertNotNull(wrapper);
when(xenServer610Resource.getConnection()).thenReturn(conn);
when(vmSpec.getName()).thenReturn(vmName);
when(vmSpec.getNics()).thenReturn(nicTOs);
when(storage1.getUuid()).thenReturn(uuid);
when(storage2.getUuid()).thenReturn(uuid);
when(vol1.getPath()).thenReturn(path);
when(vol2.getPath()).thenReturn(path);
when(xenServer610Resource.getStorageRepository(conn, storage1.getUuid())).thenReturn(sr1);
when(xenServer610Resource.getStorageRepository(conn, storage2.getUuid())).thenReturn(sr2);
when(xenServer610Resource.getVDIbyUuid(conn, storage1.getPath())).thenReturn(vdi1);
when(xenServer610Resource.getVDIbyUuid(conn, storage2.getPath())).thenReturn(vdi2);
try {
when(xenServer610Resource.getNativeNetworkForTraffic(conn, TrafficType.Storage, null)).thenReturn(nativeNetworkForTraffic);
when(nativeNetworkForTraffic.getNetwork()).thenReturn(networkForSm);
when(xenServer610Resource.getHost()).thenReturn(xsHost);
when(xsHost.getUuid()).thenReturn(uuid);
} catch (final XenAPIException e) {
fail(e.getMessage());
} catch (final XmlRpcException e) {
fail(e.getMessage());
}
final Answer answer = wrapper.execute(migrateStorageCommand, xenServer610Resource);
verify(xenServer610Resource, times(1)).getConnection();
try {
verify(xenServer610Resource, times(1)).prepareISO(conn, vmName, null, null);
verify(xenServer610Resource, times(1)).getNetwork(conn, nicTO1);
verify(xenServer610Resource, times(1)).getNetwork(conn, nicTO2);
verify(xenServer610Resource, times(1)).getNetwork(conn, nicTO3);
verify(xenServer610Resource, times(1)).getNativeNetworkForTraffic(conn, TrafficType.Storage, null);
verify(nativeNetworkForTraffic, times(1)).getNetwork();
verify(xenServer610Resource, times(1)).getHost();
verify(xsHost, times(1)).getUuid();
} catch (final XenAPIException e) {
fail(e.getMessage());
} catch (final XmlRpcException e) {
fail(e.getMessage());
}
assertFalse(answer.getResult());
}
use of com.cloud.agent.api.to.VirtualMachineTO in project cloudstack by apache.
the class XenServer610WrapperTest method testMigrateWithStorageSendCommandSRException.
@Test
public void testMigrateWithStorageSendCommandSRException() {
final String vmName = "small";
final Connection conn = Mockito.mock(Connection.class);
final VirtualMachineTO vmSpec = Mockito.mock(VirtualMachineTO.class);
final VolumeTO volume1 = Mockito.mock(VolumeTO.class);
final VolumeTO volume2 = Mockito.mock(VolumeTO.class);
final List<Pair<VolumeTO, Object>> volumeToSr = new ArrayList<Pair<VolumeTO, Object>>();
volumeToSr.add(new Pair<VolumeTO, Object>(volume1, new String("a")));
volumeToSr.add(new Pair<VolumeTO, Object>(volume2, new String("b")));
final List<Pair<NicTO, Object>> nicToNetwork = new ArrayList<Pair<NicTO, Object>>();
final Map<String, String> token = new HashMap<String, String>();
final MigrateWithStorageSendCommand migrateStorageCommand = new MigrateWithStorageSendCommand(vmSpec, volumeToSr, nicToNetwork, token);
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
assertNotNull(wrapper);
when(xenServer610Resource.getConnection()).thenReturn(conn);
when(vmSpec.getName()).thenReturn(vmName);
final Answer answer = wrapper.execute(migrateStorageCommand, xenServer610Resource);
verify(xenServer610Resource, times(1)).getConnection();
assertFalse(answer.getResult());
}
use of com.cloud.agent.api.to.VirtualMachineTO in project cloudstack by apache.
the class XenServer610WrapperTest method testMigrateWithStorageSendCommand.
@Test
public void testMigrateWithStorageSendCommand() {
final String vmName = "small";
final String path = "/";
final String mac = "3c:15:c2:c4:4f:18";
final Connection conn = Mockito.mock(Connection.class);
final VirtualMachineTO vmSpec = Mockito.mock(VirtualMachineTO.class);
final VolumeTO volume1 = Mockito.mock(VolumeTO.class);
final VolumeTO volume2 = Mockito.mock(VolumeTO.class);
final SR sr1 = Mockito.mock(SR.class);
final SR sr2 = Mockito.mock(SR.class);
final VDI vdi1 = Mockito.mock(VDI.class);
final VDI vdi2 = Mockito.mock(VDI.class);
final NicTO nic1 = Mockito.mock(NicTO.class);
final NicTO nic2 = Mockito.mock(NicTO.class);
final Network network1 = Mockito.mock(Network.class);
final Network network2 = Mockito.mock(Network.class);
final List<Pair<VolumeTO, Object>> volumeToSr = new ArrayList<Pair<VolumeTO, Object>>();
volumeToSr.add(new Pair<VolumeTO, Object>(volume1, sr1));
volumeToSr.add(new Pair<VolumeTO, Object>(volume2, sr2));
final List<Pair<NicTO, Object>> nicToNetwork = new ArrayList<Pair<NicTO, Object>>();
nicToNetwork.add(new Pair<NicTO, Object>(nic1, network1));
nicToNetwork.add(new Pair<NicTO, Object>(nic2, network2));
final Map<String, String> token = new HashMap<String, String>();
final VIF vif1 = Mockito.mock(VIF.class);
final VIF vif2 = Mockito.mock(VIF.class);
final MigrateWithStorageSendCommand migrateStorageCommand = new MigrateWithStorageSendCommand(vmSpec, volumeToSr, nicToNetwork, token);
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
assertNotNull(wrapper);
when(xenServer610Resource.getConnection()).thenReturn(conn);
when(vmSpec.getName()).thenReturn(vmName);
when(volume1.getPath()).thenReturn(path);
when(volume2.getPath()).thenReturn(path);
when(nic1.getMac()).thenReturn(mac);
when(nic2.getMac()).thenReturn(mac);
when(xenServer610Resource.getVDIbyUuid(conn, volume1.getPath())).thenReturn(vdi1);
when(xenServer610Resource.getVDIbyUuid(conn, volume2.getPath())).thenReturn(vdi2);
try {
when(xenServer610Resource.getVifByMac(conn, null, nic1.getMac())).thenReturn(vif1);
when(xenServer610Resource.getVifByMac(conn, null, nic2.getMac())).thenReturn(vif2);
} catch (final XenAPIException e) {
fail(e.getMessage());
} catch (final XmlRpcException e) {
fail(e.getMessage());
}
final Answer answer = wrapper.execute(migrateStorageCommand, xenServer610Resource);
verify(xenServer610Resource, times(1)).getConnection();
try {
verify(xenServer610Resource, times(2)).getVDIbyUuid(conn, volume1.getPath());
verify(xenServer610Resource, times(2)).getVifByMac(conn, null, nic1.getMac());
} catch (final XenAPIException e) {
fail(e.getMessage());
} catch (final XmlRpcException e) {
fail(e.getMessage());
}
assertFalse(answer.getResult());
}
use of com.cloud.agent.api.to.VirtualMachineTO in project cloudstack by apache.
the class MockVmManagerImpl method startVM.
@Override
public StartAnswer startVM(final StartCommand cmd, final SimulatorInfo info) {
final VirtualMachineTO vm = cmd.getVirtualMachine();
final String result = startVM(vm.getName(), vm.getNics(), vm.getCpus() * vm.getMaxSpeed(), vm.getMaxRam(), vm.getBootArgs(), info.getHostUuid());
if (result != null) {
return new StartAnswer(cmd, result);
} else {
return new StartAnswer(cmd);
}
}
use of com.cloud.agent.api.to.VirtualMachineTO in project cloudstack by apache.
the class MockVmManagerImpl method prepareForMigrate.
@Override
public PrepareForMigrationAnswer prepareForMigrate(final PrepareForMigrationCommand cmd) {
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
final VirtualMachineTO vmTo = cmd.getVirtualMachine();
try {
txn.start();
final MockVMVO vm = _mockVmDao.findById(vmTo.getId());
_mockVmDao.update(vm.getId(), vm);
txn.commit();
} catch (final Exception ex) {
txn.rollback();
throw new CloudRuntimeException("unable to find vm " + vmTo.getName(), ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
return new PrepareForMigrationAnswer(cmd);
}
}
Aggregations