Search in sources :

Example 11 with VirtualRoutingResource

use of com.cloud.common.virtualnetwork.VirtualRoutingResource in project cosmic by MissionCriticalCloud.

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(this.libvirtComputingResource.getVirtRouterResource()).thenReturn(routingResource);
    when(this.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, this.libvirtComputingResource);
    assertTrue(answer.getResult());
    verify(this.libvirtComputingResource, times(1)).getVirtRouterResource();
    verify(this.libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
    try {
        verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(vmName);
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) CheckRouterAnswer(com.cloud.legacymodel.communication.answer.CheckRouterAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) LibvirtRequestWrapper(com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper) LibvirtException(org.libvirt.LibvirtException) Connect(org.libvirt.Connect) RebootRouterCommand(com.cloud.legacymodel.communication.command.RebootRouterCommand) VirtualRoutingResource(com.cloud.common.virtualnetwork.VirtualRoutingResource) LibvirtUtilitiesHelper(com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper) Test(org.junit.Test)

Aggregations

VirtualRoutingResource (com.cloud.common.virtualnetwork.VirtualRoutingResource)11 Answer (com.cloud.legacymodel.communication.answer.Answer)8 LibvirtRequestWrapper (com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper)7 AttachAnswer (com.cloud.legacymodel.communication.answer.AttachAnswer)7 CheckRouterAnswer (com.cloud.legacymodel.communication.answer.CheckRouterAnswer)7 Test (org.junit.Test)7 Connect (org.libvirt.Connect)5 LibvirtException (org.libvirt.LibvirtException)5 LibvirtUtilitiesHelper (com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper)4 KvmStoragePoolManager (com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager)3 LibvirtVmDef (com.cloud.agent.resource.kvm.xml.LibvirtVmDef)3 InternalErrorException (com.cloud.legacymodel.exceptions.InternalErrorException)3 NicTO (com.cloud.legacymodel.to.NicTO)3 VirtualMachineTO (com.cloud.legacymodel.to.VirtualMachineTO)3 URISyntaxException (java.net.URISyntaxException)3 CheckSshCommand (com.cloud.legacymodel.communication.command.CheckSshCommand)2 RebootRouterCommand (com.cloud.legacymodel.communication.command.RebootRouterCommand)2 StartCommand (com.cloud.legacymodel.communication.command.StartCommand)2 Host (com.cloud.legacymodel.dc.Host)2 CheckSshAnswer (com.cloud.legacymodel.communication.answer.CheckSshAnswer)1