From 585d4e87840732c6f1257d81c344cc2b435c8305 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Tue, 23 Jul 2024 22:03:51 +0200 Subject: [PATCH] [PR #8646/e1148e6b backport][stable-9] Fix new Proxmox Volume handling (#8667) Fix new Proxmox Volume handling (#8646) * proxmox(fix): volume string builder Half of the string was incorrectly discarded * proxmox(fix): remove string conversion of values - Also converted `None` values into strings - Clashed with non-`str` values in documentation * proxmox: add changelog fragment * proxmox(fix): remove old & unused imports * proxmox(fix): correctly turn maps into lists * Update changelogs/fragments/8646-fix-bug-in-proxmox-volumes.yml Co-authored-by: Felix Fontein * Update plugins/modules/proxmox.py Co-authored-by: Felix Fontein --------- Co-authored-by: Felix Fontein (cherry picked from commit e1148e6bdcaa0bf5c0135197fb774af9f7f06cb4) Co-authored-by: JL Euler --- .../fragments/8646-fix-bug-in-proxmox-volumes.yml | 4 ++++ plugins/modules/proxmox.py | 14 ++++---------- 2 files changed, 8 insertions(+), 10 deletions(-) create mode 100644 changelogs/fragments/8646-fix-bug-in-proxmox-volumes.yml diff --git a/changelogs/fragments/8646-fix-bug-in-proxmox-volumes.yml b/changelogs/fragments/8646-fix-bug-in-proxmox-volumes.yml new file mode 100644 index 0000000000..b3b03a008b --- /dev/null +++ b/changelogs/fragments/8646-fix-bug-in-proxmox-volumes.yml @@ -0,0 +1,4 @@ +bugfixes: + - proxmox - removed the forced conversion of non-string values to strings to be consistent with the module documentation (https://github.com/ansible-collections/community.general/pull/8646). + - proxmox - fixed an issue where the new volume handling incorrectly converted ``null`` values into ``"None"`` strings (https://github.com/ansible-collections/community.general/pull/8646). + - proxmox - fixed an issue where volume strings where overwritten instead of appended to in the new ``build_volume()`` method (https://github.com/ansible-collections/community.general/pull/8646). diff --git a/plugins/modules/proxmox.py b/plugins/modules/proxmox.py index 67a67aec55..104a896362 100644 --- a/plugins/modules/proxmox.py +++ b/plugins/modules/proxmox.py @@ -590,8 +590,7 @@ import time from ansible_collections.community.general.plugins.module_utils.version import LooseVersion from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.six import string_types -from ansible.module_utils.common.text.converters import to_native, to_text +from ansible.module_utils.common.text.converters import to_native from ansible_collections.community.general.plugins.module_utils.proxmox import ( @@ -727,10 +726,11 @@ class ProxmoxLxcAnsible(ProxmoxAnsible): # 1.3 If we have a host_path, we don't have storage, a volume, or a size vol_string = ",".join( + [vol_string] + ([] if host_path is None else [host_path]) + ([] if mountpoint is None else ["mp={0}".format(mountpoint)]) + - ([] if options is None else [map("=".join, options.items())]) + - ([] if not kwargs else [map("=".join, kwargs.items())]) + ([] if options is None else ["{0}={1}".format(k, v) for k, v in options.items()]) + + ([] if not kwargs else ["{0}={1}".format(k, v) for k, v in kwargs.items()]) ) return {key: vol_string} @@ -759,9 +759,6 @@ class ProxmoxLxcAnsible(ProxmoxAnsible): if disk is not None: kwargs["disk_volume"] = parse_disk_string(disk) if "disk_volume" in kwargs: - if not all(isinstance(val, string_types) for val in kwargs["disk_volume"].values()): - self.module.warn("All disk_volume values must be strings. Converting non-string values to strings.") - kwargs["disk_volume"] = {key: to_text(val) for key, val in kwargs["disk_volume"].items()} disk_dict = build_volume(key="rootfs", **kwargs.pop("disk_volume")) kwargs.update(disk_dict) if memory is not None: @@ -775,9 +772,6 @@ class ProxmoxLxcAnsible(ProxmoxAnsible): if "mount_volumes" in kwargs: mounts_list = kwargs.pop("mount_volumes") for mount_config in mounts_list: - if not all(isinstance(val, string_types) for val in mount_config.values()): - self.module.warn("All mount_volumes values must be strings. Converting non-string values to strings.") - mount_config = {key: to_text(val) for key, val in mount_config.items()} key = mount_config.pop("id") mount_dict = build_volume(key=key, **mount_config) kwargs.update(mount_dict)