Skip to content

Commit 0f0d908

Browse files
committed
Merge pull request #2019 from Accelerite/cs-9850
CLOUDSTACK-9851 travis CI build failure after merge of PR#1953 & CLOUDSTACK-9850Fixed travis CI failures happening after merge of PR#1953. Also fixed root volume detach that was broken after merge of PR#1953. I found following logs with root volume attach. ` 2017-03-24 23:19:48,380 DEBUG [o.a.c.f.j.i.AsyncJobManagerImpl] (API-Job-Executor-27:ctx-7c53d1bc job-44) (logid:f3b54257) Executing AsyncJobVO {id:44, userId: 2, accountId: 2, instanceType: Volume, instanceId: 3, cmd: org.apache.cloudstack.api.command.admin.volume.AttachVolumeCmdByAdmin, cmdInfo: {"apiKey":"PYHMg5HhOkmTQvlmZSe1dIDfTxl8uwreeFoqfj0a4zPCC-1XTuwH7H5I8Ac9fyvPbtNO1eN9THi72q8ATfs8hg","signature":"DD+ljbVWpWQw6FCl1tCDSYe5Ui0\u003d","httpmethod":"GET","deviceid":"0","ctxAccountId":"2","uuid":"2db57cd8-c96c-48f9-83c5-b9a79c852cc5","cmdEventType":"VOLUME.ATTACH","virtualmachineid":"9cb6a944-8775-4e11-961b-0e8dbdebf5a7","response":"json","ctxUserId":"2","ctxStartEventId":"117","id":"2db57cd8-c96c-48f9-83c5-b9a79c852cc5","ctxDetails":"{\"interface com.cloud.vm.VirtualMachine\":\"9cb6a944-8775-4e11-961b-0e8dbdebf5a7\",\"interface com.cloud.storage.Volume\":\"2db57cd8-c96c-48f9-83c5-b9a79c852cc5\"}"}, cmdVersion: 0, status: IN_PROGRESS, processStatus: 0, resultCode: 0, result: null, initMsid: 4278190080, completeMsid: null, lastUpdated: null, lastPolled: null, created: null } 2017-03-24 23:19:50,160 ERROR [c.c.v.VmWorkJobHandlerProxy] (Work-Job-Executor-15:ctx-489eb1dd job-44/job-45 ctx-cce17070) (logid:f3b54257) Invocation exception, caused by: java.lang.RuntimeException: deviceId should be 1,2,4-5 ` * pr/2019: CLOUDSTACK-9851 travis CI build failure after merge of PR#1953 Signed-off-by: Rajani Karuturi <rajani.karuturi@accelerite.com>
2 parents 525c45c + 7348f94 commit 0f0d908

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,7 +1433,7 @@ public Volume attachVolumeToVM(Long vmId, Long volumeId, Long deviceId) {
14331433
// that supported by hypervisor
14341434
if (deviceId == null || deviceId.longValue() != 0) {
14351435
List<VolumeVO> existingDataVolumes = _volsDao.findByInstanceAndType(vmId, Volume.Type.DATADISK);
1436-
int maxAttachableDataVolumesSupported = getMaxDataVolumesSupported(vm) - 2; //IDs: 0 (ROOT) and 3 (CD-ROM) are reserved
1436+
int maxAttachableDataVolumesSupported = getMaxDataVolumesSupported(vm);
14371437
if (existingDataVolumes.size() >= maxAttachableDataVolumesSupported) {
14381438
throw new InvalidParameterValueException("The specified VM already has the maximum number of data disks (" + maxAttachableDataVolumesSupported + ") attached. Please specify another VM.");
14391439
}
@@ -2634,11 +2634,12 @@ private int getMaxDataVolumesSupported(UserVmVO vm) {
26342634

26352635
private Long getDeviceId(UserVmVO vm, Long deviceId) {
26362636
// allocate deviceId
2637-
int maxDeviceId = getMaxDataVolumesSupported(vm) - 1;
2637+
int maxDevices = getMaxDataVolumesSupported(vm) + 2; // add 2 to consider devices root volume and cdrom
2638+
int maxDeviceId = maxDevices - 1;
26382639
List<VolumeVO> vols = _volsDao.findByInstance(vm.getId());
26392640
if (deviceId != null) {
2640-
if (deviceId.longValue() <= 0 || deviceId.longValue() > maxDeviceId || deviceId.longValue() == 3) {
2641-
throw new RuntimeException("deviceId should be 1,2,4-" + maxDeviceId);
2641+
if (deviceId.longValue() < 0 || deviceId.longValue() > maxDeviceId || deviceId.longValue() == 3) {
2642+
throw new RuntimeException("deviceId should be 0,1,2,4-" + maxDeviceId);
26422643
}
26432644
for (VolumeVO vol : vols) {
26442645
if (vol.getDeviceId().equals(deviceId)) {

0 commit comments

Comments
 (0)