Exemple #1
0
def main():
   supportedArgs = [ (["h:", "host="], "localhost", "Host name", "host"),
                     (["u:", "user="******"root", "User name", "user"),
                     (["p:", "pwd="], "ca$hc0w", "Password", "pwd"),
                     (["d:", "d1="], "storage1", "Datastore 1", "ds1"),
                     (["q:", "d2="], "local", "Datastore 2", "ds2"),
                     (["i:", "numiter="], "1", "Number of iterations", "iter"),
                     (["f:", "deltaDiskFormat="], "redoLogFormat", "Delta Disk Format: nativeFormat/seSparseFormat/redoLogFormat", "delta"),
                     (["b:", "backingType="], "flat", "Backing type of disk", "backing"),
                     (["v:", "vmxVersion="], "vmx-08", "The VMX version", "vmx") ]

   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.SmartConnect(host=args.GetKeyValue("host"),
                user=args.GetKeyValue("user"),
                pwd=args.GetKeyValue("pwd"))
   atexit.register(connect.Disconnect, si)

   # Process command line
   numiter = int(args.GetKeyValue("iter"))
   ds1 = args.GetKeyValue("ds1")
   ds2 = args.GetKeyValue("ds2")
   deltaDiskFormat = args.GetKeyValue("delta")
   backingType = args.GetKeyValue("backing")
   vmxVersion = args.GetKeyValue("vmx")
   status = "PASS"

   resultsArray = []
   testLinkedClone(si, numiter, deltaDiskFormat, backingType, vmxVersion, ds1, ds2, status, resultsArray)
Exemple #2
0
def main():
    supportedArgs = [(["h:", "host="], "localhost", "Host name", "host"),
                     (["u:", "user="******"root", "User name", "user"),
                     (["p:", "pwd="], "ca$hc0w", "Password", "pwd"),
                     (["v:", "vmname="], "",
                      "VM prefix (deletes everything by default)", "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(host=args.GetKeyValue("host"),
                 user=args.GetKeyValue("user"),
                 pwd=args.GetKeyValue("pwd"))

    # Process command line
    vmname = args.GetKeyValue("vmname")

    vms = folder.FindPrefix(vmname)
    if len(vms) != 0:
        for vm in vms:
            try:
                vm.Destroy()
            except Exception, e:
                raise
Exemple #3
0
def main():
    supportedArgs = [(["h:", "host="], "localhost", "Host name", "host"),
                     (["u:", "user="******"root", "User name", "user"),
                     (["p:", "pwd="], "", "Password", "pwd")]

    supportedToggles = [(["burn", "use"], False, "Burn the ticket", "burn"),
                        (["usage",
                          "help"], False, "Show usage information", "usage")]

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

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

    # Obtain a ticket
    sm = si.GetContent().GetSessionManager()
    ticket = sm.AcquireCloneTicket()
    print "Clone Ticket: " + ticket

    if not args.GetKeyValue("burn") == True:
        return

    # Use the ticket
    try:
        (host, port) = args.GetKeyValue("host").split(":", 1)
        port = int(port)
    except ValueError, ve:
        host = args.GetKeyValue("host")
        port = 902
Exemple #4
0
def main():
   supportedArgs = [ (["h:", "host="], "10.112.184.217", "Host name", "host"),
                     (["u:", "user="******"root", "User name", "user"),
                     (["p:", "pwd="], "", "Password", "pwd")]

   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.SmartConnect(host=args.GetKeyValue("host"),
                             user=args.GetKeyValue("user"),
                             pwd=args.GetKeyValue("pwd"))
   atexit.register(connect.Disconnect, si)

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

   vffs = Vffs(si)
   vffs.__init__(si)
   fs = vffs.formatVffs("vffs")
   if fs == None:
      print("XXX::HostCacheConfig test FAILED")
   else:
      if vffs.testHostCache(fs.uuid) == 1:
           print("***::HostCacheConfig test PASSED")
      else:
           print("XXX::HostCacheConfig test FAILED")
Exemple #5
0
def main():
    supportedArgs = [
        (["h:", "host="], "localhost", "Secondary host name", "host"),
        (["u:", "user="******"root", "User name", "user"),
        (["p:", "pwd="], "ca$hc0w", "Password", "pwd"),
        (["v:", "VM name="], "vmFT", "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)

    vmname = args.GetKeyValue("vmname")

    try:
        si = Connect(host=args.GetKeyValue("host"),
                     user=args.GetKeyValue("user"),
                     pwd=args.GetKeyValue("pwd"))
        atexit.register(Disconnect, si)
        Log("Connected to host")
        CleanupVm(vmname, True)
        Log("Cleaned up secondary VM")
    except Exception as e:
        Log("Caught exception : " + str(e))
Exemple #6
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)
Exemple #7
0
def main():
   supportedArgs = [ (["h:", "host="], "10.112.184.217", "Host name", "host"),
                     (["u:", "user="******"root", "User name", "user"),
                     (["p:", "pwd="], "", "Password", "pwd")]

   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.SmartConnect(host=args.GetKeyValue("host"),
                             user=args.GetKeyValue("user"),
                             pwd=args.GetKeyValue("pwd"))
   atexit.register(connect.Disconnect, si)

   qt = QueryTest(si)
   qt.__init__(si)

   if qt.test() == 0:
	print("QueryAvailableDisksForVmfs test PASSED")
   else:
	print("QueryAvailableDisksForVmfs test FAILED")
Exemple #8
0
def main():
    supportedArgs = [(["h:", "host="], "localhost", "Host name", "host"),
                     (["u:", "user="******"root", "User name", "user"),
                     (["p:", "pwd="], "ca$hc0w", "Password", "pwd")]

    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)

    reg = GetRegistry(args.GetKeyValue("host"), args.GetKeyValue("user"),
                      args.GetKeyValue("pwd"))
    if reg == None:
        print("Stats registry instance is NULL!")
        sys.exit(0)

    #get supported stats definition
    stats = GetStatList(reg)
    print(stats)

    #get stat value
    statValues = GetStatValue(reg, [[1], [2, '1']])
Exemple #9
0
def main():
   supportedArgs = [ (["h:", "host="], "localhost", "Host name", "host"),
                     (["u:", "user="******"root", "User name", "user"),
                     (["p:", "pwd="], "", "Password", "pwd"),
                     (["v:", "vmname="], "SATATest", "Name of the virtual machine", "vmname") ]

   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")
   runall = args.GetKeyValue("runall")
   noDelete = args.GetKeyValue("nodelete")
   status = "PASS"
   vm1 = None

   try:
      Log("Cleaning up VMs from previous runs...")
      vm.Delete(vmname, True)

      ## Positive tests on a hwVersion 10 VM
      Log("Creating Hw10 VM..")
      vm1 = vm.CreateQuickDummy(vmname, vmxVersion = "vmx-10",
                                memory = 4, guest = "otherGuest")

      # Test add of SATA controller
      TestSataCtlrReconfig(vm1)

      # Mess with SATA disks
      TestEditSataDisk(vm1)

      # Mess with SATA cdroms
      TestEditSataCdrom(vm1)

      Log("Tests completed.")

   except Exception as e:
      status = "FAIL"
      Log("Caught exception : " + str(e))
   finally:
      # Delete the vm as cleanup
      if noDelete == False:
         if vm1 != None:
            task = vm1.Destroy()
            WaitForTask(task)
         vm1 = None

   Log("TEST RUN COMPLETE: " + status)
Exemple #10
0
def main():
   supportedArgs = [ (["h:", "host="], "10.112.184.217", "Host name", "host"),
                     (["u:", "user="******"root", "User name", "user"),
                     (["p:", "pwd="], "", "Password", "pwd")]

   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.SmartConnect(host=args.GetKeyValue("host"),
                             user=args.GetKeyValue("user"),
                             pwd=args.GetKeyValue("pwd"))
   atexit.register(connect.Disconnect, si)

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

   pt = PartTest(si)
   pt.__init__(si)
   ret = pt.testPart()
   if ret == 1:
      Log ("test successful")
   else:
      Log ("test failed")
      return
Exemple #11
0
def main():
    supportedArgs = [
        (["h:", "host="], "localhost", "Host name", "host"),
        (["u:", "user="******"root", "User name", "user"),
        (["p:", "pwd="], None, "Password", "pwd"),
        (["v:", "vmname="], None, "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
    connection = Connection(host=args.GetKeyValue("host"),
                            user=args.GetKeyValue("user"),
                            pwd=args.GetKeyValue("pwd"),
                            namespace="vim25/5.5")
    with connection as si:
        # Process command line
        vmname = args.GetKeyValue("vmname")
        vm = folder.Find(vmname)
        if vm == None:
            print "Could not find VM", vmname
            sys.exit(1)
        print SerializeToConfig(vm.config, tag="configInfo")
Exemple #12
0
def main():
    supportedArgs = [(["h:", "host="], "localhost", "Host name", "host"),
                     (["u:", "user="******"root", "User name", "user"),
                     (["p:", "pwd="], "", "Password", "pwd"),
                     (["v:", "vmname="], "", "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(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")

    vm1 = None
    try:
        # Find the VM
        vm1 = folder.Find(vmname)
        if vm1 == None:
            raise Exception("VM with name " + vmname + " cannot be found!")

        instanceId = "0"
        # Inspired by InternalCommand() in vim/py/tests/vmTestHbr.py!!
        vprobesMgr = Hostd.VprobesManager("ha-internalsvc-vprobesmgr",
                                          si._stub)
        bad_script = '''0
         (vprobe VMXLoad (printf \"Test script loaded\\n\"))
         (vprobe VMM1Hz (printf \"Hello World\\n\"))
         (vprobe badProbeName (printf \"Test script unloaded\\n\"))
         '''
        task = vprobesMgr.LoadVprobes(vm1, bad_script)
        WaitForTask(task)

        Log("FAILURE: Failed to catch exception")

    except Vmodl.Fault.SystemError as e:
        Log("EXPECTED FAILURE: Load failed: " + e.reason)
        Log("SUCCESS: VProbes tests completed")
        return
    except Exception as e:
        Log("FAILURE: Caught exception : " + str(e))
        raise e

    return
Exemple #13
0
def main():
    # Process command line
    supportedArgs = [(["h:", "host="], "localhost", "Host name", "host"),
                     (["u:", "user="******"root", "User name", "user"),
                     (["p:", "pwd="], "ca$hc0w", "Password", "pwd")]

    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(host=args.GetKeyValue("host"),
                 user=args.GetKeyValue("user"),
                 pwd=args.GetKeyValue("pwd"))
    atexit.register(Disconnect, si)

    # Connect
    status = "PASS"
    try:
        content = si.RetrieveContent()

        # Gee, getting to hostSystem require quit a bit of works
        dataCenter = content.GetRootFolder().GetChildEntity()[0]
        hostFolder = dataCenter.GetHostFolder()
        computeResource = hostFolder.GetChildEntity()[0]
        hostSystem = computeResource.GetHost()[0]

        # Performance manager
        perfManager = content.GetPerfManager()
        querySpecs = []

        querySpec = Vim.PerformanceManager.QuerySpec()
        querySpec.entity = hostSystem
        querySpecs.append(querySpec)
        for i in range(0, 4):
            # Query stats
            entityMetrics = perfManager.QueryStats(querySpecs)

            # Query composite stats
            metricIds = perfManager.QueryAvailableMetric(hostSystem)
            querySpec.metricId = metricIds
            entityMetrics = perfManager.QueryCompositeStats(querySpecs[0])
    except Exception as e:
        Log("Failed test due to exception: " + str(e))
        status = "FAIL"
    finally:
        pass
    Log("TEST RUN COMPLETE: " + status)
Exemple #14
0
def main():
   supportedArgs = [ (["h:", "host="], "10.20.109.41", "Host name", "host"),
                     (["u:", "user="******"root", "User name", "user"),
                     (["p:", "pwd="], "vmware", "Password", "pwd"),
                     (["vpuser="******"root", "VP User name", "vpuser"),
                     (["vppwd="], "ca$hc0w", " VP Password", "vppwd"),
                     (["n:", "nfs="], "10.20.108.115", "nfs host name", "nfs"),
                     (["m:", "mount="], "/mnt/pes/pepsi_nfs_pe", "Nfs server mount point", "mount"),
                     (["d:", "pe="], "pepsi_nfs_pe", "PE name", "pe"),
                     (["v:", "verbose="], "3", "log level(1-3), the lesser the more verbose", "verbose")]

   supportedToggles = [(["usage", "help"], False, "Show usage information", "usage")]

   args = arguments.Arguments(sys.argv, supportedArgs, supportedToggles)
   if args.GetKeyValue("usage") == True:
      args.Usage()
      print('Prerequisite:\n\
               1. VC with minimum of one host configured\n\
               2. VP is registered with SMS\n\
               3. VP is configured with NFS pe')
      sys.exit(0)

   global verbose
   verbose = int(args.GetKeyValue("verbose"))



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

   ds = VvolDs(args)

   ds.CleanupExistingTestDatastores()
   ds.addPE()
   ds.TestDummyCreateVvolDs()
   ds.TestCreateVvolDs()
   ds.TestDestroyVvolDs()
   ds.TestBulkCreateVvolDs()
   ds.TestBulkRemoveVvolDs()
   ds.TestBulkRemoveNonVvolDs()
   ds.TestRemoveVvolDsWithVms()
   ds.TestCreateDir()
   ds.TestVmMigrate()
   ds.TestDisconnectedHost()
   ds.TestUpdateVvolDs()
Exemple #15
0
def main():
    ssl._create_default_https_context = ssl._create_unverified_context
    supportedArgs = [(["s:", "server="], "localhost", "Host name", "server")]
    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)

    try:
        host = args.GetKeyValue("server")
        stub = SoapStubAdapter(host, 443, "vim25/2.5", "/sdk")
        si = Vim.ServiceInstance("ServiceInstance", stub)
        sc = si.RetrieveContent()
        print sc.about.build
    except Exception, e:
        print e
        sys.exit(1)
Exemple #16
0
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")
Exemple #17
0
def main():
    supportedArgs = [(["h:", "host="], "localhost", "Host name", "host"),
                     (["u:", "user="******"root", "User name", "user"),
                     (["p:", "pwd="], "", "Password", "pwd"),
                     (["d:", "disk="], "/vmfs/devices/", "Disk", "disk"),
                     (["s:", "ds="], "datastore1", "Datastore 1", "ds")]
    supportedToggles = [(["usage",
                          "help"], False, "Show usage information", "usage")]

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

    options = Options()
    options.disk = args.GetKeyValue("disk")
    options.datastore = args.GetKeyValue("ds")
    options.hostname = args.GetKeyValue("host")
    options.username = args.GetKeyValue("user")
    options.password = args.GetKeyValue("pwd")
    run(options)
Exemple #18
0
def main():
    supportedArgs = [(["h:", "host="], "localhost", "Host name", "host"),
                     (["u:", "user="******"root", "User name", "user"),
                     (["p:", "pwd="], "ca$hc0w", "Password", "pwd"),
                     (["i:", "id="], "1", "ID of client", "id"),
                     (["f:", "flag="], None, "Toggle dispatcher flag", "flag")]

    supportedToggles = [
        (["usage", "help"], False, "Show usage information", "usage"),
    ]

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

    host = args.GetKeyValue("host")

    status = "PASS"

    try:
        # Connect to hosts.
        si = connect.Connect(host=host,
                             user=args.GetKeyValue("user"),
                             pwd=args.GetKeyValue("pwd"),
                             version="vim.version.version9")

        atexit.register(Disconnect, si)

        id = args.GetKeyValue("id")
        if args.GetKeyValue("flag"):
            ToggleDispatcherFlag(si, args.GetKeyValue("flag"))

        Log("TEST RUN %s COMPLETE: %s" % (id, status))
    except Exception:
        (excType, excVal, excTB) = sys.exc_info()
        Log("Caught exception: ")
        traceback.print_exception(excType, excVal, excTB)
        status = "FAIL"
Exemple #19
0
def main():
   supportedArgs = [ (["h:", "host="], "localhost", "Host name", "host"),
                     (["u:", "user="******"root", "User name", "user"),
                     (["p:", "pwd="], "ca$hc0w", "Password", "pwd"),
                     (["v:", "vmname="], "", "Name of the virtual machine", "vmname"),
                     (["d:", "snapshotdesc="], "Quick Dummy", "Snapshot description", "snapshotdesc"),
                     (["s:", "snapshotname="], "TestSnapshot", "Name of the snapshot", "snapshotname")]
   
   supportedToggles = [ (["usage", "help"], False, "Show usage information", "usage"),
                        (["dontDelete", "d"], False, "Dont delete created snapshot", "del")]

   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")
   snapshotname = args.GetKeyValue("snapshotname")
   snapshotdesc = args.GetKeyValue("snapshotdesc")
   doDelete = not args.GetKeyValue("del")
   if len(vmname) == 0 or len(snapshotname) == 0:
      args.Usage()
      sys.exit(0)

   aVm = folder.FindPrefix(vmname)[0]
   task = aVm.CreateSnapshot(snapshotname, snapshotdesc, memory=False, quiesce=False)
   snap = aVm.GetSnapshot().currentSnapshot
   print "Snapshot: %s" % repr(snap)
   if doDelete:
      print "Waiting for snapshot to be created: %s ..." % repr(snap)
      WaitForTask(task)
      print "Snapshot created. Removing ..."
      vm.RemoveSnapshot(snap)
Exemple #20
0
def main():
   supportedArgs = [ (["h:", "host="], "localhost", "Host name", "host"),
                    (["u:", "user="******"root", "User name", "user"),
                    (["p:", "pwd="], "", "password", "pwd"),
                    (("t:", "test="), "lun", "test lun, vmfs, or nas", "test")
                    ]

   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)

   si = Connect(host=args.GetKeyValue("host"),
                user=args.GetKeyValue("user"),
                pwd=args.GetKeyValue("pwd"),
                version=newestVersions.get('vim'))

   atexit.register(Disconnect, si)
   global datastoreSystem
   datastoreSystem = host.GetHostConfigManager(si).GetDatastoreSystem()
   global storageSystem
   storageSystem = host.GetHostConfigManager(si).GetStorageSystem()
   test = args.GetKeyValue("test")
   if test == "lun":
      LunVerify()
      LunSimpleTest()
      LunNegativeTest()
   elif test == "vmfs":
      VmfsVerify()
      VmfsSimpleTest()
      VmfsNegativeTest()
   elif test == "nas":
      NasVerify()
      NasSimpleTest()
      NasNegativeTest()
   else:
      raise Exception("Unsupported test = " + test)
Exemple #21
0
def main():
    supportedArgs = [(["h:", "host="], "localhost", "Host name", "host"),
                     (["u:", "user="******"root", "User name", "user"),
                     (["p:", "pwd="], "ca$hc0w", "Password", "pwd")]

    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 = SmartConnect(host=args.GetKeyValue("host"),
                      user=args.GetKeyValue("user"),
                      pwd=args.GetKeyValue("pwd"))
    atexit.register(Disconnect, si)

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

    vmfs5 = Vmfs5(si)
    vmfs5.TestCreateAndUpgradeVmfsDatastores()
Exemple #22
0
def main():
    supportedArgs = [(["h:", "host="], "localhost", "Host name", "host"),
                     (["u:", "user="******"root", "User name", "user"),
                     (["p:", "pwd="], "", "Password", "pwd")]

    supportedToggles = [(["burn", "use"], False, "Burn the ticket", "burn"),
                        (["usage", "help"], False, "usage", "usage")]

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

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

    time.sleep(5)

    print "VMs found:"
    for vm1 in folder.GetVmAll():
        print "   " + str(vm1)

    print "Selecting VM:" + str(vm1)
    time.sleep(2)

    PowerOff(vm1)

    PowerOn(vm1)

    # Obtain a ticket
    print "Obtaining ticket from:" + str(vm1)
    ticket_ = vm1.AcquireTicket('vmconsole')
    time.sleep(2)
    print "Ticket: " + ticket_.ticket
Exemple #23
0
import atexit

# Process command line
supportedArgs = [
    (["h:", "host="], "localhost", "Host name", "host"),
    (["u:", "user="******"root", "User name", "user"),
    (["p:", "pwd="], "", "Password", "pwd"),
    (["v:", "vmname="], "VM01", "Virtual Machine Name", "vmname"),
    (["d:", "diskInstance="], "scsi0:1", "Disk Instance", "diskInstance"),
    (["m:", "moduleInstance="], "vfc", "Module Instance", "moduleInstance"),
]

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(host=args.GetKeyValue("host"),
             user=args.GetKeyValue("user"),
             pwd=args.GetKeyValue("pwd"))
atexit.register(Disconnect, si)

vmname = args.GetKeyValue("vmname")
vm1 = folder.Find(vmname)

content = si.RetrieveContent()
dataCenter = content.GetRootFolder().GetChildEntity()[0]
Exemple #24
0
def main():
    supportedArgs = [
        (["P:",
          "primary host="], "localhost", "Primary host name", "primaryHost"),
        (["S:", "secondary host="], "localhost", "Secondary host name",
         "secondaryHost"),
        (["d:", "shared datastore name="], "storage1", "shared datastore name",
         "dsName"),
        (["k:", "keep="], "0", "Keep configs", "keep"),
        (["u:", "user="******"root", "User name", "user"),
        (["p:", "pwd="], "", "Password", "pwd"),
        (["v:", "vmname="], "vmFT", "Name of the virtual machine", "vmname"),
        (["i:", "numiter="], "1", "Number of iterations", "iter"),
        (["t:",
          "FT type="], "up", "Type of fault tolerance [up|smp]", "ftType"),
    ]
    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)

    # Process command line
    vmname = args.GetKeyValue("vmname")
    numiter = int(args.GetKeyValue("iter"))
    keep = int(args.GetKeyValue("keep"))
    dsName = args.GetKeyValue("dsName")
    primaryHost = args.GetKeyValue("primaryHost")
    secondaryHost = args.GetKeyValue("secondaryHost")
    ftType = args.GetKeyValue("ftType")

    numCPU = 2 if ftType == "smp" else 1
    memSize = 64

    for i in range(numiter):
        primaryVm = None
        primarySi = None
        secondarySi = None
        try:
            # Connect to primary host
            primarySi = SmartConnect(host=primaryHost,
                                     user=args.GetKeyValue("user"),
                                     pwd=args.GetKeyValue("pwd"))
            Log("Connected to Primary host")

            # Cleanup from previous runs
            try:
                CleanupVm(vmname)
            except vim.fault.InvalidOperationOnSecondaryVm:
                pass

# Connect to secondary host
            secondarySi = SmartConnect(host=secondaryHost,
                                       user=args.GetKeyValue("user"),
                                       pwd=args.GetKeyValue("pwd"))
            Log("Connected to Secondary host")

            for si in [primarySi, secondarySi]:
                if len(FindNicType(si, ftLoggingNicType)) == 0:
                    SelectVnic(si, "vmk0", ftLoggingNicType)
                if len(FindNicType(si, vmotionNicType)) == 0:
                    SelectVnic(si, "vmk0", vmotionNicType)

            ftMgrDst = host.GetFaultToleranceMgr(secondarySi)

            # Cleanup from previous runs
            CleanupVm(vmname)
            CleanupVm(vmname, True)

            connect.SetSi(primarySi)
            CleanupDir(dsName, vmname)
            if ftType == "smp":
                CleanupDir(dsName, "%s_shared" % vmname)

# Create new VM
            Log("Creating primary VM " + vmname)
            primaryVm = vm.CreateQuickDummy(vmname,
                                            guest="winNetEnterpriseGuest",
                                            numScsiDisks=2,
                                            scrubDisks=True,
                                            memory=memSize,
                                            datastoreName=dsName)
            primaryUuid = primaryVm.GetConfig().GetInstanceUuid()
            primaryCfgPath = primaryVm.GetConfig().GetFiles().GetVmPathName()
            primaryDir = primaryCfgPath[:primaryCfgPath.rfind("/")]

            ftMetadataDir = GetSharedPath(primarySi, primaryVm)

            Log("Using VM : " + primaryVm.GetName() + " with instanceUuid " +
                primaryUuid)

            ftMetadataDir = GetSharedPath(primarySi, primaryVm)
            cSpec = vim.vm.ConfigSpec()
            if ftType != "smp":
                # Enable record/replay for the primaryVm
                # See PR 200254
                flags = vim.vm.FlagInfo(recordReplayEnabled=True)
                cSpec.SetFlags(flags)
                task = primaryVm.Reconfigure(cSpec)
                WaitForTask(task)
                Log("Enabled record/replay for Primary VM.")
                CheckFTState(
                    primaryVm,
                    vim.VirtualMachine.FaultToleranceState.notConfigured)
            else:
                cSpec.files = vim.vm.FileInfo(
                    ftMetadataDirectory=ftMetadataDir)
                cSpec.numCPUs = numCPU
                task = primaryVm.Reconfigure(cSpec)
                WaitForTask(task)

            # Create secondary VM
            connect.SetSi(secondarySi)
            Log("Creating secondary VM " + vmname)
            secondaryVm = vm.CreateQuickSecondary(vmname,
                                                  primaryVm,
                                                  ftType=ftType,
                                                  scrubDisks=True,
                                                  numScsiDisks=2,
                                                  datastoreName=dsName,
                                                  ftMetadataDir=ftMetadataDir)
            if secondaryVm == None:
                raise "Secondary VM creation failed"
            secondaryUuid = secondaryVm.GetConfig().GetInstanceUuid()
            secondaryCfgPath = secondaryVm.GetConfig().GetFiles(
            ).GetVmPathName()
            Log("Created secondary VM " + secondaryVm.GetName())
            Log("Secondry VM: instanceUuid " + secondaryUuid)
            Log("Secondary cfg path: " + secondaryCfgPath)

            ##  Configure some additional config variables needed for FT
            ##  This should eventually be done automatically at FT Vmotion time
            Log("Setting up extra config settings for the primary VM...")

            cSpec = vim.Vm.ConfigSpec()
            extraCfgs = []
            if ftType == "smp":  # some of these options are temporary
                cSpec.flags = vim.vm.FlagInfo(
                    faultToleranceType=FTType.checkpointing)
                AddExtraConfig(extraCfgs, "ftcpt.maxDiskBufferPages", "0")
                AddExtraConfig(extraCfgs, "sched.mem.pshare.enable", "FALSE")
                AddExtraConfig(extraCfgs, "sched.mem.fullreservation", "TRUE")
                AddExtraConfig(extraCfgs,
                               "monitor_control.disable_mmu_largepages",
                               "TRUE")
                AddExtraConfig(extraCfgs, "sched.mem.min", memSize)
                AddExtraConfig(extraCfgs, "migration.dataTimeout", "2000")
                cSpec.files = vim.vm.FileInfo(
                    ftMetadataDirectory=ftMetadataDir)
            else:
                cSpec.flags = vim.vm.FlagInfo(
                    faultToleranceType=FTType.recordReplay)
                AddExtraConfig(extraCfgs, "replay.allowBTOnly", "TRUE")

            cSpec.SetExtraConfig(extraCfgs)
            WaitForTask(primaryVm.Reconfigure(cSpec))

            # Register secondary VM
            Log("Register secondary VM with the primary")
            ftMgr = host.GetFaultToleranceMgr(primarySi)
            connect.SetSi(primarySi)
            task = ftMgr.RegisterSecondary(primaryVm, secondaryUuid,
                                           secondaryCfgPath)
            WaitForTask(task)
            Log("Secondary VM registered successfully")

            # Verify FT role & state
            CheckFTRole(primaryVm, 1)
            CheckFTState(primaryVm,
                         vim.VirtualMachine.FaultToleranceState.enabled)

            Log("FT configured successfully.")

            # PowerOn FT VM
            Log("Powering on Primary VM")
            vm.PowerOn(primaryVm)
            if ftType == "smp":  # some of these options are temporary
                task = primaryVm.CreateSnapshot("snap-early",
                                                "before secondary starts",
                                                memory=False,
                                                quiesce=True)
                WaitForTask(task)

# Perform the FT VMotion
            Log("Calling StartSecondary on remote host...")
            primaryThumbprint = GetHostThumbprint(primaryHost)
            secondaryThumbprint = GetHostThumbprint(secondaryHost)
            Log("Primary thumbprint: %s" % primaryThumbprint)
            Log("Secondary thumbprint: %s" % secondaryThumbprint)

            secondaryHostSystem = secondarySi.content.rootFolder.childEntity[
                0].hostFolder.childEntity[0].host[0]
            sslThumbprintInfo = vim.host.SslThumbprintInfo(
                ownerTag='hostd-test', principal='vpxuser')
            sslThumbprintInfo.sslThumbprints = [primaryThumbprint]
            secondaryHostSystem.UpdateSslThumbprintInfo(
                sslThumbprintInfo, "add")

            sslThumbprintInfo.sslThumbprints = [secondaryThumbprint]
            primaryHostSystem = primarySi.content.rootFolder.childEntity[
                0].hostFolder.childEntity[0].host[0]
            primaryHostSystem.UpdateSslThumbprintInfo(sslThumbprintInfo, "add")

            task = ftMgr.StartSecondaryOnRemoteHost(primaryVm,
                                                    secondaryCfgPath,
                                                    secondaryHost, 80,
                                                    secondaryThumbprint)
            WaitForTask(task)
            Log("Start secondary done.")

            if ftType == "smp":
                # Verify snapshot is gone
                if primaryVm.snapshot is not None:
                    raise Exception("Snapshot still exists on primary")

                task = primaryVm.CreateSnapshot("snap",
                                                "without memory snapshot",
                                                memory=False,
                                                quiesce=True)
                WaitForTask(task)

                if not primaryVm.snapshot or not primaryVm.snapshot.currentSnapshot:
                    raise Exception("Snapshot was not created")
                else:
                    Log("Snapshot %s exists as expected" %
                        primaryVm.snapshot.currentSnapshot)

            # Retrieve reference to new secondary VM
            connect.SetSi(secondarySi)
            secondaryVm = folder.FindCfg(secondaryCfgPath)
            connect.SetSi(primarySi)

            # FT state check
            CheckFTState(primaryVm,
                         vim.VirtualMachine.FaultToleranceState.running)
            CheckFTState(secondaryVm,
                         vim.VirtualMachine.FaultToleranceState.running)

            Log("Start secondary done.")

            # allows some time for FT to run and checkpoint before failing
            # over. This seems more necessary on nested VM environments
            # than physical
            time.sleep(20)

            Log("Failing over to the secondary.")
            WaitForTask(ftMgr.MakePrimary(primaryVm, secondaryUuid))
            WaitForPowerState(primaryVm, primarySi,
                              vim.VirtualMachine.PowerState.poweredOff)
            Log("Verified primary power state is off.")
            WaitForFTState(secondaryVm, FTState.needSecondary)

            Log("Starting secondary.")
            task = ftMgrDst.StartSecondaryOnRemoteHost(secondaryVm,
                                                       primaryCfgPath,
                                                       primaryHost, 80,
                                                       primaryThumbprint)
            WaitForTask(task)

            # Verify snapshot is gone
            if primaryVm.snapshot is not None:
                raise Exception("Snapshot still exists on old primary")

            Log("Failing over to the old-primary.")
            WaitForTask(ftMgrDst.MakePrimary(secondaryVm, secondaryUuid))
            WaitForPowerState(secondaryVm, secondarySi,
                              vim.VirtualMachine.PowerState.poweredOff)
            Log("Verified primary power state is off.")
            WaitForFTState(primaryVm, FTState.needSecondary)

            task = ftMgr.StartSecondaryOnRemoteHost(primaryVm,
                                                    secondaryCfgPath,
                                                    secondaryHost, 80,
                                                    secondaryThumbprint)
            WaitForTask(task)

            # PowerOff FT VMs
            Log("Power off Primary VM")
            vm.PowerOff(primaryVm)
            connect.SetSi(secondarySi)
            for i in range(10):
                if secondaryVm.GetRuntime().GetPowerState(
                ) == vim.VirtualMachine.PowerState.poweredOn:
                    time.sleep(1)
            if secondaryVm.GetRuntime().GetPowerState(
            ) == vim.VirtualMachine.PowerState.poweredOn:
                raise Exception("Secondary VM is still powered on!")
            Log("Verified secondary power state.")

            Log("Unregistering secondary VM " + vmname)
            ftMgrDst.Unregister(secondaryVm)

            # Cleanup
            if not keep:
                connect.SetSi(primarySi)
                CleanupVm(vmname)
                CleanupDir(dsName, vmname)
                if ftType == "smp":
                    CleanupDir(dsName, "%s_shared" % vmname)

                connect.SetSi(secondarySi)
                CleanupVm(vmname, True)
        except Exception as e:
            Log("Caught exception : %s" % e)
            stackTrace = " ".join(
                traceback.format_exception(sys.exc_info()[0],
                                           sys.exc_info()[1],
                                           sys.exc_info()[2]))
            Log(stackTrace)
            global status
            status = "FAIL"
            Disconnect(primarySi)
            Disconnect(secondarySi)
            return

        Disconnect(primarySi)
        Disconnect(secondarySi)
Exemple #25
0
def main():
   supportedArgs = [ (["h:", "host="], "localhost", "Host name", "host"),
                     (["u:", "user="******"root", "User name", "user"),
                     (["p:", "pwd="], "ca$hc0w", "Password", "pwd"),
                     (["d:", "disk="], "/vmfs/devices/", "Disk", "disk"),
                     (["s:", "ds="], "storage1", "Datastore 1", "ds"),
                     (["f:", "file="], "[datastore1] rdm/rdm.vmdk", "Virtual Disk", "file"),
                     (["v:", "vmname="], "RdmVM", "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")
   disk = args.GetKeyValue("disk")
   ds = args.GetKeyValue("ds")
   rdmDiskFile = args.GetKeyValue("file")


   status = "PASS"

   for i in range(numiter):
       bigClock = StopWatch()
       vm1 = None
       try:
           ## Cleanup old VMs
           vm1 = folder.Find(vmname)
           if vm1 != None:
               vm1.Destroy()

           Log("Creating VM: " + str(vmname))

           ## Add scsi disk
           Log("Adding a new rdm disk to VM: " + str(vmname))
           cspec = Vim.Vm.ConfigSpec()
           cspec = vmconfig.CreateDefaultSpec(name = vmname, datastoreName = ds)
           cspec = vmconfig.AddScsiCtlr(cspec)

           # Get config options and targets
           cfgOption = vmconfig.GetCfgOption(None)
           cfgTarget = vmconfig.GetCfgTarget(None)

           rdmBacking = Vim.Vm.Device.VirtualDisk.RawDiskMappingVer1BackingInfo()
           rdmBacking.SetFileName("");
           rdmBacking.SetDeviceName(disk);
           rdmBacking.SetCompatibilityMode("physicalMode");
           rdmBacking.SetDiskMode("");
           rdmBacking.SetParent(None);

           diskDev = Vim.Vm.Device.VirtualDisk()
           diskDev.SetKey(vmconfig.GetFreeKey(cspec))
           diskDev.SetBacking(rdmBacking)
           ctlrs = vmconfig.GetControllers(cfgOption, Vim.Vm.Device.VirtualSCSIController, None, cspec)

           # XXX Fix this up
           for ctlrIdx in range(len(ctlrs)):
              freeSlot = vmconfig.GetFreeSlot(cspec, None, cfgOption, ctlrs[ctlrIdx])
              if (freeSlot >= 0):
                 diskDev.SetControllerKey(ctlrs[ctlrIdx].GetKey())
                 diskDev.SetUnitNumber(-1)
                 diskDev.SetCapacityInKB(long(4096))
                 break


           vmconfig.AddDeviceToSpec(cspec, diskDev, \
                    Vim.Vm.Device.VirtualDeviceSpec.Operation.add, \
                    Vim.Vm.Device.VirtualDeviceSpec.FileOperation.create)

           Log("create VM: " + str(vmname) + " with the RDM disk")
           vmFolder = vm.GetVmFolder()
           resPool = vm.GetResourcePool()

           task = vmFolder.CreateVm(cspec, resPool)
           WaitForTask(task)
           Log("Finished Reconfiguring VM: " + str(vmname));
           vm1 = task.info.result

           Log("Now reconfiguring VM: " + str(vmname));

           cspec = Vim.Vm.ConfigSpec()

           rdmBacking = Vim.Vm.Device.VirtualDisk.RawDiskMappingVer1BackingInfo()
           rdmBacking.SetFileName(rdmDiskFile);
           rdmBacking.SetCompatibilityMode("physicalMode");
           rdmBacking.SetDiskMode("persistent");
           rdmBacking.SetParent(None);

           diskDev = Vim.Vm.Device.VirtualDisk()
           diskDev.SetKey(vmconfig.GetFreeKey(cspec))
           diskDev.SetBacking(rdmBacking)
           ctlrs = vmconfig.GetControllers(cfgOption, Vim.Vm.Device.VirtualSCSIController, vm1.GetConfig(), cspec)
           # XXX Fix this up
           for ctlrIdx in range(len(ctlrs)):
              freeSlot = vmconfig.GetFreeSlot(cspec, vm1.GetConfig(), cfgOption, ctlrs[ctlrIdx])
              if (freeSlot >= 0):
                 diskDev.SetControllerKey(ctlrs[ctlrIdx].GetKey())
                 diskDev.SetUnitNumber(-1)
                 diskDev.SetCapacityInKB(long(4096))
                 break


           vmconfig.AddDeviceToSpec(cspec, diskDev, \
                    Vim.Vm.Device.VirtualDeviceSpec.Operation.add, \
                    Vim.Vm.Device.VirtualDeviceSpec.FileOperation.create)
           vm.Reconfigure(vm1, cspec)
           task = vmFolder.ReconfigVm(cspec, resPool)
           WaitForTask(task)
           Log("Finished Reconfiguring VM: " + str(vmname));


       except Exception as e:
           status = "FAIL"
           Log("Caught exception : " + str(e))
   Log("TEST RUN COMPLETE: " + status)
Exemple #26
0
def main():
    supportedArgs = [(["h:", "host="], "localhost", "Host name", "host"),
                     (["u:", "user="******"root", "User name", "user"),
                     (["p:", "pwd="], "", "password", "pwd"),
                     (("t:", "test="), "all", "test Options", "test")]

    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)
    '''
    si = Connect(host=args.GetKeyValue("host"),  #can be VC too
                 user=args.GetKeyValue("user"),
                 pwd=args.GetKeyValue("pwd"),
                 version=newestVersions.Get('vim'))
                 '''
    si = SmartConnect(host=args.GetKeyValue("host"),
                      user=args.GetKeyValue("user"),
                      pwd=args.GetKeyValue("pwd"))

    atexit.register(Disconnect, si)

    global datastoreSystem
    datastoreSystem = host.GetHostConfigManager(si).GetDatastoreSystem()

    global storageSystem
    storageSystem = host.GetHostConfigManager(si).GetStorageSystem()
    test = args.GetKeyValue("test")
    #    print(storageSystem.storageDeviceInfo)

    if test == "printDS":
        PrintDatastoreNames()

    if test == "getLuns":
        getLuns()
    if test == "getVolumes":
        getVolumes()
    if test == "getDisks":
        getDisks()
    if test == "getDS":
        getDS()
    if test == "getAll":
        getLuns()
        getVolumes()
        getDisks()
        getDS()
    if test == "testVMSpec":
        testVMSpec()

    if test == "datastoreSystem":
        getDS()
        RemoveDatastores()
        getDisks()
        CreateDatastores(diskIDs)
        if debug: PrintDatastoreNames()
        pass  # for Syntax check in case uncommneted all the up function call
    #separate different API calls, error prone if test them all together.
    if test == "storageSystem":
        getLuns()
        getVolumes()
        UnmountVolumes()  # must run this twice to successfully do detach
        UnmountVolumes()
        UnmountVolumes()
        UnmountVolumes()
        UnmountVolumes()
        DetachLuns()
        AttachLuns()
        MountVolumes(
        )  #must run twice for the host really see the mounts, i.e.
        #i.e.      able to see all  ls /vmfs/volume
        MountVolumes()
        pass

    if test == "all":
        getLuns()
        getVolumes()
        getDisks()
        RemoveDatastores()
        CreateDatastores(diskIDs)
        UnmountVolumes()  # must run this twice to successfully do detach
        UnmountVolumes()
        DetachLuns()
        AttachLuns()
        MountVolumes()  #must run twice for the host really see the mounts
        MountVolumes()

    if test == "removeDS":
        getDS()
        RemoveDatastores()

    if test == "createDS":
        getDisks()
        CreateDatastores(diskIDs)

    if test == "unmount":
        getVolumes()
        UnmountVolumes()
        UnmountVolumes()
        pass
    if test == "detach":
        print("Going to detach, make sure the volumes are unmounted first.")
        getLuns()
        DetachLuns()
        pass
    if test == "attach":
        getLuns()
        AttachLuns()
        pass
    if test == "mount":
        getVolumes()
        MountVolumes()
        MountVolumes()
        pass
    if test == "rescanVmfs":
        RescanVmfs()
    if test == "rescanHBA":
        RescanHBA()

    if test == "extra":
        global vols
        vols = []
        QueryUnresolvedVmfsVolume()
Exemple #27
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])
Exemple #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="], "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
	   vm1 = folder.Find(vmname)
	   if vm1 != None:
	      vm1.Destroy()

	   Log("Creating virtual machine")
	   vm1 = vm.CreateQuickDummy(vmname, 1, diskSizeInMB = 4096)

	   devices = vmconfig.CheckDevice(vm1.GetConfig(), Vim.Vm.Device.VirtualDisk)
	   if len(devices) < 1:
	         raise Exception("Failed to find added disk!")
	   cspec = Vim.Vm.ConfigSpec()
	   for i in range(0, len(devices)) :
	       disk = devices[i]
	       backing = disk.GetBacking()
	       backing.SetEagerlyScrub(True)
	       disk.SetBacking(backing)
	       vmconfig.AddDeviceToSpec(cspec, disk, Vim.Vm.Device.VirtualDeviceSpec.Operation.edit)

	   Log("Scrubbing existing disks of the VM")
	   task = vm1.Reconfigure(cspec)
	   WaitForTask(task)

	   Log("Add a new scrubbed disk to the VM")
	   cspec = Vim.Vm.ConfigSpec()
	   cspec = vmconfig.AddScsiCtlr(cspec)
	   vmconfig.AddScsiDisk(cspec, capacity = 128 * 1024, scrub = True)
	   #task = vm1.Reconfigure(cspec)
	   #WaitForTask(task)

       except Exception as e:
           status = "FAIL"
           Log("Caught exception : " + str(e))
   Log("TEST RUN COMPLETE: " + status)
Exemple #29
0
def main():
    status = "PASS"

    supportedArgs = [
        (["H:", "primary host="], "localhost", "Host name", "host"),
        (["u:", "user="******"root", "User name", "user"),
        (["p:", "pwd="], "", "Password", "pwd"),
        (["v:", "vc="], "", "VC Server", "vc"),
        (["d:", "datastore="], None, "Datastore", "datastore"),
    ]

    supportedToggles = [
        (["usage", "help"], False, "Show usage information", "usage"),
        (["sim"], False, "Host simulator", "sim"),
    ]

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

    # Process command line
    global user
    global pwd
    user = args.GetKeyValue("user")
    pwd = args.GetKeyValue("pwd")

    hostname = args.GetKeyValue("host")
    vc = args.GetKeyValue("vc")
    datastore = args.GetKeyValue("datastore")
    si = None
    global useVc
    if vc:
        useVc = True
    else:
        useVc = False
    global connectHost
    connectHost = vc if useVc else hostname

    try:
        # Connect to host
        si = Connect()
        if si is None:
            raise Exception("Failed to connect to %s" % connectHost)
        Log("Connected to %s" % connectHost)
        if useVc:
            configs = []
            configs.append(
                vim.option.OptionValue(key='config.featureCompat.enable',
                                       value='true'))
            configs.append(
                vim.option.OptionValue(key='config.featureCompat.enableHWv9',
                                       value='true'))
            si.content.setting.UpdateValues(configs)

        GetHostByName(si, hostname)
        Test0(si)
        Test1(si)
        Test2(si)
        Test3(si)
        Test4(si)
        Test5(si, datastore)
        Test6(si)
        Test7(si)
        Test8(si, datastore, args.GetKeyValue("sim"))
        Test9(si)
        Test10(si)
        Test11(si, datastore, args.GetKeyValue("sim"))
        Test12(si)
        Test13(si)
        Test14(si, datastore, args.GetKeyValue("sim"))
        Test15(si, datastore, args.GetKeyValue("sim"))
        Test16(si)
        Log("ALL TESTS PASSED")
    except Exception as e:
        Log("Caught exception : " + str(e))
        traceback.print_exc()
        status = "FAIL"
    finally:
        if si:
            connect.Disconnect(si)
    if status == "FAIL":
        sys.exit(1)
Exemple #30
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 = 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)