use of org.ovirt.engine.core.common.businessentities.VM in project ovirt-engine by oVirt.
the class StorageDomainValidatorTest method invalidRunningVmsAndVmLeasesForBackupDomain.
@Test
public void invalidRunningVmsAndVmLeasesForBackupDomain() {
QueryReturnValue ret = new QueryReturnValue();
List<VmBase> vmLeases = new ArrayList<>();
VM vmWithLease = new VM();
vmWithLease.setName("firstVM");
vmLeases.add(vmWithLease.getStaticData());
ret.setReturnValue(vmLeases);
ret.setSucceeded(true);
// VM1
VM vm1 = new VM();
vm1.setName("firstVM");
Map<Guid, Disk> attachedDisksForVm1 = new HashMap<>();
DiskImage diskVm1 = new DiskImage();
diskVm1.setStorageIds(new ArrayList<>(Collections.singletonList(domain.getId())));
diskVm1.setPlugged(true);
attachedDisksForVm1.put(Guid.newGuid(), diskVm1);
vm1.setDiskMap(attachedDisksForVm1);
// VM2
VM vm2 = new VM();
vm2.setName("secondVM");
Map<Guid, Disk> attachedDisksForVm2 = new HashMap<>();
DiskImage diskVm2 = new DiskImage();
diskVm2.setStorageIds(new ArrayList<>(Collections.singletonList(domain.getId())));
diskVm2.setPlugged(true);
attachedDisksForVm2.put(Guid.newGuid(), diskVm2);
vm2.setDiskMap(attachedDisksForVm2);
List<VM> runningVMs = new ArrayList<>();
runningVMs.add(vm1);
runningVMs.add(vm2);
when(vmDao.getAllActiveForStorageDomain(any())).thenReturn(runningVMs);
doReturn(ret).when(validator).getEntitiesWithLeaseIdForStorageDomain(any());
assertThat(validator.isRunningVmsOrVmLeasesForBackupDomain(vmHandler), failsWith(EngineMessage.ACTION_TYPE_FAILED_RUNNING_VM_OR_VM_LEASES_PRESENT_ON_STORAGE_DOMAIN));
}
use of org.ovirt.engine.core.common.businessentities.VM in project ovirt-engine by oVirt.
the class StorageDomainValidatorTest method validRunningVmsWithUnpluggedDisksForBackupDomain.
@Test
public void validRunningVmsWithUnpluggedDisksForBackupDomain() {
// VM1
VM vm1 = new VM();
vm1.setName("firstVM");
Map<Guid, Disk> attachedDisksForVm1 = new HashMap<>();
DiskImage diskVm1 = new DiskImage();
diskVm1.setStorageIds(new ArrayList<>(Collections.singletonList(domain.getId())));
diskVm1.setPlugged(false);
attachedDisksForVm1.put(Guid.newGuid(), diskVm1);
vm1.setDiskMap(attachedDisksForVm1);
List<VM> runningVMs = new ArrayList<>();
runningVMs.add(vm1);
when(vmDao.getAllActiveForStorageDomain(any())).thenReturn(runningVMs);
QueryReturnValue ret = new QueryReturnValue();
ret.setReturnValue(new ArrayList<VmBase>());
ret.setSucceeded(true);
doReturn(ret).when(validator).getEntitiesWithLeaseIdForStorageDomain(any());
assertThat(validator.isRunningVmsOrVmLeasesForBackupDomain(vmHandler), isValid());
}
use of org.ovirt.engine.core.common.businessentities.VM in project ovirt-engine by oVirt.
the class StorageDomainValidatorTest method validVmLeasesForBackupDomain.
@Test
public void validVmLeasesForBackupDomain() {
when(vmDao.getAllActiveForStorageDomain(any())).thenReturn(Collections.EMPTY_LIST);
QueryReturnValue ret = new QueryReturnValue();
List<VmBase> vmLeases = new ArrayList<>();
VM vm1 = new VM();
vm1.setName("firstVM");
vm1.setStatus(VMStatus.Down);
vmLeases.add(vm1.getStaticData());
ret.setReturnValue(vmLeases);
ret.setSucceeded(true);
doReturn(ret).when(validator).getEntitiesWithLeaseIdForStorageDomain(any());
when(vmDao.get(vm1.getId())).thenReturn(vm1);
assertThat(validator.isRunningVmsOrVmLeasesForBackupDomain(vmHandler), isValid());
}
use of org.ovirt.engine.core.common.businessentities.VM in project ovirt-engine by oVirt.
the class RunVmValidatorTest method canRunVmDuringInit.
@Test
public void canRunVmDuringInit() {
final VM vm = new VM();
doReturn(true).when(runVmValidator).isVmDuringInitiating(any());
validateResult(runVmValidator.vmDuringInitialization(vm), false, EngineMessage.ACTION_TYPE_FAILED_VM_IS_RUNNING);
}
use of org.ovirt.engine.core.common.businessentities.VM in project ovirt-engine by oVirt.
the class RunVmValidatorTest method canRunVmFailVmRunning.
@Test
public void canRunVmFailVmRunning() {
final VM vm = new VM();
vm.setStatus(VMStatus.Up);
validateResult(runVmValidator.vmDuringInitialization(vm), false, EngineMessage.ACTION_TYPE_FAILED_VM_IS_RUNNING);
}
Aggregations