Fix nested virt marvin test

This commit is contained in:
nvazquez 2020-10-02 04:46:57 -03:00 committed by Harikrishna Patnala
parent 94bebe8792
commit 897cc4bdba
3 changed files with 74 additions and 66 deletions

View File

@ -1942,30 +1942,28 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
VmwareHelper.setBasicVmConfig(vmConfigSpec, vmSpec.getCpus(), vmSpec.getMaxSpeed(), getReservedCpuMHZ(vmSpec), (int) (vmSpec.getMaxRam() / (1024 * 1024)), VmwareHelper.setBasicVmConfig(vmConfigSpec, vmSpec.getCpus(), vmSpec.getMaxSpeed(), getReservedCpuMHZ(vmSpec), (int) (vmSpec.getMaxRam() / (1024 * 1024)),
getReservedMemoryMb(vmSpec), guestOsId, vmSpec.getLimitCpuUse(), deployAsIs); getReservedMemoryMb(vmSpec), guestOsId, vmSpec.getLimitCpuUse(), deployAsIs);
if (!deployAsIs) { // Check for multi-cores per socket settings
// Check for multi-cores per socket settings int numCoresPerSocket = 1;
int numCoresPerSocket = 1; String coresPerSocket = vmSpec.getDetails().get(VmDetailConstants.CPU_CORE_PER_SOCKET);
String coresPerSocket = vmSpec.getDetails().get(VmDetailConstants.CPU_CORE_PER_SOCKET); if (coresPerSocket != null) {
if (coresPerSocket != null) { String apiVersion = HypervisorHostHelper.getVcenterApiVersion(vmMo.getContext());
String apiVersion = HypervisorHostHelper.getVcenterApiVersion(vmMo.getContext()); // Property 'numCoresPerSocket' is supported since vSphere API 5.0
// Property 'numCoresPerSocket' is supported since vSphere API 5.0 if (apiVersion.compareTo("5.0") >= 0) {
if (apiVersion.compareTo("5.0") >= 0) { numCoresPerSocket = NumbersUtil.parseInt(coresPerSocket, 1);
numCoresPerSocket = NumbersUtil.parseInt(coresPerSocket, 1); vmConfigSpec.setNumCoresPerSocket(numCoresPerSocket);
vmConfigSpec.setNumCoresPerSocket(numCoresPerSocket);
}
} }
}
// Check for hotadd settings // Check for hotadd settings
vmConfigSpec.setMemoryHotAddEnabled(vmMo.isMemoryHotAddSupported(guestOsId)); vmConfigSpec.setMemoryHotAddEnabled(vmMo.isMemoryHotAddSupported(guestOsId));
String hostApiVersion = ((HostMO) hyperHost).getHostAboutInfo().getApiVersion(); String hostApiVersion = ((HostMO) hyperHost).getHostAboutInfo().getApiVersion();
if (numCoresPerSocket > 1 && hostApiVersion.compareTo("5.0") < 0) { if (numCoresPerSocket > 1 && hostApiVersion.compareTo("5.0") < 0) {
s_logger.warn("Dynamic scaling of CPU is not supported for Virtual Machines with multi-core vCPUs in case of ESXi hosts 4.1 and prior. Hence CpuHotAdd will not be" s_logger.warn("Dynamic scaling of CPU is not supported for Virtual Machines with multi-core vCPUs in case of ESXi hosts 4.1 and prior. Hence CpuHotAdd will not be"
+ " enabled for Virtual Machine: " + vmInternalCSName); + " enabled for Virtual Machine: " + vmInternalCSName);
vmConfigSpec.setCpuHotAddEnabled(false); vmConfigSpec.setCpuHotAddEnabled(false);
} else { } else {
vmConfigSpec.setCpuHotAddEnabled(vmMo.isCpuHotAddSupported(guestOsId)); vmConfigSpec.setCpuHotAddEnabled(vmMo.isCpuHotAddSupported(guestOsId));
}
} }
configNestedHVSupport(vmMo, vmSpec, vmConfigSpec); configNestedHVSupport(vmMo, vmSpec, vmConfigSpec);
@ -2479,11 +2477,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
} }
private String getGuestOsIdFromVmSpec(VirtualMachineTO vmSpec, boolean deployAsIs) { private String getGuestOsIdFromVmSpec(VirtualMachineTO vmSpec, boolean deployAsIs) {
String guestOsId = null; return translateGuestOsIdentifier(vmSpec.getArch(), vmSpec.getOs(), vmSpec.getPlatformEmulator()).value();
if (!deployAsIs) {
guestOsId = translateGuestOsIdentifier(vmSpec.getArch(), vmSpec.getOs(), vmSpec.getPlatformEmulator()).value();
}
return guestOsId;
} }
private Pair<String, String> getControllerInfoFromVmSpec(VirtualMachineTO vmSpec) throws CloudRuntimeException { private Pair<String, String> getControllerInfoFromVmSpec(VirtualMachineTO vmSpec) throws CloudRuntimeException {

View File

@ -98,51 +98,61 @@ class TestNestedVirtualization(cloudstackTestCase):
self.logger.debug("Updated global setting vmware.nested.virtualization.perVM to true") self.logger.debug("Updated global setting vmware.nested.virtualization.perVM to true")
rollback_nv_per_vm = True rollback_nv_per_vm = True
# 2) Deploy a vm try:
virtual_machine = VirtualMachine.create( # 2) Deploy a vm
self.apiclient, virtual_machine = VirtualMachine.create(
self.services["small"], self.apiclient,
accountid=self.account.name, self.services["small"],
domainid=self.account.domainid, accountid=self.account.name,
serviceofferingid=self.service_offering.id, domainid=self.account.domainid,
mode=self.services['mode'] serviceofferingid=self.service_offering.id,
) mode=self.services['mode']
self.assert_(virtual_machine is not None, "VM failed to deploy") )
self.assert_(virtual_machine.state == 'Running', "VM is not running") self.assert_(virtual_machine is not None, "VM failed to deploy")
self.logger.debug("Deployed vm: %s" % virtual_machine.id) self.assert_(virtual_machine.state == 'Running', "VM is not running")
self.logger.debug("Deployed vm: %s" % virtual_machine.id)
isolated_network = Network.create( isolated_network = Network.create(
self.apiclient, self.apiclient,
self.services["isolated_network"], self.services["isolated_network"],
self.account.name, self.account.name,
self.account.domainid, self.account.domainid,
networkofferingid=self.isolated_network_offering.id) networkofferingid=self.isolated_network_offering.id)
virtual_machine.add_nic(self.apiclient, isolated_network.id) virtual_machine.stop(self.apiclient)
virtual_machine.add_nic(self.apiclient, isolated_network.id)
virtual_machine.start(self.apiclient)
# 3) SSH into vm # 3) SSH into vm
ssh_client = virtual_machine.get_ssh_client() ssh_client = virtual_machine.get_ssh_client()
if ssh_client: if ssh_client:
# run ping test # run ping test
result = ssh_client.execute("cat /proc/cpuinfo | grep flags") result = ssh_client.execute("cat /proc/cpuinfo | grep flags")
self.logger.debug(result) self.logger.debug(result)
else: else:
self.fail("Failed to setup ssh connection to %s" % virtual_machine.public_ip) self.fail("Failed to setup ssh connection to %s" % virtual_machine.public_ip)
# 4) Revert configurations, if needed # 4) Revert configurations, if needed
self.rollback_nested_configurations(rollback_nv, rollback_nv_per_vm)
#5) Check for CPU flags: vmx for Intel and svm for AMD indicates nested virtualization is enabled
self.assert_(result is not None, "Empty result for CPU flags")
res = str(result)
self.assertTrue('vmx' in res or 'svm' in res or 'lm' in res)
except Exception as e:
self.debug('Error=%s' % e)
self.rollback_nested_configurations(rollback_nv, rollback_nv_per_vm)
raise e
def rollback_nested_configurations(self, rollback_nv, rollback_nv_per_vm):
if rollback_nv: if rollback_nv:
config_update = Configurations.update(self.apiclient, "vmware.nested.virtualization", "false") config_update = Configurations.update(self.apiclient, "vmware.nested.virtualization", "false")
self.logger.debug("Reverted global setting vmware.nested.virtualization back to false") self.logger.debug("Reverted global setting vmware.nested.virtualization back to false")
if rollback_nv_per_vm: if rollback_nv_per_vm:
config_update = Configurations.update(self.apiclient, "vmware.nested.virtualization", "false") config_update = Configurations.update(self.apiclient, "vmware.nested.virtualization.perVM", "false")
self.logger.debug("Reverted global setting vmware.nested.virtualization.perVM back to false") self.logger.debug("Reverted global setting vmware.nested.virtualization.perVM back to false")
#5) Check for CPU flags: vmx for Intel and svm for AMD indicates nested virtualization is enabled
self.assert_(result is not None, "Empty result for CPU flags")
res = str(result)
self.assertTrue('vmx' in res or 'svm' in res)
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
try: try:

View File

@ -227,11 +227,15 @@ public class VirtualMachineMO extends BaseMO {
s_logger.info("msg id: " + msg.getId()); s_logger.info("msg id: " + msg.getId());
s_logger.info("msg text: " + msg.getText()); s_logger.info("msg text: " + msg.getText());
} }
String logMsg = "Found that VM has a pending question that we need to answer programmatically, question id: " + msg.getId();
if ("msg.uuid.altered".equalsIgnoreCase(msg.getId())) { if ("msg.uuid.altered".equalsIgnoreCase(msg.getId())) {
s_logger.info("Found that VM has a pending question that we need to answer programmatically, question id: " + msg.getId() s_logger.info(logMsg + ", we will automatically answer as 'moved it' to address out of band HA for the VM");
+ ", we will automatically answer as 'moved it' to address out of band HA for the VM");
vmMo.answerVM(question.getId(), "1"); vmMo.answerVM(question.getId(), "1");
break; break;
} else if (msg.getId().equalsIgnoreCase("msg.cpuid.noVHVQuestion")) {
s_logger.info(logMsg + ", automatically answering 'yes'");
vmMo.answerVM(question.getId(), "0");
break;
} }
} }
} }