use of com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResourceTest method testPlugNicCommandMatchMack.
@Test
public void testPlugNicCommandMatchMack() {
final NicTO nic = Mockito.mock(NicTO.class);
final String instanceName = "Test";
final VirtualMachineType vmtype = VirtualMachineType.DomainRouter;
final PlugNicCommand command = new PlugNicCommand(nic, instanceName, vmtype);
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
final Connect conn = Mockito.mock(Connect.class);
final Domain vm = Mockito.mock(Domain.class);
final List<InterfaceDef> nics = new ArrayList<>();
final InterfaceDef intDef = Mockito.mock(InterfaceDef.class);
nics.add(intDef);
when(this.libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
when(this.libvirtComputingResource.getInterfaces(conn, command.getVmName())).thenReturn(nics);
when(intDef.getDevName()).thenReturn("eth0");
when(intDef.getBrName()).thenReturn("br0");
when(intDef.getMacAddress()).thenReturn("00:00:00:00");
when(nic.getMac()).thenReturn("00:00:00:00");
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(command.getVmName())).thenReturn(conn);
when(this.libvirtComputingResource.getDomain(conn, instanceName)).thenReturn(vm);
} catch (final LibvirtException e) {
fail(e.getMessage());
}
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
assertTrue(answer.getResult());
verify(this.libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(command.getVmName());
verify(this.libvirtComputingResource, times(1)).getDomain(conn, instanceName);
} 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 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();
}
use of com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResourceTest method testCreatePrivateTemplateFromSnapshotCommandConfigurationException.
@Test
public void testCreatePrivateTemplateFromSnapshotCommandConfigurationException() {
final StoragePool pool = Mockito.mock(StoragePool.class);
final String secondaryStoragePoolURL = "nfs:/127.0.0.1/storage/secondary";
final Long dcId = 1l;
final Long accountId = 1l;
final Long volumeId = 1l;
final String backedUpSnapshotUuid = "/run/9a0afe7c-26a7-4585-bf87-abf82ae106d9/";
final String backedUpSnapshotName = "snap";
final String origTemplateInstallPath = "/install/path/";
final Long newTemplateId = 2l;
final String templateName = "templ";
final int wait = 0;
final CreatePrivateTemplateFromSnapshotCommand command = new CreatePrivateTemplateFromSnapshotCommand(pool, secondaryStoragePoolURL, dcId, accountId, volumeId, backedUpSnapshotUuid, backedUpSnapshotName, origTemplateInstallPath, newTemplateId, templateName, wait);
final String templatePath = "/template/path";
final String localPath = "/mnt/local";
final String tmplName = "ce97bbc1-34fe-4259-9202-74bbce2562ab";
final KvmStoragePoolManager storagePoolMgr = Mockito.mock(KvmStoragePoolManager.class);
final KvmStoragePool secondaryPool = Mockito.mock(KvmStoragePool.class);
final KvmStoragePool snapshotPool = Mockito.mock(KvmStoragePool.class);
final KvmPhysicalDisk snapshot = Mockito.mock(KvmPhysicalDisk.class);
final StorageLayer storage = Mockito.mock(StorageLayer.class);
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
final TemplateLocation location = Mockito.mock(TemplateLocation.class);
final Processor qcow2Processor = Mockito.mock(Processor.class);
final TemplateFormatInfo info = Mockito.mock(TemplateFormatInfo.class);
when(this.libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
String snapshotPath = command.getSnapshotUuid();
final int index = snapshotPath.lastIndexOf("/");
snapshotPath = snapshotPath.substring(0, index);
when(storagePoolMgr.getStoragePoolByUri(command.getSecondaryStorageUrl() + snapshotPath)).thenReturn(snapshotPool);
when(storagePoolMgr.getStoragePoolByUri(command.getSecondaryStorageUrl())).thenReturn(secondaryPool);
when(snapshotPool.getPhysicalDisk(command.getSnapshotName())).thenReturn(snapshot);
when(secondaryPool.getLocalPath()).thenReturn(localPath);
when(this.libvirtComputingResource.getStorage()).thenReturn(storage);
when(this.libvirtComputingResource.createTmplPath()).thenReturn(templatePath);
when(this.libvirtComputingResource.getCmdsTimeout()).thenReturn(1);
final String templateFolder = command.getAccountId() + File.separator + command.getNewTemplateId();
final String templateInstallFolder = "template/tmpl/" + templateFolder;
final String tmplPath = secondaryPool.getLocalPath() + File.separator + templateInstallFolder;
when(this.libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
when(libvirtUtilitiesHelper.buildTemplateLocation(storage, tmplPath)).thenReturn(location);
when(libvirtUtilitiesHelper.generateUuidName()).thenReturn(tmplName);
try {
when(libvirtUtilitiesHelper.buildQcow2Processor(storage)).thenThrow(ConfigurationException.class);
when(qcow2Processor.process(tmplPath, null, tmplName)).thenReturn(info);
} catch (final ConfigurationException e) {
fail(e.getMessage());
} catch (final InternalErrorException 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)).getStoragePoolMgr();
verify(storagePoolMgr, times(1)).getStoragePoolByUri(command.getSecondaryStorageUrl() + snapshotPath);
verify(storagePoolMgr, times(1)).getStoragePoolByUri(command.getSecondaryStorageUrl());
}
use of com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResourceTest method testPvlanSetupCommandDhcpDelete.
@Test
public void testPvlanSetupCommandDhcpDelete() {
final String op = "delete";
final URI uri = URI.create("http://localhost");
final String networkTag = "/105";
final String dhcpName = "dhcp";
final String dhcpMac = "00:00:00:00";
final String dhcpIp = "127.0.0.1";
final PvlanSetupCommand command = PvlanSetupCommand.createDhcpSetup(op, uri, networkTag, dhcpName, dhcpMac, dhcpIp);
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
final String guestBridgeName = "br0";
when(this.libvirtComputingResource.getGuestBridgeName()).thenReturn(guestBridgeName);
final int timeout = 0;
when(this.libvirtComputingResource.getScriptsTimeout()).thenReturn(timeout);
final String ovsPvlanDhcpHostPath = "/pvlan";
when(this.libvirtComputingResource.getOvsPvlanDhcpHostPath()).thenReturn(ovsPvlanDhcpHostPath);
when(this.libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
assertFalse(answer.getResult());
}
use of com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResourceTest method testModifyStoragePoolCommandFailure.
@Test
public void testModifyStoragePoolCommandFailure() {
final StoragePool pool = Mockito.mock(StoragePool.class);
final ModifyStoragePoolCommand command = new ModifyStoragePoolCommand(true, pool);
final KvmStoragePoolManager storagePoolMgr = Mockito.mock(KvmStoragePoolManager.class);
when(this.libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
when(storagePoolMgr.createStoragePool(command.getPool().getUuid(), command.getPool().getHost(), command.getPool().getPort(), command.getPool().getPath(), command.getPool().getUserInfo(), command.getPool().getType())).thenReturn(null);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
assertFalse(answer.getResult());
verify(this.libvirtComputingResource, times(1)).getStoragePoolMgr();
verify(storagePoolMgr, times(1)).createStoragePool(command.getPool().getUuid(), command.getPool().getHost(), command.getPool().getPort(), command.getPool().getPath(), command.getPool().getUserInfo(), command.getPool().getType());
}
Aggregations