use of com.cloud.agent.api.MigrateCommand.MigrateDiskInfo in project cloudstack by apache.
the class LibvirtMigrateCommandWrapper method replaceStorage.
/**
* Pass in a list of the disks to update in the XML (xmlDesc). Each disk passed in needs to have a serial number. If any disk's serial number in the
* list does not match a disk in the XML, an exception should be thrown.
* In addition to the serial number, each disk in the list needs the following info:
* <ul>
* <li>The value of the 'type' of the disk (ex. file, block)
* <li>The value of the 'type' of the driver of the disk (ex. qcow2, raw)
* <li>The source of the disk needs an attribute that is either 'file' or 'dev' as well as its corresponding value.
* </ul>
*/
protected String replaceStorage(String xmlDesc, Map<String, MigrateCommand.MigrateDiskInfo> migrateStorage, boolean migrateStorageManaged) throws IOException, ParserConfigurationException, SAXException, TransformerException {
InputStream in = IOUtils.toInputStream(xmlDesc);
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document doc = docBuilder.parse(in);
// Get the root element
Node domainNode = doc.getFirstChild();
NodeList domainChildNodes = domainNode.getChildNodes();
for (int i = 0; i < domainChildNodes.getLength(); i++) {
Node domainChildNode = domainChildNodes.item(i);
if ("devices".equals(domainChildNode.getNodeName())) {
NodeList devicesChildNodes = domainChildNode.getChildNodes();
for (int x = 0; x < devicesChildNodes.getLength(); x++) {
Node deviceChildNode = devicesChildNodes.item(x);
if ("disk".equals(deviceChildNode.getNodeName())) {
Node diskNode = deviceChildNode;
String sourceText = getSourceText(diskNode);
String path = getPathFromSourceText(migrateStorage.keySet(), sourceText);
if (path != null) {
MigrateCommand.MigrateDiskInfo migrateDiskInfo = migrateStorage.get(path);
NamedNodeMap diskNodeAttributes = diskNode.getAttributes();
Node diskNodeAttribute = diskNodeAttributes.getNamedItem("type");
diskNodeAttribute.setTextContent(migrateDiskInfo.getDiskType().toString());
NodeList diskChildNodes = diskNode.getChildNodes();
for (int z = 0; z < diskChildNodes.getLength(); z++) {
Node diskChildNode = diskChildNodes.item(z);
if (migrateStorageManaged && "driver".equals(diskChildNode.getNodeName())) {
Node driverNode = diskChildNode;
NamedNodeMap driverNodeAttributes = driverNode.getAttributes();
Node driverNodeAttribute = driverNodeAttributes.getNamedItem("type");
driverNodeAttribute.setTextContent(migrateDiskInfo.getDriverType().toString());
} else if ("source".equals(diskChildNode.getNodeName())) {
diskNode.removeChild(diskChildNode);
Element newChildSourceNode = doc.createElement("source");
newChildSourceNode.setAttribute(migrateDiskInfo.getSource().toString(), migrateDiskInfo.getSourceText());
diskNode.appendChild(newChildSourceNode);
} else if (migrateStorageManaged && "auth".equals(diskChildNode.getNodeName())) {
diskNode.removeChild(diskChildNode);
}
}
}
}
}
}
}
return getXml(doc);
}
use of com.cloud.agent.api.MigrateCommand.MigrateDiskInfo in project cloudstack by apache.
the class LibvirtMigrateCommandWrapperTest method testReplaceStorage.
@Test
public void testReplaceStorage() throws Exception {
Map<String, MigrateDiskInfo> mapMigrateStorage = new HashMap<String, MigrateDiskInfo>();
MigrateDiskInfo diskInfo = new MigrateDiskInfo("123456", DiskType.BLOCK, DriverType.RAW, Source.FILE, "sourctest");
mapMigrateStorage.put("/mnt/812ea6a3-7ad0-30f4-9cab-01e3f2985b98/4650a2f7-fce5-48e2-beaa-bcdf063194e6", diskInfo);
final String result = libvirtMigrateCmdWrapper.replaceStorage(fullfile, mapMigrateStorage, true);
InputStream in = IOUtils.toInputStream(result);
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document doc = docBuilder.parse(in);
assertXpath(doc, "/domain/devices/disk/iotune/write_iops_sec", "500");
assertXpath(doc, "/domain/devices/disk/@type", "block");
assertXpath(doc, "/domain/devices/disk/driver/@type", "raw");
}
use of com.cloud.agent.api.MigrateCommand.MigrateDiskInfo in project cloudstack by apache.
the class LibvirtMigrateCommandWrapperTest method configureAndVerifyTestSearchDiskDefOnMigrateDiskInfoList.
private void configureAndVerifyTestSearchDiskDefOnMigrateDiskInfoList(String serialNumber, String diskPath, boolean isExpectedDiskInfoNull) {
MigrateDiskInfo migrateDiskInfo = new MigrateDiskInfo(serialNumber, DiskType.FILE, DriverType.QCOW2, Source.FILE, "sourceText");
List<MigrateDiskInfo> migrateDiskInfoList = new ArrayList<>();
migrateDiskInfoList.add(migrateDiskInfo);
DiskDef disk = new DiskDef();
disk.setDiskPath(diskPath);
MigrateDiskInfo returnedMigrateDiskInfo = libvirtMigrateCmdWrapper.searchDiskDefOnMigrateDiskInfoList(migrateDiskInfoList, disk);
if (isExpectedDiskInfoNull)
Assert.assertEquals(null, returnedMigrateDiskInfo);
else
Assert.assertEquals(migrateDiskInfo, returnedMigrateDiskInfo);
}
use of com.cloud.agent.api.MigrateCommand.MigrateDiskInfo in project cloudstack by apache.
the class LibvirtMigrateCommandWrapperTest method createMigrateDiskInfo.
private MigrateDiskInfo createMigrateDiskInfo(boolean isSourceDiskOnStorageFileSystem) {
MigrateDiskInfo migrateDiskInfo = new MigrateDiskInfo("serialNumber", DiskType.FILE, DriverType.QCOW2, Source.FILE, "sourceText");
migrateDiskInfo.setSourceDiskOnStorageFileSystem(isSourceDiskOnStorageFileSystem);
return migrateDiskInfo;
}
use of com.cloud.agent.api.MigrateCommand.MigrateDiskInfo in project cloudstack by apache.
the class LibvirtMigrateCommandWrapperTest method deleteOrDisconnectDisksOnSourcePoolTest.
@Test
public void deleteOrDisconnectDisksOnSourcePoolTest() {
LibvirtMigrateCommandWrapper spyLibvirtMigrateCmdWrapper = PowerMockito.spy(libvirtMigrateCmdWrapper);
Mockito.doNothing().when(spyLibvirtMigrateCmdWrapper).deleteLocalVolume("volPath");
List<MigrateDiskInfo> migrateDiskInfoList = new ArrayList<>();
MigrateDiskInfo migrateDiskInfo0 = createMigrateDiskInfo(true);
MigrateDiskInfo migrateDiskInfo2 = createMigrateDiskInfo(false);
List<DiskDef> disks = new ArrayList<>();
DiskDef diskDef0 = new DiskDef();
DiskDef diskDef1 = new DiskDef();
DiskDef diskDef2 = new DiskDef();
diskDef0.setDiskPath("volPath");
disks.add(diskDef0);
disks.add(diskDef1);
disks.add(diskDef2);
LibvirtComputingResource libvirtComputingResource = Mockito.spy(new LibvirtComputingResource());
Mockito.doReturn(true).when(libvirtComputingResource).cleanupDisk(diskDef1);
Mockito.doReturn(migrateDiskInfo0).when(spyLibvirtMigrateCmdWrapper).searchDiskDefOnMigrateDiskInfoList(migrateDiskInfoList, diskDef0);
Mockito.doReturn(null).when(spyLibvirtMigrateCmdWrapper).searchDiskDefOnMigrateDiskInfoList(migrateDiskInfoList, diskDef1);
Mockito.doReturn(migrateDiskInfo2).when(spyLibvirtMigrateCmdWrapper).searchDiskDefOnMigrateDiskInfoList(migrateDiskInfoList, diskDef2);
spyLibvirtMigrateCmdWrapper.deleteOrDisconnectDisksOnSourcePool(libvirtComputingResource, migrateDiskInfoList, disks);
InOrder inOrder = Mockito.inOrder(spyLibvirtMigrateCmdWrapper, libvirtComputingResource);
inOrderVerifyDeleteOrDisconnect(inOrder, spyLibvirtMigrateCmdWrapper, libvirtComputingResource, migrateDiskInfoList, diskDef0, 1, 0);
inOrderVerifyDeleteOrDisconnect(inOrder, spyLibvirtMigrateCmdWrapper, libvirtComputingResource, migrateDiskInfoList, diskDef1, 0, 1);
inOrderVerifyDeleteOrDisconnect(inOrder, spyLibvirtMigrateCmdWrapper, libvirtComputingResource, migrateDiskInfoList, diskDef2, 0, 1);
}
Aggregations