use of com.xensource.xenapi.Types.BadServerResponse in project cloudstack by apache.
the class NotAValidCommand method testOvsCreateTunnelCommandSuccess.
@Test
public void testOvsCreateTunnelCommandSuccess() {
final String bridge = "tunnel";
final Connection conn = Mockito.mock(Connection.class);
final Network network = Mockito.mock(Network.class);
final OvsCreateTunnelCommand createTunnel = new OvsCreateTunnelCommand("127.0.0.1", 1, 1l, 2l, 1l, "127.0.1.1", "net01", "cd84c713-f448-48c9-ba25-e6740d4a9003");
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
assertNotNull(wrapper);
when(citrixResourceBase.getConnection()).thenReturn(conn);
try {
when(citrixResourceBase.findOrCreateTunnelNetwork(conn, createTunnel.getNetworkName())).thenReturn(network);
when(network.getBridge(conn)).thenReturn(bridge);
when(citrixResourceBase.callHostPlugin(conn, "ovstunnel", "create_tunnel", "bridge", bridge, "remote_ip", createTunnel.getRemoteIp(), "key", createTunnel.getKey().toString(), "from", createTunnel.getFrom().toString(), "to", createTunnel.getTo().toString(), "cloudstack-network-id", createTunnel.getNetworkUuid())).thenReturn("SUCCESS:0");
} 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(createTunnel, citrixResourceBase);
verify(citrixResourceBase, times(1)).getConnection();
verify(citrixResourceBase, times(1)).configureTunnelNetwork(conn, createTunnel.getNetworkId(), createTunnel.getFrom(), createTunnel.getNetworkName());
assertTrue(answer.getResult());
}
use of com.xensource.xenapi.Types.BadServerResponse in project cloudstack by apache.
the class CitrixOvsSetTagAndFlowCommandWrapper method execute.
@Override
public Answer execute(final OvsSetTagAndFlowCommand 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);
/*
* If VM is domainRouter, this will try to set flow and tag on its
* none guest network nic. don't worry, it will fail silently at
* host plugin side
*/
final String result = citrixResourceBase.callHostPlugin(conn, "ovsgre", "ovs_set_tag_and_flow", "bridge", bridge, "vmName", command.getVmName(), "tag", command.getTag(), "vlans", command.getVlans(), "seqno", command.getSeqNo());
s_logger.debug("set flow for " + command.getVmName() + " " + result);
if (result != null && result.equalsIgnoreCase("SUCCESS")) {
return new OvsSetTagAndFlowAnswer(command, true, result);
} else {
return new OvsSetTagAndFlowAnswer(command, false, result);
}
} catch (final BadServerResponse e) {
s_logger.error("Failed to set tag and flow", e);
} catch (final XenAPIException e) {
s_logger.error("Failed to set tag and flow", e);
} catch (final XmlRpcException e) {
s_logger.error("Failed to set tag and flow", e);
}
return new OvsSetTagAndFlowAnswer(command, false, "EXCEPTION");
}
use of com.xensource.xenapi.Types.BadServerResponse in project cloudstack by apache.
the class XenServerStorageProcessor method deleteVolume.
@Override
public Answer deleteVolume(final DeleteCommand cmd) {
final DataTO volume = cmd.getData();
final Connection conn = hypervisorResource.getConnection();
String errorMsg = null;
try {
final VDI vdi = VDI.getByUuid(conn, volume.getPath());
for (VDI svdi : vdi.getSnapshots(conn)) {
deleteVDI(conn, svdi);
}
deleteVDI(conn, vdi);
return new Answer(null);
} catch (final BadServerResponse e) {
s_logger.debug("Failed to delete volume", e);
errorMsg = e.toString();
} catch (final XenAPIException e) {
s_logger.debug("Failed to delete volume", e);
errorMsg = e.toString();
} catch (final XmlRpcException e) {
s_logger.debug("Failed to delete volume", e);
errorMsg = e.toString();
}
return new Answer(null, false, errorMsg);
}
use of com.xensource.xenapi.Types.BadServerResponse in project cloudstack by apache.
the class XenServerConnectionPool method slaveLocalLoginWithPassword.
protected Session slaveLocalLoginWithPassword(Connection conn, String username, Queue<String> password) throws BadServerResponse, XenAPIException, XmlRpcException {
Session s = null;
boolean logged_in = false;
Exception ex = null;
while (!logged_in) {
try {
s = Session.slaveLocalLoginWithPassword(conn, username, password.peek());
logged_in = true;
} catch (BadServerResponse e) {
logged_in = false;
ex = e;
} catch (XenAPIException e) {
logged_in = false;
ex = e;
} catch (XmlRpcException e) {
logged_in = false;
ex = e;
}
if (logged_in && conn != null) {
break;
} else {
if (password.size() > 1) {
password.remove();
continue;
} else {
// the last password did not work leave it and flag error
if (ex instanceof BadServerResponse) {
throw (BadServerResponse) ex;
} else if (ex instanceof XmlRpcException) {
throw (XmlRpcException) ex;
} else if (ex instanceof Types.SessionAuthenticationFailed) {
throw (Types.SessionAuthenticationFailed) ex;
} else if (ex instanceof XenAPIException) {
throw (XenAPIException) ex;
}
break;
}
}
}
return s;
}
use of com.xensource.xenapi.Types.BadServerResponse in project cloudstack by apache.
the class XenServerConnectionPool method loginWithPassword.
protected Session loginWithPassword(Connection conn, String username, Queue<String> password, String version) throws BadServerResponse, XenAPIException, XmlRpcException {
Session s = null;
boolean logged_in = false;
Exception ex = null;
while (!logged_in) {
try {
s = Session.loginWithPassword(conn, username, password.peek(), APIVersion.latest().toString());
logged_in = true;
} catch (BadServerResponse e) {
logged_in = false;
ex = e;
} catch (XenAPIException e) {
logged_in = false;
ex = e;
} catch (XmlRpcException e) {
logged_in = false;
ex = e;
}
if (logged_in && conn != null) {
break;
} else {
if (password.size() > 1) {
password.remove();
continue;
} else {
// the last password did not work leave it and flag error
if (ex instanceof BadServerResponse) {
throw (BadServerResponse) ex;
} else if (ex instanceof XmlRpcException) {
throw (XmlRpcException) ex;
} else if (ex instanceof Types.SessionAuthenticationFailed) {
throw (Types.SessionAuthenticationFailed) ex;
} else if (ex instanceof XenAPIException) {
throw (XenAPIException) ex;
}
}
}
}
return s;
}
Aggregations