From 50ae8fd7ae6c7f596bc7ec105b669c8e4d2f1408 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Wed, 12 Nov 2025 21:58:44 +0100 Subject: [PATCH] [PR #11102/e5ee3eb8 backport][stable-12] replace batch of redundant to_native() occurrences (#11137) replace batch of redundant to_native() occurrences (#11102) * replace batch of redundant to_native() occurrences * add changelog frag * Update plugins/modules/idrac_redfish_config.py * reformat * Apply suggestions from code review * Update plugins/modules/dimensiondata_network.py --------- (cherry picked from commit e5ee3eb88bbbf505b4fef7e72c1720c970f4e461) Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> Co-authored-by: Felix Fontein --- changelogs/fragments/11102-tonative-2.yml | 13 +++++++++++++ plugins/modules/atomic_container.py | 3 +-- plugins/modules/circonus_annotation.py | 3 +-- plugins/modules/dimensiondata_network.py | 9 +++------ plugins/modules/idrac_redfish_config.py | 3 +-- plugins/modules/jenkins_plugin.py | 20 +++++++++----------- plugins/modules/ldap_attrs.py | 4 ++-- plugins/modules/ldap_entry.py | 4 ++-- plugins/modules/ldap_inc.py | 4 ++-- plugins/modules/onepassword_info.py | 2 +- plugins/modules/sensu_subscription.py | 5 +---- plugins/modules/statusio_maintenance.py | 7 +++---- plugins/modules/vmadm.py | 7 +++---- 13 files changed, 42 insertions(+), 42 deletions(-) create mode 100644 changelogs/fragments/11102-tonative-2.yml diff --git a/changelogs/fragments/11102-tonative-2.yml b/changelogs/fragments/11102-tonative-2.yml new file mode 100644 index 0000000000..d62a26f4c3 --- /dev/null +++ b/changelogs/fragments/11102-tonative-2.yml @@ -0,0 +1,13 @@ +minor_changes: + - atomic_container - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/11102). + - circonus_annotation - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/11102). + - dimensiondata_network - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/11102). + - idrac_redfish_config - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/11102). + - jenkins_plugin - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/11102). + - ldap_attrs - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/11102). + - ldap_entry - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/11102). + - ldap_inc - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/11102). + - onepassword_info - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/11102). + - sensu_subscription - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/11102). + - statusio_maintenance - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/11102). + - vmadm - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/11102). diff --git a/plugins/modules/atomic_container.py b/plugins/modules/atomic_container.py index c22377c45e..f94a00bacf 100644 --- a/plugins/modules/atomic_container.py +++ b/plugins/modules/atomic_container.py @@ -103,7 +103,6 @@ msg: import traceback from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.common.text.converters import to_native def do_install(module, mode, rootfs, container, image, values_list, backend): @@ -227,7 +226,7 @@ def main(): try: core(module) except Exception as e: - module.fail_json(msg="Unanticipated error running atomic: %s" % to_native(e), exception=traceback.format_exc()) + module.fail_json(msg=f"Unanticipated error running atomic: {e}", exception=traceback.format_exc()) if __name__ == "__main__": diff --git a/plugins/modules/circonus_annotation.py b/plugins/modules/circonus_annotation.py index 5a9b8c7eb7..035029c4ab 100644 --- a/plugins/modules/circonus_annotation.py +++ b/plugins/modules/circonus_annotation.py @@ -160,7 +160,6 @@ except ImportError: HAS_REQUESTS = False from ansible.module_utils.basic import AnsibleModule, missing_required_lib -from ansible.module_utils.common.text.converters import to_native def check_requests_dep(module): @@ -235,7 +234,7 @@ def main(): try: resp = post_annotation(annotation, module.params["api_key"]) except requests.exceptions.RequestException as e: - module.fail_json(msg="Request Failed", reason=to_native(e), exception=traceback.format_exc()) + module.fail_json(msg="Request Failed", reason=f"{e}", exception=traceback.format_exc()) module.exit_json(changed=True, annotation=resp.json()) diff --git a/plugins/modules/dimensiondata_network.py b/plugins/modules/dimensiondata_network.py index 01af072e55..44e9fec815 100644 --- a/plugins/modules/dimensiondata_network.py +++ b/plugins/modules/dimensiondata_network.py @@ -120,7 +120,6 @@ import traceback from ansible.module_utils.basic import AnsibleModule from ansible_collections.community.general.plugins.module_utils.dimensiondata import HAS_LIBCLOUD, DimensionDataModule -from ansible.module_utils.common.text.converters import to_native if HAS_LIBCLOUD: from libcloud.compute.base import NodeLocation @@ -223,9 +222,7 @@ class DimensionDataNetworkModule(DimensionDataModule): self.location, self.name, self.module.params["service_plan"], description=self.description ) except DimensionDataAPIException as e: - self.module.fail_json( - msg="Failed to create new network: %s" % to_native(e), exception=traceback.format_exc() - ) + self.module.fail_json(msg=f"Failed to create new network: {e}", exception=traceback.format_exc()) if self.module.params["wait"] is True: network = self._wait_for_network_state(network.id, "NORMAL") @@ -245,7 +242,7 @@ class DimensionDataNetworkModule(DimensionDataModule): self.module.fail_json("Unexpected failure deleting network with id %s" % network.id) except DimensionDataAPIException as e: - self.module.fail_json(msg="Failed to delete network: %s" % to_native(e), exception=traceback.format_exc()) + self.module.fail_json(msg=f"Failed to delete network: {e}", exception=traceback.format_exc()) def _wait_for_network_state(self, net_id, state_to_wait_for): try: @@ -258,7 +255,7 @@ class DimensionDataNetworkModule(DimensionDataModule): ) except DimensionDataAPIException as e: self.module.fail_json( - msg="Network did not reach % state in time: %s" % (state_to_wait_for, to_native(e)), + msg=f"Network did not reach {state_to_wait_for} state in time: {e}", exception=traceback.format_exc(), ) diff --git a/plugins/modules/idrac_redfish_config.py b/plugins/modules/idrac_redfish_config.py index ec21cec3fa..0f3f56ec09 100644 --- a/plugins/modules/idrac_redfish_config.py +++ b/plugins/modules/idrac_redfish_config.py @@ -170,8 +170,7 @@ class IdracRedfishUtils(RedfishUtils): check_required_arguments(required_arg_spec, self.module.params) except TypeError as e: - msg = to_native(e) - self.module.fail_json(msg=msg) + self.module.fail_json(msg=f"{e}") key = "Attributes" command_manager_attributes_uri_map = { diff --git a/plugins/modules/jenkins_plugin.py b/plugins/modules/jenkins_plugin.py index f30175626d..5dc49649f1 100644 --- a/plugins/modules/jenkins_plugin.py +++ b/plugins/modules/jenkins_plugin.py @@ -401,7 +401,7 @@ class JenkinsPlugin: try: json_data = json.loads(to_native(r.read())) except Exception as e: - self.module.fail_json(msg=f"Cannot parse {what} JSON data.", details=to_native(e)) + self.module.fail_json(msg=f"Cannot parse {what} JSON data.", details=f"{e}") return json_data @@ -477,7 +477,7 @@ class JenkinsPlugin: if dont_fail: raise FailedInstallingWithPluginManager(e) from e else: - self.module.fail_json(msg=msg_exception, details=to_native(e)) + self.module.fail_json(msg=msg_exception, details=f"{e}") return response @@ -695,7 +695,7 @@ class JenkinsPlugin: except Exception as e: if os.path.exists(cache_path): os.remove(cache_path) - self.module.fail_json(msg="Failed to parse plugin-versions.json", details=to_native(e)) + self.module.fail_json(msg="Failed to parse plugin-versions.json", details=f"{e}") plugin_versions = plugin_data.get("plugins", {}).get(name) if not plugin_versions: @@ -743,7 +743,7 @@ class JenkinsPlugin: try: updates_file, download_updates = download_updates_file(self.params["updates_expiration"]) except OSError as e: - self.module.fail_json(msg="Cannot create temporal directory.", details=to_native(e)) + self.module.fail_json(msg="Cannot create temporal directory.", details=f"{e}") # Download the updates file if needed if download_updates: @@ -761,9 +761,7 @@ class JenkinsPlugin: try: os.close(tmp_update_fd) except IOError as e: - self.module.fail_json( - msg=f"Cannot close the tmp updates file {tmp_updates_file}.", details=to_native(e) - ) + self.module.fail_json(msg=f"Cannot close the tmp updates file {tmp_updates_file}.", details=f"{e}") else: tmp_updates_file = updates_file @@ -777,12 +775,12 @@ class JenkinsPlugin: except IOError as e: self.module.fail_json( msg=f"Cannot open{' temporary' if tmp_updates_file != updates_file else ''} updates file.", - details=to_native(e), + details=f"{e}", ) except Exception as e: self.module.fail_json( msg=f"Cannot load JSON data from the{' temporary' if tmp_updates_file != updates_file else ''} updates file.", - details=to_native(e), + details=f"{e}", ) # Move the updates file to the right place if we could read it @@ -812,7 +810,7 @@ class JenkinsPlugin: try: os.close(tmp_f_fd) except IOError as e: - self.module.fail_json(msg=f"Cannot close the temporal plugin file {tmp_f}.", details=to_native(e)) + self.module.fail_json(msg=f"Cannot close the temporal plugin file {tmp_f}.", details=f"{e}") # Move the file onto the right place self.module.atomic_move(os.path.abspath(tmp_f), os.path.abspath(f)) @@ -923,7 +921,7 @@ def main(): try: module.params["timeout"] = float(module.params["timeout"]) except ValueError as e: - module.fail_json(msg=f"Cannot convert {module.params['timeout']} to float.", details=to_native(e)) + module.fail_json(msg=f"Cannot convert {module.params['timeout']} to float.", details=f"{e}") # Instantiate the JenkinsPlugin object jp = JenkinsPlugin(module) diff --git a/plugins/modules/ldap_attrs.py b/plugins/modules/ldap_attrs.py index 3ae14da4d6..a1f1413da6 100644 --- a/plugins/modules/ldap_attrs.py +++ b/plugins/modules/ldap_attrs.py @@ -160,7 +160,7 @@ modlist: import traceback from ansible.module_utils.basic import AnsibleModule, missing_required_lib -from ansible.module_utils.common.text.converters import to_native, to_bytes, to_text +from ansible.module_utils.common.text.converters import to_bytes, to_text from ansible_collections.community.general.plugins.module_utils.ldap import ( LdapGeneric, gen_specs, @@ -327,7 +327,7 @@ def main(): try: ldap.connection.modify_s(ldap.dn, modlist) except Exception as e: - module.fail_json(msg="Attribute action failed.", details=to_native(e)) + module.fail_json(msg="Attribute action failed.", details=f"{e}") module.exit_json(changed=changed, modlist=modlist, diff={"before": old_attrs, "after": new_attrs}) diff --git a/plugins/modules/ldap_entry.py b/plugins/modules/ldap_entry.py index 5d95aeeb33..9404b1cb0d 100644 --- a/plugins/modules/ldap_entry.py +++ b/plugins/modules/ldap_entry.py @@ -132,7 +132,7 @@ RETURN = r""" import traceback from ansible.module_utils.basic import AnsibleModule, missing_required_lib -from ansible.module_utils.common.text.converters import to_native, to_bytes +from ansible.module_utils.common.text.converters import to_bytes from ansible_collections.community.general.plugins.module_utils.ldap import ( LdapGeneric, gen_specs, @@ -264,7 +264,7 @@ def main(): try: action() except Exception as e: - module.fail_json(msg="Entry action failed.", details=to_native(e), exception=traceback.format_exc()) + module.fail_json(msg="Entry action failed.", details=f"{e}", exception=traceback.format_exc()) module.exit_json(changed=(action is not None)) diff --git a/plugins/modules/ldap_inc.py b/plugins/modules/ldap_inc.py index 0aff1f5434..c2ed38f50a 100644 --- a/plugins/modules/ldap_inc.py +++ b/plugins/modules/ldap_inc.py @@ -115,7 +115,7 @@ rfc4525: """ from ansible.module_utils.basic import AnsibleModule, missing_required_lib -from ansible.module_utils.common.text.converters import to_native, to_bytes +from ansible.module_utils.common.text.converters import to_bytes from ansible_collections.community.general.plugins.module_utils import deps from ansible_collections.community.general.plugins.module_utils.ldap import ( LdapGeneric, @@ -222,7 +222,7 @@ def main(): module.fail_json(msg="The entry does not exist or does not contain the specified attribute.") except Exception as e: - module.fail_json(msg="Attribute action failed.", details=to_native(e)) + module.fail_json(msg="Attribute action failed.", details=f"{e}") module.exit_json(changed=changed, incremented=changed, attribute=mod.attr, value=ret, rfc4525=rfc4525) diff --git a/plugins/modules/onepassword_info.py b/plugins/modules/onepassword_info.py index 42ea0d4e83..2cfd691894 100644 --- a/plugins/modules/onepassword_info.py +++ b/plugins/modules/onepassword_info.py @@ -266,7 +266,7 @@ class OnePasswordInfo: return output except Exception as e: - if re.search(".*not found.*", to_native(e)): + if re.search(".*not found.*", f"{e}"): module.fail_json(msg=f"Unable to find an item in 1Password named '{item_id}'.") else: module.fail_json(msg=f"Unexpected error attempting to find an item in 1Password named '{item_id}': {e}") diff --git a/plugins/modules/sensu_subscription.py b/plugins/modules/sensu_subscription.py index 9ac9cb2fb3..162f7daf6e 100644 --- a/plugins/modules/sensu_subscription.py +++ b/plugins/modules/sensu_subscription.py @@ -72,7 +72,6 @@ import json import traceback from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.common.text.converters import to_native def sensu_subscription(module, path, name, state="present", backup=False): @@ -128,9 +127,7 @@ def sensu_subscription(module, path, name, state="present", backup=False): try: open(path, "w").write(json.dumps(config, indent=2) + "\n") except IOError as e: - module.fail_json( - msg="Failed to write to file %s: %s" % (path, to_native(e)), exception=traceback.format_exc() - ) + module.fail_json(msg=f"Failed to write to file {path}: {e}", exception=traceback.format_exc()) return changed, reasons diff --git a/plugins/modules/statusio_maintenance.py b/plugins/modules/statusio_maintenance.py index d0cebc148b..46f003b6dd 100644 --- a/plugins/modules/statusio_maintenance.py +++ b/plugins/modules/statusio_maintenance.py @@ -178,7 +178,6 @@ import datetime import json from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.common.text.converters import to_native from ansible.module_utils.urls import open_url from ansible_collections.community.general.plugins.module_utils.datetime import ( @@ -198,7 +197,7 @@ def get_api_auth_headers(api_id, api_key, url, statuspage): auth_headers = headers auth_content = data except Exception as e: - return 1, None, None, to_native(e) + return 1, None, None, f"{e}" return 0, auth_headers, auth_content, None @@ -310,7 +309,7 @@ def create_maintenance( if data["status"]["error"] == "yes": return 1, None, data["status"]["message"] except Exception as e: - return 1, None, to_native(e) + return 1, None, f"{e}" return 0, None, None @@ -327,7 +326,7 @@ def delete_maintenance(auth_headers, url, statuspage, maintenance_id): if data["status"]["error"] == "yes": return 1, None, "Invalid maintenance_id" except Exception as e: - return 1, None, to_native(e) + return 1, None, f"{e}" return 0, None, None diff --git a/plugins/modules/vmadm.py b/plugins/modules/vmadm.py index cecd589ed1..f657e9c20c 100644 --- a/plugins/modules/vmadm.py +++ b/plugins/modules/vmadm.py @@ -346,7 +346,6 @@ import traceback from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.common.text.converters import to_native # While vmadm(1M) supports a -E option to return any errors in JSON, the # generated JSON does not play well with the JSON parsers of Python. @@ -369,7 +368,7 @@ def get_vm_prop(module, uuid, prop): except Exception as e: module.fail_json( msg=f"Invalid JSON returned by vmadm for uuid lookup of {prop}", - details=to_native(e), + details=f"{e}", exception=traceback.format_exc(), ) @@ -395,7 +394,7 @@ def get_vm_uuid(module, alias): except Exception as e: module.fail_json( msg=f"Invalid JSON returned by vmadm for uuid lookup of {alias}", - details=to_native(e), + details=f"{e}", exception=traceback.format_exc(), ) @@ -416,7 +415,7 @@ def get_all_vm_uuids(module): stdout_json = json.loads(stdout) return [v["uuid"] for v in stdout_json] except Exception as e: - module.fail_json(msg="Could not retrieve VM UUIDs", details=to_native(e), exception=traceback.format_exc()) + module.fail_json(msg="Could not retrieve VM UUIDs", details=f"{e}", exception=traceback.format_exc()) def new_vm(module, uuid, vm_state):