Search in sources :

Example 71 with Answer

use of com.cloud.legacymodel.communication.answer.Answer in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testPvlanSetupCommandDhcpDelete.

@Test
public void testPvlanSetupCommandDhcpDelete() {
    final String op = "delete";
    final URI uri = URI.create("http://localhost");
    final String networkTag = "/105";
    final String dhcpName = "dhcp";
    final String dhcpMac = "00:00:00:00";
    final String dhcpIp = "127.0.0.1";
    final PvlanSetupCommand command = PvlanSetupCommand.createDhcpSetup(op, uri, networkTag, dhcpName, dhcpMac, dhcpIp);
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
    final String guestBridgeName = "br0";
    when(this.libvirtComputingResource.getGuestBridgeName()).thenReturn(guestBridgeName);
    final int timeout = 0;
    when(this.libvirtComputingResource.getScriptsTimeout()).thenReturn(timeout);
    final String ovsPvlanDhcpHostPath = "/pvlan";
    when(this.libvirtComputingResource.getOvsPvlanDhcpHostPath()).thenReturn(ovsPvlanDhcpHostPath);
    when(this.libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
    assertFalse(answer.getResult());
}
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) PvlanSetupCommand(com.cloud.legacymodel.communication.command.PvlanSetupCommand) URI(java.net.URI) LibvirtUtilitiesHelper(com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper) Test(org.junit.Test)

Example 72 with Answer

use of com.cloud.legacymodel.communication.answer.Answer in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testModifyStoragePoolCommandFailure.

@Test
public void testModifyStoragePoolCommandFailure() {
    final StoragePool pool = Mockito.mock(StoragePool.class);
    final ModifyStoragePoolCommand command = new ModifyStoragePoolCommand(true, pool);
    final KvmStoragePoolManager storagePoolMgr = Mockito.mock(KvmStoragePoolManager.class);
    when(this.libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
    when(storagePoolMgr.createStoragePool(command.getPool().getUuid(), command.getPool().getHost(), command.getPool().getPort(), command.getPool().getPath(), command.getPool().getUserInfo(), command.getPool().getType())).thenReturn(null);
    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(storagePoolMgr, times(1)).createStoragePool(command.getPool().getUuid(), command.getPool().getHost(), command.getPool().getPort(), command.getPool().getPath(), command.getPool().getUserInfo(), command.getPool().getType());
}
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) NfsStoragePool(com.cloud.agent.resource.kvm.ha.KvmHaBase.NfsStoragePool) KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) StoragePool(com.cloud.legacymodel.storage.StoragePool) KvmStoragePoolManager(com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager) ModifyStoragePoolCommand(com.cloud.legacymodel.communication.command.ModifyStoragePoolCommand) Test(org.junit.Test)

Example 73 with Answer

use of com.cloud.legacymodel.communication.answer.Answer 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 74 with Answer

use of com.cloud.legacymodel.communication.answer.Answer 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 75 with Answer

use of com.cloud.legacymodel.communication.answer.Answer in project cosmic by MissionCriticalCloud.

the class VirtualRoutingResource method execute.

private Answer execute(final AggregationControlCommand aggregationCommand) {
    assert aggregationCommand.getRouterAccessIp() != null;
    final String routerName = aggregationCommand.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
    assert routerName != null;
    final Action action = aggregationCommand.getAction();
    if (Action.Start.equals(action)) {
        assert (!this._vrAggregateCommandsSet.containsKey(routerName));
        this._vrAggregateCommandsSet.put(routerName, new LinkedBlockingQueue<>());
        return new Answer(aggregationCommand, true, "Command aggregation started");
    } else if (Action.Finish.equals(action)) {
        final Queue<NetworkElementCommand> queue = this._vrAggregateCommandsSet.get(routerName);
        try {
            for (final NetworkElementCommand command : queue) {
                final List<ConfigItem> cfg = generateCommandCfg(command);
                if (cfg == null) {
                    s_logger.warn("Unknown commands for VirtualRoutingResource, but continue: " + aggregationCommand.toString());
                    continue;
                }
                final Answer commandAnswer = applyConfig(command, cfg);
                if (!commandAnswer.getResult()) {
                    return new Answer(aggregationCommand, false, "Aggregated command failed to execute " + commandAnswer.getDetails());
                }
            }
            return new Answer(aggregationCommand, true, "Command aggregation finished");
        } finally {
            queue.clear();
            this._vrAggregateCommandsSet.remove(routerName);
        }
    }
    return new Answer(aggregationCommand, false, "Fail to recognize aggregation action " + action.toString());
}
Also used : GroupAnswer(com.cloud.legacymodel.communication.answer.GroupAnswer) CheckS2SVpnConnectionsAnswer(com.cloud.legacymodel.communication.answer.CheckS2SVpnConnectionsAnswer) CheckRouterAnswer(com.cloud.legacymodel.communication.answer.CheckRouterAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) GetDomRVersionAnswer(com.cloud.legacymodel.communication.answer.GetDomRVersionAnswer) Action(com.cloud.legacymodel.communication.command.AggregationControlCommand.Action) ArrayList(java.util.ArrayList) List(java.util.List) NetworkElementCommand(com.cloud.legacymodel.communication.command.NetworkElementCommand) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Queue(java.util.Queue)

Aggregations

Answer (com.cloud.legacymodel.communication.answer.Answer)342 Test (org.junit.Test)201 AttachAnswer (com.cloud.legacymodel.communication.answer.AttachAnswer)173 CheckRouterAnswer (com.cloud.legacymodel.communication.answer.CheckRouterAnswer)116 LibvirtRequestWrapper (com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper)110 RebootAnswer (com.cloud.legacymodel.communication.answer.RebootAnswer)63 LibvirtUtilitiesHelper (com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper)61 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)58 CreateAnswer (com.cloud.legacymodel.communication.answer.CreateAnswer)54 LibvirtException (org.libvirt.LibvirtException)53 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)53 KvmStoragePoolManager (com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager)48 Connection (com.xensource.xenapi.Connection)48 ArrayList (java.util.ArrayList)45 KvmStoragePool (com.cloud.agent.resource.kvm.storage.KvmStoragePool)39 StoragePool (com.cloud.legacymodel.storage.StoragePool)38 Connect (org.libvirt.Connect)38 NfsStoragePool (com.cloud.agent.resource.kvm.ha.KvmHaBase.NfsStoragePool)29 CopyCmdAnswer (com.cloud.legacymodel.communication.answer.CopyCmdAnswer)29 EndPoint (com.cloud.engine.subsystem.api.storage.EndPoint)27