use of com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper in project cloudstack by apache.
the class LibvirtComputingResourceTest method testBackupSnapshotCommandLibvirtException.
@SuppressWarnings("unchecked")
@Test
public void testBackupSnapshotCommandLibvirtException() {
//Simple test used to make sure the flow (LibvirtComputingResource => Request => CommandWrapper) is working.
//The code is way to big and complex. Will finish the refactor and come back to this to add more cases.
final StoragePool pool = Mockito.mock(StoragePool.class);
;
final String secondaryStorageUrl = "nfs:/127.0.0.1/storage/secondary";
final long accountId = 1l;
final String volumePath = "/123/vol";
final String vmName = "Test";
final int wait = 0;
final long snapshotId = 1l;
final String snapshotName = "snap";
final Long dcId = 1l;
final Long volumeId = 1l;
final Long secHostId = 1l;
final String snapshotUuid = "9a0afe7c-26a7-4585-bf87-abf82ae106d9";
final String prevBackupUuid = "003a0cc2-2e04-417a-bee0-534ef1724561";
final boolean isVolumeInactive = false;
final String prevSnapshotUuid = "1791efae-f22d-474b-87c6-92547d6c5877";
final BackupSnapshotCommand command = new BackupSnapshotCommand(secondaryStorageUrl, dcId, accountId, volumeId, snapshotId, secHostId, volumePath, pool, snapshotUuid, snapshotName, prevSnapshotUuid, prevBackupUuid, isVolumeInactive, vmName, wait);
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
//final Connect conn = Mockito.mock(Connect.class);
when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(command.getVmName())).thenThrow(LibvirtException.class);
} catch (final LibvirtException e) {
fail(e.getMessage());
}
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, libvirtComputingResource);
assertFalse(answer.getResult());
verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(command.getVmName());
} catch (final LibvirtException e) {
fail(e.getMessage());
}
}
use of com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper in project cloudstack by apache.
the class LibvirtComputingResourceTest method testOvsDestroyBridgeCommandFailure.
@Test
public void testOvsDestroyBridgeCommandFailure() {
final String name = "Test";
final Long hostId = 1l;
final Long networkId = 1l;
final OvsDestroyBridgeCommand command = new OvsDestroyBridgeCommand(networkId, name, hostId);
when(libvirtComputingResource.destroyTunnelNetwork(command.getBridgeName())).thenReturn(false);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, libvirtComputingResource);
assertFalse(answer.getResult());
verify(libvirtComputingResource, times(1)).destroyTunnelNetwork(command.getBridgeName());
}
use of com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper in project cloudstack by apache.
the class LibvirtComputingResourceTest method testNetworkRulesSystemVmCommand.
@Test
public void testNetworkRulesSystemVmCommand() {
final String vmName = "Test";
final Type type = Type.SecondaryStorageVm;
final NetworkRulesSystemVmCommand command = new NetworkRulesSystemVmCommand(vmName, type);
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
final Connect conn = Mockito.mock(Connect.class);
when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(command.getVmName())).thenReturn(conn);
} catch (final LibvirtException e) {
fail(e.getMessage());
}
when(libvirtComputingResource.configureDefaultNetworkRulesForSystemVm(conn, command.getVmName())).thenReturn(true);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, libvirtComputingResource);
assertTrue(answer.getResult());
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(command.getVmName());
} catch (final LibvirtException e) {
fail(e.getMessage());
}
verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
verify(libvirtComputingResource, times(1)).configureDefaultNetworkRulesForSystemVm(conn, command.getVmName());
}
use of com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper in project cloudstack by apache.
the class LibvirtComputingResourceTest method testPlugNicCommandLibvirtException.
@SuppressWarnings("unchecked")
@Test
public void testPlugNicCommandLibvirtException() {
final NicTO nic = Mockito.mock(NicTO.class);
final String instanceName = "Test";
final Type vmtype = Type.DomainRouter;
final PlugNicCommand command = new PlugNicCommand(nic, instanceName, vmtype);
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(command.getVmName())).thenThrow(LibvirtException.class);
} catch (final LibvirtException e) {
fail(e.getMessage());
}
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, libvirtComputingResource);
assertFalse(answer.getResult());
verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(command.getVmName());
} catch (final LibvirtException e) {
fail(e.getMessage());
}
}
use of com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper in project cloudstack by apache.
the class LibvirtComputingResourceTest method testCheckSshCommandFailure.
@Test
public void testCheckSshCommandFailure() {
final String instanceName = "Test";
final String ip = "127.0.0.1";
final int port = 22;
final CheckSshCommand command = new CheckSshCommand(instanceName, ip, port);
final VirtualRoutingResource virtRouterResource = Mockito.mock(VirtualRoutingResource.class);
final String privateIp = command.getIp();
final int cmdPort = command.getPort();
when(libvirtComputingResource.getVirtRouterResource()).thenReturn(virtRouterResource);
when(virtRouterResource.connect(privateIp, cmdPort)).thenReturn(false);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, libvirtComputingResource);
assertFalse(answer.getResult());
verify(libvirtComputingResource, times(1)).getVirtRouterResource();
verify(virtRouterResource, times(1)).connect(privateIp, cmdPort);
}
Aggregations