use of com.cloud.hypervisor.kvm.storage.KvmPhysicalDisk in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResource method attachOrDetachIso.
public synchronized String attachOrDetachIso(final Connect conn, final String vmName, String isoPath, final boolean isAttach) throws LibvirtException, URISyntaxException, InternalErrorException {
String isoXml = null;
if (isoPath != null && isAttach) {
final int index = isoPath.lastIndexOf("/");
final String path = isoPath.substring(0, index);
final String name = isoPath.substring(index + 1);
final KvmStoragePool secondaryPool = storagePoolMgr.getStoragePoolByUri(path);
final KvmPhysicalDisk isoVol = secondaryPool.getPhysicalDisk(name);
isoPath = isoVol.getPath();
final LibvirtDiskDef iso = new LibvirtDiskDef();
iso.defIsoDisk(isoPath);
isoXml = iso.toString();
} else {
final LibvirtDiskDef iso = new LibvirtDiskDef();
iso.defIsoDisk(null);
isoXml = iso.toString();
}
final List<LibvirtDiskDef> disks = getDisks(conn, vmName);
final String result = attachOrDetachDevice(conn, true, vmName, isoXml);
if (result == null && !isAttach) {
for (final LibvirtDiskDef disk : disks) {
if (disk.getDeviceType() == LibvirtDiskDef.DeviceType.CDROM) {
cleanupDisk(disk);
}
}
}
return result;
}
use of com.cloud.hypervisor.kvm.storage.KvmPhysicalDisk in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResourceTest method testCreateCommandNoTemplate.
@Test
public void testCreateCommandNoTemplate() {
final DiskProfile diskCharacteristics = Mockito.mock(DiskProfile.class);
final StorageFilerTO pool = Mockito.mock(StorageFilerTO.class);
final boolean executeInSequence = false;
final CreateCommand command = new CreateCommand(diskCharacteristics, pool, executeInSequence);
final KvmStoragePoolManager poolManager = Mockito.mock(KvmStoragePoolManager.class);
final KvmStoragePool primary = Mockito.mock(KvmStoragePool.class);
final KvmPhysicalDisk vol = Mockito.mock(KvmPhysicalDisk.class);
when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(poolManager);
when(poolManager.getStoragePool(pool.getType(), pool.getUuid())).thenReturn(primary);
when(primary.createPhysicalDisk(diskCharacteristics.getPath(), diskCharacteristics.getProvisioningType(), diskCharacteristics.getSize())).thenReturn(vol);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, libvirtComputingResource);
assertTrue(answer.getResult());
verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
verify(poolManager, times(1)).getStoragePool(pool.getType(), pool.getUuid());
}
use of com.cloud.hypervisor.kvm.storage.KvmPhysicalDisk in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResourceTest method testManageSnapshotCommandLibvirt.
@Test
public void testManageSnapshotCommandLibvirt() {
final StoragePool storagePool = Mockito.mock(StoragePool.class);
final String volumePath = "/123/vol";
final String vmName = "Test";
final long snapshotId = 1l;
final String preSnapshotPath = "/snapshot/path";
final String snapshotName = "snap";
final ManageSnapshotCommand command = new ManageSnapshotCommand(snapshotId, volumePath, storagePool, preSnapshotPath, snapshotName, vmName);
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
final Connect conn = Mockito.mock(Connect.class);
final KvmStoragePoolManager storagePoolMgr = Mockito.mock(KvmStoragePoolManager.class);
final KvmStoragePool primaryPool = Mockito.mock(KvmStoragePool.class);
final Domain vm = Mockito.mock(Domain.class);
final DomainInfo info = Mockito.mock(DomainInfo.class);
final DomainState state = DomainInfo.DomainState.VIR_DOMAIN_RUNNING;
info.state = state;
final KvmPhysicalDisk disk = Mockito.mock(KvmPhysicalDisk.class);
final StorageFilerTO pool = command.getPool();
when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(vmName)).thenReturn(conn);
when(libvirtComputingResource.getDomain(conn, command.getVmName())).thenReturn(vm);
when(vm.getInfo()).thenReturn(info);
} catch (final LibvirtException e) {
fail(e.getMessage());
}
when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
when(storagePoolMgr.getStoragePool(pool.getType(), pool.getUuid())).thenReturn(primaryPool);
when(primaryPool.getPhysicalDisk(command.getVolumePath())).thenReturn(disk);
when(primaryPool.isExternalSnapshot()).thenReturn(false);
try {
when(vm.getUUIDString()).thenReturn("cdb18980-546d-4153-b916-70ee9edf0908");
} catch (final LibvirtException e) {
fail(e.getMessage());
}
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, libvirtComputingResource);
assertTrue(answer.getResult());
verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(vmName);
} catch (final LibvirtException e) {
fail(e.getMessage());
}
}
use of com.cloud.hypervisor.kvm.storage.KvmPhysicalDisk in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResourceTest method testResizeVolumeCommand.
@Test
public void testResizeVolumeCommand() {
final String path = "nfs:/127.0.0.1/storage/secondary";
final StorageFilerTO pool = Mockito.mock(StorageFilerTO.class);
final Long currentSize = 100l;
final Long newSize = 200l;
final boolean shrinkOk = true;
final String vmInstance = "Test";
final ResizeVolumeCommand command = new ResizeVolumeCommand(path, pool, currentSize, newSize, shrinkOk, vmInstance);
final KvmStoragePoolManager storagePoolMgr = Mockito.mock(KvmStoragePoolManager.class);
final KvmStoragePool storagePool = Mockito.mock(KvmStoragePool.class);
final KvmPhysicalDisk vol = Mockito.mock(KvmPhysicalDisk.class);
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
final Connect conn = Mockito.mock(Connect.class);
final StorageVol v = Mockito.mock(StorageVol.class);
when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
when(storagePoolMgr.getStoragePool(pool.getType(), pool.getUuid())).thenReturn(storagePool);
when(storagePool.getPhysicalDisk(path)).thenReturn(vol);
when(vol.getPath()).thenReturn(path);
when(libvirtComputingResource.getResizeScriptType(storagePool, vol)).thenReturn("FILE");
when(storagePool.getType()).thenReturn(StoragePoolType.RBD);
when(vol.getFormat()).thenReturn(PhysicalDiskFormat.FILE);
when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnection()).thenReturn(conn);
when(conn.storageVolLookupByPath(path)).thenReturn(v);
when(conn.getLibVirVersion()).thenReturn(10010l);
} catch (final LibvirtException e) {
fail(e.getMessage());
}
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, libvirtComputingResource);
assertTrue(answer.getResult());
verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnection();
} catch (final LibvirtException e) {
fail(e.getMessage());
}
}
use of com.cloud.hypervisor.kvm.storage.KvmPhysicalDisk in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResourceTest method testCopyVolumeCommand.
@Test
public void testCopyVolumeCommand() {
final StoragePool storagePool = Mockito.mock(StoragePool.class);
final String secondaryStoragePoolURL = "nfs:/127.0.0.1/storage/secondary";
final Long volumeId = 1l;
final int wait = 0;
final String volumePath = "/vol/path";
final boolean toSecondaryStorage = true;
final boolean executeInSequence = false;
final CopyVolumeCommand command = new CopyVolumeCommand(volumeId, volumePath, storagePool, secondaryStoragePoolURL, toSecondaryStorage, wait, executeInSequence);
final String destVolumeName = "ce97bbc1-34fe-4259-9202-74bbce2562ab";
final String volumeDestPath = "/volumes/" + command.getVolumeId() + File.separator;
final KvmStoragePoolManager storagePoolMgr = Mockito.mock(KvmStoragePoolManager.class);
final KvmStoragePool secondary = Mockito.mock(KvmStoragePool.class);
final KvmStoragePool primary = Mockito.mock(KvmStoragePool.class);
final KvmPhysicalDisk disk = Mockito.mock(KvmPhysicalDisk.class);
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
final StorageFilerTO pool = command.getPool();
when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
when(storagePoolMgr.getStoragePool(pool.getType(), pool.getUuid())).thenReturn(primary);
when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
when(libvirtUtilitiesHelper.generateUuidName()).thenReturn(destVolumeName);
when(primary.getPhysicalDisk(command.getVolumePath())).thenReturn(disk);
when(storagePoolMgr.getStoragePoolByUri(secondaryStoragePoolURL)).thenReturn(secondary);
when(secondary.getType()).thenReturn(StoragePoolType.ManagedNFS);
when(secondary.getUuid()).thenReturn("60d979d8-d132-4181-8eca-8dfde50d7df6");
when(secondary.createFolder(volumeDestPath)).thenReturn(true);
when(storagePoolMgr.deleteStoragePool(secondary.getType(), secondary.getUuid())).thenReturn(true);
when(storagePoolMgr.getStoragePoolByUri(secondaryStoragePoolURL + volumeDestPath)).thenReturn(secondary);
when(storagePoolMgr.copyPhysicalDisk(disk, destVolumeName, secondary, 0)).thenReturn(disk);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, libvirtComputingResource);
assertTrue(answer.getResult());
verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
}
Aggregations