1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-04-21 11:19:00 +00:00

Replace .format() calls with f-strings across multiple plugins (#11879)

* Replace .format() calls with f-strings across multiple plugins

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>

* Add changelog fragment for PR 11879

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Alexei Znamensky 2026-04-19 22:37:32 +12:00 committed by GitHub
parent d0d213a41d
commit 77509be2aa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 88 additions and 114 deletions

View file

@ -53,7 +53,6 @@ def check_client(module: AnsibleModule) -> None:
def validate_connection_params(module: AnsibleModule) -> dict[str, t.Any]:
params: dict[str, t.Any] = module.params["manageiq_connection"]
error_str = "missing required argument: manageiq_connection[{}]"
url: str | None = params["url"]
token: str | None = params["token"]
username: str | None = params["username"]
@ -63,7 +62,7 @@ def validate_connection_params(module: AnsibleModule) -> dict[str, t.Any]:
return params
for arg in ["url", "username", "password"]:
if params[arg] in (None, ""):
module.fail_json(msg=error_str.format(arg))
module.fail_json(msg=f"missing required argument: manageiq_connection[{arg}]")
raise AssertionError("should be unreachable")
@ -218,9 +217,9 @@ class ManageIQPolicies:
def query_resource_profiles(self):
"""Returns a set of the profile objects objects assigned to the resource"""
url = "{resource_url}/policy_profiles?expand=resources"
url = f"{self.resource_url}/policy_profiles?expand=resources"
try:
response = self.client.get(url.format(resource_url=self.resource_url))
response = self.client.get(url)
except Exception as e:
msg = f"Failed to query {self.resource_type} policies: {e}"
self.module.fail_json(msg=msg)
@ -235,9 +234,9 @@ class ManageIQPolicies:
def query_profile_policies(self, profile_id):
"""Returns a set of the policy objects assigned to the resource"""
url = "{api_url}/policy_profiles/{profile_id}?expand=policies"
url = f"{self.api_url}/policy_profiles/{profile_id}?expand=policies"
try:
response = self.client.get(url.format(api_url=self.api_url, profile_id=profile_id))
response = self.client.get(url)
except Exception as e:
msg = f"Failed to query {self.resource_type} policies: {e}"
self.module.fail_json(msg=msg)
@ -370,9 +369,9 @@ class ManageIQTags:
def query_resource_tags(self):
"""Returns a set of the tag objects assigned to the resource"""
url = "{resource_url}/tags?expand=resources&attributes=categorization"
url = f"{self.resource_url}/tags?expand=resources&attributes=categorization"
try:
response = self.client.get(url.format(resource_url=self.resource_url))
response = self.client.get(url)
except Exception as e:
msg = f"Failed to query {self.resource_type} tags: {e}"
self.module.fail_json(msg=msg)

View file

@ -186,7 +186,6 @@ class OneViewModuleBase(metaclass=abc.ABCMeta):
MSG_DELETED = "Resource deleted successfully."
MSG_ALREADY_PRESENT = "Resource is already present."
MSG_ALREADY_ABSENT = "Resource is already absent."
MSG_DIFF_AT_KEY = "Difference found at key '{0}'. "
ONEVIEW_COMMON_ARGS = dict(
config=dict(type="path"),
@ -407,7 +406,7 @@ class OneViewModuleBase(metaclass=abc.ABCMeta):
if key not in resource2:
if resource1[key] is not None:
# Inexistent key is equivalent to exist with value None
self.module.log(self.MSG_DIFF_AT_KEY.format(key) + debug_resources)
self.module.log(f"Difference found at key '{key}'. {debug_resources}")
return False
# If both values are null, empty or False it will be considered equal.
elif not resource1[key] and not resource2[key]:
@ -415,15 +414,15 @@ class OneViewModuleBase(metaclass=abc.ABCMeta):
elif isinstance(resource1[key], Mapping):
# recursive call
if not self.compare(resource1[key], resource2[key]):
self.module.log(self.MSG_DIFF_AT_KEY.format(key) + debug_resources)
self.module.log(f"Difference found at key '{key}'. {debug_resources}")
return False
elif isinstance(resource1[key], list):
# change comparison function to compare_list
if not self.compare_list(resource1[key], resource2[key]):
self.module.log(self.MSG_DIFF_AT_KEY.format(key) + debug_resources)
self.module.log(f"Difference found at key '{key}'. {debug_resources}")
return False
elif _standardize_value(resource1[key]) != _standardize_value(resource2[key]):
self.module.log(self.MSG_DIFF_AT_KEY.format(key) + debug_resources)
self.module.log(f"Difference found at key '{key}'. {debug_resources}")
return False
# Checks all keys in the second dict, looking for missing elements
@ -431,7 +430,7 @@ class OneViewModuleBase(metaclass=abc.ABCMeta):
if key not in resource1:
if resource2[key] is not None:
# Inexistent key is equivalent to exist with value None
self.module.log(self.MSG_DIFF_AT_KEY.format(key) + debug_resources)
self.module.log(f"Difference found at key '{key}'. {debug_resources}")
return False
return True