def TestVQATDeviceType(vm1): """ Test adding QAT devices with various deviceTypes """ CheckQATNotPresent(vm1) Log("Adding VQAT with deviceType") cspec = vim.vm.ConfigSpec() # Add VQAT devices with a variety of deviceTypes to VM. deviceTypes = ["C62XVF", "C62XVF-crypto", "C62XVF-compression"] for deviceType in deviceTypes: AddVQAT(cspec, deviceType=deviceType) vm.Reconfigure(vm1, cspec) # Iterate through qatDevices and build both a remove spec # and a list of the QAT backing deviceTypes seen. qatDevices = vmconfig.CheckDevice(vm1.config, vim.vm.device.VirtualQAT) backingDeviceTypes = [] cspec = vim.vm.ConfigSpec() for qat in qatDevices: deviceType = qat.backing.deviceType if deviceType is None: raise Exception("qat device with unset deviceType") backingDeviceTypes.append(deviceType) vmconfig.AddDeviceToSpec( cspec, qat, vim.vm.device.VirtualDeviceSpec.Operation.remove) # Should see all of the configured deviceTypes in the returned # backing deviceTypes. if sorted(deviceTypes) != sorted(backingDeviceTypes): raise Exception("Invalid device types after reconfiguration: " + ",".join(backingDeviceTypes)) # Remove all QAT device and verify no QAT devices remain on VM. vm.Reconfigure(vm1, cspec) CheckQATNotPresent(vm1)
def TestSataCtlrReconfig(vm1): """ Test add and remove for SATA controller """ Log("Adding SATA controller to VM") cspec = Vim.Vm.ConfigSpec() cspec = vmconfig.AddSataCtlr(cspec, cfgInfo = vm1.config) vm.Reconfigure(vm1, cspec) # Check for controller presence in VM's config ctlrs = vmconfig.CheckDevice(vm1.config, Vim.Vm.Device.VirtualAHCIController) if len(ctlrs) != 1: raise Exception("Failed to find added SATA controller :" + str(len(ctlrs))) Log("Powering on VM " + vm1.config.GetName()) vm.PowerOn(vm1) Log("Hot-add SATA controller to VM") cspec = Vim.Vm.ConfigSpec() cspec = vmconfig.AddSataCtlr(cspec, cfgInfo = vm1.config) vm.Reconfigure(vm1, cspec) ctlrs = vmconfig.CheckDevice(vm1.config, Vim.Vm.Device.VirtualAHCIController) if len(ctlrs) != 2: raise Exception("Failed to find added SATA controller :" + str(len(ctlrs))) vm.PowerOff(vm1) # Remove SATA controller from VM Log("Removing SATA controllers from VM") cspec = Vim.Vm.ConfigSpec() vmconfig.AddDeviceToSpec(cspec, ctlrs[0], Vim.Vm.Device.VirtualDeviceSpec.Operation.remove) vmconfig.AddDeviceToSpec(cspec, ctlrs[1], Vim.Vm.Device.VirtualDeviceSpec.Operation.remove) vm.Reconfigure(vm1, cspec)
def TestEK(vm1, val, fault, expected=None): tpm = CreateVTPM(TPM_DEV_KEY) if val is not None: val = [VmomiSupport.binary(v) for v in val] tpm.endorsementKeyCertificate = val Log("Trying to set EK certificate to '%s'" % val) cspec = vim.vm.ConfigSpec() vmconfig.AddDeviceToSpec(cspec, tpm, vim.vm.device.VirtualDeviceSpec.Operation.edit) if fault is None: vm.Reconfigure(vm1, cspec) else: try: vm.Reconfigure(vm1, cspec) raise Exception("Reconfigure did not fail for %s" % cspec) except vim.fault.GenericVmConfigFault as e: ok = False for m in e.faultMessage: if m.key == fault: ok = True if not ok: raise except vmodl.fault.InvalidArgument as e: if e.invalidProperty != fault: raise tpm = CheckTPMPresent(vm1) if expected is None: expected = val ekc = tpm.endorsementKeyCertificate if len(expected) != len(ekc): raise Exception("After setting EK to '%s', it is '%s'" % (val, ekc)) for l, r in zip(expected, ekc): if l != r: raise Exception("After setting EK to '%s', it is '%s'" % (val, ekc))
def TestHotPlugCpu(vm1, add, positive, opLabel): Log("Testing CPU hot " + opLabel + " for VM " + vm1.GetConfig().GetName()) curCpu = vm1.GetConfig().GetHardware().GetNumCPU() newCpu = curCpu if add: newCpu += 1 else: newCpu -= 1 # Check for a valid CPU count if newCpu == 0: raise Exception("Cpu count cannot be zero") Log("Current cpu count : " + str(curCpu)) # Making sure that hot plug cpu is not enabled Log("Powering off VM") vm.PowerOff(vm1) cspec = Vim.Vm.ConfigSpec() if add: cspec.SetCpuHotAddEnabled(False) else: cspec.SetCpuHotRemoveEnabled(False) vm.Reconfigure(vm1, cspec) Log("Powering on the VM") vm.PowerOn(vm1) # Negative test case - changing CPU count when not allowed Log("Attempting to change CPUs without setting enabled flag") ChangeCpu(vm1, newCpu, False) # Enabling CPU hot add/remove on the VM Log("Powering off VM") vm.PowerOff(vm1) Log("Enabling cpu hot plug") cspec = Vim.Vm.ConfigSpec() if add: cspec.SetCpuHotAddEnabled(True) else: cspec.SetCpuHotRemoveEnabled(True) vm.Reconfigure(vm1, cspec) Log("Powering on the VM") vm.PowerOn(vm1) # Verify reported CPU hot-plug enabled settings Log("Verifying if cpu hot plug enabled is populated") cfgInfo = vm1.GetConfig() if add and cfgInfo.GetCpuHotAddEnabled() != True or \ (not add and cfgInfo.GetCpuHotRemoveEnabled() != True) : raise Exception("Cpu hot plug enabled not set correctly!") # Test CPU hot-plug ChangeCpu(vm1, newCpu, positive) if not positive: return curCpu = vm1.GetConfig().GetHardware().GetNumCPU() if curCpu != newCpu: raise Exception("Cpu count " + str(curCpu) + " not equal to " + str(newCpu))
def TestHotPlugDevice( vm1, func, label, devType, positive, testRemove=True, leaveInVm=False, fileOp=None, ): Log("Testing " + label + " hot plug for VM " + vm1.GetConfig().GetName()) failed = False Log("Add a new " + label + " to the VM") cspec = Vim.Vm.ConfigSpec() cspec = func(cspec, cfgInfo=vm1.GetConfig()) devicesBefore = vmconfig.CheckDevice(vm1.GetConfig(), devType) # Hot-add the device try: vm.Reconfigure(vm1, cspec) except Exception as e: failed = True if not positive: Log("Caught exception as expected") return else: raise if not positive and not failed: raise Exception("Did not hit an exception as expected") # Check for device presence in VM's config devicesAfter = vmconfig.CheckDevice(vm1.GetConfig(), devType) if len(devicesAfter) == len(devicesBefore): raise Exception("Failed to find added " + label) if not testRemove: return # Hot-remove the device newDev = devicesAfter[len(devicesAfter) - 1] Log("Removing " + label + " from the VM") cspec = Vim.Vm.ConfigSpec() vmconfig.RemoveDeviceFromSpec(cspec, newDev, fileOp) vm.Reconfigure(vm1, cspec) devicesAfter = vmconfig.CheckDevice(vm1.GetConfig(), devType) # Check for device absence in the VM's config if len(devicesAfter) != len(devicesBefore): raise Exception(label + " still found in the VM") # Add device back into the VM if necessary if leaveInVm: cspec = Vim.Vm.ConfigSpec() cspec = func(cspec) vm.Reconfigure(vm1, cspec)
def TestCreateDisk(vm1): """ Creating disk with various combination of capacityInBytes and capacityInKB. """ Log("Add a new disk with capacityInKB greater than capacityInBytes.") # server must consider capacityInBytes cspec = Vim.Vm.ConfigSpec() cspec = vmconfig.AddScsiCtlr(cspec, cfgInfo = vm1.config) capacityKB = 4 * 1024 vmconfig.AddScsiDisk(cspec, cfgInfo = vm1.config, capacity = capacityKB) vm.Reconfigure(vm1, cspec) # Server must always return "capacityInBytes" devices = vmconfig.CheckDevice(vm1.config, Vim.Vm.Device.VirtualDisk, {"capacityInKB": capacityKB, "capacityInBytes": (capacityKB * 1024)}) if len(devices) != 1: raise Exception("Failed to find new disk!") Log("Add a new disk with capacityInBytes bigger than capacityInKB.") cspec = Vim.Vm.ConfigSpec() capacityBytes = (capacityKB * 1024) + SECTOR_SIZE vmconfig.AddScsiDisk(cspec, cfgInfo = vm1.GetConfig(), capacity = capacityKB, capacityInBytes = capacityBytes) vm.Reconfigure(vm1, cspec) devices = vmconfig.CheckDevice(vm1.config, Vim.Vm.Device.VirtualDisk, {"capacityInKB": capacityKB, "capacityInBytes": capacityBytes}) if len(devices) != 1: raise Exception("Capacity did not match expected values!") cspec = Vim.Vm.ConfigSpec() # server must consider capacityInBytes capacityBytes = 2*capacityKB*1024 - SECTOR_SIZE vmconfig.AddScsiDisk(cspec, cfgInfo = vm1.config, capacity = capacityKB, capacityInBytes = capacityBytes) vm.Reconfigure(vm1, cspec) devices = vmconfig.CheckDevice(vm1.config, Vim.Vm.Device.VirtualDisk, {"capacityInKB": (2 * capacityKB)-1, "capacityInBytes": capacityBytes}) if len(devices) != 1: raise Exception("Capacity did not match expected values!") Log("Removing virtual disks from VM.") devices = vmconfig.CheckDevice(vm1.config, Vim.Vm.Device.VirtualDisk) fileOp = Vim.Vm.Device.VirtualDeviceSpec.FileOperation.destroy cspec = Vim.Vm.ConfigSpec() for device in devices: vmconfig.RemoveDeviceFromSpec(cspec, device, fileOp) vm.Reconfigure(vm1, cspec)
def SetExtraConfig(vm1, key, value, positive=True): success = False extraCfg = vm1.config.extraConfig if not EditExtraConfig(extraCfg, key, value): AddExtraConfig(extraCfg, key, value) try: cspec = Vim.Vm.ConfigSpec() cspec.SetExtraConfig(extraCfg) vm.Reconfigure(vm1, cspec) Log("Reconfigured VM") success = True except Exception as e: if not positive: Log("Expected exception %s in negative test case" % e) return else: raise if success and not positive: raise Exception("Did not hit exception for negative test case.") if not VerifyInExtraConfig(vm1.config.extraConfig, key, value): raise Exception("Could not find entry in VM's extraConfig") else: Log("Validated entry in VM's extraConfig")
def TestWithSnapshot(vm1): """ Verify that it is not possible to extend delta disk by changing capacityInBytes. """ cspec = Vim.Vm.ConfigSpec() vmconfig.AddScsiDisk(cspec, cfgInfo = vm1.config) vm.Reconfigure(vm1, cspec) devices = vmconfig.CheckDevice(vm1.config, Vim.Vm.Device.VirtualDisk) if len(devices) != 1: raise Exception("Failed to find new disk!") # attempt to extend a disk with a parent Log("Creating a snapshot on the VM for negative disk extend test.") vm.CreateSnapshot(vm1, "dummy snapshot", "dummy desc", False, False) Log("Attempting to extend disk size of delta disk.") disk = vmconfig.CheckDevice(vm1.config, Vim.Vm.Device.VirtualDisk)[0] cspec = Vim.Vm.ConfigSpec() disk.capacityInBytes = disk.capacityInBytes + 1024 vmconfig.AddDeviceToSpec(cspec, disk, Vim.Vm.Device.VirtualDeviceSpec.Operation.edit) task = vm1.Reconfigure(cspec) try: WaitForTask(task) except Exception as e: Log("Hit an exception extending delta disk as expected" + str(e)) else: raise Exception("Error: Extending delta disk was allowed!") Log("Removing all snapshots on the VM.") vm.RemoveAllSnapshots(vm1)
def TestEditSataCdrom(vm1): """ Test reconfigures of SATA cdroms """ cspec = Vim.Vm.ConfigSpec() cspec = vmconfig.AddSataCtlr(cspec) vm.Reconfigure(vm1, cspec) Log("Add SATA cdrom.") AddSataCdrom(vm1) Log("Reconfigure cdrom backing.") TestReconfigCdromBacking(vm1) Log("Snapshot VM and revert to snapshot.") TestSnapshotCdrom(vm1) Log("Moving cdrom from SATA to IDE controller.") ideCtlrs = vmconfig.CheckDevice(vm1.config, Vim.Vm.Device.VirtualIDEController) cdrom = vmconfig.CheckDevice(vm1.config, Vim.Vm.Device.VirtualCdrom)[0] TestMoveDevice(vm1, cdrom, ideCtlrs[0]) Log("Remove cdrom.") RemoveSataCdrom(vm1) Log("Testing hot-add and hot-remove of SATA cdrom.") vm.PowerOn(vm1) AddSataCdrom(vm1) RemoveSataCdrom(vm1) vm.PowerOff(vm1) ctlrs = vmconfig.CheckDevice(vm1.config, Vim.Vm.Device.VirtualSATAController) vm.RemoveDevice(vm1, ctlrs[0])
def TestVQATReconfig(vm1): """ Test add and remove for VQAT controller """ Log("Adding VQAT") cspec = vim.vm.ConfigSpec() for i in range(MAX_QAT_DEV): AddVQAT(cspec) vm.Reconfigure(vm1, cspec) CheckQATPresent(vm1, MAX_QAT_DEV) TestAdd5thQAT(vm1) TestVQATRemoveInvalid(vm1) CheckQATPresent(vm1, MAX_QAT_DEV) TestVQATMove(vm1, -1) TestVQATMove(vm1, QAT_DEV_KEY) TestVQATMove(vm1, 100) vm.PowerOn(vm1) try: TestVQATRemoveInvalid(vm1) TestVQATHotRemove(vm1) finally: vm.PowerOff(vm1) # Remove QAT controller from VM Log("Removing QAT devices from VM") for i in range(MAX_QAT_DEV): RemoveDev(vm1, CreateVQAT(QAT_DEV_KEY + i)) CheckQATNotPresent(vm1)
def TestVTPMReconfig(vm1): """ Test add and remove for vTPM controller """ Log("Adding vTPM") cspec = vim.vm.ConfigSpec() AddVTPM(cspec) vm.Reconfigure(vm1, cspec) CheckTPMPresent(vm1) TestAdd2ndTPM(vm1) TestVTPMRemoveInvalid(vm1) CheckTPMPresent(vm1) TestVTPMMove(vm1, -1) TestVTPMMove(vm1, TPM_DEV_KEY) TestVTPMMove(vm1, 100) TestVTPMProps(vm1) vm.PowerOn(vm1) try: TestVTPMProps(vm1) TestVTPMRemoveInvalid(vm1) TestVTPMHotRemove(vm1) finally: vm.PowerOff(vm1) # Remove TPM controller from VM Log("Removing TPM device from VM") TestVTPMRemoveDev(vm1, CreateVTPM(TPM_DEV_KEY))
def TestVWDTReconfig(vm1): """ Test add and remove for vWDT controller """ Log("Adding vWDT") cspec = vim.vm.ConfigSpec() AddVWDT(cspec) vm.Reconfigure(vm1, cspec) CheckWDTPresent(vm1) TestAdd2ndWDT(vm1) TestVWDTRemoveInvalid(vm1) CheckWDTPresent(vm1) TestVWDTReplaceKey(vm1, -1) TestVWDTReplaceKey(vm1, WATCHDOGTIMER_DEV_KEY) TestVWDTReplaceKey(vm1, 100) vm.PowerOn(vm1) try: TestVWDTRemoveInvalid(vm1) TestVWDTHotRemove(vm1) finally: vm.PowerOff(vm1) # Remove vWDT controller from VM Log("Removing watchdog timer from VM") TestVWDTRemoveDev(vm1, CreateVWDT(WATCHDOGTIMER_DEV_KEY))
def TestVTPMMove(vm1, key): Log("Replacing vTPM device with new key=%s" % key) cspec = vim.vm.ConfigSpec() vmconfig.AddDeviceToSpec(cspec, CreateVTPM(TPM_DEV_KEY), vim.vm.device.VirtualDeviceSpec.Operation.remove) vmconfig.AddDeviceToSpec(cspec, CreateVTPM(key), vim.vm.device.VirtualDeviceSpec.Operation.add) vm.Reconfigure(vm1, cspec) CheckTPMPresent(vm1)
def TestVWDTReplaceKey(vm1, key): Log("Replacing vWDT with new key=%s" % key) cspec = vim.vm.ConfigSpec() vmconfig.AddDeviceToSpec(cspec, CreateVWDT(WATCHDOGTIMER_DEV_KEY), vim.vm.device.VirtualDeviceSpec.Operation.remove) vmconfig.AddDeviceToSpec(cspec, CreateVWDT(key), vim.vm.device.VirtualDeviceSpec.Operation.add) vm.Reconfigure(vm1, cspec) CheckWDTPresent(vm1)
def TestVQATMove(vm1, key): Log("Replacing VQAT device with new key=%s" % key) cspec = vim.vm.ConfigSpec() vmconfig.AddDeviceToSpec(cspec, CreateVQAT(QAT_DEV_KEY), vim.vm.device.VirtualDeviceSpec.Operation.remove) vmconfig.AddDeviceToSpec(cspec, CreateVQAT(key), vim.vm.device.VirtualDeviceSpec.Operation.add) vm.Reconfigure(vm1, cspec) CheckQATPresent(vm1, MAX_QAT_DEV)
def RemoveSataDisk(vm1): disk = vmconfig.CheckDevice(vm1.config, Vim.Vm.Device.VirtualDisk)[0] cspec = Vim.Vm.ConfigSpec() fileOp = Vim.Vm.Device.VirtualDeviceSpec.FileOperation.destroy vmconfig.RemoveDeviceFromSpec(cspec, disk, fileOp) vm.Reconfigure(vm1, cspec) devices = vmconfig.CheckDevice(vm1.config, Vim.Vm.Device.VirtualDisk) if len(devices) != 0: raise Exception("Found disk after delete")
def TestVTPMHotAdd(vm1): Log("Trying to hot-add vTPM") cspec = vim.vm.ConfigSpec() AddVTPM(cspec) try: vm.Reconfigure(vm1, cspec) raise Exception("TPM hot-add did not raise exception") except vim.fault.InvalidPowerState as e: pass CheckTPMNotPresent(vm1)
def TestNoVTPMRemoveDev(vm1, dev, fault=vim.fault.InvalidDeviceSpec): cspec = vim.vm.ConfigSpec() vmconfig.AddDeviceToSpec(cspec, dev, vim.vm.device.VirtualDeviceSpec.Operation.remove) try: vm.Reconfigure(vm1, cspec) raise Exception("Reconfigure for TPM %s did not raise exception" % cspec) except fault as e: pass
def TestVWDTHotAdd(vm1): Log("Trying to hot-add vWDT") cspec = vim.vm.ConfigSpec() AddVWDT(cspec) try: vm.Reconfigure(vm1, cspec) raise Exception("Watchdog timer hot-add did not raise exception") except vim.fault.InvalidPowerState as e: pass CheckWDTNotPresent(vm1)
def TestEditDisk(vm1): """ Test reconfigures of capacityInBytes and capacityInKB when both are set and differ. """ Log("Adding a new disk.") cspec = Vim.Vm.ConfigSpec() vmconfig.AddScsiDisk(cspec, cfgInfo = vm1.config) vm.Reconfigure(vm1, cspec) devices = vmconfig.CheckDevice(vm1.config, Vim.Vm.Device.VirtualDisk) if len(devices) != 1: raise Exception("Failed to find new disk!") disk = devices[0] Log("Increase disk size by 4MB setting capacityInBytes") cspec = Vim.Vm.ConfigSpec() newCapacity = disk.capacityInBytes + 4 * 1024 * 1024 + SECTOR_SIZE newCapacityKB = (newCapacity - SECTOR_SIZE) / 1024 disk.capacityInBytes = newCapacity vmconfig.AddDeviceToSpec(cspec, disk, Vim.Vm.Device.VirtualDeviceSpec.Operation.edit) vm.Reconfigure(vm1, cspec) devices = vmconfig.CheckDevice(vm1.config, Vim.Vm.Device.VirtualDisk, {"capacityInBytes": newCapacity, "capacityInKB": newCapacityKB}) if len(devices) != 1: raise Exception("Failed to find the disk with updated capacity: " + str(len(devices))) Log("Atempt to increase only capacityInKB.") newCapacityKB = newCapacityKB + 4*1024 disk.capacityInKB = newCapacityKB cspec = Vim.Vm.ConfigSpec() vmconfig.AddDeviceToSpec(cspec, disk, Vim.Vm.Device.VirtualDeviceSpec.Operation.edit) vm.Reconfigure(vm1, cspec) devices = vmconfig.CheckDevice(vm1.config, Vim.Vm.Device.VirtualDisk, {"capacityInKB": newCapacityKB}) if len(devices) != 1: raise Exception("Failed to find the disk with updated capacity: " + str(len(devices))) Log("Removing virtual disk from VM") cspec = Vim.Vm.ConfigSpec() fileOp = Vim.Vm.Device.VirtualDeviceSpec.FileOperation.destroy vmconfig.RemoveDeviceFromSpec(cspec, devices[0], fileOp) vm.Reconfigure(vm1, cspec)
def TestReconfigCdromBacking(vm1): cdrom = vmconfig.CheckDevice(vm1.config, Vim.Vm.Device.VirtualCdrom)[0] cspec = Vim.Vm.ConfigSpec() backing = Vim.Vm.Device.VirtualCdrom.IsoBackingInfo(fileName="[]") cdrom.backing = backing vmconfig.AddDeviceToSpec(cspec, cdrom, Vim.Vm.Device.VirtualDeviceSpec.Operation.edit) vm.Reconfigure(vm1, cspec) devices = vmconfig.CheckDevice(vm1.config, Vim.Vm.Device.VirtualCdrom, {"backing.fileName": "[]"}) if len(devices) != 1: raise Exception("Failed to find edited cdrom!")
def editDisk(options, machine, diskDev, shared): cspec = Vim.Vm.ConfigSpec() if shared: diskDev.backing.sharing = VirtualDisk.Sharing.sharingMultiWriter else: diskDev.backing.sharing = VirtualDisk.Sharing.sharingNone vmconfig.AddDeviceToSpec(cspec, diskDev, VirtualDeviceSpec.Operation.edit) vm.Reconfigure(machine, cspec) Log("Reconfigure(%s) - edit disk" % machine.name)
def TestVTPMVDRemove(vm1): """ Test vTPM removal via key """ Log("Adding vTPM with positive key") cspec = vim.vm.ConfigSpec() AddVTPM(cspec, key=TPM_DEV_KEY) vm.Reconfigure(vm1, cspec) CheckTPMPresent(vm1) Log("Removing vTPM device from VM using virtual device with vTPM key") TestVTPMRemoveDev(vm1, CreateVD(TPM_DEV_KEY))
def main(): options, remainingOptions = ParseArgs(sys.argv[1:]) # Connect to hosts. si = connect.Connect(host=options.host, user=options.user, pwd=options.pwd) atexit.register(Disconnect, si) if options.verbose: logger.setLevel(logging.DEBUG) logger.info("Starting test run") vm1 = None status = "FAIL" try: logger.info("Retrieving vm: %s", options.vmname) vm1 = vm.CreateOrReturnExisting(options.vmname) config = vm1.GetConfig() cspec = Vim.Vm.ConfigSpec() files = config.files logger.info("Changing %s 's snapshotDir to %s", options.vmname, options.dspath) try: m = re.match('\[([^\]]+)\] .*', options.dspath) except: logger.error('path "%s" is not valid datastore path', options.dspath) raise Exception, "dspath is not valid" files.snapshotDirectory = options.dspath dsListOld = [ds for ds in vm1.datastore if ds.name == m.groups()[0]] if not dsListOld: cspec.SetFiles(files) vm.Reconfigure(vm1, cspec) dsListNew = [ ds for ds in vm1.datastore if ds.name == m.groups()[0] ] if dsListNew: logger.info("%s has been added to vm.datastore property", options.dspath) status = "PASS" else: logger.info("%s has not been added to vm.datastore property", options.dspath) else: logger.info("%s is already present in the vm.datastore property", options.dspath) except Exception as e: logger.error("Caught exception: " + str(e)) status = "FAIL" logger.info("Test run complete: " + status)
def TestVWDTVDRemove(vm1): """ Test vWDT removal via key """ Log("Adding vWDT with positive key") cspec = vim.vm.ConfigSpec() AddVWDT(cspec, key=WATCHDOGTIMER_DEV_KEY) vm.Reconfigure(vm1, cspec) CheckWDTPresent(vm1) Log("Removing vWDT device from VM using virtual device with vWDT key") TestVWDTRemoveDev(vm1, CreateVD(WATCHDOGTIMER_DEV_KEY))
def AddSuspendDirectory(vm1, pathBase): suspendDir = pathBase + '-suspend' CreateDirectory(suspendDir) files = Vim.Vm.FileInfo() files.SetSuspendDirectory(suspendDir) cspec = Vim.Vm.ConfigSpec() cspec.SetFiles(files) vm.Reconfigure(vm1, cspec) suspendDirPath = vm1.GetConfig().GetFiles().GetSuspendDirectory() if suspendDirPath != suspendDir: raise Exception('Failed to set suspend directory') return suspendDir
def TestAdd2ndTPMKey(vm1, key): """ Test add 2nd vTPM """ Log("Adding 2nd vTPM using key=%s" % key) cspec = vim.vm.ConfigSpec() AddVTPM(cspec, key) try: vm.Reconfigure(vm1, cspec) raise Exception("Addition of 2nd vTPM did not fail with %s" % cspec) except vim.fault.TooManyDevices as e: pass CheckTPMPresent(vm1)
def AddSataDisk(vm1): cspec = Vim.Vm.ConfigSpec() vmconfig.AddSataDisk(cspec, cfgInfo = vm1.config) vm.Reconfigure(vm1, cspec) devices = vmconfig.CheckDevice(vm1.config, Vim.Vm.Device.VirtualDisk) if len(devices) < 1: raise Exception("Failed to find SATA disk!") ctlrKey = devices[0].controllerKey ctlrs = vmconfig.CheckDevice(vm1.config, Vim.Vm.Device.VirtualSATAController, {"key": ctlrKey}) if len(ctlrs) != 1: raise Exception("Failed to find SATA controller!")
def TestAdd5thQATKey(vm1, key): """ Test add 5th VQAT """ Log("Adding 5th VQAT using key=%s" % key) cspec = vim.vm.ConfigSpec() AddVQAT(cspec, key) try: vm.Reconfigure(vm1, cspec) raise Exception("Addition of 5th VQAT did not fail with %s" % cspec) except vim.fault.TooManyDevices as e: pass CheckQATPresent(vm1, MAX_QAT_DEV)
def TestExtendDisk(vm1): disk = vmconfig.CheckDevice(vm1.config, Vim.Vm.Device.VirtualDisk)[0] # increase disk size Log("Increase disk size by 8 MB") cspec = Vim.Vm.ConfigSpec() newCapacity = disk.capacityInKB + 8192 disk.capacityInKB = newCapacity vmconfig.AddDeviceToSpec(cspec, disk, Vim.Vm.Device.VirtualDeviceSpec.Operation.edit) vm.Reconfigure(vm1, cspec) devices = vmconfig.CheckDevice(vm1.config, Vim.Vm.Device.VirtualDisk, {"capacityInKB": newCapacity}) if len(devices) != 1: raise Exception("Failed to find the disk with updated capacity")