Skip to content

Commit 7d788dc

Browse files
shwstppryadvr
authored andcommitted
engine-orchestration: fix issue for empty product in vm metadata (apache#9610)
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com> Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> Co-authored-by: Rohit Yadav <rohit.yadav@shapeblue.com>
1 parent 855f4ea commit 7d788dc

4 files changed

Lines changed: 20 additions & 2 deletions

File tree

engine/api/src/main/java/com/cloud/vm/VirtualMachineManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public interface VirtualMachineManager extends Manager {
9696
ConfigKey<String> VmMetadataProductName = new ConfigKey<>("Advanced", String.class,
9797
"vm.metadata.product", "",
9898
"If provided, a custom product name will be used in the instance metadata. When an empty" +
99-
"value is set then default product name will be 'CloudStack <HYPERVISIOR_NAME> Hypervisor'. " +
99+
"value is set then default product name will be 'CloudStack <HYPERVISOR_NAME> Hypervisor'. " +
100100
"A custom product name may break cloud-init functionality with CloudStack datasource. Please " +
101101
"refer documentation",
102102
true, ConfigKey.Scope.Zone);

engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,7 @@ protected void updateVmMetadataManufacturerAndProduct(VirtualMachineTO vmTO, VMI
11141114
}
11151115
vmTO.setMetadataManufacturer(metadataManufacturer);
11161116
String metadataProduct = VmMetadataProductName.valueIn(vm.getDataCenterId());
1117-
if (StringUtils.isBlank(metadataManufacturer)) {
1117+
if (StringUtils.isBlank(metadataProduct)) {
11181118
metadataProduct = String.format("CloudStack %s Hypervisor", vm.getHypervisorType().toString());
11191119
}
11201120
vmTO.setMetadataProductName(metadataProduct);

engine/orchestration/src/test/java/com/cloud/vm/VirtualMachineManagerImplTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,6 +1272,7 @@ private Pair<VirtualMachineTO, VMInstanceVO> getDummyVmTOAndVm() {
12721272
false, false, "Pass");
12731273
VMInstanceVO vm = Mockito.mock(VMInstanceVO.class);
12741274
Mockito.when(vm.getDataCenterId()).thenReturn(1L);
1275+
Mockito.when(vm.getHypervisorType()).thenReturn(HypervisorType.KVM);
12751276
return new Pair<>(virtualMachineTO, vm);
12761277
}
12771278

@@ -1284,6 +1285,17 @@ public void testUpdateVmMetadataManufacturerAndProductDefaultManufacturer() {
12841285
Assert.assertEquals(VirtualMachineManager.VmMetadataManufacturer.defaultValue(), to.getMetadataManufacturer());
12851286
}
12861287

1288+
@Test
1289+
public void testUpdateVmMetadataManufacturerAndProductCustomManufacturerDefaultProduct() {
1290+
String manufacturer = "Custom";
1291+
overrideVmMetadataConfigValue(manufacturer, "");
1292+
Pair<VirtualMachineTO, VMInstanceVO> pair = getDummyVmTOAndVm();
1293+
VirtualMachineTO to = pair.first();
1294+
virtualMachineManagerImpl.updateVmMetadataManufacturerAndProduct(to, pair.second());
1295+
Assert.assertEquals(manufacturer, to.getMetadataManufacturer());
1296+
Assert.assertEquals("CloudStack KVM Hypervisor", to.getMetadataProductName());
1297+
}
1298+
12871299
@Test
12881300
public void testUpdateVmMetadataManufacturerAndProductCustomManufacturer() {
12891301
String manufacturer = UUID.randomUUID().toString();

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ public GuestType getGuestType() {
147147
}
148148

149149
public String getManufacturer() {
150+
if (StringUtils.isEmpty(manufacturer)) {
151+
return "Apache Software Foundation";
152+
}
150153
return manufacturer;
151154
}
152155

@@ -155,6 +158,9 @@ public void setManufacturer(String manufacturer) {
155158
}
156159

157160
public String getProduct() {
161+
if (StringUtils.isEmpty(product)) {
162+
return "CloudStack KVM Hypervisor";
163+
}
158164
return product;
159165
}
160166

0 commit comments

Comments
 (0)