Skip to content
This repository was archived by the owner on Jan 15, 2020. It is now read-only.

Commit 4d7ede5

Browse files
author
Likitha Shetty
committed
CLOUDSTACK-8119. Propagate error message to UI for attach/detach volume failure operations.
For AttachVolume/DetachVolume API command, improve user error message in case of RuntimeException by throwing the exception instead of 'Unexpected Exception'.
1 parent 67eff27 commit 4d7ede5

3 files changed

Lines changed: 17 additions & 1 deletion

File tree

plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1367,7 +1367,11 @@ private Answer attachVolume(Command cmd, DiskTO disk, boolean isAttach, boolean
13671367
hostService.invalidateServiceContext(null);
13681368
}
13691369

1370-
String msg = "AttachVolumeCommand failed due to " + VmwareHelper.getExceptionMessage(e);
1370+
String msg = "";
1371+
if (isAttach)
1372+
msg += "Failed to attach volume: " + e.getMessage();
1373+
else
1374+
msg += "Failed to detach volume: " + e.getMessage();
13711375
s_logger.error(msg, e);
13721376
return new AttachAnswer(msg);
13731377
}

server/src/com/cloud/storage/VolumeApiServiceImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,6 +1378,8 @@ public Volume attachVolumeToVM(Long vmId, Long volumeId, Long deviceId) {
13781378
throw (ConcurrentOperationException)jobResult;
13791379
else if (jobResult instanceof InvalidParameterValueException)
13801380
throw (InvalidParameterValueException)jobResult;
1381+
else if (jobResult instanceof RuntimeException)
1382+
throw (RuntimeException)jobResult;
13811383
else if (jobResult instanceof Throwable)
13821384
throw new RuntimeException("Unexpected exception", (Throwable)jobResult);
13831385
else if (jobResult instanceof Long) {
@@ -1580,6 +1582,8 @@ public Volume detachVolumeFromVM(DetachVolumeCmd cmmd) {
15801582
if (jobResult != null) {
15811583
if (jobResult instanceof ConcurrentOperationException)
15821584
throw (ConcurrentOperationException)jobResult;
1585+
else if (jobResult instanceof RuntimeException)
1586+
throw (RuntimeException)jobResult;
15831587
else if (jobResult instanceof Throwable)
15841588
throw new RuntimeException("Unexpected exception", (Throwable)jobResult);
15851589
else if (jobResult instanceof Long) {

vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,6 +1126,14 @@ public List<Pair<String, ManagedObjectReference>> detachDisk(String vmdkDatastor
11261126
throw new Exception("No such disk device: " + vmdkDatastorePath);
11271127
}
11281128

1129+
// IDE virtual disk cannot be detached if VM is running
1130+
if (deviceInfo.second() != null && deviceInfo.second().contains("ide")) {
1131+
if (getPowerState() == VirtualMachinePowerState.POWERED_ON) {
1132+
throw new Exception("Removing a virtual disk over IDE controller is not supported while VM is running in VMware hypervisor. " +
1133+
"Please re-try when VM is not running.");
1134+
}
1135+
}
1136+
11291137
List<Pair<String, ManagedObjectReference>> chain = getDiskDatastorePathChain(deviceInfo.first(), true);
11301138

11311139
VirtualMachineConfigSpec reConfigSpec = new VirtualMachineConfigSpec();

0 commit comments

Comments
 (0)