-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix lookups return empty string when looking up resources inside folders #445
Conversation
Build failed. ❌ ansible-test-cloud-integration-vmware-rest FAILURE in 23m 02s |
Is this something I can fix? To me it seems that the CI pipeline can't connect to the vcenter. |
recheck |
Build succeeded. ✔️ ansible-test-cloud-integration-vmware-rest SUCCESS in 15m 44s |
recheck |
Merge Failed. This change or one of its cross-repo dependencies was unable to be automatically merged with the current state of its repository. Please rebase the change and upload a new patchset. |
SUMMARY This change rewrites the lookup plugin logic to use a top down approach to finding objects. The plugins will now step through an objects path and try to lookup each intermediate object until it gets to the final object. The old method has a few issues: The existing plugins use an incorrect search method which yield inconsistent results (as described in #500) They also cannot find resources with the same name, even if the paths given are unique. For example, if /datacenter/vms/my-folder and /datacenter/hosts/my-folder both exist, you can never find either one Items with the same name will cause conflicts, even if those items have slightly different paths. For example: /datacenter/vms/foo and /datacenter/hosts/foo existing at the same time makes it difficult to search for either folder Fixes: #500 #445 #324 ISSUE TYPE Bugfix Pull Request COMPONENT NAME all lookup plugins ADDITIONAL INFORMATION The original top down approach is described in #445. I tried to get that version working but ran into a few issues. Reviewed-by: Danielle Barda Reviewed-by: Ondra Machacek <machacek.ondra@gmail.com> Reviewed-by: mikemorency
You're welcome and thanks to all contributors for providing us with such a helpful collection. |
SUMMARY
When lookups search for resources inside folders, they return an empty string even if the resource is available in this path. For example, a vm_moid lookup with the term
/mydc/vm/myfolder1/myvm2
returns an empty string while a lookup for/mydc/vm/myvm1
returns the expected moid.One could've fixed this issue with no major overhaul of the file. But by looking at the code, I expect that more issues would arise such as finding the wrong folder if multiple folders have the same name, e. g.
/mydc/vm/myfolder1/foo
and/mydc/vm/myfolder2/foo
.So I rewrote large parts of the file to strictly follow the path top-down. On some occasions the lookups now make multiple requests against the api to ensure we find the correct resource (e. g. finding the root resource pool on a standalone host). This will certainly decrease performance at the expense of correct results.
Also I think the code is no easier to read and reason about as there is no complex recursive function anymore.
ISSUE TYPE
COMPONENT NAME
cluster_moid
datacenter_moid
datastore_moid
folder_moid
host_moid
network_moid
resource_pool_moid
vm_moid
ADDITIONAL INFORMATION
I used an ansible playbook to reproduce the issue. Please note that parts of this playbook (path, moid) must be adjusted to the environment in which the tests are executed. The credentials were set via environment variables.
The output before the changes was:
The output after the changes was: