Search in sources :

Example 56 with Connection

use of com.xensource.xenapi.Connection 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)

Example 57 with Connection

use of com.xensource.xenapi.Connection in project cloudstack by apache.

the class NotAValidCommand method testPvlanSetupCommandVmFailure.

@Test
public void testPvlanSetupCommandVmFailure() {
    final String label = "net";
    final Connection conn = Mockito.mock(Connection.class);
    final XsLocalNetwork network = Mockito.mock(XsLocalNetwork.class);
    final Network network2 = Mockito.mock(Network.class);
    final PvlanSetupCommand lanSetup = PvlanSetupCommand.createVmSetup("add", URI.create("http://127.0.0.1"), "tag", "0:0:0:0:0:0");
    final String primaryPvlan = lanSetup.getPrimary();
    final String isolatedPvlan = lanSetup.getIsolated();
    final String op = lanSetup.getOp();
    final String vmMac = lanSetup.getVmMac();
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    when(citrixResourceBase.getConnection()).thenReturn(conn);
    try {
        when(citrixResourceBase.getNativeNetworkForTraffic(conn, TrafficType.Guest, "tag")).thenReturn(network);
        when(network.getNetwork()).thenReturn(network2);
        when(network2.getNameLabel(conn)).thenReturn(label);
    } catch (final XenAPIException e) {
        fail(e.getMessage());
    } catch (final XmlRpcException e) {
        fail(e.getMessage());
    }
    when(citrixResourceBase.callHostPlugin(conn, "ovs-pvlan", "setup-pvlan-vm", "op", op, "nw-label", label, "primary-pvlan", primaryPvlan, "isolated-pvlan", isolatedPvlan, "vm-mac", vmMac)).thenReturn("false");
    final Answer answer = wrapper.execute(lanSetup, citrixResourceBase);
    verify(citrixResourceBase, times(1)).getConnection();
    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) XsLocalNetwork(com.cloud.hypervisor.xenserver.resource.XsLocalNetwork) Network(com.xensource.xenapi.Network) XsLocalNetwork(com.cloud.hypervisor.xenserver.resource.XsLocalNetwork) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) PvlanSetupCommand(com.cloud.agent.api.PvlanSetupCommand) XmlRpcException(org.apache.xmlrpc.XmlRpcException) Test(org.junit.Test)

Example 58 with Connection

use of com.xensource.xenapi.Connection in project cloudstack by apache.

the class CitrixResizeVolumeCommandWrapper method execute.

@Override
public Answer execute(final ResizeVolumeCommand command, final CitrixResourceBase citrixResourceBase) {
    Connection conn = citrixResourceBase.getConnection();
    String volId = command.getPath();
    long newSize = command.getNewSize();
    try {
        if (command.getCurrentSize() >= newSize) {
            s_logger.info("No need to resize volume: " + volId + ", current size " + command.getCurrentSize() + " is same as  new size " + newSize);
            return new ResizeVolumeAnswer(command, true, "success", newSize);
        }
        if (command.isManaged()) {
            resizeSr(conn, command);
        }
        VDI vdi = citrixResourceBase.getVDIbyUuid(conn, volId);
        vdi.resize(conn, newSize);
        return new ResizeVolumeAnswer(command, true, "success", newSize);
    } catch (Exception ex) {
        s_logger.warn("Unable to resize volume", ex);
        String error = "Failed to resize volume: " + ex;
        return new ResizeVolumeAnswer(command, false, error);
    }
}
Also used : Connection(com.xensource.xenapi.Connection) ResizeVolumeAnswer(com.cloud.agent.api.storage.ResizeVolumeAnswer) VDI(com.xensource.xenapi.VDI) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 59 with Connection

use of com.xensource.xenapi.Connection in project cloudstack by apache.

the class NotAValidCommand method testOvsDestroyBridgeCommand.

@Test
public void testOvsDestroyBridgeCommand() {
    final Connection conn = Mockito.mock(Connection.class);
    final Network network = Mockito.mock(Network.class);
    final OvsDestroyBridgeCommand destroyBridge = new OvsDestroyBridgeCommand(1l, "bridge", 1l);
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    when(citrixResourceBase.getConnection()).thenReturn(conn);
    when(citrixResourceBase.findOrCreateTunnelNetwork(conn, destroyBridge.getBridgeName())).thenReturn(network);
    final Answer answer = wrapper.execute(destroyBridge, citrixResourceBase);
    verify(citrixResourceBase, times(1)).getConnection();
    try {
        verify(citrixResourceBase, times(1)).cleanUpTmpDomVif(conn, network);
    } catch (final XenAPIException e) {
        fail(e.getMessage());
    } catch (final XmlRpcException e) {
        fail(e.getMessage());
    }
    verify(citrixResourceBase, times(1)).destroyTunnelNetwork(conn, network, destroyBridge.getHostId());
    assertTrue(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) Network(com.xensource.xenapi.Network) XsLocalNetwork(com.cloud.hypervisor.xenserver.resource.XsLocalNetwork) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) OvsDestroyBridgeCommand(com.cloud.agent.api.OvsDestroyBridgeCommand) XmlRpcException(org.apache.xmlrpc.XmlRpcException) Test(org.junit.Test)

Example 60 with Connection

use of com.xensource.xenapi.Connection in project cloudstack by apache.

the class NotAValidCommand method testNetworkRulesSystemVmCommandNonUser.

@Test
public void testNetworkRulesSystemVmCommandNonUser() {
    final Connection conn = Mockito.mock(Connection.class);
    final NetworkRulesSystemVmCommand netRules = new NetworkRulesSystemVmCommand("Test", VirtualMachine.Type.DomainRouter);
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    when(citrixResourceBase.getConnection()).thenReturn(conn);
    when(citrixResourceBase.callHostPlugin(conn, "vmops", "default_network_rules_systemvm", "vmName", netRules.getVmName())).thenReturn("true");
    final Answer answer = wrapper.execute(netRules, citrixResourceBase);
    verify(citrixResourceBase, times(1)).getConnection();
    assertTrue(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) Connection(com.xensource.xenapi.Connection) NetworkRulesSystemVmCommand(com.cloud.agent.api.NetworkRulesSystemVmCommand) Test(org.junit.Test)

Aggregations

Connection (com.xensource.xenapi.Connection)165 XenAPIException (com.xensource.xenapi.Types.XenAPIException)88 XmlRpcException (org.apache.xmlrpc.XmlRpcException)86 Answer (com.cloud.agent.api.Answer)79 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)58 Test (org.junit.Test)53 VDI (com.xensource.xenapi.VDI)47 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)46 SR (com.xensource.xenapi.SR)42 InternalErrorException (com.cloud.exception.InternalErrorException)39 RebootAnswer (com.cloud.agent.api.RebootAnswer)38 CreateAnswer (com.cloud.agent.api.storage.CreateAnswer)38 Network (com.xensource.xenapi.Network)35 VM (com.xensource.xenapi.VM)32 XsLocalNetwork (com.cloud.hypervisor.xenserver.resource.XsLocalNetwork)23 HashMap (java.util.HashMap)23 CopyCmdAnswer (org.apache.cloudstack.storage.command.CopyCmdAnswer)23 BadServerResponse (com.xensource.xenapi.Types.BadServerResponse)20 Host (com.xensource.xenapi.Host)19 URI (java.net.URI)19