Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions agent/conf/agent.properties
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,9 @@ hypervisor.type=kvm
# If null (default), defaults to the VM's OS architecture
#guest.cpu.arch=

# This param will require CPU features on the CPU section.
# The features listed in this property must be separated by a blank space (e.g.: vmx vme)
# Specifies required CPU features for end-user and system VMs.
# These features must be present on the host CPU for VM deployment.
# Multiple features should be separated by whitespace (e.g.: vmx vme).
#guest.cpu.features=

# Disables memory ballooning on VM guests for overcommit.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,9 @@ public class AgentProperties{
public static final Property<String> GUEST_CPU_ARCH = new Property<>("guest.cpu.arch", null, String.class);

/**
* This param will require CPU features on the CPU section.<br>
* The features listed in this property must be separated by a blank space (see example below).<br>
* Specifies required CPU features for end-user and system VMs.<br>
* These features must be present on the host CPU for VM deployment.<br>
* Multiple features should be separated by whitespace (see example below).<br>
* Possible values: vmx vme <br>
* Data type: String.<br>
* Default value: <code>null</code>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1316,15 +1316,7 @@ public boolean configure(final String name, final Map<String, Object> params) th
params.put("guest.cpu.model", guestCpuModel);
}

final String cpuFeatures = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.GUEST_CPU_FEATURES);
if (cpuFeatures != null) {
this.cpuFeatures = new ArrayList<String>();
for (final String feature: cpuFeatures.split(" ")) {
if (!feature.isEmpty()) {
this.cpuFeatures.add(feature);
}
}
}
this.cpuFeatures = parseCpuFeatures(AgentPropertiesFileHandler.getPropertyValue(AgentProperties.GUEST_CPU_FEATURES));

final String[] info = NetUtils.getNetworkParams(privateNic);

Expand Down Expand Up @@ -1430,6 +1422,22 @@ public boolean configure(final String name, final Map<String, Object> params) th
return true;
}

/**
* Parses a string containing whitespace-separated CPU feature names and converts it into a list.
*
* @param features A string containing whitespace-separated CPU feature names to be parsed.
* @return A list of CPU feature strings. Returns an empty list if {@code features} is null.
*/
protected List<String> parseCpuFeatures(String features) {
if (features == null) {
return new ArrayList<>();
}

return Arrays.stream(features.split(" "))
.filter(feature -> !feature.isEmpty())
.collect(Collectors.toList());
}

/**
* Gets the ID list of the VMs to set memory balloon stats period.
* @param conn the Libvirt connection.
Expand Down Expand Up @@ -3210,9 +3218,7 @@ private CpuModeDef createCpuModeDef(VirtualMachineTO vmTO, int vcpus) {
String cpuModel = MapUtils.isNotEmpty(details) && details.get(VmDetailConstants.GUEST_CPU_MODEL) != null ? details.get(VmDetailConstants.GUEST_CPU_MODEL) : guestCpuModel;
cmd.setMode(cpuMode);
cmd.setModel(cpuModel);
if (VirtualMachine.Type.User.equals(vmTO.getType())) {
cmd.setFeatures(cpuFeatures);
}
cmd.setFeatures(cpuFeatures);
int vCpusInDef = vmTO.getVcpuMaxLimit() == null ? vcpus : vmTO.getVcpuMaxLimit();
setCpuTopology(cmd, vCpusInDef, vmTO.getDetails());
return cmd;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7126,4 +7126,20 @@ public void testParseGpuDevicesFromResult_withSuccess() {
assertEquals("2g.10gb", vfInstance2.getModelName());
assertNull(vfInstance2.getVmName());
}

@Test
public void parseCpuFeaturesTestReturnEmptyListWhenFeaturesIsNull() {
List<String> cpuFeatures = libvirtComputingResourceSpy.parseCpuFeatures(null);
Assert.assertEquals(0, cpuFeatures.size());
}

@Test
public void parseCpuFeaturesTestReturnListOfCpuFeaturesAndIgnoreMultipleWhitespacesAlongsideEachOther() {
List<String> cpuFeatures = libvirtComputingResourceSpy.parseCpuFeatures(" -mca mce -mmx hle ");
Assert.assertEquals(4, cpuFeatures.size());
Assert.assertEquals("-mca", cpuFeatures.get(0));
Assert.assertEquals("mce", cpuFeatures.get(1));
Assert.assertEquals("-mmx", cpuFeatures.get(2));
Assert.assertEquals("hle", cpuFeatures.get(3));
}
}
Loading