Search in sources :

Example 11 with GetHostStatsCommand

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

the class LibvirtComputingResourceTest method testGetHostStatsCommand.

@Test
public void testGetHostStatsCommand() {
    // A bit difficult to test due to the logger being passed and the parser itself relying on the connection.
    // Have to spend some more time afterwards in order to refactor the wrapper itself.
    final CPUStat cpuStat = Mockito.mock(CPUStat.class);
    final MemStat memStat = Mockito.mock(MemStat.class);
    final String uuid = "e8d6b4d0-bc6d-4613-b8bb-cb9e0600f3c6";
    final GetHostStatsCommand command = new GetHostStatsCommand(uuid, "summer", 1l);
    when(libvirtComputingResource.getCPUStat()).thenReturn(cpuStat);
    when(libvirtComputingResource.getMemStat()).thenReturn(memStat);
    when(libvirtComputingResource.getNicStats(Mockito.anyString())).thenReturn(new Pair<Double, Double>(1.0d, 1.0d));
    when(cpuStat.getCpuUsedPercent()).thenReturn(0.5d);
    when(memStat.getAvailable()).thenReturn(1500.5d);
    when(memStat.getTotal()).thenReturn(15000d);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, libvirtComputingResource);
    assertTrue(answer.getResult());
    verify(libvirtComputingResource, times(1)).getCPUStat();
    verify(libvirtComputingResource, times(1)).getMemStat();
    verify(cpuStat, times(1)).getCpuUsedPercent();
    verify(memStat, times(1)).getAvailable();
    verify(memStat, times(1)).getTotal();
}
Also used : AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) LibvirtRequestWrapper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper) CPUStat(org.apache.cloudstack.utils.linux.CPUStat) MemStat(org.apache.cloudstack.utils.linux.MemStat) GetHostStatsCommand(com.cloud.agent.api.GetHostStatsCommand) Test(org.junit.Test)

Aggregations

GetHostStatsCommand (com.cloud.agent.api.GetHostStatsCommand)11 Answer (com.cloud.agent.api.Answer)9 Test (org.junit.Test)5 AttachIsoCommand (com.cloud.agent.api.AttachIsoCommand)3 BackupSnapshotCommand (com.cloud.agent.api.BackupSnapshotCommand)3 CheckHealthCommand (com.cloud.agent.api.CheckHealthCommand)3 CheckNetworkCommand (com.cloud.agent.api.CheckNetworkCommand)3 CreatePrivateTemplateFromSnapshotCommand (com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand)3 CreatePrivateTemplateFromVolumeCommand (com.cloud.agent.api.CreatePrivateTemplateFromVolumeCommand)3 CreateStoragePoolCommand (com.cloud.agent.api.CreateStoragePoolCommand)3 CreateVolumeFromSnapshotCommand (com.cloud.agent.api.CreateVolumeFromSnapshotCommand)3 DeleteStoragePoolCommand (com.cloud.agent.api.DeleteStoragePoolCommand)3 GetHostStatsAnswer (com.cloud.agent.api.GetHostStatsAnswer)3 GetStorageStatsCommand (com.cloud.agent.api.GetStorageStatsCommand)3 GetVmStatsCommand (com.cloud.agent.api.GetVmStatsCommand)3 GetVncPortCommand (com.cloud.agent.api.GetVncPortCommand)3 MaintainCommand (com.cloud.agent.api.MaintainCommand)3 ManageSnapshotCommand (com.cloud.agent.api.ManageSnapshotCommand)3 MigrateCommand (com.cloud.agent.api.MigrateCommand)3 ModifyStoragePoolCommand (com.cloud.agent.api.ModifyStoragePoolCommand)3