Skip to content

Commit 8a7f360

Browse files
patchback[bot]russozfelixfontein
authored
[PR #11143/23e81b8d backport][stable-12] replace redundant to_native()/to_text() occurrences, batch 8 (#11164)
replace redundant to_native()/to_text() occurrences, batch 8 (#11143) * replace redundant to_native()/to_text() occurrences, batch 8 * add changelog frag * Update plugins/modules/jira.py --------- (cherry picked from commit 23e81b8) Co-authored-by: Alexei Znamensky <[email protected]> Co-authored-by: Felix Fontein <[email protected]>
1 parent 15d4fff commit 8a7f360

22 files changed

+68
-58
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
minor_changes:
2+
- cloudflare_dns - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/1114).
3+
- dconf - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/1114).
4+
- idrac_redfish_command - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/1114).
5+
- idrac_redfish_config - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/1114).
6+
- idrac_redfish_info - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/1114).
7+
- ilo_redfish_command - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/1114).
8+
- ilo_redfish_config - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/1114).
9+
- jenkins_plugin - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/1114).
10+
- jenkins_script - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/1114).
11+
- jira - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/1114).
12+
- mail - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/1114).
13+
- maven_artifact - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/1114).
14+
- onepassword_info - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/1114).
15+
- packet_volume - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/1114).
16+
- redfish_command - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/1114).
17+
- redfish_config - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/1114).
18+
- sensu_silence - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/1114).
19+
- svc - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/1114).
20+
- wdc_redfish_command - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/1114).
21+
- wdc_redfish_info - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/1114).
22+
- xcc_redfish_command - remove redundant conversions to unicode (https://github.com/ansible-collections/community.general/pull/1114).

plugins/modules/cloudflare_dns.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@
441441
from urllib.parse import urlencode
442442

443443
from ansible.module_utils.basic import AnsibleModule, env_fallback
444-
from ansible.module_utils.common.text.converters import to_native, to_text
444+
from ansible.module_utils.common.text.converters import to_text
445445
from ansible.module_utils.urls import fetch_url
446446

447447

@@ -587,7 +587,7 @@ def _cf_simple_api_call(self, api_call, method="GET", payload=None):
587587
try:
588588
result = json.loads(to_text(content, errors="surrogate_or_strict"))
589589
except getattr(json, "JSONDecodeError", ValueError) as e:
590-
error_msg += f"; Failed to parse API response with error {to_native(e)}: {content}"
590+
error_msg += f"; Failed to parse API response with error {e}: {content}"
591591

592592
# Without a valid/parsed JSON response no more error processing can be done
593593
if result is None:

plugins/modules/dconf.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@
130130
probe_interpreters_for_module,
131131
respawn_module,
132132
)
133-
from ansible.module_utils.common.text.converters import to_native
134133
from ansible_collections.community.general.plugins.module_utils import deps
135134

136135
glib_module_name = "gi.repository.GLib"
@@ -442,7 +441,7 @@ def main():
442441
if isinstance(module.params["value"], bool):
443442
module.params["value"] = "true" if module.params["value"] else "false"
444443
else:
445-
module.params["value"] = to_native(module.params["value"], errors="surrogate_or_strict")
444+
module.params["value"] = str(module.params["value"])
446445

447446
if Variant is None:
448447
module.warn(

plugins/modules/idrac_redfish_command.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@
101101
RedfishUtils,
102102
REDFISH_COMMON_ARGUMENT_SPEC,
103103
)
104-
from ansible.module_utils.common.text.converters import to_native
105104

106105

107106
class IdracRedfishUtils(RedfishUtils):
@@ -217,14 +216,14 @@ def main():
217216
result = rf_utils._find_systems_resource()
218217
rf_utils.data_modification = True
219218
if result["ret"] is False:
220-
module.fail_json(msg=to_native(result["msg"]))
219+
module.fail_json(msg=result["msg"])
221220

222221
for command in command_list:
223222
if command == "CreateBiosConfigJob":
224223
# execute only if we find a Managers resource
225224
result = rf_utils._find_managers_resource()
226225
if result["ret"] is False:
227-
module.fail_json(msg=to_native(result["msg"]))
226+
module.fail_json(msg=result["msg"])
228227
result = rf_utils.create_bios_config_job()
229228
if "job_id" in result:
230229
return_values["job_id"] = result["job_id"]
@@ -234,7 +233,7 @@ def main():
234233
del result["ret"]
235234
module.exit_json(changed=True, msg="Action was successful", return_values=return_values)
236235
else:
237-
module.fail_json(msg=to_native(result["msg"]))
236+
module.fail_json(msg=result["msg"])
238237

239238

240239
if __name__ == "__main__":

plugins/modules/idrac_redfish_config.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@
158158
RedfishUtils,
159159
REDFISH_COMMON_ARGUMENT_SPEC,
160160
)
161-
from ansible.module_utils.common.text.converters import to_native
162161

163162

164163
class IdracRedfishUtils(RedfishUtils):
@@ -314,7 +313,7 @@ def main():
314313
# execute only if we find a Manager resource
315314
result = rf_utils._find_managers_resource()
316315
if result["ret"] is False:
317-
module.fail_json(msg=to_native(result["msg"]))
316+
module.fail_json(msg=result["msg"])
318317

319318
for command in command_list:
320319
if command in ["SetManagerAttributes", "SetLifecycleControllerAttributes", "SetSystemAttributes"]:
@@ -323,11 +322,11 @@ def main():
323322
# Return data back or fail with proper message
324323
if result["ret"] is True:
325324
if result.get("warning"):
326-
module.warn(to_native(result["warning"]))
325+
module.warn(result["warning"])
327326

328-
module.exit_json(changed=result["changed"], msg=to_native(result["msg"]))
327+
module.exit_json(changed=result["changed"], msg=result["msg"])
329328
else:
330-
module.fail_json(msg=to_native(result["msg"]))
329+
module.fail_json(msg=result["msg"])
331330

332331

333332
if __name__ == "__main__":

plugins/modules/idrac_redfish_info.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@
133133
RedfishUtils,
134134
REDFISH_COMMON_ARGUMENT_SPEC,
135135
)
136-
from ansible.module_utils.common.text.converters import to_native
137136

138137

139138
class IdracRedfishUtils(RedfishUtils):
@@ -235,7 +234,7 @@ def main():
235234
# execute only if we find a Manager resource
236235
result = rf_utils._find_managers_resource()
237236
if result["ret"] is False:
238-
module.fail_json(msg=to_native(result["msg"]))
237+
module.fail_json(msg=result["msg"])
239238

240239
for command in command_list:
241240
if command == "GetManagerAttributes":
@@ -246,7 +245,7 @@ def main():
246245
del result["ret"]
247246
module.exit_json(redfish_facts=result)
248247
else:
249-
module.fail_json(msg=to_native(result["msg"]))
248+
module.fail_json(msg=result["msg"])
250249

251250

252251
if __name__ == "__main__":

plugins/modules/ilo_redfish_command.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@
9797
from ansible_collections.community.general.plugins.module_utils.ilo_redfish_utils import iLORedfishUtils
9898
from ansible_collections.community.general.plugins.module_utils.redfish_utils import REDFISH_COMMON_ARGUMENT_SPEC
9999
from ansible.module_utils.basic import AnsibleModule
100-
from ansible.module_utils.common.text.converters import to_native
101100

102101

103102
def main():
@@ -153,7 +152,7 @@ def main():
153152

154153
result = rf_utils._find_systems_resource()
155154
if result["ret"] is False:
156-
module.fail_json(msg=to_native(result["msg"]))
155+
module.fail_json(msg=result["msg"])
157156

158157
for command in command_list:
159158
if command == "WaitforiLORebootCompletion":

plugins/modules/ilo_redfish_config.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@
117117
from ansible_collections.community.general.plugins.module_utils.ilo_redfish_utils import iLORedfishUtils
118118
from ansible_collections.community.general.plugins.module_utils.redfish_utils import REDFISH_COMMON_ARGUMENT_SPEC
119119
from ansible.module_utils.basic import AnsibleModule
120-
from ansible.module_utils.common.text.converters import to_native
121120

122121

123122
def main():
@@ -171,7 +170,7 @@ def main():
171170
if category == "Manager":
172171
resource = rf_utils._find_managers_resource()
173172
if not resource["ret"]:
174-
module.fail_json(msg=to_native(resource["msg"]))
173+
module.fail_json(msg=resource["msg"])
175174

176175
dispatch = dict(
177176
SetTimeZone=rf_utils.set_time_zone,

plugins/modules/jenkins_plugin.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,6 @@
342342

343343
from ansible.module_utils.basic import AnsibleModule, to_bytes
344344
from ansible.module_utils.urls import fetch_url, url_argument_spec, basic_auth_header
345-
from ansible.module_utils.common.text.converters import to_native
346345

347346
from ansible_collections.community.general.plugins.module_utils.jenkins import download_updates_file
348347

@@ -399,7 +398,7 @@ def _get_json_data(self, url, what, **kwargs):
399398

400399
# Parse the JSON data
401400
try:
402-
json_data = json.loads(to_native(r.read()))
401+
json_data = json.loads(r.read())
403402
except Exception as e:
404403
self.module.fail_json(msg=f"Cannot parse {what} JSON data.", details=f"{e}")
405404

@@ -683,7 +682,7 @@ def _get_latest_compatible_plugin_version(self, plugin_name=None):
683682
now = time.time()
684683
if now - file_mtime >= 86400:
685684
response = self._get_urls_data(plugin_version_urls, what="plugin-versions.json")
686-
plugin_data = json.loads(to_native(response.read()), object_pairs_hook=OrderedDict)
685+
plugin_data = json.loads(response.read(), object_pairs_hook=OrderedDict)
687686

688687
# Save it to file for next time
689688
with open(cache_path, "w") as f:

plugins/modules/jenkins_script.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,7 @@ def is_csrf_protection_enabled(module):
115115
if info["status"] != 200:
116116
module.fail_json(msg=f"HTTP error {info['status']} {info['msg']}", output="")
117117

118-
content = to_native(resp.read())
119-
return json.loads(content).get("useCrumbs", False)
118+
return json.loads(resp.read()).get("useCrumbs", False)
120119

121120

122121
def get_crumb(module, cookies):
@@ -130,8 +129,7 @@ def get_crumb(module, cookies):
130129
if info["status"] != 200:
131130
module.fail_json(msg=f"HTTP error {info['status']} {info['msg']}", output="")
132131

133-
content = to_native(resp.read())
134-
return json.loads(content)
132+
return json.loads(resp.read())
135133

136134

137135
def main():

0 commit comments

Comments
 (0)