예제 #1
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)
예제 #2
0
def main():
    options, remainingOptions = ParseArgs(sys.argv[1:])

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

    if options.verbose:
        logger.setLevel(logging.DEBUG)

    status = "PASS"
    for i in range(options.iter):
        try:
            logger.info("Starting iteration %d." % (i + 1))
            vm1 = None
            logger.debug("Cleaning up VMs from previous runs...")
            vm.Delete(options.vmname, True)

            logger.debug("Creating Hw7 VM..")
            vm1 = vm.CreateQuickDummy(options.vmname,
                                      vmxVersion="vmx-07",
                                      memory=4,
                                      guest="rhel5Guest")

            logger.debug("Adding an extra config setting to the VM")
            SetExtraConfig(vm1, options.key, options.val1)

            logger.debug("Editing an extra config setting on the VM")
            SetExtraConfig(vm1, options.key, options.val2)

            logger.debug("Adding a bogus extra config setting on the VM")
            SetExtraConfig(vm1, options.invalidKey, "", False)

            logger.debug("Destroying VM")
            vm.Delete(options.vmname, True)

            logger.info("End of iteration %d." % (i + 1))
        except Exception as e:
            logger.error("Caught exception : " + str(e))
            status = "FAIL"

    logger.info("TEST RUN COMPLETE: " + status)
예제 #3
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
예제 #4
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)
예제 #5
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)
예제 #6
0
 def tearDown(self):
     if self.v1 != None:
         vm.Delete(self.vmname)
예제 #7
0
파일: vmTestVTPM.py 프로젝트: free-Zen/pvc
def main():
    supportedArgs = [(["h:", "host="], "localhost", "Host name", "host"),
                     (["u:", "user="******"root", "User name", "user"),
                     (["p:", "pwd="], "", "Password", "pwd"),
                     (["v:", "vmname="], "VTPMTest",
                      "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)

        Log("Prepare host for crypto...")
        vimcrypto.CryptoEnableHost(host.GetHostSystem(si))

        Log("Adding key for encrypted VM...")
        cryptoMgr = si.RetrieveContent().cryptoManager
        keyId, cryptoKey = CreateKeyForVM(si)
        cryptoMgr.AddKeys([cryptoKey])

        ## vTPM requires hardware version 14.
        Log("Creating Hw14 VM...")
        cfg = vm.CreateQuickDummySpec(vmname,
                                      vmxVersion="vmx-14",
                                      memory=4,
                                      guest="otherGuest")
        cryptoSpec = vimcrypto.CreateCryptoSpecEncrypt(keyId, None)
        cfg.crypto = cryptoSpec
        AddVTPM(cfg)
        vm1 = vm.CreateFromSpec(cfg)
        TestVTPMProps(vm1)
        task = vm1.Destroy()
        WaitForTask(task)
        vm1 = None

        vm1 = vm.CreateQuickDummy(vmname,
                                  vmxVersion="vmx-14",
                                  memory=4,
                                  guest="otherGuest")

        Log("Encrypting VM...")
        vimcrypto.EncryptVM(vm1, keyId, None, disks=False)

        TestVTPMReconfig(vm1)
        TestNoVTPM(vm1)
        TestVTPMVDRemove(vm1)

        Log("Tests completed.")

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

    Log("TEST RUN COMPLETE: " + status)
예제 #8
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)
예제 #9
0
파일: vmTestVQAT.py 프로젝트: free-Zen/pvc
def main():
    supportedArgs = [(["h:", "host="], "localhost", "Host name", "host"),
                     (["u:", "user="******"root", "User name", "user"),
                     (["p:", "pwd="], "", "Password", "pwd"),
                     (["v:", "vmname="], "VQATTest",
                      "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)

        cfg = TestVQATCreateSpec(vmname, memSize=4)
        for i in range(MAX_QAT_DEV):
            AddVQAT(cfg)
        vm1 = TestVQATCreateVM(cfg)
        TestVQATDestroyVM(vm1)
        vm1 = None

        cfg = TestVQATCreateSpec(vmname, memSize=8)
        vm1 = TestVQATCreateVM(cfg)
        TestVQATReconfig(vm1)
        TestVQATDeviceType(vm1)
        TestNoVQAT(vm1)
        TestVQATVDRemove(vm1)
        TestVQATDestroyVM(vm1)
        vm1 = None

        Log("Tests completed.")

    except Exception as e:
        status = "FAIL"
        Log("Caught exception : %s, %r" % (e, e))
        raise
    finally:
        # Delete the vm as cleanup
        if noDelete == False:
            if vm1 != None:
                TestVQATDestroyVM(vm1)
            vm1 = None

    Log("TEST RUN COMPLETE: " + status)
예제 #10
0
def main():
    options, remainingOptions = ParseArgs(sys.argv[1:])

    # Connect
    si = SmartConnect(host=options.host,
                      user=options.user,
                      pwd=options.pwd)
    atexit.register(Disconnect, si)

    if options.verbose:
        logger.setLevel(logging.DEBUG)

    status = "PASS"
    for i in range(options.iter):
        try:
            logger.info("Starting iteration %d." % (i + 1))
            vm1 = None
            logger.debug("Cleaning up VMs from previous runs...")
            vm.Delete(options.vmname, True)

            logger.debug("Creating VM")
            vm1 = vm.CreateQuickDummy(options.vmname, memory = 4,
                                      vmxVersion = "vmx-07",
                                      guest = "rhel5Guest")

            logger.debug("Reconfiguring VM to have a serial port")
            cspec = Vim.Vm.ConfigSpec()
            backing = Vim.Vm.Device.VirtualSerialPort.FileBackingInfo()
            backing.SetFileName(vm1.config.files.logDirectory + "/serial.log")
            vmconfig.AddSerial(cspec, backing)
            vm.Reconfigure(vm1, cspec)

            logger.debug("Powering on VM")
            vm.PowerOn(vm1)

            logger.debug("Resetting VM")
            vm.Reset(vm1)

            if vm1.runtime.question == None:
                raise Exception("VM did not post a question")

            logger.debug("VM posted a question. Terminating VM")
            vm1.Terminate()

            #
            # The Terminate API sends a hard kill to the VMX. It takes
            # a few seconds after that for the VMX to be re-mounted in
            # Hostd.
            #
            time.sleep(5)
            if vm1.runtime.question != None:
                raise Exception("VM question was not cleared.")

            logger.debug("Verified VM question was cleared.")
            logger.debug("Destroying VM")
            vm.Delete(options.vmname, True)

            logger.info("End of iteration %d." % (i + 1))
        except Exception as e:
            logger.error("Caught exception : " + str(e))
            status = "FAIL"

    logger.info("TEST RUN COMPLETE: " + status)
예제 #11
0
def main():
    supportedArgs = [(["h:", "host="], "localhost", "Host name", "host"),
                     (["u:", "user="******"root", "User name", "user"),
                     (["p:", "pwd="], "", "Password", "pwd"),
                     (["v:", "vmname="], "VWDTTest",
                      "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)

        ## vWDT requires hardware version 17.
        Log("Creating Hw17 VM...")
        cfg = vm.CreateQuickDummySpec(vmname,
                                      vmxVersion="vmx-17",
                                      memory=4,
                                      guest="otherGuest")
        AddVWDT(cfg)
        vm1 = vm.CreateFromSpec(cfg)
        task = vm1.Destroy()
        WaitForTask(task)
        vm1 = None

        vm1 = vm.CreateQuickDummy(vmname,
                                  vmxVersion="vmx-17",
                                  memory=4,
                                  guest="otherGuest")

        TestVWDTReconfig(vm1)
        TestNoVWDT(vm1)
        TestVWDTVDRemove(vm1)

        TestVWDTRunOnBootAndRunning(vm1)

        Log("Tests completed.")

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

    Log("TEST RUN COMPLETE: " + status)
예제 #12
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))
예제 #13
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"),
                     (["d:", "datastore="], None, "datastore", "datastore"),
                     (["v:", "volume="], None, "VMFS volume", "volume"),
                     (["i:", "iter="], "1", "Num of iterations", "iter")]
    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"),
                      port=443)
    atexit.register(Disconnect, si)

    # Process command line
    # Process command line
    vmname = args.GetKeyValue("vmname")
    numiter = int(args.GetKeyValue("iter"))
    datastore = args.GetKeyValue("datastore")
    volume = args.GetKeyValue("volume")

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

    start = datetime.datetime.now()

    vmcleanup = False
    # Cleanup from previous runs.
    # If defined VM exists, run power cycle test on it.
    # If not, create dummy VM to run test.
    testVMName = "PowerCycleTestVM"
    if vmname:
        # Cleanup from previous runs.
        vm1 = folder.Find(vmname)
        if vm1 == None:
            Log("VM not found, Let's create a dymmy VM to run power-on cycle tests."
                )
            # Create a simple vm
            try:
                vm1 = vm.CreateQuickDummy(testVMName,
                                          1,
                                          datastoreName=datastore)
            except Exception as e:
                Log("Failed to create quick dummy VM %s: %s" % (testVMName, e))
                sys.exit(-1)
            vmcleanup = True
            Log("Dummy VM %s is created." % testVMName)
        else:
            Log("Found VM %s to perform test, verify it is in power off state."
                % vm1.config.name)
            if (vm1.runtime.powerState !=
                    Vim.VirtualMachine.PowerState.poweredOff):
                try:
                    WaitForTask(vm1.PowerOff())
                except:
                    Log("Problem power off %s VM. exit" % vm1.config.name)
                    sys.exit(-1)
    else:
        vm1 = folder.Find(testVMName)
        if vm1 == None:
            # Create a simple vm
            try:
                vm1 = vm.CreateQuickDummy(testVMName,
                                          1,
                                          datastoreName=datastore)
            except Exception as e:
                Log("Failed to create quick dummy VM %s: %s" % (testVMName, e))
                sys.exit(-1)
            vmcleanup = True
            Log("Dummy VM %s is created." % testVMName)
        else:
            if (vm1.runtime.powerState !=
                    Vim.VirtualMachine.PowerState.poweredOff):
                try:
                    WaitForTask(vm1.PowerOff())
                except:
                    Log("Problem power off %s VM. exit" % vm1.config.name)
                    sys.exit(-1)

    print(
        "This test purposely adds a bad vmx.log.filename parameter to generate an early Msg_Post from VMX."
    )
    print(
        "The goal of this test is verify Msg_Post will not cause hostd to disconnect with VMX and lost track of power on status."
    )
    print(
        "To verify fix for PR 998381, please run at least 20 power cycle iterations."
    )
    # Add extra config key value to set the vmx logging path to a non-existed file.
    # e.g. vmx.log.filename = "testpowercycle-vmware.log"
    # This line will config the vmx log file to "testpowercycle-vmware.log" instead of the default "vmware.log"
    # Msg_Post will not be triggered in this case.
    optionKey = "vmx.log.filename"
    # Let's use log file that is pretty much guaranteed to not exist.
    # e.g. "/vmfs/volumes/badpathname/vmware.log" PR 998381
    # Msg_Post will be triggered in this case.
    optionValue = "/vmfs/volumes/badpathname/vmware.log"
    Log("Add %s = %s to %s VM config before power cycle test." %
        (optionKey, optionValue, vm1.config.name))
    SetExtraConfig(vm1, optionKey, optionValue)

    teststatus = "PASS"
    Log("Start Power Cycle tests for %s iterations on %s VM." %
        (numiter, vm1.config.name))

    for i in xrange(numiter):
        try:

            Log("Power On Cycle %s" % i)
            vm.PowerOn(vm1)

            Log("Power off")
            vm.PowerOff(vm1)

        except Exception as e:
            Log("Caught exception at iter %s: %s" % (i, e))
            teststatus = "FAIL"

    end = datetime.datetime.now()
    print("Power Cycle Test Result: %s" % teststatus)
    duration = end - start
    print("Total time taken: %s" % duration)

    if vmcleanup:
        Log("Delete created dummy test VM %s after test completes." %
            vm1.config.name)
        vm.Delete(vm1.config.name)
예제 #14
0
def main():
    options, remainingOptions = ParseArgs(sys.argv[1:])

    # Connect
    si = SmartConnect(host=options.host, user=options.user, pwd=options.pwd)
    atexit.register(Disconnect, si)

    if options.verbose:
        logger.setLevel(logging.DEBUG)

    status = "PASS"

    # Get hold of the VMCI access manager through the host system
    # config manager

    rootFolder = si.content.GetRootFolder()
    dataCenter = rootFolder.GetChildEntity()[0]
    hostFolder = dataCenter.hostFolder
    host = hostFolder.childEntity[0]
    hostSystem = host.host[0]
    configManager = hostSystem.GetConfigManager()
    vmciAccessManager = si.RetrieveInternalContent().vmciAccessManager

    for i in range(options.iter):
        try:
            logger.info("Starting iteration %d." % (i + 1))

            vm.Delete("VmciAccessMgrTest1", True)
            vm1 = vm.CreateQuickDummy("VmciAccessMgrTest1",
                                      vmxVersion="vmx-07",
                                      memory=4,
                                      guest="rhel5Guest")

            TestInvalidServiceTags(vm1, ["foo:", "", "foo:bar:", ":foo"],
                                   vmciAccessManager)

            GrantVmService(vmciAccessManager, vm1, [
                "foo:bar.foo", "foo:bar.bar", "foo:bar.bar", "bar:bar.bar",
                "foo"
            ])

            services = vmciAccessManager.RetrieveGrantedServices(vm1)
            if sorted(services) != [
                    "bar:bar.bar", "foo", "foo:bar.bar", "foo:bar.foo"
            ]:
                status = "FAIL"
                raise Exception("Mismatch in services granted to vm1")

            vm.Delete("VmciAccessMgrTest2", True)
            vm2 = vm.CreateQuickDummy("VmciAccessMgrTest2",
                                      vmxVersion="vmx-07",
                                      memory=4,
                                      guest="rhel5Guest")

            GrantVmService(vmciAccessManager, vm2,
                           ["foo:bar.foo", "foo:bar.bar", "bar:bar.bar"])

            services = vmciAccessManager.RetrieveGrantedServices(vm2)
            if sorted(services) != [
                    "bar:bar.bar", "foo:bar.bar", "foo:bar.foo"
            ]:
                status = "FAIL"
                raise Exception("Mismatch in services granted to vm2")

            RevokeMultiVmService(vmciAccessManager, [vm1, vm2],
                                 ["foo:bar.foo"])

            services = vmciAccessManager.RetrieveGrantedServices(vm1)
            services2 = vmciAccessManager.RetrieveGrantedServices(vm2)
            if "foo:bar.foo" in services or "foo:bar.foo" in services2:
                status = "FAIL"
                raise Exception("Services foo:bar.foo still granted to a VM")

            vms = vmciAccessManager.QueryAccessToService(
                hostSystem, "foo:bar.bar")
            if not VmInVmList(vm1, vms) or not VmInVmList(vm2, vms):
                status = "FAIL"
                raise Exception(
                    "Not all VMs reported as beeing a grantee of foo:bar.bar")

            RevokeVmService(vmciAccessManager, vm1, [])

            vms = vmciAccessManager.QueryAccessToService(
                hostSystem, "foo:bar.bar")
            if VmInVmList(vm1, vms):
                status = "FAIL"
                raise Exception(
                    "vm1 still reported as beeing a grantee of foo:bar.bar")

            if not VmInVmList(vm2, vms):
                status = "FAIL"
                raise Exception(
                    "vm2 not reported as beeing a grantee of foo:bar.bar")

            services = vmciAccessManager.RetrieveGrantedServices(vm1)
            if services != []:
                status = "FAIL"
                raise Exception("vm1 is still granted services")

            vm.Delete("VmciAccessMgrTest1", True)
            vm.Delete("VmciAccessMgrTest2", True)

            services = vmciAccessManager.RetrieveGrantedServices(vm2)
            if services != []:
                status = "FAIL"
                raise Exception("vm2 is still granted services after deletion")

            logger.info("End of iteration %d." % (i + 1))
        except Exception as e:
            logger.error("Caught exception : " + str(e))
            status = "FAIL"

    logger.info("TEST RUN COMPLETE: " + status)
예제 #15
0
def TestCleanupLocks(dsName, remoteHost, remotePath):
    print("Create datastore ... ")
    ds = CreateNasDs(dsName, remoteHost, remotePath)
    if (not ds):
        raise Exception("TestCleanLocks datastore create failed with " +
                        dsName)

    print("create vm")
    vmName = "testvm2"
    vm1 = vm.CreateQuickDummy(vmname=vmName, datastoreName=dsName)
    if (not vm1):
        raise Exception("TestCleanLocks vm cannot be created " + vmName)
    print("create vm done")

    print("test remove file locks with vm ... ")
    try:
        vimutil.InvokeAndTrack(ds.CleanupLocks)
    except Vim.Fault.ResourceInUse as e:
        print("TestCleanupLocks with vm test succeeded with " + str(e))
    except Exception as e:
        print("TestCleanupLocks with vm failed with incorrect exception " +
              str(e))
    else:
        raise Exception(
            "TestCleanupLocks with vm failed because write action is allowd on read-only volume"
        )

    print("destroy vm")
    vm.Delete(vm1)
    print("destory vm done")

    print("test remove locks on datastore or subdirectory")
    try:
        vimutil.InvokeAndTrack(ds.CleanupLocks)
        print("TestCleanLocks positive test succeeds")
        vimutil.InvokeAndTrack(ds.CleanupLocks, "something")
        print("TestCleanLocks positive subdir test succeeds")
    except Exception as e:
        raise Exception("TestCleanLocks positive test failed " + str(e))
    finally:
        datastoreSystem.RemoveDatastore(ds)

    print("Create datastore ")
    ds = CreateNasDs(dsName, remoteHost, remotePath, accessMode="readOnly")
    if (not ds):
        raise Exception("TestCleanLocks readly datastore create failed with " +
                        dsName)
    "Create datastore done"

    print("test remove locks with read permission")
    try:
        vimutil.InvokeAndTrack(ds.CleanupLocks)
    except Vim.Fault.InaccessibleDatastore as e:
        print("TestCleanupLocks readonly test succeeded, with exception " +
              str(e))
    except Exception as e:
        print(
            "TestCleanupLocks readonly test failed with incorrect exception " +
            str(e))
    else:
        raise Exception(
            "TestCleanupLocks readonly test failed because write action is allowd on read-only volume"
        )
    finally:
        datastoreSystem.RemoveDatastore(ds)

    print("Test remove locks on vmfs")
    try:
        vmds = [
            ds for ds in datastoreSystem.datastore
            if isinstance(ds.info, Vim.Host.VmfsDatastoreInfo)
        ]
        vimutil.InvokeAndTrack(vmds[0].CleanupLocks)
        print("TestCleanLocks positive test on vmfs " + vmds[0].summary.name +
              " succeeds")
    except Exception as e:
        raise Exception("TestCleanLocks positive test on vmfs failed " +
                        str(e))