Search in sources :

Example 76 with LibvirtRequestWrapper

use of com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper in project cloudstack by apache.

the class LibvirtComputingResourceTest method testBackupSnapshotCommandLibvirtException.

@SuppressWarnings("unchecked")
@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(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, libvirtComputingResource);
    assertFalse(answer.getResult());
    verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
    try {
        verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(command.getVmName());
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
}
Also used : BackupSnapshotCommand(com.cloud.agent.api.BackupSnapshotCommand) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) LibvirtRequestWrapper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper) KVMStoragePool(com.cloud.hypervisor.kvm.storage.KVMStoragePool) StoragePool(com.cloud.storage.StoragePool) NfsStoragePool(com.cloud.hypervisor.kvm.resource.KVMHABase.NfsStoragePool) LibvirtException(org.libvirt.LibvirtException) LibvirtUtilitiesHelper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper) Test(org.junit.Test)

Example 77 with LibvirtRequestWrapper

use of com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper in project cloudstack by apache.

the class LibvirtComputingResourceTest method testOvsDestroyBridgeCommandFailure.

@Test
public void testOvsDestroyBridgeCommandFailure() {
    final String name = "Test";
    final Long hostId = 1l;
    final Long networkId = 1l;
    final OvsDestroyBridgeCommand command = new OvsDestroyBridgeCommand(networkId, name, hostId);
    when(libvirtComputingResource.destroyTunnelNetwork(command.getBridgeName())).thenReturn(false);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, libvirtComputingResource);
    assertFalse(answer.getResult());
    verify(libvirtComputingResource, times(1)).destroyTunnelNetwork(command.getBridgeName());
}
Also used : AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) LibvirtRequestWrapper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper) OvsDestroyBridgeCommand(com.cloud.agent.api.OvsDestroyBridgeCommand) Test(org.junit.Test)

Example 78 with LibvirtRequestWrapper

use of com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper in project cloudstack by apache.

the class LibvirtComputingResourceTest method testNetworkRulesSystemVmCommand.

@Test
public void testNetworkRulesSystemVmCommand() {
    final String vmName = "Test";
    final Type type = Type.SecondaryStorageVm;
    final NetworkRulesSystemVmCommand command = new NetworkRulesSystemVmCommand(vmName, type);
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
    final Connect conn = Mockito.mock(Connect.class);
    when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    try {
        when(libvirtUtilitiesHelper.getConnectionByVmName(command.getVmName())).thenReturn(conn);
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
    when(libvirtComputingResource.configureDefaultNetworkRulesForSystemVm(conn, command.getVmName())).thenReturn(true);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, libvirtComputingResource);
    assertTrue(answer.getResult());
    try {
        verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(command.getVmName());
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
    verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
    verify(libvirtComputingResource, times(1)).configureDefaultNetworkRulesForSystemVm(conn, command.getVmName());
}
Also used : AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) TrafficType(com.cloud.network.Networks.TrafficType) Type(com.cloud.vm.VirtualMachine.Type) StoragePoolType(com.cloud.storage.Storage.StoragePoolType) BootloaderType(com.cloud.template.VirtualMachineTemplate.BootloaderType) LibvirtRequestWrapper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper) LibvirtException(org.libvirt.LibvirtException) Connect(org.libvirt.Connect) NetworkRulesSystemVmCommand(com.cloud.agent.api.NetworkRulesSystemVmCommand) LibvirtUtilitiesHelper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper) Test(org.junit.Test)

Example 79 with LibvirtRequestWrapper

use of com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper in project cloudstack by apache.

the class LibvirtComputingResourceTest method testPlugNicCommandLibvirtException.

@SuppressWarnings("unchecked")
@Test
public void testPlugNicCommandLibvirtException() {
    final NicTO nic = Mockito.mock(NicTO.class);
    final String instanceName = "Test";
    final Type vmtype = Type.DomainRouter;
    final PlugNicCommand command = new PlugNicCommand(nic, instanceName, vmtype);
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
    when(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, libvirtComputingResource);
    assertFalse(answer.getResult());
    verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
    try {
        verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(command.getVmName());
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
}
Also used : AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) TrafficType(com.cloud.network.Networks.TrafficType) Type(com.cloud.vm.VirtualMachine.Type) StoragePoolType(com.cloud.storage.Storage.StoragePoolType) BootloaderType(com.cloud.template.VirtualMachineTemplate.BootloaderType) LibvirtRequestWrapper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper) LibvirtException(org.libvirt.LibvirtException) PlugNicCommand(com.cloud.agent.api.PlugNicCommand) UnPlugNicCommand(com.cloud.agent.api.UnPlugNicCommand) NicTO(com.cloud.agent.api.to.NicTO) LibvirtUtilitiesHelper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper) Test(org.junit.Test)

Example 80 with LibvirtRequestWrapper

use of com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper in project cloudstack by apache.

the class LibvirtComputingResourceTest method testCheckSshCommandFailure.

@Test
public void testCheckSshCommandFailure() {
    final String instanceName = "Test";
    final String ip = "127.0.0.1";
    final int port = 22;
    final CheckSshCommand command = new CheckSshCommand(instanceName, ip, port);
    final VirtualRoutingResource virtRouterResource = Mockito.mock(VirtualRoutingResource.class);
    final String privateIp = command.getIp();
    final int cmdPort = command.getPort();
    when(libvirtComputingResource.getVirtRouterResource()).thenReturn(virtRouterResource);
    when(virtRouterResource.connect(privateIp, cmdPort)).thenReturn(false);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, libvirtComputingResource);
    assertFalse(answer.getResult());
    verify(libvirtComputingResource, times(1)).getVirtRouterResource();
    verify(virtRouterResource, times(1)).connect(privateIp, cmdPort);
}
Also used : AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) LibvirtRequestWrapper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper) CheckSshCommand(com.cloud.agent.api.check.CheckSshCommand) VirtualRoutingResource(com.cloud.agent.resource.virtualnetwork.VirtualRoutingResource) Test(org.junit.Test)

Aggregations

Answer (com.cloud.agent.api.Answer)135 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)135 LibvirtRequestWrapper (com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper)135 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)135 Test (org.junit.Test)135 LibvirtUtilitiesHelper (com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper)68 LibvirtException (org.libvirt.LibvirtException)55 KVMStoragePoolManager (com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager)44 Connect (org.libvirt.Connect)39 KVMStoragePool (com.cloud.hypervisor.kvm.storage.KVMStoragePool)36 NfsStoragePool (com.cloud.hypervisor.kvm.resource.KVMHABase.NfsStoragePool)29 StoragePool (com.cloud.storage.StoragePool)28 ArrayList (java.util.ArrayList)21 KVMPhysicalDisk (com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk)20 NicTO (com.cloud.agent.api.to.NicTO)19 StorageFilerTO (com.cloud.agent.api.to.StorageFilerTO)16 VirtualMachineTO (com.cloud.agent.api.to.VirtualMachineTO)13 InternalErrorException (com.cloud.exception.InternalErrorException)13 Domain (org.libvirt.Domain)11 InterfaceDef (com.cloud.hypervisor.kvm.resource.LibvirtVMDef.InterfaceDef)10