use of org.ovirt.engine.core.common.businessentities.HostDevice in project ovirt-engine by oVirt.
the class NetworkDeviceHelperImplTest method setVmIdOnVfs.
@Test
public void setVmIdOnVfs() {
List<HostDevice> vfs = mockVfsOnNetDevice(1);
vfs.forEach(vf -> vf.setVmId(null));
mockHostDevices(vfs);
HostDevice vf = vfs.get(0);
Guid vmId = Guid.newGuid();
networkDeviceHelper.setVmIdOnVfs(HOST_ID, vmId, Collections.singleton(vf.getDeviceName()));
verify(hostDeviceDao).setVmIdOnHostDevice(hostDeviceIdCaptor.capture(), vmIdCaptor.capture());
HostDeviceId capturedDeviceId = hostDeviceIdCaptor.getValue();
Guid capturedVmId = vmIdCaptor.getValue();
assertEquals(vf.getId(), capturedDeviceId);
assertEquals(vmId, capturedVmId);
}
use of org.ovirt.engine.core.common.businessentities.HostDevice in project ovirt-engine by oVirt.
the class NetworkDeviceHelperImplTest method testGetVfMap.
@Test
public void testGetVfMap() {
final HostDevice pfNetDevice = new HostDevice();
final HostDevice pfPciDevice = new HostDevice();
final Guid pfNicId = Guid.newGuid();
final String pfNicName = "pf" + NIC_NAME;
final String pfPciDeviceName = "pf" + PCI_DEVICE_NAME;
pfNetDevice.setHostId(HOST_ID);
pfNetDevice.setDeviceName("pf" + NET_DEVICE_NAME);
pfNetDevice.setNetworkInterfaceName(pfNicName);
pfNetDevice.setParentDeviceName(pfPciDeviceName);
pfPciDevice.setHostId(HOST_ID);
pfPciDevice.setDeviceName(pfPciDeviceName);
pfPciDevice.setDeviceName(pfPciDeviceName);
when(pciDevice.getParentPhysicalFunction()).thenReturn(pfPciDeviceName);
mockHostDevices(Arrays.asList(pfNetDevice, pfPciDevice, new HostDevice()));
when(nic.getVlanId()).thenReturn(null);
final VdsNetworkInterface pfNic = new VdsNetworkInterface();
pfNic.setId(pfNicId);
pfNic.setName(pfNetDevice.getNetworkInterfaceName());
final VdsNetworkInterface bondNic = new VdsNetworkInterface();
bondNic.setBonded(true);
final VdsNetworkInterface vlanNic = new VdsNetworkInterface();
vlanNic.setVlanId(666);
mockNics(Arrays.asList(pfNic, bondNic, vlanNic), true);
final Map<Guid, Guid> actual = networkDeviceHelper.getVfMap(HOST_ID);
assertEquals(1, actual.size());
assertThat(actual, hasEntry(NIC_ID, pfNicId));
}
use of org.ovirt.engine.core.common.businessentities.HostDevice in project ovirt-engine by oVirt.
the class NetworkDeviceHelperImplTest method freeVfCommon.
private List<HostDevice> freeVfCommon(int numOfFreeVfs, int numOfVfsAttachedToVm, int numOfVfsHasNoNic, int numOfVfsHasNetworkAttached, int numOfVfsHasVlanDeviceAttached, int numOfVfsArePartOfBond) {
networkDeviceHelper = spy(new NetworkDeviceHelperImpl(interfaceDao, hostDeviceDao, hostNicVfsConfigDao));
List<HostDevice> devices = new ArrayList<>();
List<HostDevice> freeVfs = new ArrayList<>();
int numOfVfs = numOfFreeVfs + numOfVfsAttachedToVm + numOfVfsHasNoNic + numOfVfsHasNetworkAttached + numOfVfsHasVlanDeviceAttached + numOfVfsArePartOfBond;
List<HostDevice> vfs = mockVfsOnNetDevice(numOfVfs);
List<VdsNetworkInterface> nics = new ArrayList<>();
devices.addAll(vfs);
for (HostDevice vfPciDevice : vfs) {
HostDevice vfNetDevice = mockNetworkDeviceForPciDevice(vfPciDevice);
devices.add(vfNetDevice);
if (numOfVfsHasNoNic != 0) {
--numOfVfsHasNoNic;
} else {
VdsNetworkInterface vfNic = mockNicForNetDevice(vfNetDevice);
nics.add(vfNic);
if (numOfVfsAttachedToVm != 0) {
--numOfVfsAttachedToVm;
vfPciDevice.setVmId(Guid.newGuid());
} else if (numOfVfsHasNetworkAttached != 0) {
--numOfVfsHasNetworkAttached;
vfNic.setNetworkName("netName");
} else if (numOfVfsHasVlanDeviceAttached != 0) {
--numOfVfsHasVlanDeviceAttached;
doReturn(true).when(networkDeviceHelper).isVlanDeviceAttached(vfNic);
} else if (numOfVfsArePartOfBond != 0) {
--numOfVfsArePartOfBond;
vfNic.setBondName("bondName");
} else {
doReturn(false).when(networkDeviceHelper).isVlanDeviceAttached(vfNic);
freeVfs.add(vfPciDevice);
}
}
}
mockHostDevices(devices);
mockNics(nics, true);
return freeVfs;
}
use of org.ovirt.engine.core.common.businessentities.HostDevice in project ovirt-engine by oVirt.
the class NetworkDeviceHelperImplTest method mockVfsOnNetDevice.
private List<HostDevice> mockVfsOnNetDevice(int numOfVfs, Guid vmId) {
List<HostDevice> vfs = new ArrayList<>();
for (int i = 0; i < numOfVfs; ++i) {
HostDevice vfPciDevice = new HostDevice();
vfPciDevice.setParentPhysicalFunction(pciDevice.getDeviceName());
vfPciDevice.setDeviceName(String.valueOf(i));
vfPciDevice.setHostId(HOST_ID);
vfPciDevice.setVmId(vmId);
vfs.add(vfPciDevice);
}
return vfs;
}
use of org.ovirt.engine.core.common.businessentities.HostDevice in project ovirt-engine by oVirt.
the class AddVmHostDevicesCommand method executeCommand.
@Override
protected void executeCommand() {
Set<HostDevice> affectedHostDevices = getAffectedHostDevices();
Map<String, VmHostDevice> existingDevices = getExistingVmHostDevicesByName();
List<VmDevice> devicesToAdd = new ArrayList<>();
List<VmDevice> devicesToUpdate = new ArrayList<>();
for (HostDevice hostDevice : affectedHostDevices) {
if (!existingDevices.containsKey(hostDevice.getDeviceName())) {
VmHostDevice device = new VmHostDevice(getVmId(), hostDevice);
// if the device was not explicitly intended by the user (only added due to the IOMMU group
// we mark it as as placeholder
boolean required = getPrimaryDeviceNames().contains(device.getDevice());
device.setIommuPlaceholder(!required);
devicesToAdd.add(device);
} else {
VmHostDevice device = new VmHostDevice(existingDevices.get(hostDevice.getDeviceName()));
// as it is now explicitly requested by the user
if (getPrimaryDeviceNames().contains(device.getDevice()) && device.isIommuPlaceholder()) {
device.setIommuPlaceholder(false);
devicesToUpdate.add(device);
}
}
}
vmDeviceDao.saveAllInBatch(devicesToAdd);
vmDeviceDao.updateAllInBatch(devicesToUpdate);
setSucceeded(true);
}
Aggregations