use of com.cloud.legacymodel.storage.StoragePool in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResourceTest method testBackupSnapshotCommandLibvirtException.
@Test
public void testBackupSnapshotCommandLibvirtException() {
// Simple test used to make sure the flow (LibvirtComputingResource => Request => CommandWrapper) is working.
// The code is way to big and complex. Will finish the refactor and come back to this to add more cases.
final StoragePool pool = Mockito.mock(StoragePool.class);
final String secondaryStorageUrl = "nfs:/127.0.0.1/storage/secondary";
final long accountId = 1l;
final String volumePath = "/123/vol";
final String vmName = "Test";
final int wait = 0;
final long snapshotId = 1l;
final String snapshotName = "snap";
final Long dcId = 1l;
final Long volumeId = 1l;
final Long secHostId = 1l;
final String snapshotUuid = "9a0afe7c-26a7-4585-bf87-abf82ae106d9";
final String prevBackupUuid = "003a0cc2-2e04-417a-bee0-534ef1724561";
final boolean isVolumeInactive = false;
final String prevSnapshotUuid = "1791efae-f22d-474b-87c6-92547d6c5877";
final BackupSnapshotCommand command = new BackupSnapshotCommand(secondaryStorageUrl, dcId, accountId, volumeId, snapshotId, secHostId, volumePath, pool, snapshotUuid, snapshotName, prevSnapshotUuid, prevBackupUuid, isVolumeInactive, vmName, wait);
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
// final Connect conn = Mockito.mock(Connect.class);
when(this.libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(command.getVmName())).thenThrow(LibvirtException.class);
} catch (final LibvirtException e) {
fail(e.getMessage());
}
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
assertFalse(answer.getResult());
verify(this.libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(command.getVmName());
} catch (final LibvirtException e) {
fail(e.getMessage());
}
}
use of com.cloud.legacymodel.storage.StoragePool in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResourceTest method testDeleteStoragePoolCommand.
@Test
public void testDeleteStoragePoolCommand() {
final StoragePool storagePool = Mockito.mock(StoragePool.class);
final KvmStoragePoolManager storagePoolMgr = Mockito.mock(KvmStoragePoolManager.class);
final DeleteStoragePoolCommand command = new DeleteStoragePoolCommand(storagePool);
final StorageFilerTO pool = command.getPool();
when(this.libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
when(storagePoolMgr.deleteStoragePool(pool.getType(), pool.getUuid())).thenReturn(true);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
assertTrue(answer.getResult());
verify(this.libvirtComputingResource, times(1)).getStoragePoolMgr();
verify(storagePoolMgr, times(1)).deleteStoragePool(pool.getType(), pool.getUuid());
}
use of com.cloud.legacymodel.storage.StoragePool in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResourceTest method testCreatePrivateTemplateFromSnapshotCommandConfigurationException.
@Test
public void testCreatePrivateTemplateFromSnapshotCommandConfigurationException() {
final StoragePool pool = Mockito.mock(StoragePool.class);
final String secondaryStoragePoolURL = "nfs:/127.0.0.1/storage/secondary";
final Long dcId = 1l;
final Long accountId = 1l;
final Long volumeId = 1l;
final String backedUpSnapshotUuid = "/run/9a0afe7c-26a7-4585-bf87-abf82ae106d9/";
final String backedUpSnapshotName = "snap";
final String origTemplateInstallPath = "/install/path/";
final Long newTemplateId = 2l;
final String templateName = "templ";
final int wait = 0;
final CreatePrivateTemplateFromSnapshotCommand command = new CreatePrivateTemplateFromSnapshotCommand(pool, secondaryStoragePoolURL, dcId, accountId, volumeId, backedUpSnapshotUuid, backedUpSnapshotName, origTemplateInstallPath, newTemplateId, templateName, wait);
final String templatePath = "/template/path";
final String localPath = "/mnt/local";
final String tmplName = "ce97bbc1-34fe-4259-9202-74bbce2562ab";
final KvmStoragePoolManager storagePoolMgr = Mockito.mock(KvmStoragePoolManager.class);
final KvmStoragePool secondaryPool = Mockito.mock(KvmStoragePool.class);
final KvmStoragePool snapshotPool = Mockito.mock(KvmStoragePool.class);
final KvmPhysicalDisk snapshot = Mockito.mock(KvmPhysicalDisk.class);
final StorageLayer storage = Mockito.mock(StorageLayer.class);
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
final TemplateLocation location = Mockito.mock(TemplateLocation.class);
final Processor qcow2Processor = Mockito.mock(Processor.class);
final TemplateFormatInfo info = Mockito.mock(TemplateFormatInfo.class);
when(this.libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
String snapshotPath = command.getSnapshotUuid();
final int index = snapshotPath.lastIndexOf("/");
snapshotPath = snapshotPath.substring(0, index);
when(storagePoolMgr.getStoragePoolByUri(command.getSecondaryStorageUrl() + snapshotPath)).thenReturn(snapshotPool);
when(storagePoolMgr.getStoragePoolByUri(command.getSecondaryStorageUrl())).thenReturn(secondaryPool);
when(snapshotPool.getPhysicalDisk(command.getSnapshotName())).thenReturn(snapshot);
when(secondaryPool.getLocalPath()).thenReturn(localPath);
when(this.libvirtComputingResource.getStorage()).thenReturn(storage);
when(this.libvirtComputingResource.createTmplPath()).thenReturn(templatePath);
when(this.libvirtComputingResource.getCmdsTimeout()).thenReturn(1);
final String templateFolder = command.getAccountId() + File.separator + command.getNewTemplateId();
final String templateInstallFolder = "template/tmpl/" + templateFolder;
final String tmplPath = secondaryPool.getLocalPath() + File.separator + templateInstallFolder;
when(this.libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
when(libvirtUtilitiesHelper.buildTemplateLocation(storage, tmplPath)).thenReturn(location);
when(libvirtUtilitiesHelper.generateUuidName()).thenReturn(tmplName);
try {
when(libvirtUtilitiesHelper.buildQcow2Processor(storage)).thenThrow(ConfigurationException.class);
when(qcow2Processor.process(tmplPath, null, tmplName)).thenReturn(info);
} catch (final ConfigurationException e) {
fail(e.getMessage());
} catch (final InternalErrorException e) {
fail(e.getMessage());
}
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
assertFalse(answer.getResult());
verify(this.libvirtComputingResource, times(1)).getStoragePoolMgr();
verify(storagePoolMgr, times(1)).getStoragePoolByUri(command.getSecondaryStorageUrl() + snapshotPath);
verify(storagePoolMgr, times(1)).getStoragePoolByUri(command.getSecondaryStorageUrl());
}
use of com.cloud.legacymodel.storage.StoragePool in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResourceTest method testModifyStoragePoolCommandFailure.
@Test
public void testModifyStoragePoolCommandFailure() {
final StoragePool pool = Mockito.mock(StoragePool.class);
final ModifyStoragePoolCommand command = new ModifyStoragePoolCommand(true, pool);
final KvmStoragePoolManager storagePoolMgr = Mockito.mock(KvmStoragePoolManager.class);
when(this.libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
when(storagePoolMgr.createStoragePool(command.getPool().getUuid(), command.getPool().getHost(), command.getPool().getPort(), command.getPool().getPath(), command.getPool().getUserInfo(), command.getPool().getType())).thenReturn(null);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
assertFalse(answer.getResult());
verify(this.libvirtComputingResource, times(1)).getStoragePoolMgr();
verify(storagePoolMgr, times(1)).createStoragePool(command.getPool().getUuid(), command.getPool().getHost(), command.getPool().getPort(), command.getPool().getPath(), command.getPool().getUserInfo(), command.getPool().getType());
}
use of com.cloud.legacymodel.storage.StoragePool in project cosmic by MissionCriticalCloud.
the class AbstractHyperVisorStorageMotionStrategy method buildVolumeMapping.
protected List<Pair<VolumeTO, StorageFilerTO>> buildVolumeMapping(final Map<VolumeInfo, DataStore> volumeToPool) {
final List<Pair<VolumeTO, StorageFilerTO>> volumeToFilerto = new ArrayList<>();
for (final Map.Entry<VolumeInfo, DataStore> entry : volumeToPool.entrySet()) {
final VolumeInfo volume = entry.getKey();
final StoragePool storagePool = storagePoolDao.findById(volume.getPoolId());
final VolumeTO volumeTo = new VolumeTO(volume.getId(), volume.getVolumeType(), storagePool.getPoolType(), storagePool.getUuid(), volume.getName(), volume.getFolder(), volume.getPath(), volume.getSize(), volume.getChainInfo(), volume.getFormat(), volume.getProvisioningType());
final StorageFilerTO filerTo = new StorageFilerTO((StoragePool) entry.getValue());
volumeToFilerto.add(new Pair<>(volumeTo, filerTo));
}
return volumeToFilerto;
}
Aggregations