예제 #1
0
def CreateDatastores(availableDisks):
    i = 0
    sw = StopWatch()
    for availableDisk in availableDisks:
        createOptions = datastoreSystem.QueryVmfsDatastoreCreateOptions(
            availableDisk.deviceName)
        for createOption in createOptions:
            if type(createOption.info
                    ) == Vim.Host.VmfsDatastoreOption.AllExtentInfo:
                i = i + 1
                createOption.info.layout.partition[
                    0].end.block /= random.choice([2, 3, 4, 5, 6])
                diskPartInfo = storageSystem.ComputeDiskPartitionInfo(
                    availableDisk.devicePath, createOption.info.layout)
                #             Assign DS Name and Set the adjusted partition size
                #              createOption.spec.vmfs.volumeName="ds_%s" % i
                createOption.spec.vmfs.volumeName = "ds_%04d" % i
                print("Creating datastore %s" %
                      createOption.spec.vmfs.volumeName)
                createOption.spec.partition = diskPartInfo.spec
                bt = time.time()
                try:
                    ds = datastoreSystem.CreateVmfsDatastore(createOption.spec)
                except Exception as e:
                    print("Unable to create Datastore. Error: %s " % e)
                print("create one datastore took " + str(time.time() - bt) +
                      " sec.")
    sw.finish("  create all datastores")
예제 #2
0
def main():
    supportedArgs = [(["h:", "host="], "localhost", "Host name", "host"),
                     (["u:", "user="******"root", "User name", "user"),
                     (["p:", "pwd="], "ca$hc0w", "Password", "pwd"),
                     (["i:", "numiter="], "1", "Number of iterations", "iter"),
                     (["t:", "test="], "", "Speciffic test to run", "test")]

    supportedToggles = [
        (["usage", "help"], False, "Show usage information", "usage"),
        (["runall", "r"], True, "Run all the tests", "runall"),
        (["nodelete"], False, "Dont delete vm on completion", "nodelete")
    ]

    allTests = {'firmware': mainTestFirmware, 'multicore': mainTestMulticore}

    args = arguments.Arguments(sys.argv, supportedArgs, supportedToggles)
    if args.GetKeyValue("usage") == True:
        args.Usage()

        print("\nTests available:")
        for k in allTests.keys():
            print("\t" + k)

        sys.exit(0)

    # Connect
    si = SmartConnect(host=args.GetKeyValue("host"),
                      user=args.GetKeyValue("user"),
                      pwd=args.GetKeyValue("pwd"))
    atexit.register(Disconnect, si)

    # Process command line
    numiter = int(args.GetKeyValue("iter"))
    runall = args.GetKeyValue("runall")
    noDelete = args.GetKeyValue("nodelete")
    test = args.GetKeyValue("test")
    status = "PASS"

    for i in range(numiter):
        bigClock = StopWatch()

        partialStatus = "PASS"

        if test == "":
            for k in allTests.keys():
                partialStatus = allTests[k]()
        else:
            if test in allTests.keys():
                partialStatus = allTests[test]()
            else:
                Log("Test '" + test +
                    "' not found. Check usage for list of tests.")

        if partialStatus == "FAIL":
            status = "FAIL"

        Log("Tests completed.")
        bigClock.finish("iteration " + str(i))

    Log("TEST RUN COMPLETE: " + status)
예제 #3
0
파일: createvm.py 프로젝트: free-Zen/pvc
def main():
    """
   Simple command-line program for creating virtual machines on a
   system managed by hostd.
   """

    options = GetOptions()

    Connect(host=options.host, user=options.user, pwd=options.password)

    # Create vms
    envBrowser = GetEnv()
    cfgOption = envBrowser.QueryConfigOption(None, None)
    cfgTarget = envBrowser.QueryConfigTarget(None)
    for i in range(int(options.num_iterations)):
        vm1 = vm.CreateQuickDummy(options.vm_name + "_" + str(i),
                                  options.num_scsi_disks,
                                  options.num_ide_disks,
                                  datastoreName=options.datastore_name,
                                  cfgOption=cfgOption,
                                  cfgTarget=cfgTarget)

        for _ in range(int(options.num_power_cycles)):
            clock = StopWatch()
            vm.PowerOn(vm1)
            clock.finish("PowerOn done")
            clock = StopWatch()
            vm.PowerOff(vm1)
            clock.finish("PowerOff done")

        # Delete the vm as cleanup
        if not options.dont_delete:
            task = vm1.Destroy()
            WaitForTask(task)
예제 #4
0
def UnmountVolumes():
    sw = StopWatch()
    task = storageSystem.UnmountVmfsVolumeEx(volumeUUIDs)
    WaitForTask(task)
    sw.finish(" unmount VMFS volumes")  #TODO add str(len(volumeUUIDs))
    time.sleep(
        60)  # rest a bit, in case un-expected things happens to do next op
예제 #5
0
def QueryUnresolvedVmfsVolume():
    if debug:
        print(" Calling QueryUnresolvedVmfsVolume() API")
    sw = StopWatch()
    vols[:] = storageSystem.QueryUnresolvedVmfsVolume()
    sw.finish(" query unresolved Vmfs Volumes")
    print("Found " + str(len(vols)) + " number of unresolved volumes.")
예제 #6
0
class Phase:
   def __init__(self):
      self.phaseNumber = 0
      self.phaseClock = StopWatch()

   def SetPhase(self, msg):
      Log("Phase " + str(self.phaseNumber) + ": " + msg + " completed")
      self.phaseClock.finish("phase " + str(self.phaseNumber))
      self.phaseClock = StopWatch()
      self.phaseNumber = self.phaseNumber + 1
예제 #7
0
def RemoveDatastoresEx():
    if len(vmfsDs) == 0:
        print("no interested datastore found!")
        return
    sw = StopWatch()
    #./vimbase/apiref/vim-apiref/vim.host.DatastoreSystem.html
    task = datastoreSystem.RemoveDatastoreEx(vmfsDs)
    #not sure if datastore is refreshing, it worked.
    WaitForTask(task)
    sw.finish(" remove VMFS datastoreEX")
예제 #8
0
def RescanVmfs():
    sw = StopWatch()
    storageSystem.RescanVmfs()
    #task = storageSystem.RescanVmfs()
    #WaitForTask(task)  #if si is None:  si = Vim.ServiceInstance("ServiceInstance", task._stub)
    #AttributeError: 'NoneType' object has no attribute '_stub'
    #we cannot measure latency use task here. Jus measure directly.
    #This function call is helpful!
    #../py.sh storagePerfBench/storageBenchPhyhost.py -h 10.133.251.208  -u 'root' -p '' -t rescanVmfs

    sw.finish("rescan VMFS")
    time.sleep(60)
예제 #9
0
def main():
    """
   Simple command-line program for creating virtual machines on a
   system managed by hostd.
   """

    options = GetOptions()

    Connect(host=options.host,
            user=options.user,
            namespace=newestVersions.GetNamespace('vim'),
            pwd=options.password)

    # Create vms
    envBrowser = GetEnv()
    cfgOption = envBrowser.QueryConfigOption(None, None)
    cfgTarget = envBrowser.QueryConfigTarget(None)

    for i in range(int(options.num_iterations)):
        vm1 = vm.CreateQuickDummy(options.vm_name + "_" + str(i),
                                  options.num_scsi_disks,
                                  options.num_ide_disks,
                                  datastoreName=options.datastore_name,
                                  cfgOption=cfgOption,
                                  cfgTarget=cfgTarget)

        if options.opaquenetwork_id:
            config = Vim.Vm.ConfigSpec()
            config = vmconfig.AddOpaqueNetwork(config, cfgOption, opaqueNetworkId=options.opaquenetwork_id, \
                                               opaqueNetworkType=options.opaquenetwork_type, \
                                               externalId=options.externalID)
            vm.Reconfigure(vm1, config)

        for _ in range(int(options.num_power_cycles)):
            clock = StopWatch()
            vm.PowerOn(vm1)
            clock.finish("PowerOn done")
            clock = StopWatch()
            vm.PowerOff(vm1)
            clock.finish("PowerOff done")

        # Delete the vm as cleanup
        if not options.dont_delete:
            task = vm1.Destroy()
            WaitForTask(task)
예제 #10
0
def TestDVSLimits(si, uuid, dvsName):
    # Create the dvs.
    prodSpec = Vim.Dvs.ProductSpec(vendor="VMware", version = "6.5.0")
    dvsManager = si.RetrieveInternalContent().hostDistributedVirtualSwitchManager
    createSpec = Vim.Dvs.HostDistributedVirtualSwitchManager.DVSCreateSpec(
        uuid = uuid,
        name = dvsName,
        backing = Vim.Dvs.HostMember.PnicBacking(),
        productSpec = prodSpec,
        maxProxySwitchPorts = 64,
        modifyVendorSpecificDvsConfig = True,
        modifyVendorSpecificHostMemberConfig = True
        )
    vmwsetting = Vim.Dvs.HostDistributedVirtualSwitchManager.VmwareDVSSettingSpec()
    createSpec.SetVmwareSetting(vmwsetting)

    dvsManager.CreateDistributedVirtualSwitch(createSpec)
    portgroupList = []
    numIter = 512
    print("testing early binding portgroups limits")
    for i in range(numIter):
       name = "pg" + str(i)
       pg = GeneratePortgroupCfg(name, "add", "earlyBinding")
       portgroupList.append(pg)
    bigClock = StopWatch()
    dvsManager.UpdateDVPortgroups(uuid, portgroupList)
    bigClock.finish("creating " + str(numIter) + " static pgs")
    ValidateEarlyBindingPgState(name)
    cleanup(si, uuid, "")
    print("testing ephemeral binding portgroups limits")
    dvsManager.CreateDistributedVirtualSwitch(createSpec)
    portgroupList = []
    j = 0
    for j in range(numIter):
       name = "pg" + str(j)
       pg = GeneratePortgroupCfg(name, "add", "ephemeral")
       portgroupList.append(pg)
    bigClock = StopWatch()
    dvsManager.UpdateDVPortgroups(uuid, portgroupList)
    bigClock.finish("creating " + str(numIter) + " ephemeral pgs")
    ValidateEphemeralPgState(name)
    cleanup(si, uuid, "")
예제 #11
0
파일: registervm.py 프로젝트: free-Zen/pvc
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"),
                     (["i:", "numiter="], "1", "Number of iterations", "iter")]

    supportedToggles = [
        (["usage", "help"], False, "Show usage information", "usage"),
        (["unregister"], False, "Do an unregister of all registered vms",
         "unregister")
    ]

    args = arguments.Arguments(sys.argv, supportedArgs, supportedToggles)
    if args.GetKeyValue("usage") == True:
        args.Usage()
        sys.exit(0)

    # Connect
    si = Connect(host=args.GetKeyValue("host"),
                 user=args.GetKeyValue("user"),
                 pwd=args.GetKeyValue("pwd"))

    # Process command line
    vmname = args.GetKeyValue("vmname")
    numiter = int(args.GetKeyValue("iter"))
    dounreg = int(args.GetKeyValue("unregister"))

    # The unregister case
    if (dounreg):
        for v in folder.GetAll():
            v.Unregister()
        sys.exit(0)

    # Create vms
    for i in range(numiter):
        clock = StopWatch()
        folder.Register("[storage1] " + vmname + "_" + str(i) + "/" + vmname +
                        "_" + str(i) + ".vmx")
        clock.finish("Register done")
예제 #12
0
def main():
   """
   Simple command-line program for creating virtual machines on a
   system managed by hostd.
   """

   options = GetOptions()

   curSi = SmartConnect(host=options.host,
                        user=options.user,
                        pwd=options.password)

   # Create vms
   envBrowser = GetEnv()
   cfgOption = envBrowser.QueryConfigOption(None, None)
   cfgTarget = envBrowser.QueryConfigTarget(None)

   vmList = []
   tasks = []
   clock = StopWatch()
   for i in range(int(options.num_iterations)):
      vm1 = vm.CreateQuickDummy(options.vm_name + "_" + str(i),
                                options.num_scsi_disks, options.num_ide_disks,
                                datastoreName=options.datastore_name,
                                cfgOption=cfgOption, cfgTarget=cfgTarget)
      vmList.append(vm1)
      if options.opaquenetwork_id:
         config = Vim.Vm.ConfigSpec()
         config = vmconfig.AddOpaqueNetwork(config, cfgOption, opaqueNetworkId=options.opaquenetwork_id, \
                                            opaqueNetworkType=options.opaquenetwork_type)
         task = vm1.Reconfigure(config)
         tasks.append(task)
   WaitForTasks(tasks)
   clock.finish("Reconfigure VMs done")

   # Delete the vm as cleanup
   if not options.dont_delete:
      clock = StopWatch()
      WaitForTasks([curVm.Destroy() for curVm in vmList])
      clock.finish("Destroy VMs done")
예제 #13
0
def mainTestFirmware():
    Log("---[ TEST " + testName + " ]---")

    vmname = "HwV8_Firmware"
    status = "PASS"

    bigClock = StopWatch()
    vm1 = None
    try:
        macosVmName = vmname + "_MacOS"
        Log("Cleaning up VMs from previous runs...")

        vm.Delete(macosVmName, True)

        Log("Creating Mac OS VM..")
        vm1 = vm.CreateQuickDummy(macosVmName,
                                  vmxVersion="vmx-08",
                                  memory=4,
                                  guest="darwin11Guest")

        firmware = "efi"
        ChangeFirmware(vm1, firmware, True)
        if firmware != vm1.config.firmware:
            raise Exception("Firmware don't match set value")

        firmware = "bios"
        ChangeFirmware(vm1, firmware, True)
        if firmware != vm1.config.firmware:
            raise Exception("Firmware don't match set value")

        Log("Deleting VM " + macosVmName)
        vm.Delete(macosVmName, True)

        bigClock.finish(testName)
    except Exception as e:
        status = "FAIL"
        Log("Caught exception : " + str(e))

    Log("TEST [" + testName + "] COMPLETE: " + status)
    return status
예제 #14
0
def RemoveDatastores():
    sw = StopWatch()
    for ds in vmfsDs:
        dsname = ds.info.name
        #easy to fail, try multiple times, most QE try 12 times(PR1457852, PR1422995)
        retry = 0
        while retry < 1:  # can try 12 if needed
            bt = time.time()
            try:
                datastoreSystem.RemoveDatastore(ds)
            except Exception as obj:
                print("try %d Failed to delete datastore: %s : Error Msg: %s" %
                      (retry, ds, obj))
            else:
                print("remove " + dsname + " took " + str(time.time() - bt) +
                      " sec.")
                break
            retry += 1


#note: calculate individual latency may affect the overall latency
    sw.finish(" removing all datastores")
예제 #15
0
def testVMSpec():
    sw = StopWatch()
    envBrowser = GetEnv()
    sw.finish("getEnv")

    sw = StopWatch()
    cfgOption = envBrowser.QueryConfigOption(None, None)
    sw.finish("queryConfigOption")

    sw = StopWatch()
    cfgTarget = envBrowser.QueryConfigTarget(None)
    sw.finish("queryConfigTarget")

    sw = StopWatch()
    #    vmSpec = Vim.Vm.ConfigSpec()
    #    vmSpec = vmconfig.AddScsiCtlr(vmSpec, cfgOption, cfgTarget)
    #    print(vmSpec)
    sw.finish("testVMSpec")
예제 #16
0
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])
예제 #17
0
def main():
    supportedArgs = [(["h:", "host="], "localhost", "Host name", "host"),
                     (["u:", "user="******"root", "User name", "user"),
                     (["p:", "pwd="], "ca$hc0w", "Password", "pwd"),
                     (["v:", "vmname="], "Hw7ReconfigTest",
                      "Name of the virtual machine", "vmname"),
                     (["i:", "numiter="], "1", "Number of iterations", "iter")]

    supportedToggles = [
        (["usage", "help"], False, "Show usage information", "usage"),
        (["runall", "r"], True, "Run all the tests", "runall"),
        (["nodelete"], False, "Dont delete vm on completion", "nodelete")
    ]

    args = arguments.Arguments(sys.argv, supportedArgs, supportedToggles)
    if args.GetKeyValue("usage") == True:
        args.Usage()
        sys.exit(0)

    # Connect
    si = Connect(host=args.GetKeyValue("host"),
                 user=args.GetKeyValue("user"),
                 pwd=args.GetKeyValue("pwd"),
                 version="vim.version.version9")
    atexit.register(Disconnect, si)

    # Process command line
    vmname = args.GetKeyValue("vmname")
    numiter = int(args.GetKeyValue("iter"))
    runall = args.GetKeyValue("runall")
    noDelete = args.GetKeyValue("nodelete")
    status = "PASS"

    for i in range(numiter):
        bigClock = StopWatch()
        vm1 = None
        try:
            ## Cleanup old VMs
            posVmName = vmname + "_Pos_" + str(i)
            negVmName = vmname + "_Neg_" + str(i)
            CleanupVm(posVmName)
            CleanupVm(negVmName)

            ## Positive tests on a hwVersion 7 VM
            Log("Creating Hw7 VM..")
            vm1 = vm.CreateQuickDummy(posVmName, 0, 1, vmxVersion="vmx-07")

            # Test add & removal Vmxnet3 device to VM
            TestAddRemoveVmxet3Device(vm1)
            # Test add & removal of LsiLogicSAS controller to VM
            TestAddRemoveLsiLogicSasDevice(vm1)
            # Test enabling VAsserts in the VM.
            TestVAssertToggle(vm1, True)
            TestVAssertToggle(vm1, False)
            # Test VMCI device
            TestPosVMCIDevice(vm1)
            TestNegVMCIDevice(vm1, True)
            # Test PCI passthrough device
            TestPCIPassthroughDevice(vm1, True)

            ## Negative tests on a hwVersion 4 VM
            Log("Creating Hw4 VM..")
            vm2 = vm.CreateQuickDummy(vmname + "_Neg_" + str(i), 1)
            # Test add & removal Vmxnet3 device to VM
            TestAddRemoveVmxet3Device(vm2, False)
            # Test add & removal of LsiLogicSAS controller to VM
            TestAddRemoveLsiLogicSasDevice(vm2, False)
            # Test if VMCI device is present by default
            TestNegVMCIDevice(vm2, False)
            # Test adds of PCI passthrough device are disallowed
            TestPCIPassthroughDevice(vm2, False)
            Log("Destroying VMs")
            vm.Destroy(vm1)
            vm.Destroy(vm2)
            Log("Tests completed.")
            bigClock.finish("iteration " + str(i))
        except Exception as e:
            status = "FAIL"
            Log("Caught exception : " + str(e))

    Log("TEST RUN COMPLETE: " + status)
예제 #18
0
def main():
    supportedArgs = [
        (["h:", "host="], "localhost", "Host name", "host"),
        (["u:", "user="******"root", "User name", "user"),
        (["p:", "pwd="], "ca$hc0w", "Password", "pwd"),
        (["o:", "otherhost="], "", "Host name of other host", "otherhost"),
        (["q:", "otherpwd="], "ca$hc0w", "Password of other host", "otherpwd"),
        (["d:", "ds="], None, "Datastore name", "ds"),
        (["v:", "vm="], "vdm_multihost", "VM name", "vm"),
        (["i:", "numiter="], "1", "Number of iterations", "iter")
    ]

    supportedToggles = [
        (["usage", "help"], False, "Show usage information", "usage"),
        (["cleanup",
          "c"], True, "Try to cleanup test vms from previous runs", "cleanup")
    ]

    args = arguments.Arguments(sys.argv, supportedArgs, supportedToggles)
    if args.GetKeyValue("usage") == True:
        args.Usage()
        sys.exit(0)

    si = SmartConnect(host=args.GetKeyValue("host"),
                      user=args.GetKeyValue("user"),
                      pwd=args.GetKeyValue("pwd"))
    Log("Connected to host " + args.GetKeyValue("host"))

    # Process command line
    numiter = int(args.GetKeyValue("iter"))
    doCleanup = args.GetKeyValue("cleanup")
    status = "PASS"

    resultsArray = []

    serviceInstanceContent = si.RetrieveContent()
    vdiskMgr = serviceInstanceContent.GetVirtualDiskManager()
    if vdiskMgr == None:
        Log("Virtual Disk Manager not found")
        sys.exit(0)

    otherHostSetup = OtherHostSetup(args)
    otherHostSetup.SetupOtherHost()
    for i in range(numiter):
        bigClock = StopWatch()
        try:
            try:
                ph = Phase()

                vdiskMgrTest = VirtualDiskManagerTest(si, vdiskMgr, args)
                vdiskMgrTest.RunTests()

                ph.SetPhase("Virtual Disk Manager Tests")
                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)

    otherHostSetup.CleanupOtherHost()

    Log("Results for each iteration: ")
    for i in range(len(resultsArray)):
        Log("Iteration " + str(i) + ": " + resultsArray[i])
예제 #19
0
def RescanHBA():
    sw = StopWatch()
    storageSystem.RescanHba(
        "vmhba2")  #TODO: need pass in an adapater,let me hardcode first.
    sw.finish("rescan ")
예제 #20
0
def AttachLuns():
    sw = StopWatch()
    task = storageSystem.AttachScsiLunEx(lunUUIDs)
    WaitForTask(task)
    sw.finish(" attach LUNs")
    time.sleep(360)  # tried 180 still not enough
예제 #21
0
def MountVolumes():
    sw = StopWatch()
    task = storageSystem.MountVmfsVolumeEx(volumeUUIDs)
    WaitForTask(task)
    sw.finish(" mount VMFS volumes")
    time.sleep(60)
예제 #22
0
def main():
    supportedArgs = [(["h:", "host="], "localhost", "Host name", "host"),
                     (["u:", "user="******"root", "User name", "user"),
                     (["p:", "pwd="], "ca$hc0w", "Password", "pwd"),
                     (["v:", "vmname="], "BasicReconfigTest",
                      "Name of the virtual machine", "vmname"),
                     (["i:", "numiter="], "1", "Number of iterations", "iter")]

    supportedToggles = [
        (["usage", "help"], False, "Show usage information", "usage"),
        (["runall", "r"], True, "Run all the tests", "runall"),
        (["nodelete"], False, "Dont delete vm on completion", "nodelete")
    ]

    args = arguments.Arguments(sys.argv, supportedArgs, supportedToggles)
    if args.GetKeyValue("usage") == True:
        args.Usage()
        sys.exit(0)

    # Connect
    si = Connect(host=args.GetKeyValue("host"),
                 user=args.GetKeyValue("user"),
                 pwd=args.GetKeyValue("pwd"))
    atexit.register(Disconnect, si)

    # Process command line
    vmname = args.GetKeyValue("vmname")
    numiter = int(args.GetKeyValue("iter"))
    runall = args.GetKeyValue("runall")
    noDelete = args.GetKeyValue("nodelete")
    status = "PASS"

    try:
        # Enumerate devices
        target = vmconfig.GetCfgTarget(None)
        numSound = 0
        numFloppy = 0

        numSound = EnumerateDevice(target.GetSound, "Sound")
        EnumerateDevice(target.GetParallel, "Parallel")
        EnumerateDevice(target.GetSerial, "Serial")
        numFloppy = EnumerateDevice(target.GetFloppy, "Floppy")
        EnumerateDevice(target.GetCdRom, "Cdrom")

        for i in range(numiter):
            bigClock = StopWatch()
            vm1 = None
            try:
                vm1 = vm.CreateQuickDummy(vmname + "_" + str(i), 1)
                ### How can we combine very similar tests across multipe types
                ### of devices?

                if numFloppy == 0:
                    Log("No floppies found. Skipping floppy tests")
                else:
                    floppy.BasicCreateDelete(vm1)
                    # These tests fail for as yet unknown reasons.
                    #floppy.CreateFloppyRemoteWithAutoDetect(vm1, True)
                    #floppy.CreateFloppyRemoteWithAutoDetect(vm1, False)
                    floppy.CreateFloppyDevWithAutoDetect(vm1, True)
                    floppy.CreateFloppyDevWithAutoDetect(vm1, False)
                    floppy.CreateFloppyWithNoDeviceAndAutoDetect(vm1)
                    floppy.CreateFloppyWithNoDeviceAndNoAutoDetect(vm1)
                    floppy.EditFloppySetAndUnsetAutodetect(vm1)

                if numSound == 0:
                    Log("No sound cards found. Skipping sound tests")
                else:
                    soundcard.BasicCreateDelete(vm1)
                    soundcard.CreateEnsoniqWithAutoDetect(vm1)
                    soundcard.CreateEnsoniqWithNoAutoDetect(vm1)
                    soundcard.CreateSB16WithAutoDetect(vm1)
                    soundcard.CreateSB16NoAuto(vm1)
                    soundcard.CreateSoundCardWithNoDeviceAndAutoDetect(vm1)
                    soundcard.CreateSoundCardWithNoDeviceAndNoAutoDetect(vm1)
                    soundcard.EditExistingEnsoniqToSetAndUnsetAutodetect(vm1)
                    # This test fails since the current implementation overwrites
                    # sound cards
                    #CreateMultipleSoundCards(vm1)
                    status = "PASS"
            finally:
                # Delete the vm as cleanup
                if noDelete == False:
                    if vm1 != None:
                        task = vm1.Destroy()
                        WaitForTask(task)
                vm1 = None
                bigClock.finish("iteration " + str(i))
    except Exception as e:
        status = "FAIL"
        Log("Caught exception : " + str(e))
예제 #23
0
def DetachLuns():
    sw = StopWatch()
    task = storageSystem.DetachScsiLunEx(lunUUIDs)
    WaitForTask(task)
    sw.finish(" detach LUNs")
    time.sleep(60)
예제 #24
0
def main():
   supportedArgs = [
      (["h:", "host="], "localhost", "Host name", "host"),
      (["u:", "user="******"root", "User name", "user"),
      (["p:", "pwd="], "ca$hc0w", "Password", "pwd"),
      (["d:", "ds="], None, "Datastore name", "ds"),
      (["r:", "rdm="], None, "Device path used in rdm creation", "rdm"),
      (["n:", "nas="], None,
              "Nas datastore creation info format:'host:share:dsname'", "nas"),
#     (["s:", "subdir="], "testvdm/", "Subdirectory in selected datastore as "
#                         "possible destination for disks'", "subdir"),
      (["i:", "numiter="], "1", "Number of iterations", "iter") ]

   supportedToggles = [
          (["usage", "help"], False, "Show usage information", "usage"),
          (["cleanup", "c"], True, "Try to cleanup test vms from previous runs",
                                   "cleanup")]

   args = arguments.Arguments(sys.argv, supportedArgs, supportedToggles)
   if args.GetKeyValue("usage") == True:
      args.Usage()
      sys.exit(0)

   # Connect
   si = SmartConnect(host=args.GetKeyValue("host"),
                     user=args.GetKeyValue("user"),
                     pwd=args.GetKeyValue("pwd"))

   Log("Connected to host " + args.GetKeyValue("host"))

   # Process command line
   numiter = int(args.GetKeyValue("iter"))
   doCleanup = args.GetKeyValue("cleanup")
   status = "PASS"

   resultsArray = []

   serviceInstanceContent = si.RetrieveContent()
   vdiskMgr = serviceInstanceContent.GetVirtualDiskManager()

   hostSystem = host.GetHostSystem(si)
   hostConfigManager = hostSystem.GetConfigManager()
   global datastoreSystem
   datastoreSystem = hostConfigManager.GetDatastoreSystem()

   if vdiskMgr == None:
      Log("Virtual Disk Manager not found")
      sys.exit(0)

   for i in range(numiter):
      bigClock = StopWatch()
      try:
         try:
            ph = Phase()

            vdiskMgrTest = VirtualDiskManagerTest(vdiskMgr, args)
            vdiskMgrTest.RunTests()

            ph.SetPhase("Virtual Disk Manager Tests")
            status = "PASS"

         finally:
            bigClock.finish("iteration " + str(i))

      # While debugging, uncomment the line below to see backtraces
      # when an exception occurs.
      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])
예제 #25
0
def main():
    supportedArgs = [(["h:", "host="], "localhost", "Host name", "host"),
                     (["u:", "user="******"root", "User name", "user"),
                     (["p:", "pwd="], "ca$hc0w", "Password", "pwd"),
                     (["v:", "vmname="], "HotPlugTest",
                      "Name of the virtual machine", "vmname"),
                     (["i:", "numiter="], "1", "Number of iterations", "iter")]

    supportedToggles = [
        (["usage", "help"], False, "Show usage information", "usage"),
        (["runall", "r"], True, "Run all the tests", "runall"),
        (["nodelete"], False, "Dont delete vm on completion", "nodelete")
    ]

    args = arguments.Arguments(sys.argv, supportedArgs, supportedToggles)
    if args.GetKeyValue("usage") == True:
        args.Usage()
        sys.exit(0)

    # Connect
    si = Connect(host=args.GetKeyValue("host"),
                 user=args.GetKeyValue("user"),
                 pwd=args.GetKeyValue("pwd"),
                 version="vim.version.version9")
    atexit.register(Disconnect, si)

    # Process command line
    vmname = args.GetKeyValue("vmname")
    numiter = int(args.GetKeyValue("iter"))
    runall = args.GetKeyValue("runall")
    noDelete = args.GetKeyValue("nodelete")
    status = "PASS"

    for i in range(numiter):
        bigClock = StopWatch()
        vm1 = folder.Find(vmname)
        try:
            if vm1:
                Log("Powering on VM " + vm1.GetConfig().GetName())
                if vm1.GetRuntime().GetPowerState(
                ) == Vim.VirtualMachine.PowerState.poweredOff:
                    vm.PowerOn(vm1)

                ## Positive test for the vm
                TestDeviceHotPlugForVm(vm1, True)

            else:
                Log("Did not specify a vmname or the VM was not found. Using the default name HotPlugTest"
                    )

                posVmName = vmname + "_Pos_" + str(i)
                negVmName = vmname + "_Neg_" + str(i)
                Log("Cleaning up VMs from previous runs...")

                vm.Delete(posVmName, True)
                vm.Delete(negVmName, True)

                ## Positive tests on a hwVersion 8 VM
                Log("Creating Hw8 VM..")
                vm1 = vm.CreateQuickDummy(posVmName,
                                          vmxVersion="vmx-08",
                                          memory="1024",
                                          guest="rhel5Guest")
                Log("Powering on VM " + vm1.GetConfig().GetName())
                vm.PowerOn(vm1)

                # Positive tests for hw8 VM
                TestDeviceHotPlugForVm(vm1, True)
                Log("Powering off and deleting VM " + vm1.GetName())
                vm.Delete(posVmName, True)

                ## Positive tests on a hwVersion 7 VM
                Log("Creating Hw7 VM..")
                vm1 = vm.CreateQuickDummy(posVmName,
                                          vmxVersion="vmx-07",
                                          memory="1024",
                                          guest="rhel5Guest")
                Log("Powering on VM " + vm1.GetConfig().GetName())
                vm.PowerOn(vm1)

                # Positive tests for hw7 VM
                TestDeviceHotPlugForVm(vm1, True)
                Log("Powering off and deleting VM " + vm1.GetName())
                vm.Delete(posVmName, True)

                Log("Creating Hw4 VM..")
                vm2 = vm.CreateQuickDummy(negVmName, 1, vmxVersion="vmx-04")
                Log("Powering on VM " + negVmName)
                vm.PowerOn(vm2)

                # Negative tests for hw4 VM
                TestDeviceHotPlugForVm(vm2, False)
                Log("Powering off and deleting VM " + vm2.GetName())
                vm.Delete(negVmName, True)

            Log("Tests completed.")
            bigClock.finish("iteration " + str(i))
        except Exception as e:
            status = "FAIL"
            Log("Caught exception : " + str(e))

    if testFailedCount == 0:
        Log("TEST RUN COMPLETE: " + status)
    else:
        Log("TEST RUN COMPLETE: FAIL")
        Log("Number of total tests failed : " + str(testFailedCount))
예제 #26
0
def main():
    supportedArgs = [(["h:", "host="], "localhost", "Host name", "host"),
                     (["u:", "user="******"root", "User name", "user"),
                     (["p:", "pwd="], "ca$hc0w", "Password", "pwd"),
                     (["v:", "vmname="], "Hw7HotPlugTest",
                      "Name of the virtual machine", "vmname"),
                     (["i:", "numiter="], "1", "Number of iterations", "iter")]

    supportedToggles = [
        (["usage", "help"], False, "Show usage information", "usage"),
        (["runall", "r"], True, "Run all the tests", "runall"),
        (["nodelete"], False, "Dont delete vm on completion", "nodelete")
    ]

    args = arguments.Arguments(sys.argv, supportedArgs, supportedToggles)
    if args.GetKeyValue("usage") == True:
        args.Usage()
        sys.exit(0)

    # Connect
    si = Connect(host=args.GetKeyValue("host"),
                 user=args.GetKeyValue("user"),
                 pwd=args.GetKeyValue("pwd"),
                 version="vim.version.version9")
    atexit.register(Disconnect, si)

    # Process command line
    vmname = args.GetKeyValue("vmname")
    numiter = int(args.GetKeyValue("iter"))
    runall = args.GetKeyValue("runall")
    noDelete = args.GetKeyValue("nodelete")
    status = "PASS"

    for i in range(numiter):
        bigClock = StopWatch()
        vm1 = None
        try:
            Log("Cleaning up VMs from previous runs...")
            vm.Delete(vmname, True)

            ## Positive tests on a hwVersion 7 VM
            Log("Creating Hw7 VM..")
            vm1 = vm.CreateQuickDummy(vmname,
                                      vmxVersion="vmx-07",
                                      memory=4,
                                      guest="rhel5Guest")

            Log("Powering on VM " + vm1.GetConfig().GetName())
            vm.PowerOn(vm1)

            # Test hot plug of multiple devices
            TestHotPlugScsiCtlr(vm1)

            Log("Deleting VM")
            vm.Delete(vmname, True)

            Log("Tests completed.")
            bigClock.finish("iteration " + str(i))
        except Exception as e:
            status = "FAIL"
            Log("Caught exception : " + str(e))
    Log("TEST RUN COMPLETE: " + status)
예제 #27
0
파일: linkedClone.py 프로젝트: free-Zen/pvc
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])
예제 #28
0
def main():
    supportedArgs = [(["h:", "host="], "localhost", "Host name", "host"),
                     (["u:", "user="******"root", "User name", "user"),
                     (["p:", "pwd="], "ca$hc0w", "Password", "pwd"),
                     (["v:", "vmname="], "SerialPortTest",
                      "Name of the virtual machine", "vmname"),
                     (["i:", "numiter="], "1", "Number of iterations", "iter")]

    supportedToggles = [
        (["usage", "help"], False, "Show usage information", "usage"),
        (["runall", "r"], True, "Run all the tests", "runall"),
        (["nodelete"], False, "Dont delete vm on completion", "nodelete")
    ]

    args = arguments.Arguments(sys.argv, supportedArgs, supportedToggles)
    if args.GetKeyValue("usage") == True:
        args.Usage()
        sys.exit(0)

    # Connect
    si = Connect(host=args.GetKeyValue("host"),
                 user=args.GetKeyValue("user"),
                 pwd=args.GetKeyValue("pwd"),
                 version="vim.version.version9")
    atexit.register(Disconnect, si)

    # Process command line
    vmname = args.GetKeyValue("vmname")
    numiter = int(args.GetKeyValue("iter"))
    runall = args.GetKeyValue("runall")
    noDelete = args.GetKeyValue("nodelete")
    status = "PASS"

    for i in xrange(numiter):
        bigClock = StopWatch()
        vm1 = None
        try:
            Log("Cleaning up VMs from previous runs...")
            vm.Delete(vmname, True)

            Log("Creating VM..")
            vm1 = vm.CreateQuickDummy(vmname)

            Log("Adding serial port with device backing")
            TestAddSerial(vm1,
                          Vim.Vm.Device.VirtualSerialPort.DeviceBackingInfo)

            Log("Adding serial port with file backing")
            TestAddSerial(vm1, Vim.Vm.Device.VirtualSerialPort.FileBackingInfo)

            Log("Adding serial port with pipe backing")
            TestAddSerial(vm1, Vim.Vm.Device.VirtualSerialPort.PipeBackingInfo)

            Log("Adding serial port with URI backing")
            TestAddSerial(vm1, Vim.Vm.Device.VirtualSerialPort.URIBackingInfo)

            Log("Deleting VM..")
            vm.Delete(vmname, True)

            Log("Tests completed.")
            bigClock.finish("iteration " + str(i))
        except Exception as e:
            status = "FAIL"
            Log("Caught exception : " + str(e))
    Log("TEST RUN COMPLETE: " + status)
예제 #29
0
파일: vmTestUSB.py 프로젝트: free-Zen/pvc
def main():
    supportedArgs = [(["h:", "host="], "localhost", "Host name", "host"),
                     (["u:", "user="******"root", "User name", "user"),
                     (["p:", "pwd="], "ca$hc0w", "Password", "pwd"),
                     (["v:", "vmname="], "HotPlugTest",
                      "Name of the virtual machine", "vmname"),
                     (["i:", "numiter="], "1", "Number of iterations", "iter")]

    supportedToggles = [
        (["usage", "help"], False, "Show usage information", "usage"),
        (["runall", "r"], True, "Run all the tests", "runall"),
        (["nodelete"], False, "Dont delete vm on completion", "nodelete")
    ]

    args = arguments.Arguments(sys.argv, supportedArgs, supportedToggles)
    if args.GetKeyValue("usage") == True:
        args.Usage()
        sys.exit(0)

    # Connect
    si = SmartConnect(host=args.GetKeyValue("host"),
                      user=args.GetKeyValue("user"),
                      pwd=args.GetKeyValue("pwd"))
    atexit.register(Disconnect, si)

    # Process command line
    vmname = args.GetKeyValue("vmname")
    numiter = int(args.GetKeyValue("iter"))
    runall = args.GetKeyValue("runall")
    noDelete = args.GetKeyValue("nodelete")
    status = "PASS"

    # Find a USB device on the host to passthrough
    envBrowser = invt.GetEnv()
    cfgTarget = envBrowser.QueryConfigTarget(None)
    if len(cfgTarget.usb) < 1:
        Log("No USB devices available for passthrough on " +
            args.GetKeyValue("host"))
        return

    device = cfgTarget.usb[0]

    for i in range(numiter):
        bigClock = StopWatch()
        vm1 = None
        try:
            vmname7 = vmname + "_HwV7"
            vmname8 = vmname + "_HwV8"
            Log("Cleaning up VMs from previous runs...")
            vm.Delete(vmname7, True)
            vm.Delete(vmname8, True)

            ## Positive tests on a hwVersion 7 VM
            Log("Creating Hw7 VM..")
            vm1 = vm.CreateQuickDummy(vmname7,
                                      vmxVersion="vmx-07",
                                      memory=4,
                                      guest="rhel5Guest")

            Log("Add a new USB controller to the VM")
            cspec = Vim.Vm.ConfigSpec()
            cspec = vmconfig.AddUSBCtlr(cspec)
            vm.Reconfigure(vm1, cspec)

            DoPlugTests(vm1, device, Vim.Vm.Device.VirtualUSBController, True)
            vm.Delete(vm1.name, True)

            ## Positive tests on a hwVersion 8 VM
            Log("Creating Hw8 VM..")
            vm1 = vm.CreateQuickDummy(vmname8,
                                      vmxVersion="vmx-08",
                                      memory=4,
                                      guest="rhel5Guest")

            Log("Add a new xHCI USB controller to the VM")
            cspec = Vim.Vm.ConfigSpec()
            cspec = vmconfig.AddUSBXHCICtlr(cspec)
            vm.Reconfigure(vm1, cspec)
            xhciCtlr = CheckDevice(vm1, Vim.Vm.Device.VirtualUSBXHCIController,
                                   "xHCI controller")
            DoPlugTests(vm1, device, Vim.Vm.Device.VirtualUSBXHCIController,
                        True)

            Log("Add a new USB controller to the VM")
            cspec = Vim.Vm.ConfigSpec()
            cspec = vmconfig.AddUSBCtlr(cspec)
            vm.Reconfigure(vm1, cspec)
            usbCtlr = CheckDevice(vm1, Vim.Vm.Device.VirtualUSBController,
                                  "USB controller")
            DoPlugTests(vm1, device, Vim.Vm.Device.VirtualUSBController, True)

            Log("Remove xHCI USB controller from the VM")
            cspec = vmconfig.RemoveDeviceFromSpec(Vim.Vm.ConfigSpec(),
                                                  xhciCtlr)
            vm.Reconfigure(vm1, cspec)
            CheckNoDevice(vm1, Vim.Vm.Device.VirtualUSBXHCIController,
                          "xHCI controller")

            Log("Remove USB controller from the VM")
            cspec = vmconfig.RemoveDeviceFromSpec(Vim.Vm.ConfigSpec(), usbCtlr)
            vm.Reconfigure(vm1, cspec)
            CheckNoDevice(vm1, Vim.Vm.Device.VirtualUSBController,
                          "USB controller")

            vm.Delete(vm1.name, True)

            Log("Tests completed.")
            bigClock.finish("iteration " + str(i))
        except Exception as e:
            status = "FAIL"
            Log("Caught exception : " + str(e))
    Log("TEST RUN COMPLETE: " + status)
예제 #30
0
def RunTests(argv):
    global isMockup
    global options

    # Can't use built-in help option because -h is used for hostname
    parser = OptionParser(add_help_option=False)

    parser.add_option('-v', '--vc', dest='vcHost', help='VC Host name')
    parser.add_option('-d', '--dc', dest='dcName', help='Datacenter name')
    parser.add_option('-h',
                      '--host',
                      dest='host',
                      help='ESX Host name',
                      default='localhost')
    parser.add_option('-u',
                      '--user',
                      dest='user',
                      help='User name',
                      default='root')
    parser.add_option('-p', '--pwd', dest='pwd', help='Password', default="")
    parser.add_option('-o',
                      '--port',
                      dest='port',
                      help='Port',
                      default=443,
                      type='int')
    parser.add_option('-i',
                      '--numiter',
                      dest='iter',
                      help='Iterations',
                      default=1,
                      type='int')
    parser.add_option('-t', '--datastore', dest='datastore', help='Datastore')
    parser.add_option('-l', '--volume', dest='volume', help='VMFS volume')
    parser.add_option('-c',
                      '--cleanup',
                      dest='cleanup',
                      help='Try to clean up test VMs from previous runs',
                      default=False,
                      action='store_true')
    parser.add_option('-?',
                      '--help',
                      '--usage',
                      action='help',
                      help='Usage information')

    (options, args) = parser.parse_args(argv)

    # Connect
    global si
    if options.vcHost:
        si = SmartConnect(host=options.vcHost,
                          user="******",
                          pwd="ca$hc0w")
    else:
        si = SmartConnect(host=options.host,
                          user=options.user,
                          pwd=options.pwd,
                          port=options.port)
    atexit.register(Disconnect, si)

    isMockup = host.IsHostMockup(si)
    status = "PASS"

    # Determine the datastore name
    if options.datastore and options.volume:
        Log("Cannot specify both datastore and volume")
        sys.exit(-1)
    elif options.datastore:
        datastore = options.datastore
        Log("Using specified datastore: '%s'" % datastore)
    elif options.volume:
        # Convert absolute volume path to (dsName, relPath) tuple to get dsName
        Log("Trying to determine datastore name for volume: '%s'" %
            options.volume)
        try:
            datastore = path.FsPathToTuple(options.volume)[0]
            Log("Using datastore: '%s'" % datastore)
        except path.FilePathError:
            Log("Could not determine datastore name for volume: '%s'" %
                options.volume)
            sys.exit(-1)
    else:
        Log("No datastore or volume specified, test will choose one")
        datastore = None

    resultsArray = []
    # Do cleanup if requested
    Cleanup(testVMPrefix, options.cleanup)

    for i in range(options.iter):
        bigClock = StopWatch()
        try:
            try:
                # Find the vm without tools
                newName = testVMPrefix + str(i)
                ph = Phase()
                # Retrieve Vm Recovery Info Tests
                BasicRetrieveTests(options.host, newName)
                ph.SetPhase("Basic retrieve recovery and migration info on " +
                            newName)

                RetrieveTests(options.host)
                ph.SetPhase(
                    "Retrieve recovery and migration info on all VM's in a datastore"
                )

                # Delete Vm except disks tests
                DeleteVmExceptDisksTests(options.host, newName)
                ph.SetPhase("Delete vm except disks on " + newName)

                # Power off suspended VM test.
                PoweroffSuspendedVMTests(options.host, newName, datastore)
                ph.SetPhase("Powered Off Suspended VM " + newName)

                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)

    return_code = 0
    Log("Results for each iteration: ")
    for i in range(len(resultsArray)):
        if resultsArray[i] == "FAIL":
            return_code = -1
        Log("Iteration " + str(i) + ": " + resultsArray[i])

    return return_code