Skip to content
Open
4 changes: 4 additions & 0 deletions api/src/main/java/com/cloud/vm/VmDetailConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ public interface VmDetailConstants {
String CPU_SPEED = "cpuSpeed";
String MEMORY = "memory";

// VM deployment with custom root disk offering params
String MIN_IOPS = "minIops";
String MAX_IOPS = "maxIops";

// Misc details for internal usage (not to be set/changed by user or admin)
String CPU_OVER_COMMIT_RATIO = "cpuOvercommitRatio";
String MEMORY_OVER_COMMIT_RATIO = "memoryOvercommitRatio";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public class UpdateStoragePoolCmd extends BaseCmd {
@Parameter(name = ApiConstants.TAGS, type = CommandType.LIST, collectionType = CommandType.STRING, description = "Comma-separated list of tags for the storage pool")
private List<String> tags;

@Parameter(name = ApiConstants.CAPACITY_IOPS, type = CommandType.LONG, required = false, description = "IOPS CloudStack can provision from this storage pool")
@Parameter(name = ApiConstants.CAPACITY_IOPS, type = CommandType.LONG, required = false, description = "IOPS CloudStack can provision from this storage pool",
validations = {ApiArgValidator.PositiveNumber})
private Long capacityIops;

@Parameter(name = ApiConstants.CAPACITY_BYTES, type = CommandType.LONG, required = false, description = "Bytes CloudStack can provision from this storage pool",validations={ApiArgValidator.PositiveNumber})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,12 @@
import com.cloud.vm.NicProfile;
import com.cloud.vm.VMInstanceVO;
import com.cloud.vm.VirtualMachineManager;
import com.cloud.vm.VmDetailConstants;
import com.cloud.vm.VmDiskInfo;
import com.cloud.vm.dao.UserVmDao;
import com.cloud.vm.dao.VMInstanceDetailsDao;
import com.cloud.vm.dao.VMInstanceDao;

import static org.apache.cloudstack.api.ApiConstants.MAX_IOPS;
import static org.apache.cloudstack.api.ApiConstants.MIN_IOPS;

@Component
public class CloudOrchestrator implements OrchestrationService {

Expand Down Expand Up @@ -205,8 +203,8 @@ public VirtualMachineEntity createVirtualMachine(String id, String owner, String
Map<String, String> userVmDetails = _vmInstanceDetailsDao.listDetailsKeyPairs(vm.getId());

if (userVmDetails != null) {
String minIops = userVmDetails.get(MIN_IOPS);
String maxIops = userVmDetails.get(MAX_IOPS);
String minIops = userVmDetails.get(VmDetailConstants.MIN_IOPS);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you check for setters also for iops specific statements?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From community, someone already raised the PR so i copied the same code as per the PR, will check the setter and update

String maxIops = userVmDetails.get(VmDetailConstants.MAX_IOPS);

rootDiskOfferingInfo.setMinIops(minIops != null && minIops.trim().length() > 0 ? Long.parseLong(minIops) : null);
rootDiskOfferingInfo.setMaxIops(maxIops != null && maxIops.trim().length() > 0 ? Long.parseLong(maxIops) : null);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.cloudstack.engine.orchestration;

import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.offering.DiskOfferingInfo;
import com.cloud.service.ServiceOfferingVO;
import com.cloud.service.dao.ServiceOfferingDao;
import com.cloud.storage.DiskOfferingVO;
import com.cloud.storage.VMTemplateVO;
import com.cloud.storage.dao.DiskOfferingDao;
import com.cloud.storage.dao.VMTemplateDao;
import com.cloud.utils.component.ComponentContext;
import com.cloud.vm.VMInstanceVO;
import com.cloud.vm.VirtualMachineManager;
import com.cloud.vm.VmDetailConstants;
import com.cloud.vm.dao.VMInstanceDao;
import com.cloud.vm.dao.VMInstanceDetailsDao;
import org.apache.cloudstack.engine.cloud.entity.api.VirtualMachineEntityImpl;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;

@RunWith(MockitoJUnitRunner.class)
public class CloudOrchestratorTest {

private static final long VM_ID = 1L;
private static final long SERVICE_OFFERING_ID = 2L;
private static final long ROOT_DISK_OFFERING_ID = 3L;
private static final String TEMPLATE_ID = "4";

@InjectMocks
private CloudOrchestrator cloudOrchestrator = new CloudOrchestrator();

@Mock
private VirtualMachineManager _itMgr;
@Mock
private VMTemplateDao _templateDao;
@Mock
private VMInstanceDao _vmDao;
@Mock
private VMInstanceDetailsDao _vmInstanceDetailsDao;
@Mock
private ServiceOfferingDao _serviceOfferingDao;
@Mock
private DiskOfferingDao _diskOfferingDao;

@Test
public void createVirtualMachineSetsCustomIopsFromVmDetails() throws Exception {
VMInstanceVO vm = Mockito.mock(VMInstanceVO.class);
ServiceOfferingVO serviceOffering = Mockito.mock(ServiceOfferingVO.class);
DiskOfferingVO rootDiskOffering = Mockito.mock(DiskOfferingVO.class);
VMTemplateVO template = Mockito.mock(VMTemplateVO.class);
VirtualMachineEntityImpl vmEntity = Mockito.mock(VirtualMachineEntityImpl.class);

Mockito.when(_vmDao.findByUuid("vm-uuid")).thenReturn(vm);
Mockito.when(vm.getId()).thenReturn(VM_ID);
Mockito.when(vm.getServiceOfferingId()).thenReturn(SERVICE_OFFERING_ID);
Mockito.when(vm.getInstanceName()).thenReturn("i-1-1-VM");
Mockito.when(_serviceOfferingDao.findById(VM_ID, SERVICE_OFFERING_ID)).thenReturn(serviceOffering);
Mockito.when(_diskOfferingDao.findById(ROOT_DISK_OFFERING_ID)).thenReturn(rootDiskOffering);
Mockito.when(rootDiskOffering.isCustomizedIops()).thenReturn(true);
Mockito.when(_templateDao.findById(Long.valueOf(TEMPLATE_ID))).thenReturn(template);

Map<String, String> details = new HashMap<>();
details.put(VmDetailConstants.MIN_IOPS, "100");
details.put(VmDetailConstants.MAX_IOPS, "1000");
Mockito.when(_vmInstanceDetailsDao.listDetailsKeyPairs(VM_ID)).thenReturn(details);

try (MockedStatic<ComponentContext> componentContext = Mockito.mockStatic(ComponentContext.class)) {
componentContext.when(() -> ComponentContext.inject(VirtualMachineEntityImpl.class)).thenReturn(vmEntity);

cloudOrchestrator.createVirtualMachine("vm-uuid", "owner", TEMPLATE_ID, "host", "display", HypervisorType.KVM.name(),
1, 1000, 1024, null, Collections.emptyList(), Collections.emptyList(), Collections.emptyMap(), null,
null, null, null, null, ROOT_DISK_OFFERING_ID, null, null, null, null);
}

ArgumentCaptor<DiskOfferingInfo> rootDiskOfferingInfo = ArgumentCaptor.forClass(DiskOfferingInfo.class);
Mockito.verify(_itMgr).allocate(Mockito.eq("i-1-1-VM"), Mockito.eq(template), Mockito.eq(serviceOffering), rootDiskOfferingInfo.capture(),
Mockito.anyList(), Mockito.anyList(), Mockito.any(LinkedHashMap.class), Mockito.isNull(), Mockito.eq(HypervisorType.KVM),
Mockito.isNull(), Mockito.isNull(), Mockito.isNull(), Mockito.isNull());

Assert.assertEquals(Long.valueOf(100), rootDiskOfferingInfo.getValue().getMinIops());
Assert.assertEquals(Long.valueOf(1000), rootDiskOfferingInfo.getValue().getMaxIops());
}
}
Loading
Loading