mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-02 08:22:52 +00:00
[PR #11341/5b5f7e9e backport][stable-12] batch 1 - update Python idiom to 3.7 using pyupgrade (#11349)
batch 1 - update Python idiom to 3.7 using pyupgrade (#11341)
* batch 1 - update Python idiom to 3.7 using pyupgrade
* add changelog frag
* add changelog frag
(cherry picked from commit 5b5f7e9e64)
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
This commit is contained in:
parent
41f815be57
commit
2d07481e64
19 changed files with 48 additions and 29 deletions
|
|
@ -197,7 +197,7 @@ class InventoryModule(BaseInventoryPlugin, Cacheable):
|
|||
data = self.cobbler.get_profiles(self.token)
|
||||
else:
|
||||
data = self.cobbler.get_profiles()
|
||||
except (socket.gaierror, socket.error, xmlrpc_client.ProtocolError):
|
||||
except (socket.gaierror, OSError, xmlrpc_client.ProtocolError):
|
||||
self._reload_cache()
|
||||
else:
|
||||
self._init_cache()
|
||||
|
|
@ -221,7 +221,7 @@ class InventoryModule(BaseInventoryPlugin, Cacheable):
|
|||
data[i] = self.cobbler.get_system_as_rendered(host["name"], self.token)
|
||||
else:
|
||||
data[i] = self.cobbler.get_system_as_rendered(host["name"])
|
||||
except (socket.gaierror, socket.error, xmlrpc_client.ProtocolError):
|
||||
except (socket.gaierror, OSError, xmlrpc_client.ProtocolError):
|
||||
self._reload_cache()
|
||||
else:
|
||||
self._init_cache()
|
||||
|
|
|
|||
|
|
@ -203,7 +203,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
|
|||
ips += [instance.ips.ipv6.slaac, instance.ips.ipv6.link_local]
|
||||
ips += instance.ips.ipv6.pools
|
||||
|
||||
for ip_type in set(ip.type for ip in ips):
|
||||
for ip_type in {ip.type for ip in ips}:
|
||||
self.inventory.set_variable(
|
||||
hostname, ip_type, make_unsafe(self._ip_data([ip for ip in ips if ip.type == ip_type]))
|
||||
)
|
||||
|
|
|
|||
|
|
@ -210,9 +210,9 @@ class InventoryModule(BaseInventoryPlugin):
|
|||
Returns:
|
||||
dict(json_data): json data"""
|
||||
try:
|
||||
with open(path, "r") as json_file:
|
||||
with open(path) as json_file:
|
||||
return json.load(json_file)
|
||||
except (IOError, json.decoder.JSONDecodeError) as err:
|
||||
except (OSError, json.decoder.JSONDecodeError) as err:
|
||||
raise AnsibleParserError(f"Could not load the test data from {to_native(path)}: {err}") from err
|
||||
|
||||
def save_json_data(self, path, file_name=None):
|
||||
|
|
@ -242,7 +242,7 @@ class InventoryModule(BaseInventoryPlugin):
|
|||
cwd = os.path.abspath(os.path.dirname(__file__))
|
||||
with open(os.path.abspath(os.path.join(cwd, *path)), "w") as json_file:
|
||||
json.dump(self.data, json_file)
|
||||
except IOError as err:
|
||||
except OSError as err:
|
||||
raise AnsibleParserError(f"Could not save data: {err}") from err
|
||||
|
||||
def verify_file(self, path):
|
||||
|
|
|
|||
|
|
@ -119,10 +119,10 @@ class InventoryModule(BaseInventoryPlugin, Constructable):
|
|||
if authfile is None:
|
||||
authfile = os.path.join(os.environ.get("HOME"), ".one", "one_auth")
|
||||
try:
|
||||
with open(authfile, "r") as fp:
|
||||
with open(authfile) as fp:
|
||||
authstring = fp.read().rstrip()
|
||||
username, password = authstring.split(":")
|
||||
except (OSError, IOError) as e:
|
||||
except OSError as e:
|
||||
raise AnsibleError(f"Could not find or read ONE_AUTH file at '{authfile}'") from e
|
||||
except Exception as e:
|
||||
raise AnsibleError(f"Error occurs when reading ONE_AUTH file at '{authfile}'") from e
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue