vmware / vmware/pyvmomi

Network interruption causes WaitForUpdatesEx blocking issue

Open
#176 17 comments 0 reactions 1 assignee View on GitHub

Nobody has claimed this yet.

bug high priority
Dominant language
Python
Stars
2.3k
Forks
763
PR merge metrics
No merged PRs in 30d

Description

The following code retrieves a list of host objects every 10 seconds. For my test, I run this code on my laptop inside of a VMware Workstation Ubuntu VM. This allows me to use VMware Workstation to simulate a break in network connectivity (adapter is up, but client is unable to communicate with vSphere).

  1. Allow the code to run for a few cycles (2-3 is enough).
  2. Uncheck 'VM/Settings/Network Adapter' to simulate a break in network connectivity.
  3. Wait 30 seconds - observe that 'Waiting for updates' does not show any updates or errors
  4. Re-enable 'VM/Settings/Network Adapter' to restore network connectivity
  5. Observe that 'Waiting for updates' does not show any further updates or errors.

    from pyVim.connect import SmartConnect
    import pyVmomi

    def test_loop(username, password, host, port):
        # Connect and collect instance info
        service_instance = SmartConnect(user=username, pwd=password, host=host, port=port)
        content = service_instance.RetrieveContent()

        # Create a container view
        container_view = content.viewManager.CreateContainerView(
            container=content.rootFolder,
            type=[pyVmomi.vim.HostSystem],
            recursive=True)

        # Create a traversal spec
        traversal_spec = pyVmomi.vim.PropertyCollector.TraversalSpec(
            name='traversal_spec',
            path='view',
            skip=False,
            type=pyVmomi.vim.view.ContainerView)

        # Create an object spec
        object_spec = pyVmomi.vim.PropertyCollector.ObjectSpec(
            obj=container_view,
            selectSet=[traversal_spec],
            skip=False)

        # Create a property specs for host events
        property_spec_host_events = pyVmomi.vim.PropertyCollector.PropertySpec(
            all=False,
            pathSet=["runtime.bootTime"],
            type=pyVmomi.vim.HostSystem)

        # Create a property filter spec
        property_filter_spec = pyVmomi.vim.PropertyCollector.FilterSpec(
            objectSet=[object_spec],
            propSet=[property_spec_host_events],
            reportMissingObjectsInResults=True)

        # Create the property filter
        content.propertyCollector.CreateFilter(
            spec=property_filter_spec,
            partialUpdates=True)

        # Set up the wait options
        max_wait = 10
        wait_options = pyVmomi.vim.PropertyCollector.WaitOptions(
            maxWaitSeconds=max_wait,
            maxObjectUpdates=None)

        # Initialize update version and start time
        update_version = None

        # Loop until exit flag has been set
        while True:

            print("Waiting for updates from (v {})...({} seconds)".format(
                update_version,
                wait_options.maxWaitSeconds))

            # Block until an update is received or timeout is received
            update_set = content.propertyCollector.WaitForUpdatesEx(
                version=update_version,
                options=wait_options)

            if update_set is None:
                print("Timeout/Requery")

                # Reset the update version number to force a full requery.
                update_version = None

            else:
                print("  Received Update (v{})".format(update_set.version))
                update_version = update_set.version

            print("")

    # Run the test.
    test_loop('root', 'password', 'localhost', 443)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.