Skip to content

Commit 8a824de

Browse files
committed
Fixup
1 parent e881ee7 commit 8a824de

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtConvertInstanceCommandWrapper.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ public Answer execute(ConvertInstanceCommand cmd, LibvirtComputingResource serve
122122
final String temporaryConvertUuid = UUID.randomUUID().toString();
123123
boolean verboseModeEnabled = serverResource.isConvertInstanceVerboseModeEnabled();
124124

125+
boolean cleanupSecondaryStorage = false;
125126
try {
126127
boolean result = performInstanceConversion(sourceOVFDirPath, temporaryConvertPath, temporaryConvertUuid,
127128
timeout, verboseModeEnabled);
@@ -131,18 +132,23 @@ public Answer execute(ConvertInstanceCommand cmd, LibvirtComputingResource serve
131132
s_logger.error(err);
132133
return new Answer(cmd, false, err);
133134
}
134-
return new Answer(cmd, false, null);
135+
return new Answer(cmd, true, null);
135136
} catch (Exception e) {
136137
String error = String.format("Error converting instance %s from %s, due to: %s",
137138
sourceInstanceName, sourceHypervisorType, e.getMessage());
138139
s_logger.error(error, e);
140+
cleanupSecondaryStorage = true;
139141
return new Answer(cmd, false, error);
140142
} finally {
141143
if (ovfExported && StringUtils.isNotBlank(ovfTemplateDirOnConversionLocation)) {
142144
String sourceOVFDir = String.format("%s/%s", temporaryConvertPath, ovfTemplateDirOnConversionLocation);
143145
s_logger.debug("Cleaning up exported OVA at dir " + sourceOVFDir);
144146
FileUtil.deletePath(sourceOVFDir);
145147
}
148+
if (cleanupSecondaryStorage && conversionTemporaryLocation instanceof NfsTO) {
149+
s_logger.debug("Cleaning up secondary storage temporary location");
150+
storagePoolMgr.deleteStoragePool(temporaryStoragePool.getType(), temporaryStoragePool.getUuid());
151+
}
146152
}
147153
}
148154

server/src/main/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImpl.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1891,6 +1891,14 @@ private UnmanagedInstanceTO convertVmwareInstanceToKVMWithOVFOnConvertLocation(
18911891
throw new CloudRuntimeException(err);
18921892
}
18931893

1894+
if (!importAnswer.getResult()) {
1895+
String err = String.format(
1896+
"The import process failed for instance %s from VMware to KVM on host %s: %s",
1897+
sourceVM, destinationHost.getName(), importAnswer.getDetails());
1898+
LOGGER.error(err);
1899+
throw new CloudRuntimeException(err);
1900+
}
1901+
18941902
return ((ImportConvertedInstanceAnswer) importAnswer).getConvertedInstance();
18951903
}
18961904

@@ -1945,6 +1953,15 @@ private UnmanagedInstanceTO convertVmwareInstanceToKVMAfterExportingOVFToConvert
19451953
LOGGER.error(err, e);
19461954
throw new CloudRuntimeException(err);
19471955
}
1956+
1957+
if (!importAnswer.getResult()) {
1958+
String err = String.format(
1959+
"The import process failed for instance %s from VMware to KVM on host %s: %s",
1960+
sourceVM, destinationHost.getName(), importAnswer.getDetails());
1961+
LOGGER.error(err);
1962+
throw new CloudRuntimeException(err);
1963+
}
1964+
19481965
return ((ImportConvertedInstanceAnswer) importAnswer).getConvertedInstance();
19491966
}
19501967

server/src/test/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImplTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,7 @@ private void baseTestImportVmFromVmwareToKvm(VcenterParameter vcenterParameter,
698698
ImportConvertedInstanceAnswer convertImportedInstanceAnswer = mock(ImportConvertedInstanceAnswer.class);
699699
when(convertInstanceAnswer.getResult()).thenReturn(vcenterParameter != VcenterParameter.CONVERT_FAILURE);
700700
when(convertImportedInstanceAnswer.getConvertedInstance()).thenReturn(instance);
701+
when(convertImportedInstanceAnswer.getResult()).thenReturn(vcenterParameter != VcenterParameter.CONVERT_FAILURE);
701702
if (VcenterParameter.AGENT_UNAVAILABLE != vcenterParameter) {
702703
when(agentManager.send(Mockito.eq(convertHostId), Mockito.any(ConvertInstanceCommand.class))).thenReturn(convertInstanceAnswer);
703704
when(agentManager.send(Mockito.eq(convertHostId), Mockito.any(ImportConvertedInstanceCommand.class))).thenReturn(convertImportedInstanceAnswer);

0 commit comments

Comments
 (0)