use of com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResourceTest method testModifySshKeysCommand.
@Test
public void testModifySshKeysCommand() {
final ModifySshKeysCommand command = new ModifySshKeysCommand("", "");
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
when(this.libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
when(libvirtUtilitiesHelper.retrieveSshKeysPath()).thenReturn("/path/keys");
when(libvirtUtilitiesHelper.retrieveSshPubKeyPath()).thenReturn("/path/pub/keys");
when(libvirtUtilitiesHelper.retrieveSshPrvKeyPath()).thenReturn("/path/pvt/keys");
when(this.libvirtComputingResource.getScriptsTimeout()).thenReturn(0);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
assertFalse(answer.getResult());
verify(this.libvirtComputingResource, times(1)).getScriptsTimeout();
}
use of com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResourceTest method testUpdateHostPasswordCommand.
@Test
public void testUpdateHostPasswordCommand() {
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
final Script script = Mockito.mock(Script.class);
final String hostIp = "127.0.0.1";
final String username = "root";
final String newPassword = "password";
final UpdateHostPasswordCommand command = new UpdateHostPasswordCommand(username, newPassword, hostIp);
when(this.libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
when(this.libvirtComputingResource.getUpdateHostPasswdPath()).thenReturn("/tmp");
when(libvirtUtilitiesHelper.buildScript(this.libvirtComputingResource.getUpdateHostPasswdPath())).thenReturn(script);
when(script.execute()).thenReturn(null);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
assertTrue(answer.getResult());
}
use of com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResourceTest method testPrepareForMigrationCommandInternalErrorException.
@Test
public void testPrepareForMigrationCommandInternalErrorException() {
final Connect conn = Mockito.mock(Connect.class);
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
final VirtualMachineTO vm = Mockito.mock(VirtualMachineTO.class);
final KvmStoragePoolManager storagePoolManager = Mockito.mock(KvmStoragePoolManager.class);
final NicTO nicTO = Mockito.mock(NicTO.class);
final DiskTO volume = Mockito.mock(DiskTO.class);
final PrepareForMigrationCommand command = new PrepareForMigrationCommand(vm);
when(this.libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(vm.getName())).thenReturn(conn);
} catch (final LibvirtException e) {
fail(e.getMessage());
}
when(vm.getNics()).thenReturn(new NicTO[] { nicTO });
when(nicTO.getType()).thenReturn(TrafficType.Guest);
when(this.libvirtComputingResource.getVifDriver(nicTO.getType())).thenThrow(InternalErrorException.class);
when(this.libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolManager);
try {
when(this.libvirtComputingResource.getVolumePath(conn, volume)).thenReturn("/path");
} catch (final LibvirtException e) {
fail(e.getMessage());
} catch (final URISyntaxException 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(1)).getConnectionByVmName(vm.getName());
} catch (final LibvirtException e) {
fail(e.getMessage());
}
verify(this.libvirtComputingResource, times(1)).getStoragePoolMgr();
verify(vm, times(1)).getNics();
}
use of com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResourceTest method testCopyVolumeCommand.
@Test
public void testCopyVolumeCommand() {
final StoragePool storagePool = Mockito.mock(StoragePool.class);
final String secondaryStoragePoolURL = "nfs:/127.0.0.1/storage/secondary";
final Long volumeId = 1l;
final int wait = 0;
final String volumePath = "/vol/path";
final boolean toSecondaryStorage = true;
final boolean executeInSequence = false;
final CopyVolumeCommand command = new CopyVolumeCommand(volumeId, volumePath, storagePool, secondaryStoragePoolURL, toSecondaryStorage, wait, executeInSequence);
final String destVolumeName = "ce97bbc1-34fe-4259-9202-74bbce2562ab";
final String volumeDestPath = "/volumes/" + command.getVolumeId() + File.separator;
final KvmStoragePoolManager storagePoolMgr = Mockito.mock(KvmStoragePoolManager.class);
final KvmStoragePool secondary = Mockito.mock(KvmStoragePool.class);
final KvmStoragePool primary = Mockito.mock(KvmStoragePool.class);
final KvmPhysicalDisk disk = Mockito.mock(KvmPhysicalDisk.class);
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
final StorageFilerTO pool = command.getPool();
when(this.libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
when(storagePoolMgr.getStoragePool(pool.getType(), pool.getUuid())).thenReturn(primary);
when(this.libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
when(libvirtUtilitiesHelper.generateUuidName()).thenReturn(destVolumeName);
when(primary.getPhysicalDisk(command.getVolumePath())).thenReturn(disk);
when(storagePoolMgr.getStoragePoolByUri(secondaryStoragePoolURL)).thenReturn(secondary);
when(secondary.getType()).thenReturn(StoragePoolType.ManagedNFS);
when(secondary.getUuid()).thenReturn("60d979d8-d132-4181-8eca-8dfde50d7df6");
when(secondary.createFolder(volumeDestPath)).thenReturn(true);
when(storagePoolMgr.deleteStoragePool(secondary.getType(), secondary.getUuid())).thenReturn(true);
when(storagePoolMgr.getStoragePoolByUri(secondaryStoragePoolURL + volumeDestPath)).thenReturn(secondary);
when(storagePoolMgr.copyPhysicalDisk(disk, destVolumeName, secondary, 0)).thenReturn(disk);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
assertTrue(answer.getResult());
verify(this.libvirtComputingResource, times(1)).getStoragePoolMgr();
}
use of com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResourceTest method testPrepareForMigrationCommandLibvirtException.
@Test
public void testPrepareForMigrationCommandLibvirtException() {
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
final VirtualMachineTO vm = Mockito.mock(VirtualMachineTO.class);
final KvmStoragePoolManager storagePoolManager = Mockito.mock(KvmStoragePoolManager.class);
final NicTO nicTO = Mockito.mock(NicTO.class);
final VifDriver vifDriver = Mockito.mock(VifDriver.class);
final PrepareForMigrationCommand command = new PrepareForMigrationCommand(vm);
when(this.libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(vm.getName())).thenThrow(LibvirtException.class);
} catch (final LibvirtException e) {
fail(e.getMessage());
}
when(vm.getNics()).thenReturn(new NicTO[] { nicTO });
when(nicTO.getType()).thenReturn(TrafficType.Guest);
when(this.libvirtComputingResource.getVifDriver(nicTO.getType())).thenReturn(vifDriver);
when(this.libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolManager);
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(1)).getConnectionByVmName(vm.getName());
} catch (final LibvirtException e) {
fail(e.getMessage());
}
verify(this.libvirtComputingResource, times(1)).getStoragePoolMgr();
verify(vm, times(1)).getNics();
}
Aggregations