Search in sources :

Example 6 with BadServerResponse

use of com.xensource.xenapi.Types.BadServerResponse in project cloudstack by apache.

the class CitrixOvsDeleteFlowCommandWrapper method execute.

@Override
public Answer execute(final OvsDeleteFlowCommand command, final CitrixResourceBase citrixResourceBase) {
    citrixResourceBase.setIsOvs(true);
    final Connection conn = citrixResourceBase.getConnection();
    try {
        final Network nw = citrixResourceBase.setupvSwitchNetwork(conn);
        final String bridge = nw.getBridge(conn);
        final String result = citrixResourceBase.callHostPlugin(conn, "ovsgre", "ovs_delete_flow", "bridge", bridge, "vmName", command.getVmName());
        if (result.equalsIgnoreCase("SUCCESS")) {
            return new Answer(command, true, "success to delete flows for " + command.getVmName());
        } else {
            return new Answer(command, false, result);
        }
    } catch (final BadServerResponse e) {
        s_logger.error("Failed to delete flow", e);
    } catch (final XenAPIException e) {
        s_logger.error("Failed to delete flow", e);
    } catch (final XmlRpcException e) {
        s_logger.error("Failed to delete flow", e);
    }
    return new Answer(command, false, "failed to delete flow for " + command.getVmName());
}
Also used : Answer(com.cloud.agent.api.Answer) BadServerResponse(com.xensource.xenapi.Types.BadServerResponse) Network(com.xensource.xenapi.Network) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 7 with BadServerResponse

use of com.xensource.xenapi.Types.BadServerResponse in project cloudstack by apache.

the class NotAValidCommand method testOvsDeleteFlowCommandFailure.

@Test
public void testOvsDeleteFlowCommandFailure() {
    final String bridge = "gre";
    final Connection conn = Mockito.mock(Connection.class);
    final Network network = Mockito.mock(Network.class);
    final OvsDeleteFlowCommand deleteFlowCommand = new OvsDeleteFlowCommand("Test");
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    when(citrixResourceBase.getConnection()).thenReturn(conn);
    when(citrixResourceBase.setupvSwitchNetwork(conn)).thenReturn(network);
    try {
        when(network.getBridge(conn)).thenReturn(bridge);
        when(citrixResourceBase.callHostPlugin(conn, "ovsgre", "ovs_delete_flow", "bridge", bridge, "vmName", deleteFlowCommand.getVmName())).thenReturn("FAILED");
    } catch (final BadServerResponse e) {
        fail(e.getMessage());
    } catch (final XenAPIException e) {
        fail(e.getMessage());
    } catch (final XmlRpcException e) {
        fail(e.getMessage());
    }
    final Answer answer = wrapper.execute(deleteFlowCommand, citrixResourceBase);
    verify(citrixResourceBase, times(1)).getConnection();
    verify(citrixResourceBase, times(1)).setIsOvs(true);
    assertFalse(answer.getResult());
}
Also used : RebootAnswer(com.cloud.agent.api.RebootAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) BadServerResponse(com.xensource.xenapi.Types.BadServerResponse) Network(com.xensource.xenapi.Network) XsLocalNetwork(com.cloud.hypervisor.xenserver.resource.XsLocalNetwork) Connection(com.xensource.xenapi.Connection) OvsDeleteFlowCommand(com.cloud.agent.api.OvsDeleteFlowCommand) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 8 with BadServerResponse

use of com.xensource.xenapi.Types.BadServerResponse in project cloudstack by apache.

the class NotAValidCommand method testOvsVpcRoutingPolicyConfigCommand.

@Test
public void testOvsVpcRoutingPolicyConfigCommand() {
    final String bridge = "gre";
    final Connection conn = Mockito.mock(Connection.class);
    final Network network = Mockito.mock(Network.class);
    final OvsVpcRoutingPolicyConfigCommand.Acl[] acls = new OvsVpcRoutingPolicyConfigCommand.Acl[0];
    final OvsVpcRoutingPolicyConfigCommand.Tier[] tiers = new OvsVpcRoutingPolicyConfigCommand.Tier[0];
    final OvsVpcRoutingPolicyConfigCommand routingPolicy = new OvsVpcRoutingPolicyConfigCommand("v1", "10.0.0.1/24", acls, tiers);
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    when(citrixResourceBase.getConnection()).thenReturn(conn);
    try {
        when(citrixResourceBase.findOrCreateTunnelNetwork(conn, routingPolicy.getBridgeName())).thenReturn(network);
        when(network.getBridge(conn)).thenReturn(bridge);
        when(citrixResourceBase.callHostPlugin(conn, "ovstunnel", "configure_ovs_bridge_for_routing_policies", "bridge", bridge, "host-id", ((Long) routingPolicy.getHostId()).toString(), "config", routingPolicy.getVpcConfigInJson(), "seq-no", Long.toString(1))).thenReturn("SUCCESS");
    } catch (final BadServerResponse e) {
        fail(e.getMessage());
    } catch (final XenAPIException e) {
        fail(e.getMessage());
    } catch (final XmlRpcException e) {
        fail(e.getMessage());
    }
    final Answer answer = wrapper.execute(routingPolicy, citrixResourceBase);
    verify(citrixResourceBase, times(1)).getConnection();
    assertFalse(answer.getResult());
}
Also used : BadServerResponse(com.xensource.xenapi.Types.BadServerResponse) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) OvsVpcRoutingPolicyConfigCommand(com.cloud.agent.api.OvsVpcRoutingPolicyConfigCommand) RebootAnswer(com.cloud.agent.api.RebootAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) Network(com.xensource.xenapi.Network) XsLocalNetwork(com.cloud.hypervisor.xenserver.resource.XsLocalNetwork) XmlRpcException(org.apache.xmlrpc.XmlRpcException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 9 with BadServerResponse

use of com.xensource.xenapi.Types.BadServerResponse in project cloudstack by apache.

the class NotAValidCommand method testClusterVMMetaDataSyncCommand.

@Test
public void testClusterVMMetaDataSyncCommand() {
    final String uuid = "6172d8b7-ba10-4a70-93f9-ecaf41f51d53";
    final Connection conn = Mockito.mock(Connection.class);
    final XsHost xsHost = Mockito.mock(XsHost.class);
    final Pool pool = PowerMockito.mock(Pool.class);
    final Pool.Record poolr = Mockito.mock(Pool.Record.class);
    final Host.Record hostr = Mockito.mock(Host.Record.class);
    final Host master = Mockito.mock(Host.class);
    final ClusterVMMetaDataSyncCommand vmDataSync = new ClusterVMMetaDataSyncCommand(10, 1l);
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    when(citrixResourceBase.getConnection()).thenReturn(conn);
    try {
        when(citrixResourceBase.getHost()).thenReturn(xsHost);
        when(citrixResourceBase.getHost().getUuid()).thenReturn(uuid);
        PowerMockito.mockStatic(Pool.Record.class);
        when(pool.getRecord(conn)).thenReturn(poolr);
        poolr.master = master;
        when(poolr.master.getRecord(conn)).thenReturn(hostr);
        hostr.uuid = uuid;
    } catch (final BadServerResponse e) {
        fail(e.getMessage());
    } catch (final XenAPIException e) {
        fail(e.getMessage());
    } catch (final XmlRpcException e) {
        fail(e.getMessage());
    }
    final Answer answer = wrapper.execute(vmDataSync, citrixResourceBase);
    verify(citrixResourceBase, times(1)).getConnection();
    assertTrue(answer.getResult());
}
Also used : XsHost(com.cloud.hypervisor.xenserver.resource.XsHost) ClusterVMMetaDataSyncCommand(com.cloud.agent.api.ClusterVMMetaDataSyncCommand) BadServerResponse(com.xensource.xenapi.Types.BadServerResponse) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XsHost(com.cloud.hypervisor.xenserver.resource.XsHost) Host(com.xensource.xenapi.Host) RebootAnswer(com.cloud.agent.api.RebootAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) Pool(com.xensource.xenapi.Pool) XmlRpcException(org.apache.xmlrpc.XmlRpcException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 10 with BadServerResponse

use of com.xensource.xenapi.Types.BadServerResponse in project cloudstack by apache.

the class NotAValidCommand method testOvsSetTagAndFlowCommand.

@Test
public void testOvsSetTagAndFlowCommand() {
    final Network network = Mockito.mock(Network.class);
    final Connection conn = Mockito.mock(Connection.class);
    final OvsSetTagAndFlowCommand tagAndFlowCommand = new OvsSetTagAndFlowCommand("Test", "tag", "vlan://1", "123", 1l);
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    when(citrixResourceBase.getConnection()).thenReturn(conn);
    when(citrixResourceBase.setupvSwitchNetwork(conn)).thenReturn(network);
    try {
        when(network.getBridge(conn)).thenReturn("br0");
    } catch (final BadServerResponse e) {
        fail(e.getMessage());
    } catch (final XenAPIException e) {
        fail(e.getMessage());
    } catch (final XmlRpcException e) {
        fail(e.getMessage());
    }
    final Answer answer = wrapper.execute(tagAndFlowCommand, citrixResourceBase);
    verify(citrixResourceBase, times(1)).getConnection();
    verify(citrixResourceBase, times(1)).setupvSwitchNetwork(conn);
    verify(citrixResourceBase, times(1)).setIsOvs(true);
    assertFalse(answer.getResult());
}
Also used : OvsSetTagAndFlowCommand(com.cloud.agent.api.OvsSetTagAndFlowCommand) RebootAnswer(com.cloud.agent.api.RebootAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) BadServerResponse(com.xensource.xenapi.Types.BadServerResponse) Network(com.xensource.xenapi.Network) XsLocalNetwork(com.cloud.hypervisor.xenserver.resource.XsLocalNetwork) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

BadServerResponse (com.xensource.xenapi.Types.BadServerResponse)36 XenAPIException (com.xensource.xenapi.Types.XenAPIException)36 XmlRpcException (org.apache.xmlrpc.XmlRpcException)36 Connection (com.xensource.xenapi.Connection)25 Answer (com.cloud.agent.api.Answer)20 Network (com.xensource.xenapi.Network)14 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)14 Test (org.junit.Test)13 VDI (com.xensource.xenapi.VDI)12 RebootAnswer (com.cloud.agent.api.RebootAnswer)11 CreateAnswer (com.cloud.agent.api.storage.CreateAnswer)11 XsLocalNetwork (com.cloud.hypervisor.xenserver.resource.XsLocalNetwork)11 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)11 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)11 SR (com.xensource.xenapi.SR)8 FileNotFoundException (java.io.FileNotFoundException)6 IOException (java.io.IOException)6 KeyManagementException (java.security.KeyManagementException)6 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)6 XmlRpcClientException (org.apache.xmlrpc.client.XmlRpcClientException)6