use of com.cloud.legacymodel.communication.command.DestroyCommand in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResourceTest method testDestroyCommandError.
@Test
public void testDestroyCommandError() {
final StoragePool pool = Mockito.mock(StoragePool.class);
final Volume volume = Mockito.mock(Volume.class);
final String vmName = "Test";
final DestroyCommand command = new DestroyCommand(pool, volume, vmName);
final KvmStoragePoolManager poolManager = Mockito.mock(KvmStoragePoolManager.class);
final KvmStoragePool primary = Mockito.mock(KvmStoragePool.class);
final VolumeTO vol = command.getVolume();
when(this.libvirtComputingResource.getStoragePoolMgr()).thenReturn(poolManager);
when(poolManager.getStoragePool(vol.getPoolType(), vol.getPoolUuid())).thenReturn(primary);
when(primary.deletePhysicalDisk(vol.getPath(), null)).thenThrow(CloudRuntimeException.class);
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(poolManager, times(1)).getStoragePool(vol.getPoolType(), vol.getPoolUuid());
}
use of com.cloud.legacymodel.communication.command.DestroyCommand in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResourceTest method testDestroyCommand.
@Test
public void testDestroyCommand() {
final StoragePool pool = Mockito.mock(StoragePool.class);
final Volume volume = Mockito.mock(Volume.class);
final String vmName = "Test";
final DestroyCommand command = new DestroyCommand(pool, volume, vmName);
final KvmStoragePoolManager poolManager = Mockito.mock(KvmStoragePoolManager.class);
final KvmStoragePool primary = Mockito.mock(KvmStoragePool.class);
final VolumeTO vol = command.getVolume();
when(this.libvirtComputingResource.getStoragePoolMgr()).thenReturn(poolManager);
when(poolManager.getStoragePool(vol.getPoolType(), vol.getPoolUuid())).thenReturn(primary);
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(poolManager, times(1)).getStoragePool(vol.getPoolType(), vol.getPoolUuid());
}
use of com.cloud.legacymodel.communication.command.DestroyCommand in project cosmic by MissionCriticalCloud.
the class NotAValidCommand method testDestroyCommand.
@Test
public void testDestroyCommand() {
final VMTemplateStorageResourceAssoc templateStorage = Mockito.mock(VMTemplateStorageResourceAssoc.class);
final StoragePoolVO poolVO = Mockito.mock(StoragePoolVO.class);
final DestroyCommand destroyCommand = new DestroyCommand(poolVO, templateStorage);
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(destroyCommand, this.citrixResourceBase);
verify(this.citrixResourceBase, times(1)).getConnection();
assertFalse(answer.getResult());
}
use of com.cloud.legacymodel.communication.command.DestroyCommand in project cosmic by MissionCriticalCloud.
the class TemplateManagerImpl method evictTemplateFromStoragePool.
@Override
@DB
public void evictTemplateFromStoragePool(final VMTemplateStoragePoolVO templatePoolVO) {
// Need to hold the lock, otherwise, another thread may create a volume from the template at the same time.
// Assumption here is that, we will hold the same lock during create volume from template
final VMTemplateStoragePoolVO templatePoolRef = this._tmpltPoolDao.acquireInLockTable(templatePoolVO.getId());
if (templatePoolRef == null) {
s_logger.debug("can't aquire the lock for template pool ref:" + templatePoolVO.getId());
return;
}
try {
final StoragePool pool = (StoragePool) this._dataStoreMgr.getPrimaryDataStore(templatePoolVO.getPoolId());
final VMTemplateVO template = this._tmpltDao.findByIdIncludingRemoved(templatePoolVO.getTemplateId());
if (s_logger.isDebugEnabled()) {
s_logger.debug("Evicting " + templatePoolVO);
}
final DestroyCommand cmd = new DestroyCommand(pool, templatePoolVO);
try {
final Answer answer = this._storageMgr.sendToPool(pool, cmd);
if (answer != null && answer.getResult()) {
// Remove the templatePoolVO
if (this._tmpltPoolDao.remove(templatePoolVO.getId())) {
s_logger.debug("Successfully evicted template: " + template.getName() + " from storage pool: " + pool.getName());
}
} else {
s_logger.info("Will retry evicte template: " + template.getName() + " from storage pool: " + pool.getName());
}
} catch (final StorageUnavailableException e) {
s_logger.info("Storage is unavailable currently. Will retry evicte template: " + template.getName() + " from storage pool: " + pool.getName());
}
} finally {
this._tmpltPoolDao.releaseFromLockTable(templatePoolRef.getId());
}
}
Aggregations