use of com.xensource.xenapi.Connection 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.xensource.xenapi.Connection in project cloudstack by apache.
the class NotAValidCommand method testMaintainCommand.
@Test
public void testMaintainCommand() {
// This test needs further work.
final String uuid = "befc4dcd-f5c6-4015-8791-3c18622b7c7f";
final Connection conn = Mockito.mock(Connection.class);
final XsHost xsHost = Mockito.mock(XsHost.class);
final XmlRpcClient client = Mockito.mock(XmlRpcClient.class);
// final Host.Record hr = PowerMockito.mock(Host.Record.class);
// final Host host = PowerMockito.mock(Host.class);
final MaintainCommand maintainCommand = new MaintainCommand();
final Map<String, Object> map = new Hashtable<String, Object>();
map.put("Value", "Xen");
final Map<String, Object> spiedMap = spy(map);
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
assertNotNull(wrapper);
when(citrixResourceBase.getConnection()).thenReturn(conn);
when(citrixResourceBase.getHost()).thenReturn(xsHost);
when(xsHost.getUuid()).thenReturn(uuid);
when(conn.getSessionReference()).thenReturn("befc4dcd");
try {
final Object[] params = { Marshalling.toXMLRPC("befc4dcd"), Marshalling.toXMLRPC(uuid) };
when(client.execute("host.get_by_uuid", new Object[] { "befc4dcd", uuid })).thenReturn(spiedMap);
PowerMockito.when(conn, "dispatch", "host.get_by_uuid", params).thenReturn(spiedMap);
} catch (final Exception e) {
fail(e.getMessage());
}
// try {
// PowerMockito.mockStatic(Host.class);
// //BDDMockito.given(Host.getByUuid(conn,
// xsHost.getUuid())).willReturn(host);
// PowerMockito.when(Host.getByUuid(conn,
// xsHost.getUuid())).thenReturn(host);
// PowerMockito.verifyStatic(times(1));
// } catch (final BadServerResponse e) {
// fail(e.getMessage());
// } catch (final XenAPIException e) {
// fail(e.getMessage());
// } catch (final XmlRpcException e) {
// fail(e.getMessage());
// }
//
// PowerMockito.mockStatic(Types.class);
// PowerMockito.when(Types.toHostRecord(spiedMap)).thenReturn(hr);
// PowerMockito.verifyStatic(times(1));
//
// try {
// PowerMockito.mockStatic(Host.Record.class);
// when(host.getRecord(conn)).thenReturn(hr);
// verify(host, times(1)).getRecord(conn);
// } 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(maintainCommand, citrixResourceBase);
assertFalse(answer.getResult());
}
use of com.xensource.xenapi.Connection in project cloudstack by apache.
the class NotAValidCommand method testOvsFetchInterfaceCommand.
@Test
public void testOvsFetchInterfaceCommand() {
final String label = "[abc]";
final String uuid = "befc4dcd-f5c6-4015-8791-3c18622b7c7f";
final Connection conn = Mockito.mock(Connection.class);
final XsLocalNetwork network = Mockito.mock(XsLocalNetwork.class);
final Network network2 = Mockito.mock(Network.class);
final PIF pif = Mockito.mock(PIF.class);
final PIF.Record pifRec = Mockito.mock(PIF.Record.class);
final XsHost xsHost = Mockito.mock(XsHost.class);
final OvsFetchInterfaceCommand fetchInterCommand = new OvsFetchInterfaceCommand(label);
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
assertNotNull(wrapper);
when(citrixResourceBase.isXcp()).thenReturn(true);
when(citrixResourceBase.getLabel()).thenReturn("[abc]");
when(citrixResourceBase.getConnection()).thenReturn(conn);
when(citrixResourceBase.getHost()).thenReturn(xsHost);
try {
when(network.getNetwork()).thenReturn(network2);
when(network.getPif(conn)).thenReturn(pif);
when(network.getPif(conn)).thenReturn(pif);
when(pif.getRecord(conn)).thenReturn(pifRec);
when(network.getNetwork().getUuid(conn)).thenReturn(uuid);
when(citrixResourceBase.getNetworkByName(conn, label)).thenReturn(network);
} catch (final XenAPIException e) {
fail(e.getMessage());
} catch (final XmlRpcException e) {
fail(e.getMessage());
}
final Answer answer = wrapper.execute(fetchInterCommand, citrixResourceBase);
verify(citrixResourceBase, times(1)).getConnection();
assertTrue(answer.getResult());
}
use of com.xensource.xenapi.Connection in project cloudstack by apache.
the class NotAValidCommand method testCleanupNetworkRulesCmdLTZ.
@Test
public void testCleanupNetworkRulesCmdLTZ() {
final Connection conn = Mockito.mock(Connection.class);
final XsHost xsHost = Mockito.mock(XsHost.class);
final CleanupNetworkRulesCmd cleanupNets = new CleanupNetworkRulesCmd(20);
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
assertNotNull(wrapper);
when(citrixResourceBase.canBridgeFirewall()).thenReturn(true);
when(citrixResourceBase.getConnection()).thenReturn(conn);
when(citrixResourceBase.getHost()).thenReturn(xsHost);
when(citrixResourceBase.getVMInstanceName()).thenReturn("VM");
when(citrixResourceBase.callHostPlugin(conn, "vmops", "cleanup_rules", "instance", citrixResourceBase.getVMInstanceName())).thenReturn("-1");
final Answer answer = wrapper.execute(cleanupNets, citrixResourceBase);
verify(citrixResourceBase, times(1)).getConnection();
verify(xsHost, times(1)).getIp();
assertFalse(answer.getResult());
assertEquals(answer.getDetails(), "-1");
}
use of com.xensource.xenapi.Connection in project cloudstack by apache.
the class NotAValidCommand method testSecurityGroupRulesCommand.
@Test
public void testSecurityGroupRulesCommand() {
final Connection conn = Mockito.mock(Connection.class);
final XsHost xsHost = Mockito.mock(XsHost.class);
final String guestIp = "127.0.0.1";
final String guestIp6 = "2001:db8::cad:40ff:fefd:75c4";
final String guestMac = "00:00:00:00";
final String vmName = "Test";
final Long vmId = 1l;
final String signature = "signature";
final Long seqNum = 1l;
final IpPortAndProto[] ingressRuleSet = new IpPortAndProto[] { Mockito.mock(IpPortAndProto.class) };
final IpPortAndProto[] egressRuleSet = new IpPortAndProto[] { Mockito.mock(IpPortAndProto.class) };
final List<String> secIps = new Vector<String>();
final SecurityGroupRulesCmd sshCommand = new SecurityGroupRulesCmd(guestIp, guestIp6, guestMac, vmName, vmId, signature, seqNum, ingressRuleSet, egressRuleSet, secIps);
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
assertNotNull(wrapper);
when(citrixResourceBase.getConnection()).thenReturn(conn);
when(citrixResourceBase.getHost()).thenReturn(xsHost);
final Answer answer = wrapper.execute(sshCommand, citrixResourceBase);
verify(citrixResourceBase, times(1)).getConnection();
assertFalse(answer.getResult());
}
Aggregations