Search in sources :

Example 6 with PvlanSetupCommand

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

the class NotAValidCommand method testPvlanSetupCommandDhcpFailure.

@Test
public void testPvlanSetupCommandDhcpFailure() {
    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.createDhcpSetup("add", URI.create("http://127.0.0.1"), "tag", "dhcp", "0:0:0:0:0:0", "127.0.0.1");
    final String primaryPvlan = lanSetup.getPrimary();
    final String isolatedPvlan = lanSetup.getIsolated();
    final String op = lanSetup.getOp();
    final String dhcpName = lanSetup.getDhcpName();
    final String dhcpMac = lanSetup.getDhcpMac();
    final String dhcpIp = lanSetup.getDhcpIp();
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    when(this.citrixResourceBase.getConnection()).thenReturn(conn);
    try {
        when(this.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(this.citrixResourceBase.callHostPlugin(conn, "ovs-pvlan", "setup-pvlan-dhcp", "op", op, "nw-label", label, "primary-pvlan", primaryPvlan, "isolated-pvlan", isolatedPvlan, "dhcp-name", dhcpName, "dhcp-ip", dhcpIp, "dhcp-mac", dhcpMac)).thenReturn("false");
    final Answer answer = wrapper.execute(lanSetup, this.citrixResourceBase);
    verify(this.citrixResourceBase, times(1)).getConnection();
    assertFalse(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) 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.legacymodel.communication.command.PvlanSetupCommand) XmlRpcException(org.apache.xmlrpc.XmlRpcException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 7 with PvlanSetupCommand

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

the class NotAValidCommand method testPvlanSetupCommandVmSuccess.

@Test
public void testPvlanSetupCommandVmSuccess() {
    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(this.citrixResourceBase.getConnection()).thenReturn(conn);
    try {
        when(this.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(this.citrixResourceBase.callHostPlugin(conn, "ovs-pvlan", "setup-pvlan-vm", "op", op, "nw-label", label, "primary-pvlan", primaryPvlan, "isolated-pvlan", isolatedPvlan, "vm-mac", vmMac)).thenReturn("true");
    final Answer answer = wrapper.execute(lanSetup, 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) 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.legacymodel.communication.command.PvlanSetupCommand) XmlRpcException(org.apache.xmlrpc.XmlRpcException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 8 with PvlanSetupCommand

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

the class LibvirtComputingResourceTest method testPvlanSetupCommandDhcpAdd.

@Test
public void testPvlanSetupCommandDhcpAdd() {
    final String op = "add";
    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 Connect conn = Mockito.mock(Connect.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 List<InterfaceDef> ifaces = new ArrayList<>();
    final InterfaceDef nic = Mockito.mock(InterfaceDef.class);
    ifaces.add(nic);
    try {
        when(libvirtUtilitiesHelper.getConnectionByVmName(dhcpName)).thenReturn(conn);
        when(this.libvirtComputingResource.getInterfaces(conn, dhcpName)).thenReturn(ifaces);
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
    assertFalse(answer.getResult());
    verify(this.libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
    try {
        verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(dhcpName);
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
}
Also used : InterfaceDef(com.cloud.agent.resource.kvm.xml.LibvirtVmDef.InterfaceDef) 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) ArrayList(java.util.ArrayList) PvlanSetupCommand(com.cloud.legacymodel.communication.command.PvlanSetupCommand) URI(java.net.URI) LibvirtUtilitiesHelper(com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper) Test(org.junit.Test)

Example 9 with PvlanSetupCommand

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

the class NotAValidCommand method testPvlanSetupCommandDhcpSuccess.

@Test
public void testPvlanSetupCommandDhcpSuccess() {
    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.createDhcpSetup("add", URI.create("http://127.0.0.1"), "tag", "dhcp", "0:0:0:0:0:0", "127.0.0.1");
    final String primaryPvlan = lanSetup.getPrimary();
    final String isolatedPvlan = lanSetup.getIsolated();
    final String op = lanSetup.getOp();
    final String dhcpName = lanSetup.getDhcpName();
    final String dhcpMac = lanSetup.getDhcpMac();
    final String dhcpIp = lanSetup.getDhcpIp();
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    when(this.citrixResourceBase.getConnection()).thenReturn(conn);
    try {
        when(this.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(this.citrixResourceBase.callHostPlugin(conn, "ovs-pvlan", "setup-pvlan-dhcp", "op", op, "nw-label", label, "primary-pvlan", primaryPvlan, "isolated-pvlan", isolatedPvlan, "dhcp-name", dhcpName, "dhcp-ip", dhcpIp, "dhcp-mac", dhcpMac)).thenReturn("true");
    final Answer answer = wrapper.execute(lanSetup, 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) 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.legacymodel.communication.command.PvlanSetupCommand) XmlRpcException(org.apache.xmlrpc.XmlRpcException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 10 with PvlanSetupCommand

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

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(this.citrixResourceBase.getConnection()).thenReturn(conn);
    try {
        when(this.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(this.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, this.citrixResourceBase);
    verify(this.citrixResourceBase, times(1)).getConnection();
    assertFalse(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) 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.legacymodel.communication.command.PvlanSetupCommand) XmlRpcException(org.apache.xmlrpc.XmlRpcException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

PvlanSetupCommand (com.cloud.legacymodel.communication.command.PvlanSetupCommand)10 Answer (com.cloud.legacymodel.communication.answer.Answer)9 AttachAnswer (com.cloud.legacymodel.communication.answer.AttachAnswer)8 Test (org.junit.Test)8 LibvirtRequestWrapper (com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper)4 XsLocalNetwork (com.cloud.hypervisor.xenserver.resource.XsLocalNetwork)4 CheckRouterAnswer (com.cloud.legacymodel.communication.answer.CheckRouterAnswer)4 CreateAnswer (com.cloud.legacymodel.communication.answer.CreateAnswer)4 RebootAnswer (com.cloud.legacymodel.communication.answer.RebootAnswer)4 Connection (com.xensource.xenapi.Connection)4 Network (com.xensource.xenapi.Network)4 XenAPIException (com.xensource.xenapi.Types.XenAPIException)4 URI (java.net.URI)4 XmlRpcException (org.apache.xmlrpc.XmlRpcException)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 LibvirtUtilitiesHelper (com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper)3 LibvirtException (org.libvirt.LibvirtException)2 Commands (com.cloud.agent.manager.Commands)1 InterfaceDef (com.cloud.agent.resource.kvm.xml.LibvirtVmDef.InterfaceDef)1 GetVmDiskStatsAnswer (com.cloud.legacymodel.communication.answer.GetVmDiskStatsAnswer)1