mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-19 19:30:22 -07:00
plugins: replace to_native(), to_text(), str() with str() where possible or leave it away in f-string formatting (#9379)
* Replace to_native(), to_text(), str() with str() where possible or leave it away in f-string formatting. * Improve formulation. Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> * Use more f-strings. * Remove unicode prefix for strings. --------- Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
This commit is contained in:
parent
4b4e4b7e0a
commit
2203560867
34 changed files with 111 additions and 99 deletions
|
@ -211,7 +211,7 @@ class InventoryModule(BaseInventoryPlugin):
|
|||
with open(path, 'r') as json_file:
|
||||
return json.load(json_file)
|
||||
except (IOError, json.decoder.JSONDecodeError) as err:
|
||||
raise AnsibleParserError(f'Could not load the test data from {to_native(path)}: {to_native(err)}')
|
||||
raise AnsibleParserError(f'Could not load the test data from {to_native(path)}: {err}')
|
||||
|
||||
def save_json_data(self, path, file_name=None):
|
||||
"""save data as json
|
||||
|
@ -241,7 +241,7 @@ class InventoryModule(BaseInventoryPlugin):
|
|||
with open(os.path.abspath(os.path.join(cwd, *path)), 'w') as json_file:
|
||||
json.dump(self.data, json_file)
|
||||
except IOError as err:
|
||||
raise AnsibleParserError(f'Could not save data: {to_native(err)}')
|
||||
raise AnsibleParserError(f'Could not save data: {err}')
|
||||
|
||||
def verify_file(self, path):
|
||||
"""Check the config
|
||||
|
@ -281,7 +281,7 @@ class InventoryModule(BaseInventoryPlugin):
|
|||
if not isinstance(url, str):
|
||||
return False
|
||||
if not url.startswith(('unix:', 'https:')):
|
||||
raise AnsibleError(f'URL is malformed: {to_native(url)}')
|
||||
raise AnsibleError(f'URL is malformed: {url}')
|
||||
return True
|
||||
|
||||
def _connect_to_socket(self):
|
||||
|
@ -306,7 +306,7 @@ class InventoryModule(BaseInventoryPlugin):
|
|||
return socket_connection
|
||||
except LXDClientException as err:
|
||||
error_storage[url] = err
|
||||
raise AnsibleError(f'No connection to the socket: {to_native(error_storage)}')
|
||||
raise AnsibleError(f'No connection to the socket: {error_storage}')
|
||||
|
||||
def _get_networks(self):
|
||||
"""Get Networknames
|
||||
|
@ -579,7 +579,7 @@ class InventoryModule(BaseInventoryPlugin):
|
|||
else:
|
||||
path[instance_name][key] = value
|
||||
except KeyError as err:
|
||||
raise AnsibleParserError(f"Unable to store Information: {to_native(err)}")
|
||||
raise AnsibleParserError(f"Unable to store Information: {err}")
|
||||
|
||||
def extract_information_from_instance_configs(self):
|
||||
"""Process configuration information
|
||||
|
@ -792,7 +792,7 @@ class InventoryModule(BaseInventoryPlugin):
|
|||
network = ipaddress.ip_network(to_text(self.groupby[group_name].get('attribute')))
|
||||
except ValueError as err:
|
||||
raise AnsibleParserError(
|
||||
f"Error while parsing network range {self.groupby[group_name].get('attribute')}: {to_native(err)}")
|
||||
f"Error while parsing network range {self.groupby[group_name].get('attribute')}: {err}")
|
||||
|
||||
for instance_name in self.inventory.hosts:
|
||||
if self.data['inventory'][instance_name].get('network_interfaces') is not None:
|
||||
|
@ -1120,6 +1120,6 @@ class InventoryModule(BaseInventoryPlugin):
|
|||
self.url = self.get_option('url')
|
||||
except Exception as err:
|
||||
raise AnsibleParserError(
|
||||
f'All correct options required: {to_native(err)}')
|
||||
f'All correct options required: {err}')
|
||||
# Call our internal helper to populate the dynamic inventory
|
||||
self._populate()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue