Skip to content
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

rewrite get_resource_pool method for correct resource_pool selection #39792

Merged
merged 7 commits into from
Sep 7, 2018

Conversation

pieteravonts
Copy link
Contributor

SUMMARY

Fixes #33156 cluster option is ignored and #38043 random resource_pool selection when multiple resource_pools exist with the same name.

This change rewrites the get_resource_pool method to correctly select the resource pool based on all of the following parameters if given: datacenter, cluster, esxi_hostname and resource_pool.

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

vmware_guest

ANSIBLE VERSION
2.5.2

@ansibot
Copy link
Contributor

ansibot commented May 7, 2018

@ansibot ansibot added bug This issue/PR relates to a bug. cloud community_review In order to be merged, this PR must follow the community review workflow. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. new_contributor This PR is the first contribution by a new community member. support:community This issue/PR relates to code supported by the Ansible community. vmware VMware community needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed community_review In order to be merged, this PR must follow the community review workflow. labels May 7, 2018
@mattclay

This comment has been minimized.

@mattclay mattclay added the ci_verified Changes made in this PR are causing tests to fail. label May 10, 2018
@ansibot ansibot added community_review In order to be merged, this PR must follow the community review workflow. and removed needs_triage Needs a first human triage before being processed. ci_verified Changes made in this PR are causing tests to fail. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels May 10, 2018
@pieteravonts
Copy link
Contributor Author

"cluster": "/DC0/host/DC0_C0",
I actually did not expect that the cluster argument could be given as a path rather than just a name.

@ansibot ansibot added affects_2.6 This issue/PR affects Ansible v2.6 stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. labels May 20, 2018
@@ -66,6 +66,22 @@ def find_obj(content, vimtype, name, first=True):
return [obj for obj in obj_list if obj.name == name]


def find_objs(content, vimtypes, container=None, name=None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please re-use find_obj method for this ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can reuse the find_obj if you are ok with modifying it to accept a extra container (or folder) argument as in the get_all_objs.
Basically the container or content.rootFolder part is what I need to be able to limit the search (to a specific datacenter or cluster in the case of the resource_pool).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's also an inconsistency in the find_obj method, if name=None it ignores the first argument and always returns the first matching object or None.

vimtypes, recursive=True)
# make sure name does not contain a path
if name:
name = name.split('/')[-1]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is not required, name may not contain /

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what I expected but without it the integration tests failed.

# test/integration/targets/vmware_guest/tasks/cdrom_d1_c1_f0.yml (line 38):
# test/integration/targets/vmware_guest/tasks/vapp_d1_c1_f0.yml (line 35):
cluster: "{{ clusterlist['json'][0] }}"
# translates into
cluster: "/DC0/host/DC0_C0"

So this part can be removed if the tests are updated.

cluster: "{{ clusterlist['json'][0]|basename }}"

Although it doesn't hurt to keep it I think.

def get_resource_pool(self, cluster=None, host=None, resource_pool=None):
""" Get a resource pool, filter on cluster, esxi_hostname or resource_pool if given """

cluster_name = cluster or self.params['cluster']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use self.params.get('cluster', None) instead of self.params['cluster'] and same for below two.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the code.

@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI. test This PR relates to tests. and removed community_review In order to be merged, this PR must follow the community review workflow. stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI. labels May 22, 2018
@ansibot ansibot added the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. label Jul 27, 2018
@ansibot

This comment has been minimized.

@ansibot ansibot added merge_commit This PR contains at least one merge commit. Please resolve! and removed stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. labels Aug 27, 2018
@ansibot ansibot removed the merge_commit This PR contains at least one merge commit. Please resolve! label Aug 27, 2018
@ansibot ansibot added community_review In order to be merged, this PR must follow the community review workflow. and removed needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Aug 27, 2018
@stroobl
Copy link

stroobl commented Aug 29, 2018

Any possibility to have this merged for 2.7? This patch has been in use inside WDC since it was contributed here in May. We use it a lot on Vsphere 5.5 en 6.5 setups where we had this problem and it solved our issues. Everything works stable for us.

@gundalow
Copy link
Contributor

@pdellaert @dericcrago Could you please review this so we can get this into Ansible 2.7?

@Akasurde
Copy link
Member

Akasurde commented Sep 3, 2018

Closing and re-opening for CI trigger.

@Akasurde Akasurde closed this Sep 3, 2018
@Akasurde Akasurde reopened this Sep 3, 2018
@Akasurde Akasurde merged commit 1a810f8 into ansible:devel Sep 7, 2018
Akasurde pushed a commit to Akasurde/ansible that referenced this pull request Oct 8, 2018
…lection (ansible#39792)

* rewrite get_resource_pool method for correct resource_pool selection
* only keep name if path is given for cluster, esxi_hostname or resource_pool
* Revert "only keep name if path is given for cluster, esxi_hostname or resource_pool"
* This reverts commit 50293ec763c024b0eaceac5d775ccc0ad3ff8bd7.
* if the name argument contains a path, only use the last part for matching
* remove path from cluster argument in tests
* remove find_objs in favour of reusing find_obj with an extra folder argument
* fix find_obj ignoring first if name is not given

(cherry picked from commit 1a810f8)
abadger pushed a commit that referenced this pull request Oct 9, 2018
…lection (#39792)

* rewrite get_resource_pool method for correct resource_pool selection
* only keep name if path is given for cluster, esxi_hostname or resource_pool
* Revert "only keep name if path is given for cluster, esxi_hostname or resource_pool"
* This reverts commit 50293ec763c024b0eaceac5d775ccc0ad3ff8bd7.
* if the name argument contains a path, only use the last part for matching
* remove path from cluster argument in tests
* remove find_objs in favour of reusing find_obj with an extra folder argument
* fix find_obj ignoring first if name is not given

(cherry picked from commit 1a810f8)
@ansible ansible locked and limited conversation to collaborators Jul 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.6 This issue/PR affects Ansible v2.6 bug This issue/PR relates to a bug. cloud community_review In order to be merged, this PR must follow the community review workflow. module This issue/PR relates to a module. new_contributor This PR is the first contribution by a new community member. support:community This issue/PR relates to code supported by the Ansible community. test This PR relates to tests. vmware VMware community
Projects
None yet
Development

Successfully merging this pull request may close these issues.

vmware_guest - Cluster option stopped working
7 participants