use of org.ovirt.engine.core.common.businessentities.VmTemplate in project ovirt-engine by oVirt.
the class StorageDomainDaoTest method testRemove.
/**
* Asserts that the existing Storage Domain exists and has VMs and VM Templates, the after remove asserts
* that the existing domain is removed along with the VM and VM Templates
*/
@Test
public void testRemove() {
List<VM> vms = getDbFacade().getVmDao().getAllForStorageDomain(FixturesTool.STORAGE_DOMAIN_SCALE_SD5);
List<VmTemplate> templates = getDbFacade().getVmTemplateDao().getAllForStorageDomain(FixturesTool.STORAGE_DOMAIN_SCALE_SD5);
BaseDisk diskImage = getDbFacade().getBaseDiskDao().get(FixturesTool.DISK_ID);
assertNotNull(diskImage);
assertFalse(vms.isEmpty());
assertFalse(templates.isEmpty());
assertNotNull(dao.get(FixturesTool.STORAGE_DOMAIN_SCALE_SD5));
dao.remove(existingDomain.getId());
assertNull(dao.get(FixturesTool.STORAGE_DOMAIN_SCALE_SD5));
for (VM vm : vms) {
assertNull(getDbFacade().getVmDao().get(vm.getId()));
}
for (VmTemplate template : templates) {
assertNull(getDbFacade().getVmTemplateDao().get(template.getId()));
}
assertNull(getDbFacade().getBaseDiskDao().get(FixturesTool.DISK_ID));
}
use of org.ovirt.engine.core.common.businessentities.VmTemplate in project ovirt-engine by oVirt.
the class RemoveDiskCommandTest method testValidateTemplateEntity.
@Test
public void testValidateTemplateEntity() {
disk.setVmEntityType(VmEntityType.TEMPLATE);
StorageDomain domain = new StorageDomain();
domain.setId(Guid.newGuid());
domain.setStatus(StorageDomainStatus.Active);
cmd.getParameters().setStorageDomainId(domain.getId());
ArrayList<Guid> storageIds = new ArrayList<>();
storageIds.add(domain.getId());
storageIds.add(Guid.newGuid());
((DiskImage) disk).setStorageIds(storageIds);
doReturn(domain).when(cmd).getStorageDomain();
doReturn(new VmTemplate()).when(cmd).getVmTemplate();
doReturn(true).when(cmd).checkDerivedDisksFromDiskNotExist(any());
doReturn(disk).when(diskImageDao).get(any());
ValidateTestUtils.runAndAssertValidateSuccess(cmd);
}
use of org.ovirt.engine.core.common.businessentities.VmTemplate in project ovirt-engine by oVirt.
the class MoveOrCopyDiskCommandTest method validateTemplateImageIsLocked.
@Test
public void validateTemplateImageIsLocked() {
initializeCommand(new DiskImage(), VmEntityType.TEMPLATE);
command.getParameters().setOperation(ImageOperation.Copy);
command.getImage().setImageStatus(ImageStatus.LOCKED);
doReturn(new VmTemplate()).when(command).getTemplateForImage();
ValidateTestUtils.runAndAssertValidateFailure(command, EngineMessage.VM_TEMPLATE_IMAGE_IS_LOCKED);
}
use of org.ovirt.engine.core.common.businessentities.VmTemplate in project ovirt-engine by oVirt.
the class ProcessOvfUpdateForStoragePoolCommandTest method mockAnswers.
private void mockAnswers() {
doAnswer(invocation -> {
VM vm = (VM) invocation.getArguments()[0];
return vm.getId().toString();
}).when(ovfUpdateProcessHelper).generateVmMetadata(any(), any());
doAnswer(invocation -> {
VmTemplate template = (VmTemplate) ((FullEntityOvfData) invocation.getArguments()[0]).getVmBase();
return template.getId().toString();
}).when(ovfUpdateProcessHelper).generateVmTemplateMetadata(any());
doAnswer(invocation -> {
List<Guid> neededIds = (List<Guid>) invocation.getArguments()[0];
return neededIds.stream().map(id -> vms.get(id)).collect(Collectors.toList());
}).when(vmDao).getVmsByIds(any());
doAnswer(invocation -> {
List<Guid> neededIds = (List<Guid>) invocation.getArguments()[0];
return neededIds.stream().map(id -> templates.get(id)).collect(Collectors.toList());
}).when(vmTemplateDao).getVmTemplatesByIds(any());
doAnswer(invocation -> {
Map<Guid, KeyValuePairCompat<String, List<Guid>>> updateMap = (Map<Guid, KeyValuePairCompat<String, List<Guid>>>) invocation.getArguments()[1];
assertTrue("too many ovfs were sent in one vdsm call", updateMap.size() <= ITEMS_COUNT_PER_UPDATE);
return true;
}).when(ovfUpdateProcessHelper).executeUpdateVmInSpmCommand(any(), any(), any());
doReturn(true).when(ovfUpdateProcessHelper).executeRemoveVmInSpm(any(), any(), any());
doAnswer(invocation -> {
List<Guid> ids = (List<Guid>) invocation.getArguments()[0];
List<Long> values = (List<Long>) invocation.getArguments()[1];
assertFalse("update of ovf version in db shouldn't be called with an empty value list", values.isEmpty());
assertTrue("update of ovf version in db shouldn't be called with more items then MAX_ITEMS_PER_SQL_STATEMENT", values.size() <= StorageConstants.OVF_MAX_ITEMS_PER_SQL_STATEMENT);
assertEquals("the size of the list of ids for update is not the same as the size of the " + "list with the new ovf values", values.size(), ids.size());
Guid[] ids_array = ids.toArray(new Guid[ids.size()]);
Long[] values_array = values.toArray(new Long[values.size()]);
for (int i = 0; i < ids_array.length; i++) {
executedUpdatedOvfGenerationIdsInDb.put(ids_array[i], values_array[i]);
}
return null;
}).when(vmAndTemplatesGenerationsDao).updateOvfGenerations(any(), any(), any());
doAnswer(invocation -> {
StoragePoolStatus desiredStatus = (StoragePoolStatus) invocation.getArguments()[0];
return buildStoragePoolsList().stream().filter(p -> desiredStatus.equals(p.getStatus())).collect(Collectors.toList());
}).when(storagePoolDao).getAllByStatus(any());
doReturn(poolDomainsOvfInfo.values().stream().map(Pair::getSecond).collect(Collectors.toList())).when(storageDomainDao).getAllForStoragePool(any());
doAnswer(invocation -> {
Guid domainId = (Guid) invocation.getArguments()[0];
Pair<List<StorageDomainOvfInfo>, StorageDomain> pair = poolDomainsOvfInfo.get(domainId);
if (pair != null) {
return pair.getFirst();
}
return null;
}).when(storageDomainOvfInfoDao).getAllForDomain(any());
}
use of org.ovirt.engine.core.common.businessentities.VmTemplate in project ovirt-engine by oVirt.
the class BackendTemplateGraphicsConsolesResource method list.
@Override
public GraphicsConsoles list() {
GraphicsConsoles consoles = new GraphicsConsoles();
VmTemplate entity = loadEntity();
BackendGraphicsConsoleHelper.list(this, guid).entrySet().forEach(graphicsInfo -> consoles.getGraphicsConsoles().add(addLinks(populate(VmMapper.map(graphicsInfo, null), entity))));
return consoles;
}
Aggregations