Skip to content

vmware: keep syncing when a vCenter tag lookup fails - #637

Open
tyderian1978 wants to merge 1 commit into
bb-Ricardo:developmentfrom
tyderian1978:fix/vmware-tag-lookup-errors
Open

tyderian1978 wants to merge 1 commit into
bb-Ricardo:developmentfrom
tyderian1978:fix/vmware-tag-lookup-errors

Conversation

@tyderian1978

Copy link
Copy Markdown

Disclaimer: AI generated, based off the work we're doing with Netbox.

What happens

When the vSphere tagging API fails to list the tags attached to an object, for example after a vCenter error or a timeout, get_vmware_object_tags() logs Unable to retrieve vCenter tags for '<object>' and returns None. collect_object_tags() extends its tag list with that result, so the sync stops with TypeError: 'NoneType' object is not iterable. A single failed tag request ends the whole run. Both functions also return None when they're given no object.

We ran into it while testing #634–#636 against vcsim, whose tagging API doesn't work with the vcf-sdk, so every tag lookup there fails.

Fix

Both functions always return a list. The object only loses the tags of the lookup that failed: its other tag sources (parent folders, cluster, datacenter) still count, and the sync goes on. The error is logged as before.

Tests

tests/test_vmware_tag_errors.py fakes the tagging API:

  • a VM whose own tag lookup fails still gets its folder's tags
  • both functions return an empty list when nothing can be read, and for no object

Both fail on development, the first with the TypeError above. Full suite: 836 passed, 8 skipped.

This PR changes lines that #634 also changes: the try around list_attached_tags() in get_vmware_object_tags(). Whichever is merged second, I'll rebase it.

get_vmware_object_tags() returned None when listing the tags attached to
an object failed, and for no object at all. collect_object_tags() extends
its tag list with every result, so a single failed tag request ended the
whole run with "TypeError: 'NoneType' object is not iterable", right after
logging "Unable to retrieve vCenter tags for ...".

Both functions now always return a list. The object only loses the tags of
the lookup which failed: its other tag sources (parent folders, cluster,
datacenter) still count and the sync goes on. The error is logged as before.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant