Search in sources :

Example 1 with GetVmIpAddressCommand

use of com.cloud.agent.api.GetVmIpAddressCommand in project cloudstack by apache.

the class NotAValidCommand method testGetVmIpAddressCommand.

@Test
public void testGetVmIpAddressCommand() throws XenAPIException, XmlRpcException {
    final Connection conn = Mockito.mock(Connection.class);
    final VM vm = Mockito.mock(VM.class);
    final VMGuestMetrics mtr = Mockito.mock(VMGuestMetrics.class);
    final VMGuestMetrics.Record rec = Mockito.mock(VMGuestMetrics.Record.class);
    final Map<String, String> vmIpsMap = new HashMap<>();
    vmIpsMap.put("Test", "127.0.0.1");
    rec.networks = vmIpsMap;
    final GetVmIpAddressCommand getVmIpAddrCmd = new GetVmIpAddressCommand("Test", "127.0.0.1/24", false);
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    when(citrixResourceBase.getConnection()).thenReturn(conn);
    when(citrixResourceBase.getVM(conn, getVmIpAddrCmd.getVmName())).thenReturn(vm);
    when(vm.getGuestMetrics(conn)).thenReturn(mtr);
    when(mtr.getRecord(conn)).thenReturn(rec);
    final Answer answer = wrapper.execute(getVmIpAddrCmd, citrixResourceBase);
    verify(citrixResourceBase, times(1)).getConnection();
    assertTrue(answer.getResult());
}
Also used : RebootAnswer(com.cloud.agent.api.RebootAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) VMGuestMetrics(com.xensource.xenapi.VMGuestMetrics) HashMap(java.util.HashMap) GetVmIpAddressCommand(com.cloud.agent.api.GetVmIpAddressCommand) VM(com.xensource.xenapi.VM) Connection(com.xensource.xenapi.Connection) Test(org.junit.Test)

Aggregations

Answer (com.cloud.agent.api.Answer)1 GetVmIpAddressCommand (com.cloud.agent.api.GetVmIpAddressCommand)1 RebootAnswer (com.cloud.agent.api.RebootAnswer)1 CreateAnswer (com.cloud.agent.api.storage.CreateAnswer)1 Connection (com.xensource.xenapi.Connection)1 VM (com.xensource.xenapi.VM)1 VMGuestMetrics (com.xensource.xenapi.VMGuestMetrics)1 HashMap (java.util.HashMap)1 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)1 Test (org.junit.Test)1