diff --git a/changelogs/fragments/11143-tonative-8.yml b/changelogs/fragments/11143-tonative-8.yml new file mode 100644 index 0000000000..733bcd7594 --- /dev/null +++ b/changelogs/fragments/11143-tonative-8.yml @@ -0,0 +1,22 @@ +minor_changes: + - cloudflare_dns - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/1114). + - dconf - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/1114). + - idrac_redfish_command - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/1114). + - idrac_redfish_config - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/1114). + - idrac_redfish_info - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/1114). + - ilo_redfish_command - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/1114). + - ilo_redfish_config - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/1114). + - jenkins_plugin - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/1114). + - jenkins_script - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/1114). + - jira - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/1114). + - mail - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/1114). + - maven_artifact - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/1114). + - onepassword_info - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/1114). + - packet_volume - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/1114). + - redfish_command - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/1114). + - redfish_config - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/1114). + - sensu_silence - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/1114). + - svc - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/1114). + - wdc_redfish_command - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/1114). + - wdc_redfish_info - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/1114). + - xcc_redfish_command - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/1114). diff --git a/plugins/modules/cloudflare_dns.py b/plugins/modules/cloudflare_dns.py index dded475bcc..1e3eca03d0 100644 --- a/plugins/modules/cloudflare_dns.py +++ b/plugins/modules/cloudflare_dns.py @@ -441,7 +441,7 @@ import json from urllib.parse import urlencode from ansible.module_utils.basic import AnsibleModule, env_fallback -from ansible.module_utils.common.text.converters import to_native, to_text +from ansible.module_utils.common.text.converters import to_text from ansible.module_utils.urls import fetch_url @@ -587,7 +587,7 @@ class CloudflareAPI: try: result = json.loads(to_text(content, errors="surrogate_or_strict")) except getattr(json, "JSONDecodeError", ValueError) as e: - error_msg += f"; Failed to parse API response with error {to_native(e)}: {content}" + error_msg += f"; Failed to parse API response with error {e}: {content}" # Without a valid/parsed JSON response no more error processing can be done if result is None: diff --git a/plugins/modules/dconf.py b/plugins/modules/dconf.py index 44add1dfc5..2ee956c334 100644 --- a/plugins/modules/dconf.py +++ b/plugins/modules/dconf.py @@ -130,7 +130,6 @@ from ansible.module_utils.common.respawn import ( probe_interpreters_for_module, respawn_module, ) -from ansible.module_utils.common.text.converters import to_native from ansible_collections.community.general.plugins.module_utils import deps glib_module_name = "gi.repository.GLib" @@ -442,7 +441,7 @@ def main(): if isinstance(module.params["value"], bool): module.params["value"] = "true" if module.params["value"] else "false" else: - module.params["value"] = to_native(module.params["value"], errors="surrogate_or_strict") + module.params["value"] = str(module.params["value"]) if Variant is None: module.warn( diff --git a/plugins/modules/idrac_redfish_command.py b/plugins/modules/idrac_redfish_command.py index b21724d1e4..db0d835e39 100644 --- a/plugins/modules/idrac_redfish_command.py +++ b/plugins/modules/idrac_redfish_command.py @@ -101,7 +101,6 @@ from ansible_collections.community.general.plugins.module_utils.redfish_utils im RedfishUtils, REDFISH_COMMON_ARGUMENT_SPEC, ) -from ansible.module_utils.common.text.converters import to_native class IdracRedfishUtils(RedfishUtils): @@ -217,14 +216,14 @@ def main(): result = rf_utils._find_systems_resource() rf_utils.data_modification = True if result["ret"] is False: - module.fail_json(msg=to_native(result["msg"])) + module.fail_json(msg=result["msg"]) for command in command_list: if command == "CreateBiosConfigJob": # execute only if we find a Managers resource result = rf_utils._find_managers_resource() if result["ret"] is False: - module.fail_json(msg=to_native(result["msg"])) + module.fail_json(msg=result["msg"]) result = rf_utils.create_bios_config_job() if "job_id" in result: return_values["job_id"] = result["job_id"] @@ -234,7 +233,7 @@ def main(): del result["ret"] module.exit_json(changed=True, msg="Action was successful", return_values=return_values) else: - module.fail_json(msg=to_native(result["msg"])) + module.fail_json(msg=result["msg"]) if __name__ == "__main__": diff --git a/plugins/modules/idrac_redfish_config.py b/plugins/modules/idrac_redfish_config.py index 6ea9fc2d8f..816a919293 100644 --- a/plugins/modules/idrac_redfish_config.py +++ b/plugins/modules/idrac_redfish_config.py @@ -158,7 +158,6 @@ from ansible_collections.community.general.plugins.module_utils.redfish_utils im RedfishUtils, REDFISH_COMMON_ARGUMENT_SPEC, ) -from ansible.module_utils.common.text.converters import to_native class IdracRedfishUtils(RedfishUtils): @@ -314,7 +313,7 @@ def main(): # execute only if we find a Manager resource result = rf_utils._find_managers_resource() if result["ret"] is False: - module.fail_json(msg=to_native(result["msg"])) + module.fail_json(msg=result["msg"]) for command in command_list: if command in ["SetManagerAttributes", "SetLifecycleControllerAttributes", "SetSystemAttributes"]: @@ -323,11 +322,11 @@ def main(): # Return data back or fail with proper message if result["ret"] is True: if result.get("warning"): - module.warn(to_native(result["warning"])) + module.warn(result["warning"]) - module.exit_json(changed=result["changed"], msg=to_native(result["msg"])) + module.exit_json(changed=result["changed"], msg=result["msg"]) else: - module.fail_json(msg=to_native(result["msg"])) + module.fail_json(msg=result["msg"]) if __name__ == "__main__": diff --git a/plugins/modules/idrac_redfish_info.py b/plugins/modules/idrac_redfish_info.py index d7c3692d1d..2b515722d7 100644 --- a/plugins/modules/idrac_redfish_info.py +++ b/plugins/modules/idrac_redfish_info.py @@ -133,7 +133,6 @@ from ansible_collections.community.general.plugins.module_utils.redfish_utils im RedfishUtils, REDFISH_COMMON_ARGUMENT_SPEC, ) -from ansible.module_utils.common.text.converters import to_native class IdracRedfishUtils(RedfishUtils): @@ -235,7 +234,7 @@ def main(): # execute only if we find a Manager resource result = rf_utils._find_managers_resource() if result["ret"] is False: - module.fail_json(msg=to_native(result["msg"])) + module.fail_json(msg=result["msg"]) for command in command_list: if command == "GetManagerAttributes": @@ -246,7 +245,7 @@ def main(): del result["ret"] module.exit_json(redfish_facts=result) else: - module.fail_json(msg=to_native(result["msg"])) + module.fail_json(msg=result["msg"]) if __name__ == "__main__": diff --git a/plugins/modules/ilo_redfish_command.py b/plugins/modules/ilo_redfish_command.py index 7cd451820f..ea86f7796f 100644 --- a/plugins/modules/ilo_redfish_command.py +++ b/plugins/modules/ilo_redfish_command.py @@ -97,7 +97,6 @@ CATEGORY_COMMANDS_ALL = {"Systems": ["WaitforiLORebootCompletion"]} from ansible_collections.community.general.plugins.module_utils.ilo_redfish_utils import iLORedfishUtils from ansible_collections.community.general.plugins.module_utils.redfish_utils import REDFISH_COMMON_ARGUMENT_SPEC from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.common.text.converters import to_native def main(): @@ -153,7 +152,7 @@ def main(): result = rf_utils._find_systems_resource() if result["ret"] is False: - module.fail_json(msg=to_native(result["msg"])) + module.fail_json(msg=result["msg"]) for command in command_list: if command == "WaitforiLORebootCompletion": diff --git a/plugins/modules/ilo_redfish_config.py b/plugins/modules/ilo_redfish_config.py index bf65b9e464..90a10514bd 100644 --- a/plugins/modules/ilo_redfish_config.py +++ b/plugins/modules/ilo_redfish_config.py @@ -117,7 +117,6 @@ CATEGORY_COMMANDS_ALL = {"Manager": ["SetTimeZone", "SetDNSserver", "SetDomainNa from ansible_collections.community.general.plugins.module_utils.ilo_redfish_utils import iLORedfishUtils from ansible_collections.community.general.plugins.module_utils.redfish_utils import REDFISH_COMMON_ARGUMENT_SPEC from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.common.text.converters import to_native def main(): @@ -171,7 +170,7 @@ def main(): if category == "Manager": resource = rf_utils._find_managers_resource() if not resource["ret"]: - module.fail_json(msg=to_native(resource["msg"])) + module.fail_json(msg=resource["msg"]) dispatch = dict( SetTimeZone=rf_utils.set_time_zone, diff --git a/plugins/modules/jenkins_plugin.py b/plugins/modules/jenkins_plugin.py index 5dc49649f1..d90120b382 100644 --- a/plugins/modules/jenkins_plugin.py +++ b/plugins/modules/jenkins_plugin.py @@ -342,7 +342,6 @@ from urllib.parse import urlencode from ansible.module_utils.basic import AnsibleModule, to_bytes from ansible.module_utils.urls import fetch_url, url_argument_spec, basic_auth_header -from ansible.module_utils.common.text.converters import to_native from ansible_collections.community.general.plugins.module_utils.jenkins import download_updates_file @@ -399,7 +398,7 @@ class JenkinsPlugin: # Parse the JSON data try: - json_data = json.loads(to_native(r.read())) + json_data = json.loads(r.read()) except Exception as e: self.module.fail_json(msg=f"Cannot parse {what} JSON data.", details=f"{e}") @@ -683,7 +682,7 @@ class JenkinsPlugin: now = time.time() if now - file_mtime >= 86400: response = self._get_urls_data(plugin_version_urls, what="plugin-versions.json") - plugin_data = json.loads(to_native(response.read()), object_pairs_hook=OrderedDict) + plugin_data = json.loads(response.read(), object_pairs_hook=OrderedDict) # Save it to file for next time with open(cache_path, "w") as f: diff --git a/plugins/modules/jenkins_script.py b/plugins/modules/jenkins_script.py index b13d7de66e..c70edb1ac7 100644 --- a/plugins/modules/jenkins_script.py +++ b/plugins/modules/jenkins_script.py @@ -115,8 +115,7 @@ def is_csrf_protection_enabled(module): if info["status"] != 200: module.fail_json(msg=f"HTTP error {info['status']} {info['msg']}", output="") - content = to_native(resp.read()) - return json.loads(content).get("useCrumbs", False) + return json.loads(resp.read()).get("useCrumbs", False) def get_crumb(module, cookies): @@ -130,8 +129,7 @@ def get_crumb(module, cookies): if info["status"] != 200: module.fail_json(msg=f"HTTP error {info['status']} {info['msg']}", output="") - content = to_native(resp.read()) - return json.loads(content) + return json.loads(resp.read()) def main(): diff --git a/plugins/modules/jira.py b/plugins/modules/jira.py index a51393b2ca..76d4b820b4 100644 --- a/plugins/modules/jira.py +++ b/plugins/modules/jira.py @@ -759,7 +759,7 @@ class JIRA(StateModuleHelper): return s.replace('"', '\\"') boundary = "".join(random.choice(string.digits + string.ascii_letters) for dummy in range(30)) - name = to_native(os.path.basename(filename)) + name = os.path.basename(filename) if not mime_type: try: @@ -833,12 +833,12 @@ class JIRA(StateModuleHelper): error = json.loads(info["body"]) except Exception: msg = f'The request "{method} {url}" returned the unexpected status code {info["status"]} {info["msg"]}\n{info.get("body")}' - self.module.fail_json(msg=to_native(msg), exception=traceback.format_exc()) + self.module.fail_json(msg=msg, exception=traceback.format_exc()) if error: msg = [] for key in ("errorMessages", "errors"): if error.get(key): - msg.append(to_native(error[key])) + msg.append(str(error[key])) if msg: self.module.fail_json(msg=", ".join(msg)) self.module.fail_json(msg=f"{error}") diff --git a/plugins/modules/mail.py b/plugins/modules/mail.py index 08ce8e5130..3a0879c019 100644 --- a/plugins/modules/mail.py +++ b/plugins/modules/mail.py @@ -291,7 +291,7 @@ def main(): if secure == "always": module.fail_json( rc=1, - msg=f"Unable to start an encrypted session to {host}:{port}: {to_native(e)}", + msg=f"Unable to start an encrypted session to {host}:{port}: {e}", exception=traceback.format_exc(), ) except Exception: @@ -302,14 +302,12 @@ def main(): code, smtpmessage = smtp.connect(host, port) except smtplib.SMTPException as e: - module.fail_json(rc=1, msg=f"Unable to Connect {host}:{port}: {to_native(e)}", exception=traceback.format_exc()) + module.fail_json(rc=1, msg=f"Unable to Connect {host}:{port}: {e}", exception=traceback.format_exc()) try: smtp.ehlo() except smtplib.SMTPException as e: - module.fail_json( - rc=1, msg=f"Helo failed for host {host}:{port}: {to_native(e)}", exception=traceback.format_exc() - ) + module.fail_json(rc=1, msg=f"Helo failed for host {host}:{port}: {e}", exception=traceback.format_exc()) if int(code) > 0: if not secure_state and secure in ("starttls", "try"): @@ -361,7 +359,7 @@ def main(): for hdr in [x.strip() for x in header.split("|")]: try: h_key, h_val = hdr.split("=", 1) - h_val = to_native(Header(h_val, charset)) + h_val = to_native(Header(h_val, charset)) # TODO: use str() instead? msg.add_header(h_key, h_val) except Exception: module.warn(f"Skipping header '{hdr}', unable to parse") diff --git a/plugins/modules/maven_artifact.py b/plugins/modules/maven_artifact.py index 8353a770f4..41f7c53bba 100644 --- a/plugins/modules/maven_artifact.py +++ b/plugins/modules/maven_artifact.py @@ -274,7 +274,7 @@ except ImportError: from ansible.module_utils.basic import AnsibleModule, missing_required_lib from ansible.module_utils.urls import fetch_url -from ansible.module_utils.common.text.converters import to_bytes, to_native, to_text +from ansible.module_utils.common.text.converters import to_bytes, to_text def split_pre_existing_dir(dirname): @@ -601,7 +601,7 @@ class MavenDownloader: errors="strict", ) except UnicodeError as e: - return f"Cannot retrieve a valid {checksum_alg} checksum from {remote_url}: {to_native(e)}" + return f"Cannot retrieve a valid {checksum_alg} checksum from {remote_url}: {e}" if not remote_checksum: return f"Cannot find {checksum_alg} checksum from {remote_url}" try: diff --git a/plugins/modules/onepassword_info.py b/plugins/modules/onepassword_info.py index 2cfd691894..2f3616ee16 100644 --- a/plugins/modules/onepassword_info.py +++ b/plugins/modules/onepassword_info.py @@ -300,7 +300,7 @@ class OnePasswordInfo: rc, out, err = self._run(args, command_input=to_bytes(self.auto_login["master_password"])) self.token = out.strip() except AnsibleModuleError as e: - module.fail_json(msg=f"Failed to perform initial sign in to 1Password: {to_native(e)}") + module.fail_json(msg=f"Failed to perform initial sign in to 1Password: {e}") else: module.fail_json( msg=f"Unable to perform an initial sign in to 1Password. Please run '{self.cli_path} signin' " diff --git a/plugins/modules/packet_volume.py b/plugins/modules/packet_volume.py index fce57f6ddb..3a75454779 100644 --- a/plugins/modules/packet_volume.py +++ b/plugins/modules/packet_volume.py @@ -171,7 +171,6 @@ description: import uuid from ansible.module_utils.basic import AnsibleModule, env_fallback -from ansible.module_utils.common.text.converters import to_native HAS_PACKET_SDK = True @@ -307,7 +306,7 @@ def main(): try: module.exit_json(**act_on_volume(state, module, packet_conn)) except Exception as e: - module.fail_json(msg=f"failed to set volume state {state}: {to_native(e)}") + module.fail_json(msg=f"failed to set volume state {state}: {e}") else: module.fail_json(msg=f"{state} is not a valid state for this module") diff --git a/plugins/modules/redfish_command.py b/plugins/modules/redfish_command.py index a891965661..5b9a532635 100644 --- a/plugins/modules/redfish_command.py +++ b/plugins/modules/redfish_command.py @@ -1056,7 +1056,7 @@ def main(): # execute only if we find a System resource result = rf_utils._find_systems_resource() if result["ret"] is False: - module.fail_json(msg=to_native(result["msg"])) + module.fail_json(msg=result["msg"]) for command in command_list: if command.startswith("Power"): @@ -1082,7 +1082,7 @@ def main(): elif category == "Chassis": result = rf_utils._find_chassis_resource() if result["ret"] is False: - module.fail_json(msg=to_native(result["msg"])) + module.fail_json(msg=result["msg"]) led_commands = ["IndicatorLedOn", "IndicatorLedOff", "IndicatorLedBlink"] @@ -1113,7 +1113,7 @@ def main(): # execute only if we find a Manager service resource result = rf_utils._find_managers_resource() if result["ret"] is False: - module.fail_json(msg=to_native(result["msg"])) + module.fail_json(msg=result["msg"]) for command in command_list: # standardize on the Power* commands, but allow the legacy diff --git a/plugins/modules/redfish_config.py b/plugins/modules/redfish_config.py index 308f782f2f..8386e39fd8 100644 --- a/plugins/modules/redfish_config.py +++ b/plugins/modules/redfish_config.py @@ -521,7 +521,7 @@ def main(): # execute only if we find a System resource result = rf_utils._find_systems_resource() if result["ret"] is False: - module.fail_json(msg=to_native(result["msg"])) + module.fail_json(msg=result["msg"]) for command in command_list: if command == "SetBiosDefaultSettings": @@ -547,7 +547,7 @@ def main(): # execute only if we find a Manager service resource result = rf_utils._find_managers_resource() if result["ret"] is False: - module.fail_json(msg=to_native(result["msg"])) + module.fail_json(msg=result["msg"]) for command in command_list: if command == "SetNetworkProtocols": @@ -563,7 +563,7 @@ def main(): # execute only if we find a Sessions resource result = rf_utils._find_sessionservice_resource() if result["ret"] is False: - module.fail_json(msg=to_native(result["msg"])) + module.fail_json(msg=result["msg"]) for command in command_list: if command == "SetSessionService": diff --git a/plugins/modules/sensu_silence.py b/plugins/modules/sensu_silence.py index b8e809cf1c..fcbc6e96c4 100644 --- a/plugins/modules/sensu_silence.py +++ b/plugins/modules/sensu_silence.py @@ -101,7 +101,6 @@ RETURN = r""" import json -from ansible.module_utils.common.text.converters import to_native from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.urls import fetch_url @@ -129,7 +128,7 @@ def query(module, url, check, subscription): module.fail_json(msg="Failed to query silence %s. Reason: %s" % (subscription, info)) try: - json_out = json.loads(to_native(response.read())) + json_out = json.loads(response.read()) except Exception: json_out = "" @@ -176,7 +175,7 @@ def clear(module, url, check, subscription): module.fail_json(msg="Failed to silence %s. Reason: %s" % (subscription, info)) try: - json_out = json.loads(to_native(response.read())) + json_out = json.loads(response.read()) except Exception: json_out = "" @@ -225,7 +224,7 @@ def create(module, url, check, creator, expire, expire_on_resolve, reason, subsc module.fail_json(msg="Failed to silence %s. Reason: %s" % (subscription, info["msg"])) try: - json_out = json.loads(to_native(response.read())) + json_out = json.loads(response.read()) except Exception: json_out = "" diff --git a/plugins/modules/svc.py b/plugins/modules/svc.py index b1ba7d8d00..2cff67e1d4 100644 --- a/plugins/modules/svc.py +++ b/plugins/modules/svc.py @@ -94,7 +94,6 @@ import re import traceback from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.common.text.converters import to_native def _load_dist_subclass(cls, *args, **kwargs): @@ -159,7 +158,7 @@ class Svc: try: os.symlink(self.src_full, self.svc_full) except OSError as e: - self.module.fail_json(path=self.src_full, msg=f"Error while linking: {to_native(e)}") + self.module.fail_json(path=self.src_full, msg=f"Error while linking: {e}") else: self.module.fail_json(msg=f"Could not find source for service to enable ({self.src_full}).") diff --git a/plugins/modules/wdc_redfish_command.py b/plugins/modules/wdc_redfish_command.py index 3ced555c2f..e87f08a6a3 100644 --- a/plugins/modules/wdc_redfish_command.py +++ b/plugins/modules/wdc_redfish_command.py @@ -290,7 +290,7 @@ def main(): elif category == "Chassis": result = rf_utils._find_chassis_resource() if result["ret"] is False: - module.fail_json(msg=to_native(result["msg"])) + module.fail_json(msg=result["msg"]) led_commands = ["IndicatorLedOn", "IndicatorLedOff"] diff --git a/plugins/modules/wdc_redfish_info.py b/plugins/modules/wdc_redfish_info.py index c9fadcaca3..7af3ad5007 100644 --- a/plugins/modules/wdc_redfish_info.py +++ b/plugins/modules/wdc_redfish_info.py @@ -165,7 +165,7 @@ def main(): # Check that Category is valid if category not in CATEGORY_COMMANDS_ALL: module.fail_json( - msg=to_native(f"Invalid Category '{category}'. Valid Categories = {sorted(CATEGORY_COMMANDS_ALL.keys())}") + msg=f"Invalid Category '{category}'. Valid Categories = {sorted(CATEGORY_COMMANDS_ALL.keys())}" ) # Check that all commands are valid @@ -192,7 +192,9 @@ def main(): if command == "SimpleUpdateStatus": simple_update_status_result = rf_utils.get_simple_update_status() if simple_update_status_result["ret"] is False: - module.fail_json(msg=to_native(result["msg"])) + module.fail_json( + msg=to_native(result["msg"]) + ) # TODO result=={}, maybe simple_update_status_result? else: del simple_update_status_result["ret"] result["simple_update_status"] = simple_update_status_result diff --git a/plugins/modules/xcc_redfish_command.py b/plugins/modules/xcc_redfish_command.py index 202512d3ca..cb4e667624 100644 --- a/plugins/modules/xcc_redfish_command.py +++ b/plugins/modules/xcc_redfish_command.py @@ -748,11 +748,11 @@ def main(): # For virtual media resource locates on Systems service result = rf_utils._find_systems_resource() if result["ret"] is False: - module.fail_json(msg=to_native(result["msg"])) + module.fail_json(msg=result["msg"]) # For virtual media resource locates on Managers service result = rf_utils._find_managers_resource() if result["ret"] is False: - module.fail_json(msg=to_native(result["msg"])) + module.fail_json(msg=result["msg"]) for command in command_list: if command == "VirtualMediaInsert":