Skip to content

Commit 272f282

Browse files
Likitha Shettyyadvr
authored andcommitted
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'. (cherry picked from commit 4d7ede5) Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com> Conflicts: server/src/com/cloud/storage/VolumeApiServiceImpl.java
1 parent b9932a0 commit 272f282

3 files changed

Lines changed: 19 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
@@ -1357,7 +1357,11 @@ private Answer attachVolume(Command cmd, DiskTO disk, boolean isAttach, boolean
13571357
hostService.invalidateServiceContext(null);
13581358
}
13591359

1360-
String msg = "AttachVolumeCommand failed due to " + VmwareHelper.getExceptionMessage(e);
1360+
String msg = "";
1361+
if (isAttach)
1362+
msg += "Failed to attach volume: " + e.getMessage();
1363+
else
1364+
msg += "Failed to detach volume: " + e.getMessage();
13611365
s_logger.error(msg, e);
13621366
return new AttachAnswer(msg);
13631367
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,6 +1387,10 @@ public Volume attachVolumeToVM(Long vmId, Long volumeId, Long deviceId) {
13871387
if (jobResult != null) {
13881388
if (jobResult instanceof ConcurrentOperationException)
13891389
throw (ConcurrentOperationException)jobResult;
1390+
else if (jobResult instanceof InvalidParameterValueException)
1391+
throw (InvalidParameterValueException)jobResult;
1392+
else if (jobResult instanceof RuntimeException)
1393+
throw (RuntimeException)jobResult;
13901394
else if (jobResult instanceof Throwable)
13911395
throw new RuntimeException("Unexpected exception", (Throwable)jobResult);
13921396
else if (jobResult instanceof Long) {
@@ -1590,6 +1594,8 @@ public Volume detachVolumeFromVM(DetachVolumeCmd cmmd) {
15901594
if (jobResult != null) {
15911595
if (jobResult instanceof ConcurrentOperationException)
15921596
throw (ConcurrentOperationException)jobResult;
1597+
else if (jobResult instanceof RuntimeException)
1598+
throw (RuntimeException)jobResult;
15931599
else if (jobResult instanceof Throwable)
15941600
throw new RuntimeException("Unexpected exception", (Throwable)jobResult);
15951601
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
@@ -1164,6 +1164,14 @@ public List<Pair<String, ManagedObjectReference>> detachDisk(String vmdkDatastor
11641164
throw new Exception("No such disk device: " + vmdkDatastorePath);
11651165
}
11661166

1167+
// IDE virtual disk cannot be detached if VM is running
1168+
if (deviceInfo.second() != null && deviceInfo.second().contains("ide")) {
1169+
if (getPowerState() == VirtualMachinePowerState.POWERED_ON) {
1170+
throw new Exception("Removing a virtual disk over IDE controller is not supported while VM is running in VMware hypervisor. " +
1171+
"Please re-try when VM is not running.");
1172+
}
1173+
}
1174+
11671175
List<Pair<String, ManagedObjectReference>> chain = getDiskDatastorePathChain(deviceInfo.first(), true);
11681176

11691177
VirtualMachineConfigSpec reConfigSpec = new VirtualMachineConfigSpec();

0 commit comments

Comments
 (0)