use of com.xensource.xenapi.SR in project cloudstack by apache.
the class XenServer610MigrateVolumeCommandWrapper method execute.
@Override
public Answer execute(final MigrateVolumeCommand command, final XenServer610Resource xenServer610Resource) {
Connection connection = xenServer610Resource.getConnection();
String srcVolumeUuid = command.getVolumePath();
SR destPool = null;
Map<String, String> destDetails = command.getDestDetails();
try {
VDI srcVolume = xenServer610Resource.getVDIbyUuid(connection, srcVolumeUuid);
if (destDetails != null && Boolean.parseBoolean(destDetails.get(DiskTO.MANAGED))) {
String iScsiName = destDetails.get(DiskTO.IQN);
String storageHost = destDetails.get(DiskTO.STORAGE_HOST);
String chapInitiatorUsername = destDetails.get(DiskTO.CHAP_INITIATOR_USERNAME);
String chapInitiatorSecret = destDetails.get(DiskTO.CHAP_INITIATOR_SECRET);
destPool = xenServer610Resource.getIscsiSR(connection, iScsiName, storageHost, iScsiName, chapInitiatorUsername, chapInitiatorSecret, false);
} else {
final StorageFilerTO pool = command.getPool();
destPool = xenServer610Resource.getStorageRepository(connection, CitrixHelper.getSRNameLabel(pool.getUuid(), pool.getType(), pool.getPath()));
}
Map<String, String> other = new HashMap<>();
other.put("live", "true");
// Live migrate the VDI.
Task task = srcVolume.poolMigrateAsync(connection, destPool, other);
long timeout = xenServer610Resource.getMigrateWait() * 1000L;
xenServer610Resource.waitForTask(connection, task, 1000, timeout);
xenServer610Resource.checkForSuccess(connection, task);
VDI destVdi = Types.toVDI(task, connection);
return new MigrateVolumeAnswer(command, true, null, destVdi.getUuid(connection));
} catch (Exception ex) {
if (destDetails != null && Boolean.parseBoolean(destDetails.get(DiskTO.MANAGED)) && destPool != null) {
xenServer610Resource.removeSR(connection, destPool);
}
String msg = "Caught exception " + ex.getClass().getName() + " due to the following: " + ex.toString();
LOGGER.error(msg, ex);
return new MigrateVolumeAnswer(command, false, msg, null);
}
}
use of com.xensource.xenapi.SR in project cloudstack by apache.
the class CitrixResourceBaseTest method createStartUpStorageCommandTest.
@Test
public void createStartUpStorageCommandTest() throws XenAPIException, XmlRpcException {
String hostUuid = "hostUUid";
citrixResourceBase._host.setUuid(hostUuid);
citrixResourceBase._dcId = 1;
Connection connectionMock = Mockito.mock(Connection.class);
SR srMock = Mockito.mock(SR.class);
StoragePoolInfo storagePoolInfoMock = Mockito.mock(StoragePoolInfo.class);
Mockito.doNothing().when(citrixResourceBase).configureStorageNameAndDescription(connectionMock, srMock);
Mockito.doReturn(storagePoolInfoMock).when(citrixResourceBase).createStoragePoolInfo(connectionMock, srMock);
StartupStorageCommand startUpStorageCommand = citrixResourceBase.createStartUpStorageCommand(connectionMock, srMock);
Assert.assertEquals(hostUuid, startUpStorageCommand.getGuid());
Assert.assertEquals(storagePoolInfoMock, startUpStorageCommand.getPoolInfo());
Assert.assertEquals(citrixResourceBase._dcId + "", startUpStorageCommand.getDataCenter());
Assert.assertEquals(StorageResourceType.STORAGE_POOL, startUpStorageCommand.getResourceType());
}
use of com.xensource.xenapi.SR in project cloudstack by apache.
the class CitrixResourceBaseTest method getAllLocalSrForTypeNoSrsFoundTest.
@Test
public void getAllLocalSrForTypeNoSrsFoundTest() throws XenAPIException, XmlRpcException {
Connection connectionMock = Mockito.mock(Connection.class);
List<SR> allLocalSrForType = citrixResourceBase.getAllLocalSrForType(connectionMock, SRType.EXT);
Assert.assertTrue(allLocalSrForType.isEmpty());
}
use of com.xensource.xenapi.SR in project cloudstack by apache.
the class Xenserver625StorageProcessorTest method forgetSrTest.
@Test
public void forgetSrTest() throws XenAPIException, XmlRpcException {
PBD pbdMock = Mockito.mock(PBD.class);
Set<PBD> pbds = new HashSet<>();
pbds.add(pbdMock);
SR srMock = Mockito.mock(SR.class);
Mockito.when(srMock.getPBDs(connectionMock)).thenReturn(pbds);
Mockito.doNothing().when(xenserver625StorageProcessor).unplugPbd(connectionMock, pbdMock);
xenserver625StorageProcessor.forgetSr(connectionMock, srMock);
Mockito.verify(srMock).getPBDs(connectionMock);
Mockito.verify(xenserver625StorageProcessor, times(1)).unplugPbd(connectionMock, pbdMock);
Mockito.verify(srMock).forget(connectionMock);
}
use of com.xensource.xenapi.SR in project cloudstack by apache.
the class Xenserver625StorageProcessorTest method retrieveAlreadyConfiguredSrTestNoSrFound.
@Test
@PrepareForTest(SR.class)
public void retrieveAlreadyConfiguredSrTestNoSrFound() throws XenAPIException, XmlRpcException {
prepareToReturnSrs(null);
SR sr = xenserver625StorageProcessor.retrieveAlreadyConfiguredSr(connectionMock, pathMock);
PowerMockito.verifyStatic(SR.class);
SR.getByNameLabel(connectionMock, pathMock);
Assert.assertNull(sr);
}
Aggregations