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());
}
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());
}
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);
}
}
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());
}
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());
}
Aggregations