mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-02-04 07:51:50 +00:00
[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 e5ee3eb88b)
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
b72e38c909
commit
50ae8fd7ae
13 changed files with 42 additions and 42 deletions
|
|
@ -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__":
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -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 = {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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})
|
||||
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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}")
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue