mirror of https://github.com/apache/cloudstack.git
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>
This commit is contained in:
parent
929cfbc3e2
commit
0692a296ce
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -1108,7 +1108,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
|||
}
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -1272,6 +1272,7 @@ public class VirtualMachineManagerImplTest {
|
|||
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);
|
||||
}
|
||||
|
||||
|
|
@ -1284,6 +1285,17 @@ public class VirtualMachineManagerImplTest {
|
|||
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();
|
||||
|
|
|
|||
|
|
@ -127,6 +127,9 @@ public class LibvirtVMDef {
|
|||
}
|
||||
|
||||
public String getManufacturer() {
|
||||
if (StringUtils.isEmpty(manufacturer)) {
|
||||
return "Apache Software Foundation";
|
||||
}
|
||||
return manufacturer;
|
||||
}
|
||||
|
||||
|
|
@ -135,6 +138,9 @@ public class LibvirtVMDef {
|
|||
}
|
||||
|
||||
public String getProduct() {
|
||||
if (StringUtils.isEmpty(product)) {
|
||||
return "CloudStack KVM Hypervisor";
|
||||
}
|
||||
return product;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue