Skip to content

Commit

Permalink
core: fix import template from ova
Browse files Browse the repository at this point in the history
When importing a template from OVA we don't go through
ImportVmTemplateFromConfiguration and therefore
getImageToAvailableStorageDomains() returns an empty map and later we
fail with NPE.

This patch changes the fix for https://bugzilla.redhat.com/2043124 to be
specific for ImportVmTemplateFromConfiguration and so other
import-template flows would not face this issue.

Bug-Url: https://bugzilla.redhat.com/2074916
Signed-off-by: Arik Hadas <ahadas@redhat.com>
  • Loading branch information
ahadas committed Apr 19, 2022
1 parent 00a89aa commit f532eb7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,18 +154,7 @@ protected void initImportClonedTemplateDisks() {
if (!getParameters().isImagesExistOnTargetStorageDomain()) {
updateDiskSizeByQcowImageInfo(image);
} else {
Set<Guid> storageDomains = getParameters().getImageToAvailableStorageDomains().get(image.getImageId());
Guid sdToUse;

// Try to use the target SD, otherwise fallback to one of the available SDs
// for the image
if (storageDomains.contains(getStorageDomainId())) {
sdToUse = getStorageDomainId();
} else {
sdToUse = storageDomains.stream().findFirst().get();
}

updateDiskSizeByQcowImageInfo(image, sdToUse);
updateDiskSizeByQcowImageInfo(image, image.getStorageIds().get(0));
}

if (getParameters().isImportAsNewEntity()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,18 @@ public AuditLogType getAuditLogTypeValue() {

@Override
protected void updateDiskSizeByQcowImageInfo(DiskImage diskImage, Guid storageId) {
Set<Guid> storageDomains = getParameters().getImageToAvailableStorageDomains().get(diskImage.getImageId());

if (storageDomains != null && !storageDomains.isEmpty()) {
// Try to use the target SD, otherwise fallback to one of the available SDs
// for the image
if (storageDomains.contains(getStorageDomainId())) {
storageId = getStorageDomainId();
} else {
storageId = storageDomains.stream().findFirst().get();
}
}

if (!Guid.isNullOrEmpty(storageId)) {
super.updateDiskSizeByQcowImageInfo(diskImage, storageId);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class ImportVmTemplateFromConfParameters extends ImportVmTemplateParamete
private Map<String, String> clusterMap;
private Map<String, String> roleMap;
private Map<String, String> domainMap;
private Map<Guid, Set<Guid>> imageToAvailableStorageDomains = new HashMap<>();

private Set<DbUser> dbUsers;
private Map<String, Set<String>> userToRoles = new HashMap<>();
Expand Down Expand Up @@ -118,4 +119,12 @@ public Collection<ExternalVnicProfileMapping> getExternalVnicProfileMappings() {
public void setExternalVnicProfileMappings(Collection<ExternalVnicProfileMapping> externalVnicProfileMappings) {
this.externalVnicProfileMappings = Objects.requireNonNull(externalVnicProfileMappings);
}

public Map<Guid, Set<Guid>> getImageToAvailableStorageDomains() {
return imageToAvailableStorageDomains;
}

public void setImageToAvailableStorageDomains(Map<Guid, Set<Guid>> imageToAvailableStorageDomains) {
this.imageToAvailableStorageDomains = imageToAvailableStorageDomains;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,6 @@ public void setDiskTemplateMap(Map<Guid, DiskImage> diskTemplateMap) {
this.diskTemplateMap = diskTemplateMap;
}

private Map<Guid, Set<Guid>> imageToAvailableStorageDomains = new HashMap<>();

public Map<Guid, Set<Guid>> getImageToAvailableStorageDomains() {
return imageToAvailableStorageDomains;
}

public void setImageToAvailableStorageDomains(Map<Guid, Set<Guid>> imageToAvailableStorageDomains) {
this.imageToAvailableStorageDomains = imageToAvailableStorageDomains;
}

public ImportVmTemplateParameters() {
privateSourceDomainId = Guid.Empty;
privateDestDomainId = Guid.Empty;
Expand Down

0 comments on commit f532eb7

Please sign in to comment.