def CreateTestVm(si, dsName): # Create a VM for testing vmName = "TestStatsVm1" # Destroy old VMs for vm1 in si.content.rootFolder.childEntity[0].vmFolder.childEntity: if vm1.name == vmName: if vm1.runtime.powerState != vim.VirtualMachine.PowerState.poweredOff: vm.PowerOff(vm1) vm1.Destroy() spec = vm.CreateQuickDummySpec(vmName, nic=1, memory=32, datastoreName=dsName) resPool = invt.GetResourcePool(si=si) vmFolder = invt.GetVmFolder(si=si) t = vmFolder.CreateVm(spec, pool=resPool) WaitForTask(t) vm1 = t.info.result Log("Created VM %s on %s" % (vm1.name, resPool.owner.host[0].name)) devices = vmconfig.CheckDevice(vm1.GetConfig(), vim.vm.Device.VirtualEthernetCard) if len(devices) < 1: raise Exception("Failed to find nic") # Reconfigure to add network cspec = vim.vm.ConfigSpec() devices[0].GetConnectable().SetStartConnected(True) devices[0].GetConnectable().SetConnected(True) vmconfig.AddDeviceToSpec(cspec, devices[0], vim.vm.Device.VirtualDeviceSpec.Operation.edit) vm.Reconfigure(vm1, cspec) vm.PowerOn(vm1) return vm1
def testPromoteDisks(si, numDisks, numiter, backingType, vmxVersion, ds1, ds2, status, resultsArray): for i in range(numiter): bigClock = StopWatch() try: try: vm1Name = "Parent" + str(i) vm1 = folder.Find(vm1Name) if vm1 != None: Log("Cleaning up old vm with name: " + vm1Name) vm1.Destroy() # Create a simple vm with numDisks on ds1 vm1 = vm.CreateQuickDummy(vm1Name, numScsiDisks=numDisks, \ datastoreName=ds1, diskSizeInMB=1, \ vmxVersion=vmxVersion, \ backingType=backingType) Log("Created parent VM1 --" + vm1Name) vm1DirName = vm1.config.files.snapshotDirectory # Create snapshot vm.CreateSnapshot(vm1, "S1", "S1 is the first snaphost", \ False, False) snapshotInfo = vm1.GetSnapshot() S1Snapshot = snapshotInfo.GetCurrentSnapshot() Log("Created Snapshot S1 for VM1") # Get the name of the parent disks disks = vmconfig.CheckDevice(S1Snapshot.GetConfig(), \ Vim.Vm.Device.VirtualDisk) if len(disks) != numDisks: raise Exception("Failed to find parent disks") parentDisks = [None] * len(disks) for i in range(len(disks)): parentDisks[i] = disks[i].GetBacking().GetFileName() # Create a VM2 on ds2 that is linked off S1 vm2Name = "LinkedClone" + str(i) configSpec = vmconfig.CreateDefaultSpec(name=vm2Name, datastoreName=ds2) configSpec = vmconfig.AddScsiCtlr(configSpec) configSpec = vmconfig.AddScsiDisk(configSpec, datastorename=ds2, capacity=1024, backingType=backingType) configSpec.SetVersion(vmxVersion) childDiskBacking = configSpec.GetDeviceChange()[1].\ GetDevice().GetBacking() parentBacking = GetBackingInfo(backingType) parentBacking.SetFileName(parentDisks[0]) childDiskBacking.SetParent(parentBacking) childDiskBacking.SetDeltaDiskFormat("redoLogFormat") resPool = invt.GetResourcePool() vmFolder = invt.GetVmFolder() vimutil.InvokeAndTrack(vmFolder.CreateVm, configSpec, resPool) vm2 = folder.Find(vm2Name) Log("Created child VM2 --" + vm2Name) vm2DirName = vm2.config.files.snapshotDirectory # create delta disks off VM1 on VM2 Log("Adding delta disks off VM1 to VM2") configSpec = Vim.Vm.ConfigSpec() for i in range(len(parentDisks)): configSpec = vmconfig.AddScsiDisk(configSpec, \ datastorename = ds2, \ cfgInfo = vm2.GetConfig(), \ backingType = backingType) SetDeltaDiskBacking(configSpec, i, parentDisks[i]) vimutil.InvokeAndTrack(vm2.Reconfigure, configSpec) Log("Power (on) vm1") vm.PowerOn(vm1) time.sleep(5) Log("Power (on) vm2") vm.PowerOn(vm2) time.sleep(5) # prepare promoteDisksSpec diskList = GetVirtualDisks(vm2) promoteDisksSpec = [None] * len(diskList) for i in range(len(diskList)): promoteDisksSpec[i]=vim.host.LowLevelProvisioningManager.\ PromoteDisksSpec() promoteDisksSpec[i].SetNumLinks(1) promoteDisksSpec[i].SetOffsetFromBottom(0) diskId = diskList[i].GetKey() promoteDisksSpec[i].SetDiskId(diskId) Log("Calling LLPM PromoteDisks") llpm = invt.GetLLPM() try: task = llpm.PromoteDisks(vm2, promoteDisksSpec) WaitForTask(task) except Exception as e: print(e) Log("Caught exception : " + str(e)) status = "FAIL" status = "PASS" Log("Destroying VMs") vm.PowerOff(vm2) time.sleep(5) vm.PowerOff(vm1) time.sleep(5) vm2.Destroy() vm1.Destroy() finally: bigClock.finish("iteration " + str(i)) except Exception as e: Log("Caught exception : " + str(e)) status = "FAIL" Log("TEST RUN COMPLETE: " + status) resultsArray.append(status) Log("Results for each iteration: ") for i in range(len(resultsArray)): Log("Iteration " + str(i) + ": " + resultsArray[i])
def testLinkedClone(si, numiter, deltaDiskFormat, backingType, vmxVersion, ds1, ds2, status, resultsArray): for i in range(numiter): bigClock = StopWatch() try: try: vm1Name = "LinkedParent_" + str(i) vm1 = folder.Find(vm1Name) if vm1 != None: Log("Cleaning up old vm with name: " + vm1Name) vm1.Destroy() # Create a simple vm with nothing but two disk on ds1 vm1 = vm.CreateQuickDummy(vm1Name, numScsiDisks=2, \ datastoreName=ds1, diskSizeInMB=1, \ vmxVersion=vmxVersion, \ backingType=backingType) Log("Created parent VM1 --" + vm1Name + "with Native snapshotting" + " capability set to " + str(vm1.IsNativeSnapshotCapable())) vm1DirName = vm1.config.files.snapshotDirectory # Create snapshots # S1, S1C1, S1C1C1 and S1C2 vm.CreateSnapshot(vm1, "S1", "S1 is the first snaphost", \ False, False) snapshotInfo = vm1.GetSnapshot() S1Snapshot = snapshotInfo.GetCurrentSnapshot() Log("Create Snapshot S1 for VM1") vm.CreateSnapshot(vm1, "S1-C1", "S1-C1 is the first child of S1",\ False, False) snapshotInfo = vm1.GetSnapshot() S1C1Snapshot = snapshotInfo.GetCurrentSnapshot() Log("Create Snapshot S1C1 for VM1") vm.CreateSnapshot(vm1, "S1-C1-C1", \ "S1-C1-C1 is the grand child of S1", \ False, False) snapshotInfo = vm1.GetSnapshot() S1C1C1Snapshot = snapshotInfo.GetCurrentSnapshot() Log("Create Snapshot S1C1C1 for VM1") # revert to S1 vimutil.InvokeAndTrack(S1Snapshot.Revert) Log("Reverted VM1 to Snapshot S1C1") vm.CreateSnapshot(vm1, "S1-C2", \ "S1-C2 is the second child of S1", False, False) snapshotInfo = vm1.GetSnapshot() S1C2Snapshot = snapshotInfo.GetCurrentSnapshot() Log("Create Snapshot S1C2 for VM1") # revert to S1C1C1, so it is the current snapshot vimutil.InvokeAndTrack(S1C1C1Snapshot.Revert) Log("Reverted VM1 to Snapshot S1C1C1") # Get the name of the parent disks disks = vmconfig.CheckDevice(S1C2Snapshot.GetConfig(), \ Vim.Vm.Device.VirtualDisk) if len(disks) != 2: raise Exception("Failed to find parent disk1") parentDisk1 = disks[0].GetBacking().GetFileName() disks = vmconfig.CheckDevice(S1C1C1Snapshot.GetConfig(), Vim.Vm.Device.VirtualDisk) if len(disks) != 2: raise Exception("Failed to find parent disk2") parentDisk2 = disks[1].GetBacking().GetFileName() # Create a VM2 on ds2 that is linked off S1C2 vm2Name = "LinkedChild1_" + str(i) configSpec = vmconfig.CreateDefaultSpec(name = vm2Name, datastoreName = ds2) configSpec = vmconfig.AddScsiCtlr(configSpec) configSpec = vmconfig.AddScsiDisk(configSpec, datastorename = ds2, capacity = 1024, backingType = backingType) configSpec.SetVersion(vmxVersion) childDiskBacking = configSpec.GetDeviceChange()[1].GetDevice().GetBacking() parentBacking = GetBackingInfo(backingType) parentBacking.SetFileName(parentDisk1) childDiskBacking.SetParent(parentBacking) childDiskBacking.SetDeltaDiskFormat(deltaDiskFormat) resPool = invt.GetResourcePool() vmFolder = invt.GetVmFolder() vimutil.InvokeAndTrack(vmFolder.CreateVm, configSpec, resPool) vm2 = folder.Find(vm2Name) Log("Created child VM2 --" + vm2Name) vm2DirName = vm2.config.files.snapshotDirectory # Create a VM3 on ds2 that is linked off S1C1C1 vm3Name = "LinkedChild2_" + str(i) configSpec.SetName(vm3Name) parentBacking.SetFileName(parentDisk2) vimutil.InvokeAndTrack(vmFolder.CreateVm, configSpec, resPool) vm3 = folder.Find(vm3Name) Log("Created child VM3 --" + vm3Name) vm3DirName = vm3.config.files.snapshotDirectory # Create snapshot VM3S1 for VM3 vm.CreateSnapshot(vm3, "VM3S1", "VM3S1 is VM3 snaphost", False, False) Log("Create Snapshot VM3S1 for VM3") # Create snapshot VM3S2 for VM3 vm.CreateSnapshot(vm3, "VM3S2", "VM3S2 is VM3 snaphost", False, False) Log("Create Snapshot VM3S2 for VM3") snapshotInfo = vm3.GetSnapshot() VM3S2Snapshot = snapshotInfo.GetCurrentSnapshot() # get the disk name of VM3S2 so it can be configured as a # parent disk for VM2 disks = vmconfig.CheckDevice(VM3S2Snapshot.GetConfig(), Vim.Vm.Device.VirtualDisk) if len(disks) != 1: raise Exception("Failed to find parent disk2") parentDisk3 = disks[0].GetBacking().GetFileName() # create a delta disk off VM3S2 on VM2 Log("Adding delta disk off VM3S2 to VM2") configSpec = Vim.Vm.ConfigSpec() configSpec = vmconfig.AddScsiDisk(configSpec, \ datastorename = ds2, \ cfgInfo = vm2.GetConfig(), \ backingType = backingType) childDiskBacking = configSpec.GetDeviceChange()[0].GetDevice().GetBacking() parentBacking = GetBackingInfo(backingType) parentBacking.SetFileName(parentDisk3) childDiskBacking.SetParent(parentBacking) childDiskBacking.SetDeltaDiskFormat(deltaDiskFormat) vimutil.InvokeAndTrack(vm2.Reconfigure, configSpec) Log("Power cycle VM1...") PowerCycle(vm1) Log("Power cycle VM2...") PowerCycle(vm2) Log("Power cycle VM3...") PowerCycle(vm3) Log("OP1: delete VM1.S1C2, then power cycle VM2") vimutil.InvokeAndTrack(S1C2Snapshot.Remove, True) PowerCycle(vm2) Log("OP2: destroy VM2, power cycle VM1") vimutil.InvokeAndTrack(vm2.Destroy) PowerCycle(vm1) Log("then recreate VM2 with just disk1") configSpec = vmconfig.CreateDefaultSpec(name = vm2Name, \ datastoreName = ds2) configSpec = vmconfig.AddScsiCtlr(configSpec) configSpec = vmconfig.AddScsiDisk(configSpec, datastorename = ds2, \ capacity = 1024, \ backingType = backingType) configSpec.SetVersion(vmxVersion) childDiskBacking = configSpec.GetDeviceChange()[1].GetDevice().GetBacking() parentBacking = GetBackingInfo(backingType) parentBacking.SetFileName(parentDisk1) childDiskBacking.SetParent(parentBacking) childDiskBacking.SetDeltaDiskFormat(deltaDiskFormat) resPool = invt.GetResourcePool() vmFolder = invt.GetVmFolder() vimutil.InvokeAndTrack(vmFolder.CreateVm, configSpec, resPool) vm2 = folder.Find(vm2Name) Log("ReCreated child VM2 --" + vm2Name) Log("OP3: delete VM3S2, power cycle VM1, revert to S1C1") vimutil.InvokeAndTrack(VM3S2Snapshot.Remove, True) vimutil.InvokeAndTrack(S1C1Snapshot.Revert) PowerCycle(vm1) llpm = si.RetrieveInternalContent().GetLlProvisioningManager() Log("OP4: refresh VM2 disk and destroy the disk and its parent") llpm.ReloadDisks(vm2, ['currentConfig', 'snapshotConfig']) disks = vmconfig.CheckDevice(vm2.GetConfig(), \ Vim.Vm.Device.VirtualDisk) diskChain1 = disks[0] diskChain1.backing.parent.parent = None configSpec = Vim.Vm.ConfigSpec() configSpec = vmconfig.RemoveDeviceFromSpec(configSpec, \ diskChain1, "destroy") configSpec.files = vm2.config.files llpm.ReconfigVM(configSpec) Log("verify only the immediate parent is deleted") PowerCycle(vm1) Log("OP5: destroy VM1, power cycle VM3") vimutil.InvokeAndTrack(vm1.Destroy) PowerCycle(vm3) Log("OP6: Consolidate VM3 disk chain") disks = vmconfig.CheckDevice(vm3.GetConfig(), \ Vim.Vm.Device.VirtualDisk) shouldHaveFailed = 0 try: task = llpm.ConsolidateDisks(vm3, disks) WaitForTask(task) except Exception as e: shouldHaveFailed = 1 Log("Hit an exception when trying to consolidate cross " \ "snapshot point.") if shouldHaveFailed != 1: raise Exception("Error: allowed consolidation to merge snapshot") diskchain1 = disks[0] diskchain1.backing.parent.parent = None disks = vmconfig.CheckDevice(vm3.GetConfig(), \ Vim.Vm.Device.VirtualDisk) diskchain2 = disks[0] diskchain2.backing = diskchain2.backing.parent.parent disks = [] disks.append(diskchain1) disks.append(diskchain2) vimutil.InvokeAndTrack(llpm.ConsolidateDisks, vm3, disks) PowerCycle(vm3) Log("OP7: destroy VM2, no orphaned disks/files should have left") vimutil.InvokeAndTrack(vm2.Destroy) Log("Delete snapshot of VM3, and delete the disk with all parent." "then destroy vM3, no orphaned disks/files should have left") disks = vmconfig.CheckDevice(vm3.GetConfig(), \ Vim.Vm.Device.VirtualDisk) diskChain1 = disks[0] configSpec = Vim.Vm.ConfigSpec() configSpec = vmconfig.RemoveDeviceFromSpec(configSpec, \ diskChain1, "destroy") configSpec.files = vm3.config.files vimutil.InvokeAndTrack(llpm.ReconfigVM, configSpec) vimutil.InvokeAndTrack(vm3.Destroy) hostSystem = host.GetHostSystem(si) b = hostSystem.GetDatastoreBrowser() shouldHaveFailed = 0 try: vimutil.InvokeAndTrack(b.Search, vm1DirName) except Vim.Fault.FileNotFound: Log("Caught " + vm1DirName + "Not found as expected") shouldHaveFailed += 1 try: vimutil.InvokeAndTrack(b.Search, vm2DirName) except Vim.Fault.FileNotFound: Log("Caught " + vm2DirName + "Not found as expected") shouldHaveFailed += 1 try: vimutil.InvokeAndTrack(b.Search, vm3DirName) except Vim.Fault.FileNotFound: Log("Caught " + vm3DirName + "Not found as expected") shouldHaveFailed += 1 if shouldHaveFailed != 3: Log("Failed, orphaned disks left") raise Exception("orphaned disks") status = "PASS" finally: bigClock.finish("iteration " + str(i)) except Exception as e: Log("Caught exception : " + str(e)) status = "FAIL" Log("TEST RUN COMPLETE: " + status) resultsArray.append(status) Log("Results for each iteration: ") for i in range(len(resultsArray)): Log("Iteration " + str(i) + ": " + resultsArray[i])
def main(): supportedArgs = [ (["h:", "host="], "localhost", "Host name", "host"), (["u:", "user="******"root", "User name", "user"), (["p:", "pwd="], "ca$hc0w", "Password", "pwd"), (["v:", "vmname="], "CreateTest", "Name of the virtual machine", "vmname")] supportedToggles = [(["usage", "help"], False, "Show usage information", "usage")] args = arguments.Arguments(sys.argv, supportedArgs, supportedToggles) if args.GetKeyValue("usage") == True: args.Usage() sys.exit(0) # Connect si = Connect(args.GetKeyValue("host"), 443, args.GetKeyValue("user"), args.GetKeyValue("pwd")) atexit.register(Disconnect, si) # Process command line vmname = args.GetKeyValue("vmname") # Cleanup from previous runs. vm1 = folder.Find(vmname) if vm1 != None: vm1.Destroy() # Create vms envBrowser = invt.GetEnv() config = vm.CreateQuickDummySpec(vmname) cfgOption = envBrowser.QueryConfigOption(None, None) cfgTarget = envBrowser.QueryConfigTarget(None) NIC_DIFFERENCE = 7 config = vmconfig.AddNic(config, cfgOption, cfgTarget, unitNumber = NIC_DIFFERENCE + 0) config = vmconfig.AddNic(config, cfgOption, cfgTarget, unitNumber = NIC_DIFFERENCE + 2) config = vmconfig.AddNic(config, cfgOption, cfgTarget, unitNumber = NIC_DIFFERENCE + 3) config = vmconfig.AddNic(config, cfgOption, cfgTarget, unitNumber = NIC_DIFFERENCE + 4) config = vmconfig.AddNic(config, cfgOption, cfgTarget) config = vmconfig.AddNic(config, cfgOption, cfgTarget, unitNumber = NIC_DIFFERENCE + 6) config = vmconfig.AddNic(config, cfgOption, cfgTarget, unitNumber = NIC_DIFFERENCE + 7) config = vmconfig.AddNic(config, cfgOption, cfgTarget, unitNumber = NIC_DIFFERENCE + 8) config = vmconfig.AddNic(config, cfgOption, cfgTarget, unitNumber = NIC_DIFFERENCE + 9) config = vmconfig.AddScsiCtlr(config, cfgOption, cfgTarget, unitNumber = 3) config = vmconfig.AddScsiDisk(config, cfgOption, cfgTarget, unitNumber = 0) isofile = "[] /usr/lib/vmware/isoimages/linux.iso" config = vmconfig.AddCdrom(config, cfgOption, cfgTarget, unitNumber = 0, isoFilePath=isofile) image = "[] /vmimages/floppies/vmscsi.flp" config = vmconfig.AddFloppy(config, cfgOption, cfgTarget, unitNumber = 0, type="image", backingName=image) config = vmconfig.AddFloppy(config, cfgOption, cfgTarget, unitNumber = 1, type="image", backingName=image) backing = Vim.Vm.Device.VirtualSerialPort.FileBackingInfo() backing.SetFileName("[]") config = vmconfig.AddSerial(config, backing) try: vmFolder = invt.GetVmFolder() vimutil.InvokeAndTrack(vmFolder.CreateVm, config, invt.GetResourcePool(), None) except Exception as e: raise vm1 = folder.Find(vmname) printNicUnitNumbers(vm1, "Test 1: Creating a vm with lots of nics") cspec = Vim.Vm.ConfigSpec() cspec = vmconfig.AddNic(cspec, cfgOption, cfgTarget) task = vm1.Reconfigure(cspec) WaitForTask(task) printNicUnitNumbers(vm1, "Test 2: Added a nic") cspec = Vim.Vm.ConfigSpec() cspec = vmconfig.AddNic(cspec, cfgOption, cfgTarget) task = vm1.Reconfigure(cspec) try: WaitForTask(task) except Vim.Fault.TooManyDevices as e: print("Caught too many devices as expected") nics = printNicUnitNumbers(vm1, "Test 3: Added too many nics") cspec = Vim.Vm.ConfigSpec() uni = nics[4].GetUnitNumber() cspec = vmconfig.RemoveDeviceFromSpec(cspec, nics[0]) cspec = vmconfig.RemoveDeviceFromSpec(cspec, nics[2]) cspec = vmconfig.RemoveDeviceFromSpec(cspec, nics[4]) cspec = vmconfig.RemoveDeviceFromSpec(cspec, nics[5]) cspec = vmconfig.RemoveDeviceFromSpec(cspec, nics[6]) cspec = vmconfig.AddNic(cspec, cfgOption, cfgTarget) task = vm1.Reconfigure(cspec) WaitForTask(task) printNicUnitNumbers(vm1, "Test 4: Removed a bunch of nics") cspec = Vim.Vm.ConfigSpec() cspec = vmconfig.AddNic(cspec, cfgOption, cfgTarget, unitNumber = NIC_DIFFERENCE - 2) task = vm1.Reconfigure(cspec) WaitForTask(task) printNicUnitNumbers(vm1, "Test 5: Added a nic with slot incorrectly specified") cspec = Vim.Vm.ConfigSpec() cspec = vmconfig.AddNic(cspec, cfgOption, cfgTarget, unitNumber = uni) cspec = vmconfig.AddScsiCtlr(cspec, cfgOption, cfgTarget, unitNumber = 4) cspec = vmconfig.AddScsiDisk(cspec, cfgOption, cfgTarget, unitNumber = 1) task = vm1.Reconfigure(cspec) WaitForTask(task) printNicUnitNumbers(vm1, "Test 6: Added a nic with a slot correctly specified") cspec = Vim.Vm.ConfigSpec() cspec = vmconfig.AddNic(cspec, cfgOption, cfgTarget, unitNumber = uni) task = vm1.Reconfigure(cspec) try: WaitForTask(task) except Vim.Fault.InvalidDeviceSpec as e: print("Exception caught for adding same nic twice") printNicUnitNumbers(vm1, "Test 7: Added a nic with s slot specified to be an occupied slot") vm1.Destroy()
def TestEarlyBinding(vmName, uuid): """ Test early binding portgroup behaviour - Create a VM with a nic connecting to an early binding portgroup and start connected to true fails - Create a VM with a nic connecting to an early binding portgroup and start connected to false succeeds - Poweron the created VM succeds. - Reconfigure the VM to connect to an invalid port fails. - Hot add of device connected to an early binding portgroup fails. - Reconfigure the VM to connect to an early binding portgroup when device is not connected succeeds - Reconfigure a powered on VM to connect to an early binding portgroup when device is connected fails. """ print("Testing early binding portgroup behaviour") cleanupvm(vmName) envBrowser = invt.GetEnv() config = vm.CreateQuickDummySpec(vmName) cfgOption = envBrowser.QueryConfigOption(None, None) # Add a earlybinding dvPortgroup backed nic. config = vmconfig.AddDvPortBacking(config, "", uuid, 0, cfgOption, "pg2") try: vmFolder = invt.GetVmFolder() vimutil.InvokeAndTrack(vmFolder.CreateVm, config, invt.GetResourcePool(), None) except Vim.Fault.InvalidDeviceSpec: print("Caught invalid device backing as expected") print("Test 1: Creating a device backed by an early binding portgroup with" "startConnected = true fails as expected: PASS") config = vm.CreateQuickDummySpec(vmName) cfgOption = envBrowser.QueryConfigOption(None, None) # Add an earlybinding dvPortgroup backed nic. config = vmconfig.AddDvPortBacking(config, "", uuid, 0, cfgOption, "pg2", False) vmFolder = invt.GetVmFolder() vimutil.InvokeAndTrack(vmFolder.CreateVm, config, invt.GetResourcePool(), None) myVm = folder.Find(vmName) devices = vmconfig.CheckDevice(myVm.GetConfig(), Vim.Vm.Device.VirtualEthernetCard) if not IsBackingPortNotAllocated(devices): print(devices) raise Exception ("Nic has a dvPort assigned to it or nic add failed") print("Test 2: Creating a device backed by and early binding portgroup with" "startConnected = false succeeds: PASS") myVm = folder.Find(vmName) vm.PowerOn(myVm) devices = vmconfig.CheckDevice(myVm.GetConfig(), Vim.Vm.Device.VirtualEthernetCard) if len(devices) < 1: raise Exception("nic not present") if not IsBackingPortNotAllocated(devices): print(devices) raise Exception ("Nic has a dvPort assigned to it or nic add failed") print("Test 3: Power on VM succeeds: PASS") # Reconfigure the VM to connect to an invalid port. for device in devices: if isinstance(device.GetBacking(),\ Vim.Vm.Device.VirtualEthernetCard.DistributedVirtualPortBackingInfo): device.GetBacking().GetPort().SetPortKey("100") cspec = Vim.Vm.ConfigSpec() vmconfig.AddDeviceToSpec(cspec, device, Vim.Vm.Device.VirtualDeviceSpec.Operation.edit) break try: task = myVm.Reconfigure(cspec) WaitForTask(task) except Vim.Fault.InvalidDeviceSpec: print("Caught invalid device backing") print("Test 4: Reconfig a VM to connect to an invalid dvPort fails as expected: PASS") # Add a device to connect to an early binding portgroup with no dvPort specified. config = Vim.Vm.ConfigSpec() config = vmconfig.AddDvPortBacking(config, "", uuid, 0, cfgOption, "pg2") try: task = myVm.Reconfigure(config) WaitForTask(task) except Vim.Fault.InvalidDeviceSpec: print("Caught invalid device backing") print("Test 4: Hot add of a device to connect to an earlybinding portgroup fails as expected: PASS") # Reconfigure device to connect to an early binding portgroup. for device in devices: if isinstance(device.GetBacking(),\ Vim.Vm.Device.VirtualEthernetCard.DistributedVirtualPortBackingInfo): device.GetBacking().GetPort().SetPortgroupKey("pg2") device.GetBacking().GetPort().SetPortKey(None) device.GetBacking().GetPort().SetConnectionCookie(None) device.GetConnectable().SetConnected(True) cspec = Vim.Vm.ConfigSpec() vmconfig.AddDeviceToSpec(cspec, device, Vim.Vm.Device.VirtualDeviceSpec.Operation.edit) break try: task = myVm.Reconfigure(cspec) WaitForTask(task) except Vim.Fault.InvalidDeviceSpec: print("Caught invalid device backing") print("Test 5: Reconfig a VM to connect to an early binding portgroup fails as expected: PASS") # Reconfigure a device to disconnected state and connect to an early binding dvPortgroup. for device in devices: if isinstance(device.GetBacking(),\ Vim.Vm.Device.VirtualEthernetCard.DistributedVirtualPortBackingInfo): device.GetBacking().GetPort().SetPortgroupKey("pg2") device.GetBacking().GetPort().SetPortKey(None) device.GetBacking().GetPort().SetConnectionCookie(None) device.GetConnectable().SetConnected(False) cspec = Vim.Vm.ConfigSpec() vmconfig.AddDeviceToSpec(cspec, device, Vim.Vm.Device.VirtualDeviceSpec.Operation.edit) break task = myVm.Reconfigure(cspec) WaitForTask(task) if not IsBackingPortNotAllocated(devices): print(devices) raise Exception ("Nic has a dvPort assigned to it or nic add failed") print("Test6 complete: Reconfig powered on VM to connect to a earlybinding backing with device disconnected: PASS") print("EarlyBinding tests complete")
def TestLateBinding(vmName, uuid): """ Create a VM and connect it to a latebinding portgroup. Poweron the VM. Validate that a dvPort has not been allocated for the VM. Reconfig the VM to connect to a ephemeral dvPortgroup validate that the VM has a valid backing. Reconfigure the VM to connect back to the latebinding portgroup the reconfig should fail. Reconfigure the VM to connect back to the latebinding portgroup with the device disconnected the connect should succeed. """ cleanupvm(vmName) print("Testing latebinding portgroup behaviour") envBrowser = invt.GetEnv() config = vm.CreateQuickDummySpec(vmName) cfgOption = envBrowser.QueryConfigOption(None, None) # Add a latebinding dvPortgroup backed nic. config = vmconfig.AddDvPortBacking(config, "", uuid, 0, cfgOption, "pg4", type = 'vmxnet3') try: vmFolder = invt.GetVmFolder() vimutil.InvokeAndTrack(vmFolder.CreateVm, config, invt.GetResourcePool(), None) except Exception as e: raise myVm = folder.Find(vmName) devices = vmconfig.CheckDevice(myVm.GetConfig(), Vim.Vm.Device.VirtualEthernetCard) if len(devices) < 1: raise Exception("Failed to add nic") if not IsBackingPortNotAllocated(devices): raise Exception("dvPort allocated for a latebinding portgroup") print("Test1: Create VM with a latebinding portgroup backing: PASS") # power on the VM. vm.PowerOn(myVm) devices = vmconfig.CheckDevice(myVm.GetConfig(), Vim.Vm.Device.VirtualEthernetCard) if len(devices) < 1: raise Exception("Nic seems to be missing") if not IsBackingPortNotAllocated(devices): raise Exception("dvPort allocated for a latebinding portgroup after powerOn") print("Test2: Powering on a VM with a latebinding portgroup backing: PASS") # Reconfigure the VM to connect to an ephemeral backing. for device in devices: if isinstance(device.GetBacking(),\ Vim.Vm.Device.VirtualEthernetCard.DistributedVirtualPortBackingInfo): device.GetBacking().GetPort().SetPortgroupKey("pg3") device.GetBacking().GetPort().SetPortKey(None) device.GetBacking().GetPort().SetConnectionCookie(None) device.GetConnectable().SetConnected(True) cspec = Vim.Vm.ConfigSpec() vmconfig.AddDeviceToSpec(cspec, device, Vim.Vm.Device.VirtualDeviceSpec.Operation.edit) break task = myVm.Reconfigure(cspec) WaitForTask(task) devices = vmconfig.CheckDevice(myVm.GetConfig(), Vim.Vm.Device.VirtualEthernetCard) if len(devices) < 1: raise Exception("Failed to edit nic") if not IsBackingValid(devices): raise Exception("Invalid backing allocated") print("Test3: Reconfig poweredon with a ephemeral backing from a latebinding backing allocates a port: PASS") #Reconfig the VM to connect to a latebinding backing. for device in devices: if isinstance(device.GetBacking(),\ Vim.Vm.Device.VirtualEthernetCard.DistributedVirtualPortBackingInfo): device.GetBacking().GetPort().SetPortgroupKey("pg4") device.GetBacking().GetPort().SetPortKey(None) device.GetBacking().GetPort().SetConnectionCookie(None) cspec = Vim.Vm.ConfigSpec() vmconfig.AddDeviceToSpec(cspec, device, Vim.Vm.Device.VirtualDeviceSpec.Operation.edit) break try: task = myVm.Reconfigure(cspec) WaitForTask(task) except Vim.Fault.InvalidDeviceSpec: print("Caught invalid device backing") print("Test4: Reconfig powered on VM to connect to a latebinding backing fails as expected: PASS") # reconfigure the VM to connect to a latebinding portgroup and disconnect the device. for device in devices: if isinstance(device.GetBacking(),\ Vim.Vm.Device.VirtualEthernetCard.DistributedVirtualPortBackingInfo): device.GetBacking().GetPort().SetPortgroupKey("pg4") device.GetBacking().GetPort().SetPortKey(None) device.GetBacking().GetPort().SetConnectionCookie(None) device.GetConnectable().SetConnected(False) cspec = Vim.Vm.ConfigSpec() vmconfig.AddDeviceToSpec(cspec, device, Vim.Vm.Device.VirtualDeviceSpec.Operation.edit) break task = myVm.Reconfigure(cspec) WaitForTask(task) devices = vmconfig.CheckDevice(myVm.GetConfig(), Vim.Vm.Device.VirtualEthernetCard) if not IsBackingPortNotAllocated(devices): print(devices) raise Exception ("Nic has a dvPort assigned to it or nic add failed") print("Test5: Reconfig powered on VM to connect to a latebinding backing with device disconnected: PASS") print("Late binding tests complete")
def TestEphemeral(vmName, uuid): """ Test epehemeral portgroups. - Create a VM configure it to connect to an ephemeral portgroup. - Power on the VM and validate that backing is valid. - Hot add a nic to connect to an ephemeral portgroup and validate backing. - Poweroff and destroy the VM """ print("Testing Ephemeral portgroup behaviour") cleanupvm(vmName) envBrowser = invt.GetEnv() config = vm.CreateQuickDummySpec(vmName) cfgOption = envBrowser.QueryConfigOption(None, None) # Add a latebinding dvPortgroup backed nic. config = vmconfig.AddDvPortBacking(config, "", uuid, 0, cfgOption, "pg1") try: vmFolder = invt.GetVmFolder() vimutil.InvokeAndTrack(vmFolder.CreateVm, config, invt.GetResourcePool(), None) except Exception as e: raise myVm = folder.Find(vmName) devices = vmconfig.CheckDevice(myVm.GetConfig(), Vim.Vm.Device.VirtualEthernetCard) if len(devices) < 1: raise Exception("Failed to add nic") if not IsBackingPortNotAllocated(devices): print(devices) raise Exception ("Nic has a dvPort assigned to it or nic add failed") print("Test 1: Create a vm with an ephemeral portgroup backing: PASS") vm.PowerOn(myVm) devices = vmconfig.CheckDevice(myVm.GetConfig(), Vim.Vm.Device.VirtualEthernetCard) if len(devices) < 1: raise Exception("Failed to add nic") if not IsBackingValid(devices): raise Exception("Invalid backing allocated") print("Test 2: powerOn VM with a ephemeral backing: PASS") # Remove and add hot add a nic device to a powered on VM. vm.PowerOff(myVm) for device in devices: if isinstance(device.GetBacking(),\ Vim.Vm.Device.VirtualEthernetCard.DistributedVirtualPortBackingInfo): cspec = Vim.Vm.ConfigSpec() vmconfig.AddDeviceToSpec(cspec, device, Vim.Vm.Device.VirtualDeviceSpec.Operation.remove) break task = myVm.Reconfigure(cspec) WaitForTask(task) devices = vmconfig.CheckDevice(myVm.GetConfig(), Vim.Vm.Device.VirtualEthernetCard) if IsBackingValid(devices): print(devices) raise Exception("Remove of device failed.") # powerOn the VM and hot add the nic. vm.PowerOn(myVm) config = Vim.Vm.ConfigSpec() config = vmconfig.AddDvPortBacking(config, "", uuid, 0, cfgOption, "pg1") task = myVm.Reconfigure(config) WaitForTask(task) devices = vmconfig.CheckDevice(myVm.GetConfig(), Vim.Vm.Device.VirtualEthernetCard) if len(devices) < 1: raise Exception("Failed to add nic") if not IsBackingValid(devices): raise Exception("Invalid backing allocated") print("Test 3: remove and hot add nic to VM with a ephemeral backing: PASS") # Foundry issue wait for fix and then uncomment. time.sleep(10) for device in devices: if isinstance(device.GetBacking(),\ Vim.Vm.Device.VirtualEthernetCard.DistributedVirtualPortBackingInfo): device.GetBacking().GetPort().SetPortgroupKey("pg3") device.GetBacking().GetPort().SetPortKey(None) device.GetBacking().GetPort().SetConnectionCookie(None) device.GetConnectable().SetConnected(True) cspec = Vim.Vm.ConfigSpec() vmconfig.AddDeviceToSpec(cspec, device, Vim.Vm.Device.VirtualDeviceSpec.Operation.edit) break #task = myVm.Reconfigure(cspec) #WaitForTask(task) #devices = vmconfig.CheckDevice(myVm.GetConfig(), Vim.Vm.Device.VirtualEthernetCard) #if len(devices) < 1: # raise Exception("Failed to edit nic") #if not IsBackingValid(devices): # raise Exception("Invalid backing allocated") #print("Test4: Reconfig poweredon with a ephemeral backing: PASS") print("Ephemeral portgoup tests complete")
def TestSimulatedVcClone(vmName, uuid): """ Test the code paths that VC excercises during cloning a VM with a dvs backing. """ print("Testing hostd code corresponding to clone") cleanupvm(vmName) envBrowser = invt.GetEnv() config = vm.CreateQuickDummySpec(vmName) cfgOption = envBrowser.QueryConfigOption(None, None) # Add a nic backed by a dvs portgroup pair. config = vmconfig.AddDvPortBacking(config, "", uuid, 0, cfgOption, "invalidPg") try: vmFolder = invt.GetVmFolder() vimutil.InvokeAndTrack(vmFolder.CreateVm, config, invt.GetResourcePool(), None) except Vim.Fault.InvalidDeviceSpec: print("Test1: Caught invalid device spec as expected") else: raise "Test1: Create vm with invalid dvPortgroup backing didn't fail as expected" print("Test1: Create vm with invalid dvPortgroup backing failed as expected: PASS") config = vm.CreateQuickDummySpec(vmName) config = vmconfig.AddDvPortBacking(config, "", uuid, 0, cfgOption, "pg1") try: vmFolder = invt.GetVmFolder() vimutil.InvokeAndTrack(vmFolder.CreateVm, config, invt.GetResourcePool(), None) except Exception: print("Failed to clone a VM to connect to a dvPortgroup") raise print("Test2: Create vm with valid dvPort backing: PASS") # Create a VM only specifying the dvs uuid in its backing. vm1 = folder.Find(vmName) vm.Destroy(vm1) config = vm.CreateQuickDummySpec(vmName) config = vmconfig.AddDvPortBacking(config, "", uuid, None, cfgOption, "") try: vmFolder = invt.GetVmFolder() vimutil.InvokeAndTrack(vmFolder.CreateVm, config, invt.GetResourcePool(), None) except Exception: print("Failed to clone a VM to connected to a standalone port") raise myVm = folder.Find(vmName) devices = vmconfig.CheckDevice(myVm.GetConfig(), Vim.Vm.Device.VirtualEthernetCard) if not IsBackingPortNotAllocated(devices): print(devices) raise Exception ("Nic has a dvPort assigned to it or nic add failed") print("Test3: Create vm with valid dvs uuid specified in the dvsbacking (standalone): PASS") # Reconfigure a VM only specifying a dvs uuid in its backing for device in devices: if isinstance(device.GetBacking(),\ Vim.Vm.Device.VirtualEthernetCard.DistributedVirtualPortBackingInfo): cspec = Vim.Vm.ConfigSpec() device.GetConnectable().SetConnected(True) device.SetUnitNumber(9) vmconfig.AddDeviceToSpec(cspec, device, Vim.Vm.Device.VirtualDeviceSpec.Operation.add) break try: task = myVm.Reconfigure(cspec) WaitForTask(task) except Exception: print("Test4: failed to add a device with only dvs backing specified") print("Test4: Reconfig VM specifying only the dvsUuid in backing: PASS") print("Testing simulate vc clone done")
def TestLinkedClone(vm1, datastore=None): if datastore is None: vm1Path = vm1.GetSummary().GetConfig().GetVmPathName() m = re.search(r'\[(.+)\]', vm1Path) datastore = m.group(1) baseName = vm1.GetConfig().GetName() parentName = 'LinkedParent_' + baseName vmP = folder.Find(parentName) if vmP != None: Log('Destroying old parent VM %s' % parentName) vmP.Destroy() # Create parent VM vmP = vm.CreateQuickDummy(parentName, numScsiDisks=2, datastoreName=datastore, diskSizeInMB=1) # Create snapshots # S1 -> S1C1 -> S1C1C1 # `-> S1C2 S1Snapshot = TakeSnapshot(vmP, 'S1', 'S1 is the first snaphost') Log('Create Snapshot S1 for parent VM') S1C1Snapshot = TakeSnapshot(vmP, 'S1-C1', 'S1-C1 is the first child of S1') Log('Create Snapshot S1C1 for parent VM') S1C1C1Snapshot = TakeSnapshot(vmP, 'S1-C1-C1', 'S1-C1-C1 is the grand child of S1') Log('Create Snapshot S1C1C1 for parent VM') # Revert to S1 vimutil.InvokeAndTrack(S1Snapshot.Revert) Log('Reverted parent VM to Snapshot S1') S1C2Snapshot = TakeSnapshot(vmP, 'S1-C2', 'S1-C2 is the second child of S1') Log('Create Snapshot S1C2 for parent VM') # Revert to S1C1C1, so it is the current snapshot vimutil.InvokeAndTrack(S1C1C1Snapshot.Revert) Log('Reverted parent VM to Snapshot S1C1C1') # Get the name of the parent disks disks = vmconfig.CheckDevice(S1C2Snapshot.GetConfig(), Vim.Vm.Device.VirtualDisk) if len(disks) != 2: raise Exception('Failed to find parent disk1') parentDisk1 = disks[0].GetBacking().GetFileName() disks = vmconfig.CheckDevice(S1C1C1Snapshot.GetConfig(), Vim.Vm.Device.VirtualDisk) if len(disks) != 2: raise Exception('Failed to find parent disk2') parentDisk2 = disks[1].GetBacking().GetFileName() # Create a VMC1 whose first disk is linked off S1C2 child1Name = 'LinkedChild1_' + baseName vmC1 = folder.Find(child1Name) if vmC1 != None: Log('Destroying old child VM %s' % child1Name) vmC1.Destroy() configSpec = vmconfig.CreateDefaultSpec(name=child1Name, datastoreName=datastore) configSpec = vmconfig.AddScsiCtlr(configSpec) configSpec = vmconfig.AddScsiDisk(configSpec, datastorename=datastore, capacity=1024) SetDeltaDiskBacking(configSpec, 1, parentDisk1) resPool = invt.GetResourcePool() vmFolder = invt.GetVmFolder() vimutil.InvokeAndTrack(vmFolder.CreateVm, configSpec, resPool) vmC1 = folder.Find(child1Name) vmC1DirName = vmC1.config.files.snapshotDirectory Log('Created child VM %s' % child1Name) # Create a VMC2 that is linked off S1C1C1 child2Name = 'LinkedChild2_' + baseName vmC2 = folder.Find(child2Name) if vmC2 != None: Log('Destroying old child VM %s' % child2Name) vmC2.Destroy() configSpec.SetName(child2Name) SetDeltaDiskBacking(configSpec, 1, parentDisk2) vimutil.InvokeAndTrack(vmFolder.CreateVm, configSpec, resPool) vmC2 = folder.Find(child2Name) vmC2DirName = vmC2.config.files.snapshotDirectory Log('Created child VM %s' % child2Name) # Create snapshot VMC2S1 for VMC2 TakeSnapshot(vmC2, 'VMC2S1', 'VMC2S1 is VMC2 snaphost') Log('Create Snapshot VMC2S1 for VMC2') # Create snapshot VMC2S2 for VMC2 VMC2S2Snapshot = TakeSnapshot(vmC2, 'VMC2S2', 'VMC2S2 is VMC2 snaphost') Log('Create Snapshot VMC2S2 for VMC2') # Get the disk name of VMC2S2 to use it a parent disk for VMC1 disks = vmconfig.CheckDevice(VMC2S2Snapshot.GetConfig(), Vim.Vm.Device.VirtualDisk) if len(disks) != 1: raise Exception('Failed to find parent disk2') parentDisk3 = disks[0].GetBacking().GetFileName() # Create a delta disk off VMC2S2 on VMC1 Log('Adding delta disk off VMC2S2 to VMC1') configSpec = Vim.Vm.ConfigSpec() configSpec = vmconfig.AddScsiDisk(configSpec, datastorename=datastore, cfgInfo=vmC1.GetConfig()) SetDeltaDiskBacking(configSpec, 0, parentDisk3) vm.Reconfigure(vmC1, configSpec) # Final picture # vmP: S1 -> S1C1 -> S1C1C1 (disk1, disk2) # `-> S1C2 | # vmC2: | `-> vmC2S1 -> vmC2S2 (disk1, disk2) # vmC1: `- (disk1) `- (disk2) Log('Verify parent VM domain policy') domainP = 'hostd' + str(vmP._GetMoId()) vmPdir = GetVMHomeDir(vmP) vm.PowerOn(vmP) found = CheckInPolicy(domainP, [(vmPdir, 3)]) if len(found) != 1: DumpFilePolicy(domainP) raise Exception('Did not find parent VM home directory in policy') vm.PowerOff(vmP) Log('Verify linked child 2 has permission to the parent VM') domainC2 = 'hostd' + str(vmC2._GetMoId()) vmC2dir = GetVMHomeDir(vmC2) vm.PowerOn(vmC2) found = CheckInPolicy(domainC2, [(vmC2dir, 3), (vmPdir, 1)]) if len(found) != 2: raise Exception('Did not find all expected permission in child 2. ' + 'Found: %s' % ', '.join(found)) vm.PowerOff(vmC2) Log('Verify linked child 1 has permission to the parent VM and child 2') domainC1 = 'hostd' + str(vmC1._GetMoId()) vmC1dir = GetVMHomeDir(vmC1) vm.PowerOn(vmC1) found = CheckInPolicy(domainC1, [(vmC1dir, 3), (vmPdir, 1), (vmC2dir, 1)]) if len(found) != 3: raise Exception('Did not find all expected permission in child 1. ' + 'Found: %s' % ', '.join(found)) vm.PowerOff(vmC1) Log('Delete S1C2. Linked child 1 should not be affected.') vimutil.InvokeAndTrack(S1C2Snapshot.Remove, True) vm.PowerOn(vmC1) found = CheckInPolicy(domainC1, [(vmC1dir, 3), (vmPdir, 1), (vmC2dir, 1)]) if len(found) != 3: raise Exception('Did not find all expected permission in child 1. ' + 'Found: %s' % ', '.join(found)) vm.PowerOff(vmC1) Log('Remove disk1 from linked child 1. Verify policy does not change.') disks = vmconfig.CheckDevice(vmC1.GetConfig(), Vim.Vm.Device.VirtualDisk) disk1 = None for disk in disks: if disk.backing.parent.fileName == parentDisk1: disk1 = disk if disk1 is None: raise Exception('Did not find disk based on %s' % parentDisk1) configSpec = Vim.Vm.ConfigSpec() fileOp = Vim.Vm.Device.VirtualDeviceSpec.FileOperation.destroy vmconfig.RemoveDeviceFromSpec(configSpec, disk1, fileOp) vm.Reconfigure(vmC1, configSpec) vm.PowerOn(vmC1) found = CheckInPolicy(domainC1, [(vmC1dir, 3), (vmPdir, 1), (vmC2dir, 1)]) if len(found) != 3: raise Exception('Did not find all expected permission in child 1. ' + 'Found: %s' % ', '.join(found)) vm.PowerOff(vmC1) Log('Destroy linked child 2. Verify policy of linked child 1.') vm.Destroy(vmC2) vm.PowerOn(vmC1) found = CheckInPolicy(domainC1, [(vmC1dir, 3), (vmPdir, 1), (vmC2dir, 1)]) if len(found) != 3: raise Exception('Did not find all expected permission in child 1. ' + 'Found: %s' % ', '.join(found)) vm.PowerOff(vmC1) Log('Re-create linked child 2 by hot-adding disks based off S1C1C1.') configSpec = vmconfig.CreateDefaultSpec(name=child2Name, datastoreName=datastore) configSpec = vmconfig.AddScsiCtlr(configSpec) configSpec = vmconfig.AddScsiDisk(configSpec, datastorename=datastore, capacity=1024) vimutil.InvokeAndTrack(vmFolder.CreateVm, configSpec, resPool) vmC2 = folder.Find(child2Name) domainC2 = 'hostd' + str(vmC2._GetMoId()) vmC2dir = GetVMHomeDir(vmC2) vm.PowerOn(vmC2) found = CheckInPolicy(domainC2, [(vmC2dir, 3)]) if len(found) != 1: DumpFilePolicy(domainC2) raise Exception( 'Did not find expected permission in recreated child 2.') configSpec = Vim.Vm.ConfigSpec() configSpec = vmconfig.AddScsiDisk(configSpec, datastorename=datastore, capacity=1024, cfgInfo=vmC2.GetConfig()) SetDeltaDiskBacking(configSpec, 0, parentDisk2) vimutil.InvokeAndTrack(vmC2.Reconfigure, configSpec) found = CheckInPolicy(domainC2, [(vmC2dir, 3), (vmPdir, 1)]) if len(found) != 2: raise Exception('Did not find all expected permission in recreated ' + 'child 2. Found: %s' % ', '.join(found)) Log('Hot-remove newly added delta disk') disks = vmconfig.CheckDevice(vmC2.GetConfig(), Vim.Vm.Device.VirtualDisk) deltaDisk = None for disk in disks: if disk.backing.parent and disk.backing.parent.fileName == parentDisk2: deltaDisk = disk break assert (deltaDisk is not None) configSpec = Vim.Vm.ConfigSpec() fileOp = Vim.Vm.Device.VirtualDeviceSpec.FileOperation.destroy vmconfig.RemoveDeviceFromSpec(configSpec, deltaDisk, fileOp) vimutil.InvokeAndTrack(vmC2.Reconfigure, configSpec) found = CheckInPolicy(domainC2, [(vmPdir, 1)], True) if len(found) > 0: DumpFilePolicy(domainC2) raise Exception('Found unexpected parent disk dir permission') vm.PowerOff(vmC2) # Clean up VMs vm.Destroy(vmC1) vm.Destroy(vmC2) vm.Destroy(vmP) shutil.rmtree(vmC2dir, ignore_errors=True) shutil.rmtree(vmC1dir, ignore_errors=True) shutil.rmtree(vmPdir, ignore_errors=True)