use of com.cloud.agent.api.PvlanSetupCommand in project cloudstack by apache.
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(libvirtComputingResource.getGuestBridgeName()).thenReturn(guestBridgeName);
when(libvirtComputingResource.getTimeout()).thenReturn(Duration.ZERO);
final String ovsPvlanDhcpHostPath = "/pvlan";
when(libvirtComputingResource.getOvsPvlanDhcpHostPath()).thenReturn(ovsPvlanDhcpHostPath);
when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
final List<InterfaceDef> ifaces = new ArrayList<InterfaceDef>();
final InterfaceDef nic = Mockito.mock(InterfaceDef.class);
ifaces.add(nic);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(dhcpName)).thenReturn(conn);
when(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, libvirtComputingResource);
assertFalse(answer.getResult());
verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(dhcpName);
} catch (final LibvirtException e) {
fail(e.getMessage());
}
}
use of com.cloud.agent.api.PvlanSetupCommand in project cloudstack by apache.
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(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-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, citrixResourceBase);
verify(citrixResourceBase, times(1)).getConnection();
assertFalse(answer.getResult());
}
use of com.cloud.agent.api.PvlanSetupCommand 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());
}
use of com.cloud.agent.api.PvlanSetupCommand in project cloudstack by apache.
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(libvirtComputingResource.getGuestBridgeName()).thenReturn(guestBridgeName);
when(libvirtComputingResource.getTimeout()).thenReturn(Duration.ZERO);
final String ovsPvlanDhcpHostPath = "/pvlan";
when(libvirtComputingResource.getOvsPvlanDhcpHostPath()).thenReturn(ovsPvlanDhcpHostPath);
when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, libvirtComputingResource);
assertFalse(answer.getResult());
}
use of com.cloud.agent.api.PvlanSetupCommand in project cloudstack by apache.
the class UserVmManagerImpl method setupVmForPvlan.
@Override
public boolean setupVmForPvlan(boolean add, Long hostId, NicProfile nic) {
if (!nic.getBroadCastUri().getScheme().equals("pvlan")) {
return false;
}
String op = "add";
if (!add) {
// "delete" would remove all the rules(if using ovs) related to this vm
op = "delete";
}
Network network = _networkDao.findById(nic.getNetworkId());
Host host = _hostDao.findById(hostId);
String networkTag = _networkModel.getNetworkTag(host.getHypervisorType(), network);
PvlanSetupCommand cmd = PvlanSetupCommand.createVmSetup(op, nic.getBroadCastUri(), networkTag, nic.getMacAddress());
Answer answer = null;
try {
answer = _agentMgr.send(hostId, cmd);
} catch (OperationTimedoutException e) {
s_logger.warn("Timed Out", e);
return false;
} catch (AgentUnavailableException e) {
s_logger.warn("Agent Unavailable ", e);
return false;
}
boolean result = true;
if (answer == null || !answer.getResult()) {
result = false;
}
return result;
}
Aggregations