use of org.ovirt.engine.core.common.businessentities.HostDeviceId 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.HostDeviceId in project ovirt-engine by oVirt.
the class HostDeviceDaoTest method cleanDownVmsTest.
@Test
public void cleanDownVmsTest() {
HostDevice device = getNetworkDevice();
HostDeviceId deviceId = device.getId();
// Setting an id of VM with VMStatus.Down
Guid vmId = FixturesTool.VM_WITH_NO_ATTACHED_DISKS;
dao.setVmIdOnHostDevice(deviceId, vmId);
device = dao.get(deviceId);
assertNotNull(device);
assertEquals(vmId, device.getVmId());
dao.cleanDownVms();
device = dao.get(deviceId);
assertNull(device.getVmId());
}
use of org.ovirt.engine.core.common.businessentities.HostDeviceId in project ovirt-engine by oVirt.
the class NetworkDeviceHelperImplTest method removeVmIdFromVfsCommonTest.
private void removeVmIdFromVfsCommonTest(int numOfVfWithVmId, int numOfOtherDeviceWithVmId) {
List<HostDevice> allDevices = new ArrayList<>();
List<HostDevice> otherDeviceWithVmId = new ArrayList<>();
Guid vmId = Guid.newGuid();
List<HostDevice> vfs = mockVfsOnNetDevice(numOfVfWithVmId, vmId);
allDevices.addAll(vfs);
for (int i = 0; i <= numOfOtherDeviceWithVmId; ++i) {
HostDevice hostDevice = createHostDevice(vmId);
otherDeviceWithVmId.add(hostDevice);
}
allDevices.addAll(otherDeviceWithVmId);
mockHostDevices(allDevices);
for (HostDevice vf : vfs) {
assertEquals(vmId, vf.getVmId());
}
networkDeviceHelper.removeVmIdFromVfs(vmId);
for (HostDevice vf : vfs) {
vf.setVmId(null);
}
if (numOfVfWithVmId == 0) {
verify(hostDeviceDao, never()).setVmIdOnHostDevice(any(), any());
} else {
verify(hostDeviceDao, times(numOfVfWithVmId)).setVmIdOnHostDevice(hostDeviceIdCaptor.capture(), vmIdCaptor.capture());
List<HostDeviceId> capturedDeviceIds = hostDeviceIdCaptor.getAllValues();
List<Guid> capturedVmIds = vmIdCaptor.getAllValues();
for (HostDevice vf : vfs) {
assertTrue(capturedDeviceIds.contains(vf.getId()));
}
for (HostDevice hostDevice : otherDeviceWithVmId) {
assertFalse(capturedDeviceIds.contains(hostDevice.getId()));
}
for (Guid capturedVmId : capturedVmIds) {
assertNull(capturedVmId);
}
}
}
Aggregations