use of com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResourceTest method testStopCommandCheckException1.
@Test
public void testStopCommandCheckException1() {
final Connect conn = Mockito.mock(Connect.class);
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
final Domain vm = Mockito.mock(Domain.class);
final DomainInfo info = Mockito.mock(DomainInfo.class);
final DomainState state = DomainInfo.DomainState.VIR_DOMAIN_RUNNING;
info.state = state;
final String vmName = "Test";
final StopCommand command = new StopCommand(vmName, false, true);
when(this.libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(vmName)).thenThrow(LibvirtException.class);
when(conn.domainLookupByName(command.getVmName())).thenReturn(vm);
when(vm.getInfo()).thenReturn(info);
} catch (final LibvirtException e) {
fail(e.getMessage());
}
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
assertFalse(answer.getResult());
verify(this.libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(2)).getConnectionByVmName(vmName);
} catch (final LibvirtException e) {
fail(e.getMessage());
}
}
use of com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResourceTest method testCheckOnHostCommand.
@Test
public void testCheckOnHostCommand() {
final Host host = Mockito.mock(Host.class);
final CheckOnHostCommand command = new CheckOnHostCommand(host);
final KvmHaMonitor monitor = Mockito.mock(KvmHaMonitor.class);
when(this.libvirtComputingResource.getMonitor()).thenReturn(monitor);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
assertTrue(answer.getResult());
verify(this.libvirtComputingResource, times(1)).getMonitor();
}
use of com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResourceTest method testRebootRouterCommand.
@Test
public void testRebootRouterCommand() {
final VirtualRoutingResource routingResource = Mockito.mock(VirtualRoutingResource.class);
final Connect conn = Mockito.mock(Connect.class);
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
final String vmName = "Test";
final RebootRouterCommand command = new RebootRouterCommand(vmName, "127.0.0.1");
when(this.libvirtComputingResource.getVirtRouterResource()).thenReturn(routingResource);
when(this.libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(vmName)).thenReturn(conn);
} catch (final LibvirtException e) {
fail(e.getMessage());
}
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
assertFalse(answer.getResult());
verify(this.libvirtComputingResource, times(1)).getVirtRouterResource();
verify(this.libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(vmName);
} catch (final LibvirtException e) {
fail(e.getMessage());
}
}
use of com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResourceTest method testNetworkUsageCommandVpcNoOption.
@Test
public void testNetworkUsageCommandVpcNoOption() {
final String privateIP = "127.0.0.1";
final String domRName = "domR";
final boolean forVpc = true;
final String gatewayIP = "127.0.0.1";
final NetworkUsageCommand command = new NetworkUsageCommand(privateIP, domRName, null, forVpc, gatewayIP);
this.libvirtComputingResource.getNetworkStats(command.getPrivateIP());
when(this.libvirtComputingResource.configureVpcNetworkUsage(command.getPrivateIP(), command.getGatewayIP(), command.getOption(), command.getVpcCIDR())).thenReturn("FAILURE");
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
assertTrue(answer.getResult());
verify(this.libvirtComputingResource, times(1)).configureVpcNetworkUsage(command.getPrivateIP(), command.getGatewayIP(), command.getOption(), command.getVpcCIDR());
}
use of com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResourceTest method testCheckHealthCommand.
@Test
public void testCheckHealthCommand() {
final CheckHealthCommand command = new CheckHealthCommand();
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
assertTrue(answer.getResult());
}
Aggregations