Search in sources :

Example 1 with CheckSshCommand

use of com.cloud.legacymodel.communication.command.CheckSshCommand in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testCheckSshCommand.

@Test
public void testCheckSshCommand() {
    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(this.libvirtComputingResource.getVirtRouterResource()).thenReturn(virtRouterResource);
    when(virtRouterResource.connect(privateIp, cmdPort)).thenReturn(true);
    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(virtRouterResource, times(1)).connect(privateIp, cmdPort);
}
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) CheckSshCommand(com.cloud.legacymodel.communication.command.CheckSshCommand) VirtualRoutingResource(com.cloud.common.virtualnetwork.VirtualRoutingResource) Test(org.junit.Test)

Example 2 with CheckSshCommand

use of com.cloud.legacymodel.communication.command.CheckSshCommand in project cosmic by MissionCriticalCloud.

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(this.libvirtComputingResource.getVirtRouterResource()).thenReturn(virtRouterResource);
    when(virtRouterResource.connect(privateIp, cmdPort)).thenReturn(false);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
    assertFalse(answer.getResult());
    verify(this.libvirtComputingResource, times(1)).getVirtRouterResource();
    verify(virtRouterResource, times(1)).connect(privateIp, cmdPort);
}
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) CheckSshCommand(com.cloud.legacymodel.communication.command.CheckSshCommand) VirtualRoutingResource(com.cloud.common.virtualnetwork.VirtualRoutingResource) Test(org.junit.Test)

Example 3 with CheckSshCommand

use of com.cloud.legacymodel.communication.command.CheckSshCommand in project cosmic by MissionCriticalCloud.

the class SecondaryStorageManagerImpl method finalizeCommandsOnStart.

@Override
public boolean finalizeCommandsOnStart(final Commands cmds, final VirtualMachineProfile profile) {
    NicProfile managementNic = null;
    NicProfile controlNic = null;
    for (final NicProfile nic : profile.getNics()) {
        if (nic.getTrafficType() == TrafficType.Management) {
            managementNic = nic;
        } else if (nic.getTrafficType() == TrafficType.Control && nic.getIPv4Address() != null) {
            controlNic = nic;
        }
    }
    if (controlNic == null) {
        if (managementNic == null) {
            logger.error("Management network doesn't exist for the secondaryStorageVm " + profile.getVirtualMachine());
            return false;
        }
        controlNic = managementNic;
    }
    final CheckSshCommand check = new CheckSshCommand(profile.getInstanceName(), controlNic.getIPv4Address(), 3922);
    cmds.addCommand("checkSsh", check);
    return true;
}
Also used : CheckSshCommand(com.cloud.legacymodel.communication.command.CheckSshCommand) NicProfile(com.cloud.vm.NicProfile)

Example 4 with CheckSshCommand

use of com.cloud.legacymodel.communication.command.CheckSshCommand in project cosmic by MissionCriticalCloud.

the class VirtualNetworkApplianceManagerImpl method finalizeSshAndVersionAndNetworkUsageOnStart.

protected void finalizeSshAndVersionAndNetworkUsageOnStart(final Commands cmds, final VirtualMachineProfile profile, final DomainRouterVO router, final NicProfile controlNic) {
    final DomainRouterVO vr = _routerDao.findById(profile.getId());
    cmds.addCommand("checkSsh", new CheckSshCommand(profile.getInstanceName(), controlNic.getIPv4Address(), 3922));
    // Update router template/scripts version
    final GetDomRVersionCommand command = new GetDomRVersionCommand();
    command.setAccessDetail(NetworkElementCommand.ROUTER_IP, controlNic.getIPv4Address());
    command.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
    cmds.addCommand("getDomRVersion", command);
    // Network usage command to create iptables rules
    final boolean forVpc = vr.getVpcId() != null;
    if (!forVpc) {
        cmds.addCommand("networkUsage", new NetworkUsageCommand(controlNic.getIPv4Address(), router.getHostName(), "create", forVpc));
    }
}
Also used : GetDomRVersionCommand(com.cloud.legacymodel.communication.command.GetDomRVersionCommand) CheckSshCommand(com.cloud.legacymodel.communication.command.CheckSshCommand) NetworkUsageCommand(com.cloud.legacymodel.communication.command.NetworkUsageCommand) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 5 with CheckSshCommand

use of com.cloud.legacymodel.communication.command.CheckSshCommand in project cosmic by MissionCriticalCloud.

the class NotAValidCommand method testCheckSshCommand.

@Test
public void testCheckSshCommand() {
    final CheckSshCommand sshCommand = new CheckSshCommand("Test", "127.0.0.1", 22);
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(sshCommand, this.citrixResourceBase);
    verify(this.citrixResourceBase, times(1)).getConnection();
    assertTrue(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) CheckSshCommand(com.cloud.legacymodel.communication.command.CheckSshCommand) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

CheckSshCommand (com.cloud.legacymodel.communication.command.CheckSshCommand)6 Answer (com.cloud.legacymodel.communication.answer.Answer)3 AttachAnswer (com.cloud.legacymodel.communication.answer.AttachAnswer)3 Test (org.junit.Test)3 LibvirtRequestWrapper (com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper)2 VirtualRoutingResource (com.cloud.common.virtualnetwork.VirtualRoutingResource)2 CheckRouterAnswer (com.cloud.legacymodel.communication.answer.CheckRouterAnswer)2 NicProfile (com.cloud.vm.NicProfile)2 CreateAnswer (com.cloud.legacymodel.communication.answer.CreateAnswer)1 RebootAnswer (com.cloud.legacymodel.communication.answer.RebootAnswer)1 GetDomRVersionCommand (com.cloud.legacymodel.communication.command.GetDomRVersionCommand)1 NetworkUsageCommand (com.cloud.legacymodel.communication.command.NetworkUsageCommand)1 DomainRouterVO (com.cloud.vm.DomainRouterVO)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1