Skip to content

Commit 0692a29

Browse files
shwstppryadvr
andauthored
engine-orchestration: fix issue for empty product in vm metadata (#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 929cfbc commit 0692a29

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

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
@@ -1108,7 +1108,7 @@ protected void updateVmMetadataManufacturerAndProduct(VirtualMachineTO vmTO, VMI
11081108
}
11091109
vmTO.setMetadataManufacturer(metadataManufacturer);
11101110
String metadataProduct = VmMetadataProductName.valueIn(vm.getDataCenterId());
1111-
if (StringUtils.isBlank(metadataManufacturer)) {
1111+
if (StringUtils.isBlank(metadataProduct)) {
11121112
metadataProduct = String.format("CloudStack %s Hypervisor", vm.getHypervisorType().toString());
11131113
}
11141114
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
@@ -127,6 +127,9 @@ public GuestType getGuestType() {
127127
}
128128

129129
public String getManufacturer() {
130+
if (StringUtils.isEmpty(manufacturer)) {
131+
return "Apache Software Foundation";
132+
}
130133
return manufacturer;
131134
}
132135

@@ -135,6 +138,9 @@ public void setManufacturer(String manufacturer) {
135138
}
136139

137140
public String getProduct() {
141+
if (StringUtils.isEmpty(product)) {
142+
return "CloudStack KVM Hypervisor";
143+
}
138144
return product;
139145
}
140146

0 commit comments

Comments
 (0)