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

Fix issue of the vmware_cluster_info module does not decode of a clus… #366

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/366-vmware_cluster_info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- vmware_cluster_info - Fixed issue of a cluster name doesn't URL-decode(https://github.com/ansible-collections/vmware/pull/366)
5 changes: 3 additions & 2 deletions plugins/modules/vmware_cluster_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@
pass

from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.six.moves.urllib.parse import unquote
from ansible_collections.community.vmware.plugins.module_utils.vmware import PyVmomi, vmware_argument_spec, find_datacenter_by_name, find_cluster_by_name
from ansible_collections.community.vmware.plugins.module_utils.vmware_rest_client import VmwareRestClient

Expand Down Expand Up @@ -290,7 +291,7 @@ def gather_cluster_info(self):
if '_vimtype' in resource_summary:
del resource_summary['_vimtype']

results['clusters'][cluster.name] = dict(
results['clusters'][unquote(cluster.name)] = dict(
hosts=hosts,
enable_ha=das_config.enabled,
ha_failover_level=ha_failover_level,
Expand All @@ -314,7 +315,7 @@ def gather_cluster_info(self):
)
else:
for cluster in self.cluster_objs:
results['clusters'][cluster.name] = self.to_json(cluster, self.properties)
results['clusters'][unquote(cluster.name)] = self.to_json(cluster, self.properties)

self.module.exit_json(**results)

Expand Down
30 changes: 30 additions & 0 deletions tests/integration/targets/vmware_cluster_info/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,33 @@
# that:
# - cluster_info is defined
# - cluster_info.clusters[ccr1].tags is defined

- name: "Prepare a cluster name with character to be URL-encoded"
vmware_cluster:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: no
datacenter_name: "{{ dc1 }}"
cluster_name: 'Cluster/\%'
state: present
register: prepare_cluster_url_encoded_result

- assert:
that:
- prepare_cluster_url_encoded_result.changed is sameas true

- name: "Gather information about all datacenter"
vmware_cluster_info:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: no
datacenter: "{{ dc1 }}"
register: all_cluster_result

- name: "Ensure URL-encoded cluster name"
assert:
that:
- all_cluster_result.clusters['Cluster/\%']