Search in sources :

Example 1 with DestroyCommand

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());
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) CheckRouterAnswer(com.cloud.legacymodel.communication.answer.CheckRouterAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) VolumeTO(com.cloud.legacymodel.to.VolumeTO) LibvirtRequestWrapper(com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper) NfsStoragePool(com.cloud.agent.resource.kvm.ha.KvmHaBase.NfsStoragePool) KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) StoragePool(com.cloud.legacymodel.storage.StoragePool) KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) Volume(com.cloud.legacymodel.storage.Volume) DestroyCommand(com.cloud.legacymodel.communication.command.DestroyCommand) KvmStoragePoolManager(com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager) Test(org.junit.Test)

Example 2 with DestroyCommand

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());
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) CheckRouterAnswer(com.cloud.legacymodel.communication.answer.CheckRouterAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) VolumeTO(com.cloud.legacymodel.to.VolumeTO) LibvirtRequestWrapper(com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper) NfsStoragePool(com.cloud.agent.resource.kvm.ha.KvmHaBase.NfsStoragePool) KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) StoragePool(com.cloud.legacymodel.storage.StoragePool) KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) Volume(com.cloud.legacymodel.storage.Volume) DestroyCommand(com.cloud.legacymodel.communication.command.DestroyCommand) KvmStoragePoolManager(com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager) Test(org.junit.Test)

Example 3 with DestroyCommand

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());
}
Also used : RebootAnswer(com.cloud.legacymodel.communication.answer.RebootAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) CreateAnswer(com.cloud.legacymodel.communication.answer.CreateAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) DestroyCommand(com.cloud.legacymodel.communication.command.DestroyCommand) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) VMTemplateStorageResourceAssoc(com.cloud.legacymodel.storage.VMTemplateStorageResourceAssoc) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with DestroyCommand

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());
    }
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) Answer(com.cloud.legacymodel.communication.answer.Answer) StoragePool(com.cloud.legacymodel.storage.StoragePool) StorageUnavailableException(com.cloud.legacymodel.exceptions.StorageUnavailableException) DestroyCommand(com.cloud.legacymodel.communication.command.DestroyCommand) VMTemplateVO(com.cloud.storage.VMTemplateVO) DB(com.cloud.utils.db.DB)

Aggregations

Answer (com.cloud.legacymodel.communication.answer.Answer)4 DestroyCommand (com.cloud.legacymodel.communication.command.DestroyCommand)4 AttachAnswer (com.cloud.legacymodel.communication.answer.AttachAnswer)3 StoragePool (com.cloud.legacymodel.storage.StoragePool)3 Test (org.junit.Test)3 NfsStoragePool (com.cloud.agent.resource.kvm.ha.KvmHaBase.NfsStoragePool)2 KvmStoragePool (com.cloud.agent.resource.kvm.storage.KvmStoragePool)2 KvmStoragePoolManager (com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager)2 LibvirtRequestWrapper (com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper)2 CheckRouterAnswer (com.cloud.legacymodel.communication.answer.CheckRouterAnswer)2 Volume (com.cloud.legacymodel.storage.Volume)2 VolumeTO (com.cloud.legacymodel.to.VolumeTO)2 CreateAnswer (com.cloud.legacymodel.communication.answer.CreateAnswer)1 RebootAnswer (com.cloud.legacymodel.communication.answer.RebootAnswer)1 StorageUnavailableException (com.cloud.legacymodel.exceptions.StorageUnavailableException)1 VMTemplateStorageResourceAssoc (com.cloud.legacymodel.storage.VMTemplateStorageResourceAssoc)1 VMTemplateStoragePoolVO (com.cloud.storage.VMTemplateStoragePoolVO)1 VMTemplateVO (com.cloud.storage.VMTemplateVO)1 StoragePoolVO (com.cloud.storage.datastore.db.StoragePoolVO)1 DB (com.cloud.utils.db.DB)1