Search in sources :

Example 16 with VirtualRoutingResource

use of com.cloud.agent.resource.virtualnetwork.VirtualRoutingResource in project cloudstack by apache.

the class LibvirtComputingResourceTest method testRebootRouterCommandConnect.

@Test
public void testRebootRouterCommandConnect() {
    final VirtualRoutingResource routingResource = Mockito.mock(VirtualRoutingResource.class);
    final Connect conn = Mockito.mock(Connect.class);
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
    final String vmName = "Test";
    final RebootRouterCommand command = new RebootRouterCommand(vmName, "127.0.0.1");
    when(libvirtComputingResource.getVirtRouterResource()).thenReturn(routingResource);
    when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    when(routingResource.connect(command.getPrivateIpAddress())).thenReturn(true);
    try {
        when(libvirtUtilitiesHelper.getConnectionByVmName(vmName)).thenReturn(conn);
    } 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)).getVirtRouterResource();
    verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
    try {
        verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(vmName);
    } 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) LibvirtRequestWrapper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper) LibvirtException(org.libvirt.LibvirtException) Connect(org.libvirt.Connect) RebootRouterCommand(com.cloud.agent.api.RebootRouterCommand) VirtualRoutingResource(com.cloud.agent.resource.virtualnetwork.VirtualRoutingResource) LibvirtUtilitiesHelper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper) Test(org.junit.Test)

Example 17 with VirtualRoutingResource

use of com.cloud.agent.resource.virtualnetwork.VirtualRoutingResource in project cloudstack by apache.

the class LibvirtComputingResourceTest method testStartCommand.

@Test
public void testStartCommand() {
    final VirtualMachineTO vmSpec = Mockito.mock(VirtualMachineTO.class);
    final com.cloud.host.Host host = Mockito.mock(com.cloud.host.Host.class);
    final boolean executeInSequence = false;
    final StartCommand command = new StartCommand(vmSpec, host, executeInSequence);
    final KVMStoragePoolManager storagePoolMgr = Mockito.mock(KVMStoragePoolManager.class);
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
    final Connect conn = Mockito.mock(Connect.class);
    final LibvirtVMDef vmDef = Mockito.mock(LibvirtVMDef.class);
    final VirtualRoutingResource virtRouterResource = Mockito.mock(VirtualRoutingResource.class);
    final NicTO nic = Mockito.mock(NicTO.class);
    final NicTO[] nics = new NicTO[] { nic };
    final int[] vms = new int[0];
    final String vmName = "Test";
    final String controlIp = "127.0.0.1";
    when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
    when(vmSpec.getNics()).thenReturn(nics);
    when(vmSpec.getType()).thenReturn(VirtualMachine.Type.DomainRouter);
    when(vmSpec.getName()).thenReturn(vmName);
    when(libvirtComputingResource.createVMFromSpec(vmSpec)).thenReturn(vmDef);
    when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    try {
        when(libvirtUtilitiesHelper.getConnectionByType(vmDef.getHvsType())).thenReturn(conn);
        when(conn.listDomains()).thenReturn(vms);
        doNothing().when(libvirtComputingResource).createVbd(conn, vmSpec, vmName, vmDef);
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    } catch (final InternalErrorException e) {
        fail(e.getMessage());
    } catch (final URISyntaxException e) {
        fail(e.getMessage());
    }
    when(storagePoolMgr.connectPhysicalDisksViaVmSpec(vmSpec)).thenReturn(true);
    try {
        doNothing().when(libvirtComputingResource).createVifs(vmSpec, vmDef);
        when(libvirtComputingResource.startVM(conn, vmName, vmDef.toString())).thenReturn("SUCCESS");
        when(vmSpec.getBootArgs()).thenReturn("ls -lart");
        when(libvirtComputingResource.passCmdLine(vmName, vmSpec.getBootArgs())).thenReturn(true);
        when(nic.getIp()).thenReturn(controlIp);
        when(nic.getType()).thenReturn(TrafficType.Control);
        when(libvirtComputingResource.getVirtRouterResource()).thenReturn(virtRouterResource);
        when(virtRouterResource.connect(controlIp, 1, 5000)).thenReturn(true);
    } catch (final InternalErrorException e) {
        fail(e.getMessage());
    } 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)).getConnectionByType(vmDef.getHvsType());
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
}
Also used : KVMStoragePoolManager(com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager) LibvirtException(org.libvirt.LibvirtException) StartCommand(com.cloud.agent.api.StartCommand) Connect(org.libvirt.Connect) VirtualRoutingResource(com.cloud.agent.resource.virtualnetwork.VirtualRoutingResource) InternalErrorException(com.cloud.exception.InternalErrorException) URISyntaxException(java.net.URISyntaxException) VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO) LibvirtUtilitiesHelper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper) 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) NicTO(com.cloud.agent.api.to.NicTO) Test(org.junit.Test)

Example 18 with VirtualRoutingResource

use of com.cloud.agent.resource.virtualnetwork.VirtualRoutingResource in project cloudstack by apache.

the class LibvirtComputingResourceTest method testRebootRouterCommand.

@Test
public void testRebootRouterCommand() {
    final VirtualRoutingResource routingResource = Mockito.mock(VirtualRoutingResource.class);
    final Connect conn = Mockito.mock(Connect.class);
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
    final String vmName = "Test";
    final RebootRouterCommand command = new RebootRouterCommand(vmName, "127.0.0.1");
    when(libvirtComputingResource.getVirtRouterResource()).thenReturn(routingResource);
    when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    try {
        when(libvirtUtilitiesHelper.getConnectionByVmName(vmName)).thenReturn(conn);
    } 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)).getVirtRouterResource();
    verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
    try {
        verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(vmName);
    } 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) LibvirtRequestWrapper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper) LibvirtException(org.libvirt.LibvirtException) Connect(org.libvirt.Connect) RebootRouterCommand(com.cloud.agent.api.RebootRouterCommand) VirtualRoutingResource(com.cloud.agent.resource.virtualnetwork.VirtualRoutingResource) LibvirtUtilitiesHelper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper) Test(org.junit.Test)

Aggregations

VirtualRoutingResource (com.cloud.agent.resource.virtualnetwork.VirtualRoutingResource)18 Answer (com.cloud.agent.api.Answer)10 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)9 Test (org.junit.Test)9 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)7 LibvirtRequestWrapper (com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper)7 Connect (org.libvirt.Connect)7 LibvirtException (org.libvirt.LibvirtException)7 ConfigurationException (javax.naming.ConfigurationException)6 InternalErrorException (com.cloud.exception.InternalErrorException)5 LibvirtUtilitiesHelper (com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper)4 KVMStoragePoolManager (com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager)4 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 URISyntaxException (java.net.URISyntaxException)4 NicTO (com.cloud.agent.api.to.NicTO)3 VirtualMachineTO (com.cloud.agent.api.to.VirtualMachineTO)3 RebootAnswer (com.cloud.agent.api.RebootAnswer)2 RebootRouterCommand (com.cloud.agent.api.RebootRouterCommand)2 StartCommand (com.cloud.agent.api.StartCommand)2 CheckSshCommand (com.cloud.agent.api.check.CheckSshCommand)2