Skip to content

Commit

Permalink
engine-orchestration: fix issue for empty product in vm metadata (#9610)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
shwstppr and rohityadavcloud authored Sep 3, 2024
1 parent 929cfbc commit 0692a29
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public interface VirtualMachineManager extends Manager {
ConfigKey<String> VmMetadataProductName = new ConfigKey<>("Advanced", String.class,
"vm.metadata.product", "",
"If provided, a custom product name will be used in the instance metadata. When an empty" +
"value is set then default product name will be 'CloudStack <HYPERVISIOR_NAME> Hypervisor'. " +
"value is set then default product name will be 'CloudStack <HYPERVISOR_NAME> Hypervisor'. " +
"A custom product name may break cloud-init functionality with CloudStack datasource. Please " +
"refer documentation",
true, ConfigKey.Scope.Zone);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1108,7 +1108,7 @@ protected void updateVmMetadataManufacturerAndProduct(VirtualMachineTO vmTO, VMI
}
vmTO.setMetadataManufacturer(metadataManufacturer);
String metadataProduct = VmMetadataProductName.valueIn(vm.getDataCenterId());
if (StringUtils.isBlank(metadataManufacturer)) {
if (StringUtils.isBlank(metadataProduct)) {
metadataProduct = String.format("CloudStack %s Hypervisor", vm.getHypervisorType().toString());
}
vmTO.setMetadataProductName(metadataProduct);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1272,6 +1272,7 @@ private Pair<VirtualMachineTO, VMInstanceVO> getDummyVmTOAndVm() {
false, false, "Pass");
VMInstanceVO vm = Mockito.mock(VMInstanceVO.class);
Mockito.when(vm.getDataCenterId()).thenReturn(1L);
Mockito.when(vm.getHypervisorType()).thenReturn(HypervisorType.KVM);
return new Pair<>(virtualMachineTO, vm);
}

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

@Test
public void testUpdateVmMetadataManufacturerAndProductCustomManufacturerDefaultProduct() {
String manufacturer = "Custom";
overrideVmMetadataConfigValue(manufacturer, "");
Pair<VirtualMachineTO, VMInstanceVO> pair = getDummyVmTOAndVm();
VirtualMachineTO to = pair.first();
virtualMachineManagerImpl.updateVmMetadataManufacturerAndProduct(to, pair.second());
Assert.assertEquals(manufacturer, to.getMetadataManufacturer());
Assert.assertEquals("CloudStack KVM Hypervisor", to.getMetadataProductName());
}

@Test
public void testUpdateVmMetadataManufacturerAndProductCustomManufacturer() {
String manufacturer = UUID.randomUUID().toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ public GuestType getGuestType() {
}

public String getManufacturer() {
if (StringUtils.isEmpty(manufacturer)) {
return "Apache Software Foundation";
}
return manufacturer;
}

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

public String getProduct() {
if (StringUtils.isEmpty(product)) {
return "CloudStack KVM Hypervisor";
}
return product;
}

Expand Down

0 comments on commit 0692a29

Please sign in to comment.