Skip to content

[WIP] Fix ansible-core 2.19 compatibility #2391

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
9 changes: 9 additions & 0 deletions changelogs/fragments/2391-core-2.19.compatibility.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
bugfixes:
- vm_device_helper - Fix an issue with ansible-core 2.19
(https://github.com/ansible-collections/community.vmware/pull/2391).
- vmware_guest_controller - Fix an issue with ansible-core 2.19
(https://github.com/ansible-collections/community.vmware/pull/2391).
- vmware_guest_disk - Fix an issue with ansible-core 2.19
(https://github.com/ansible-collections/community.vmware/pull/2391).
- vmware_target_canonical_info - Fix an issue with ansible-core 2.19
(https://github.com/ansible-collections/community.vmware/pull/2391).
52 changes: 26 additions & 26 deletions plugins/module_utils/vm_device_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ def gather_disk_info(self, vm_obj):
for controller in vm_obj.config.hardware.device:
for name, type in self.disk_ctl_device_type.items():
if isinstance(controller, type):
controller_info[controller_index] = dict(
controller_info[str(controller_index)] = dict(
key=controller.key,
controller_type=name,
bus_number=controller.busNumber,
Expand All @@ -448,7 +448,7 @@ def gather_disk_info(self, vm_obj):
if disk.shares is None:
disk.shares = vim.SharesInfo()

disks_info[disk_index] = dict(
disks_info[str(disk_index)] = dict(
key=disk.key,
label=disk.deviceInfo.label,
summary=disk.deviceInfo.summary,
Expand All @@ -470,48 +470,48 @@ def gather_disk_info(self, vm_obj):
capacity_in_bytes=disk.capacityInBytes,
)
if isinstance(disk.backing, vim.vm.device.VirtualDisk.FlatVer1BackingInfo):
disks_info[disk_index]['backing_type'] = 'FlatVer1'
disks_info[str(disk_index)]['backing_type'] = 'FlatVer1'

elif isinstance(disk.backing, vim.vm.device.VirtualDisk.FlatVer2BackingInfo):
disks_info[disk_index]['backing_type'] = 'FlatVer2'
disks_info[disk_index]['backing_thinprovisioned'] = disk.backing.thinProvisioned
disks_info[disk_index]['backing_eagerlyscrub'] = disk.backing.eagerlyScrub
disks_info[str(disk_index)]['backing_type'] = 'FlatVer2'
disks_info[str(disk_index)]['backing_thinprovisioned'] = disk.backing.thinProvisioned
disks_info[str(disk_index)]['backing_eagerlyscrub'] = disk.backing.eagerlyScrub

elif isinstance(disk.backing, vim.vm.device.VirtualDisk.LocalPMemBackingInfo):
disks_info[disk_index]['backing_type'] = 'LocalPMem'
disks_info[disk_index]['backing_volumeuuid'] = disk.backing.volumeUUID
disks_info[str(disk_index)]['backing_type'] = 'LocalPMem'
disks_info[str(disk_index)]['backing_volumeuuid'] = disk.backing.volumeUUID

elif isinstance(disk.backing, vim.vm.device.VirtualDisk.PartitionedRawDiskVer2BackingInfo):
disks_info[disk_index]['backing_type'] = 'PartitionedRawDiskVer2'
disks_info[disk_index]['backing_descriptorfilename'] = disk.backing.descriptorFileName
disks_info[str(disk_index)]['backing_type'] = 'PartitionedRawDiskVer2'
disks_info[str(disk_index)]['backing_descriptorfilename'] = disk.backing.descriptorFileName

elif isinstance(disk.backing, vim.vm.device.VirtualDisk.RawDiskMappingVer1BackingInfo):
disks_info[disk_index]['backing_type'] = 'RawDiskMappingVer1'
disks_info[disk_index]['backing_devicename'] = disk.backing.deviceName
disks_info[disk_index]['backing_lunuuid'] = disk.backing.lunUuid
disks_info[disk_index]['backing_compatibility_mode'] = disk.backing.compatibilityMode
disks_info[str(disk_index)]['backing_type'] = 'RawDiskMappingVer1'
disks_info[str(disk_index)]['backing_devicename'] = disk.backing.deviceName
disks_info[str(disk_index)]['backing_lunuuid'] = disk.backing.lunUuid
disks_info[str(disk_index)]['backing_compatibility_mode'] = disk.backing.compatibilityMode

elif isinstance(disk.backing, vim.vm.device.VirtualDisk.RawDiskVer2BackingInfo):
disks_info[disk_index]['backing_type'] = 'RawDiskVer2'
disks_info[disk_index]['backing_descriptorfilename'] = disk.backing.descriptorFileName
disks_info[str(disk_index)]['backing_type'] = 'RawDiskVer2'
disks_info[str(disk_index)]['backing_descriptorfilename'] = disk.backing.descriptorFileName

elif isinstance(disk.backing, vim.vm.device.VirtualDisk.SeSparseBackingInfo):
disks_info[disk_index]['backing_type'] = 'SeSparse'
disks_info[str(disk_index)]['backing_type'] = 'SeSparse'

elif isinstance(disk.backing, vim.vm.device.VirtualDisk.SparseVer1BackingInfo):
disks_info[disk_index]['backing_type'] = 'SparseVer1'
disks_info[disk_index]['backing_spaceusedinkb'] = disk.backing.spaceUsedInKB
disks_info[disk_index]['backing_split'] = disk.backing.split
disks_info[str(disk_index)]['backing_type'] = 'SparseVer1'
disks_info[str(disk_index)]['backing_spaceusedinkb'] = disk.backing.spaceUsedInKB
disks_info[str(disk_index)]['backing_split'] = disk.backing.split

elif isinstance(disk.backing, vim.vm.device.VirtualDisk.SparseVer2BackingInfo):
disks_info[disk_index]['backing_type'] = 'SparseVer2'
disks_info[disk_index]['backing_spaceusedinkb'] = disk.backing.spaceUsedInKB
disks_info[disk_index]['backing_split'] = disk.backing.split
disks_info[str(disk_index)]['backing_type'] = 'SparseVer2'
disks_info[str(disk_index)]['backing_spaceusedinkb'] = disk.backing.spaceUsedInKB
disks_info[str(disk_index)]['backing_split'] = disk.backing.split

for controller_index in range(len(controller_info)):
if controller_info[controller_index]['key'] == disks_info[disk_index]['controller_key']:
disks_info[disk_index]['controller_bus_number'] = controller_info[controller_index]['bus_number']
disks_info[disk_index]['controller_type'] = controller_info[controller_index]['controller_type']
if controller_info[str(controller_index)]['key'] == disks_info[str(disk_index)]['controller_key']:
disks_info[str(disk_index)]['controller_bus_number'] = controller_info[str(controller_index)]['bus_number']
disks_info[str(disk_index)]['controller_type'] = controller_info[str(controller_index)]['controller_type']

disk_index += 1
return disks_info
4 changes: 2 additions & 2 deletions plugins/modules/vmware_guest_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ def gather_disk_controller_facts(self):
for device in self.current_vm_obj.config.hardware.device:
ctl_facts_dict = dict()
if isinstance(device, tuple(self.controller_types.values())):
ctl_facts_dict[device.busNumber] = dict(
ctl_facts_dict[str(device.busNumber)] = dict(
controller_summary=device.deviceInfo.summary,
controller_label=device.deviceInfo.label,
controller_busnumber=device.busNumber,
Expand All @@ -355,7 +355,7 @@ def gather_disk_controller_facts(self):
controller_disks_devicekey=device.device,
)
if hasattr(device, 'sharedBus'):
ctl_facts_dict[device.busNumber]['controller_bus_sharing'] = device.sharedBus
ctl_facts_dict[str(device.busNumber)]['controller_bus_sharing'] = device.sharedBus
if isinstance(device, tuple(self.device_helper.scsi_device_type.values())):
disk_ctl_facts['scsi'].update(ctl_facts_dict)
if isinstance(device, self.device_helper.nvme_device_type):
Expand Down
6 changes: 3 additions & 3 deletions plugins/modules/vmware_guest_disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ def ensure_disks(self, vm_obj=None):
if disk_change:
self.config_spec.deviceChange.append(disk_spec)
disk_change_list.append(disk_change)
results['disk_changes'][disk['disk_index']] = "Disk reconfigured."
results['disk_changes'][str(disk['disk_index'])] = "Disk reconfigured."

elif disk['state'] == 'absent':
# Disk already exists, deleting
Expand All @@ -762,7 +762,7 @@ def ensure_disks(self, vm_obj=None):
self.config_spec.deviceChange.append(disk_spec)
disk_change = True
disk_change_list.append(disk_change)
results['disk_changes'][disk['disk_index']] = "Disk deleted."
results['disk_changes'][str(disk['disk_index'])] = "Disk deleted."
break

if disk_found:
Expand Down Expand Up @@ -804,7 +804,7 @@ def ensure_disks(self, vm_obj=None):
self.config_spec.deviceChange.append(disk_spec)
disk_change = True
disk_change_list.append(disk_change)
results['disk_changes'][disk['disk_index']] = "Disk created."
results['disk_changes'][str(disk['disk_index'])] = "Disk created."
break
if disk_change:
# Adding multiple disks in a single attempt raises weird errors
Expand Down
4 changes: 2 additions & 2 deletions plugins/modules/vmware_target_canonical_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def gather_scsi_device_info(self):
# Associate target number with LUN uuid
for target in host.config.storageDevice.scsiTopology.adapter[0].target:
for lun in target.lun:
target_lun_uuid[target.target] = lun.scsiLun
target_lun_uuid[str(target.target)] = lun.scsiLun

scsi_tgt_info[host.name] = dict(
scsilun_canonical=scsilun_canonical,
Expand All @@ -143,7 +143,7 @@ def gather_scsi_device_info(self):
canonical = ''
temp_lun_data = scsi_tgt_info[self.esxi_hostname]['target_lun_uuid']
if self.esxi_hostname in scsi_tgt_info and \
target_id in temp_lun_data:
str(target_id) in temp_lun_data:
temp_scsi_data = scsi_tgt_info[self.esxi_hostname]['scsilun_canonical']
temp_target = temp_lun_data[target_id]
canonical = temp_scsi_data[temp_target]
Expand Down
10 changes: 5 additions & 5 deletions tests/integration/targets/vmware_cluster_info/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
name: ensure info are gathered for all clusters
assert:
that:
- all_cluster_result.clusters
- all_cluster_result.clusters | length > 0
- not all_cluster_result.changed

- name: ensure info are all defined
Expand Down Expand Up @@ -72,7 +72,7 @@
name: Ensure info are gathered for the given cluster
assert:
that:
- cluster_result.clusters
- cluster_result.clusters | length > 0
- not cluster_result.changed

- <<: *vc_cluster_data
Expand All @@ -99,7 +99,7 @@
- name: Ensure info are gathered for all clusters with properteis
assert:
that:
- all_cluster_result.clusters
- all_cluster_result.clusters | length > 0
- all_cluster_result.clusters[item].name == item
- all_cluster_result.clusters[item].configuration.dasConfig.enabled is defined
- all_cluster_result.clusters[item].summary.totalCpu is defined
Expand All @@ -123,7 +123,7 @@
- name: Ensure info are gathered for the given cluster with properties
assert:
that:
- cluster_result.clusters
- cluster_result.clusters | length > 0
- cluster_result.clusters[item].name == item
- cluster_result.clusters[item].configuration.dasConfig.enabled is defined
- cluster_result.clusters[item].summary.totalCpu is defined
Expand Down Expand Up @@ -191,4 +191,4 @@
- name: "Ensure URL-encoded cluster name"
assert:
that:
- all_cluster_result.clusters['Cluster/\%']
- all_cluster_result.clusters['Cluster/\%'] is truthy
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
- name: Ensure datacenter is present
assert:
that:
- dc_result.datacenter_info
- dc_result.datacenter_info | length > 0

- name: Gather information about all datacenter in check mode
vmware_datacenter_info:
Expand All @@ -36,7 +36,7 @@
- name: Ensure datacenter is present
assert:
that:
- dc_result.datacenter_info
- dc_result.datacenter_info | length > 0

- name: Gather information about particular datacenter
vmware_datacenter_info:
Expand All @@ -53,7 +53,7 @@
- name: Ensure datacenter is present
assert:
that:
- dc_result.datacenter_info
- dc_result.datacenter_info | length > 0

- name: Gather information about particular datacenter in check mode
vmware_datacenter_info:
Expand All @@ -71,4 +71,4 @@
- name: Ensure datacenter is present
assert:
that:
- dc_result.datacenter_info
- dc_result.datacenter_info | length > 0
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
assert:
that:
- >-
dvs_results.dvs_portgroup_info.{{ dvswitch1 }}
dvs_results.dvs_portgroup_info['{{ dvswitch1 }}']
| map(attribute='portgroup_name')
| select('==', 'dvportgroup\/%')
| list
Expand Down Expand Up @@ -107,4 +107,4 @@
- assert:
that:
- "dvs_results_0002['dvs_portgroup_info']['DVS0'] is defined"
- dvs_results_0002['dvs_portgroup_info']['DVS0'][0].key
- dvs_results_0002['dvs_portgroup_info']['DVS0'][0].key is truthy
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
- name: ensure info are gathered for all hosts
assert:
that:
- all_hosts_result.hosts_info
- all_hosts_result.hosts_info is truthy

- name: gather info about all hosts in given cluster in check mode
vmware_host_config_info:
Expand All @@ -36,7 +36,7 @@
- name: ensure info are gathered for all hosts
assert:
that:
- all_hosts_result_check_mode.hosts_info
- all_hosts_result_check_mode.hosts_info is truthy

- name: gather info about a given host in check mode
vmware_host_config_info:
Expand All @@ -50,7 +50,7 @@
- name: ensure info are gathered for all hosts
assert:
that:
- single_hosts_result_check_mode.hosts_info
- single_hosts_result_check_mode.hosts_info is truthy

- name: gather info about a given host
vmware_host_config_info:
Expand All @@ -63,4 +63,4 @@
- name: ensure info are gathered for all hosts
assert:
that:
- single_hosts_result.hosts_info
- single_hosts_result.hosts_info is truthy
8 changes: 4 additions & 4 deletions tests/integration/targets/vmware_host_dns_info/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
- name: ensure DNS info are gathered for all hosts in given cluster
assert:
that:
- all_hosts_dns_result.hosts_dns_info
- all_hosts_dns_result.hosts_dns_info is truthy
- not all_hosts_dns_result.changed

- name: gather DNS info about host system
Expand All @@ -34,7 +34,7 @@
- name: ensure DNS info are gathered about host system
assert:
that:
- all_hosts_dns_result.hosts_dns_info
- all_hosts_dns_result.hosts_dns_info is truthy
- not all_hosts_dns_result.changed

- name: gather DNS info about all hosts in given cluster in check mode
Expand All @@ -50,7 +50,7 @@
- name: ensure DNS info are gathered for all hosts in given cluster
assert:
that:
- all_hosts_dns_result_check_mode.hosts_dns_info
- all_hosts_dns_result_check_mode.hosts_dns_info is truthy
- not all_hosts_dns_result_check_mode.changed

- name: gather DNS info about host system in check mode
Expand All @@ -66,5 +66,5 @@
- name: ensure DNS info are gathered about host system
assert:
that:
- all_hosts_dns_result_check_mode.hosts_dns_info
- all_hosts_dns_result_check_mode.hosts_dns_info is truthy
- not all_hosts_dns_result_check_mode.changed
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
- name: Ensure SCSI disks info are gathered for all hosts in given cluster
assert:
that:
- all_hosts_disk_result.hosts_scsidisk_info
- all_hosts_disk_result.hosts_scsidisk_info is truthy
- not all_hosts_disk_result.changed

- name: Gather SCSI disks info about host system
Expand All @@ -35,7 +35,7 @@
- name: Ensure SCSI disks info are gathered about host system
assert:
that:
- all_hosts_disk_result.hosts_scsidisk_info
- all_hosts_disk_result.hosts_scsidisk_info is truthy
- not all_hosts_disk_result.changed

- name: Gather SCSI disks info about all hosts in given cluster in check mode
Expand All @@ -51,7 +51,7 @@
- name: Ensure SCSI disks info are gathered for all hosts in given cluster
assert:
that:
- all_hosts_disk_result_check_mode.hosts_scsidisk_info
- all_hosts_disk_result_check_mode.hosts_scsidisk_info is truthy
- not all_hosts_disk_result_check_mode.changed

- name: Ensure SCSI disks info about host system in check mode
Expand All @@ -67,5 +67,5 @@
- name: Ensure SCSI disks info are gathered about host system
assert:
that:
- all_hosts_disk_result_check_mode.hosts_scsidisk_info
- all_hosts_disk_result_check_mode.hosts_scsidisk_info is truthy
- not all_hosts_disk_result_check_mode.changed
Loading