fix ruff case B007 (#11115)

* fix ruff case B007

* rollback inventory/iocage

* re-do the fix in inventory/iocage

* add cases in tests/unit/plugins

* rollback plugins/module_utils/memset.py

* rollback extraneous changes in plugins/modules/xcc_redfish_command.py

* add changelog frag
This commit is contained in:
Alexei Znamensky
2025-11-13 09:06:14 +13:00
committed by GitHub
parent 40aea793ee
commit 58bb1e7c04
32 changed files with 90 additions and 73 deletions

View File

@@ -890,7 +890,7 @@ def main():
if state == "present":
if not instance_ids:
if len(instances) > count:
for i in range(0, len(instances) - count):
for _i in range(0, len(instances) - count):
inst = instances[len(instances) - 1]
if inst.status != "stopped" and not force:
module.fail_json(

View File

@@ -215,7 +215,7 @@ def update_package_db(module):
def dir_size(module, path):
total_size = 0
for cur_path, dirs, files in os.walk(path):
for cur_path, _dirs, files in os.walk(path):
for f in files:
total_size += os.path.getsize(os.path.join(cur_path, f))
return total_size

View File

@@ -133,7 +133,7 @@ def get_repo_states(module):
repos = dict()
last_repo = ""
for i, line in enumerate(out.split("\n")):
for line in out.split("\n"):
m = REPO_ID_RE.match(line)
if m:
if len(last_repo) > 0:

View File

@@ -359,7 +359,7 @@ class HAProxy:
the expected status in that time, the module will fail. If the service was
not found, the module will fail.
"""
for i in range(1, self.wait_retries):
for _i in range(1, self.wait_retries):
state = self.get_state_for(pxname, svname)
# We can assume there will only be 1 element in state because both svname and pxname are always set when we get here

View File

@@ -234,7 +234,7 @@ def main():
if memory_details_summary:
info["hw_memory_details_summary"] = memory_details_summary
info["hw_memory_total"] = 0
for cpu, details in memory_details_summary.items():
for details in memory_details_summary.values():
cpu_total_memory_size = details.get("total_memory_size")
if cpu_total_memory_size:
ram = re.search(r"(\d+)\s+(\w+)", cpu_total_memory_size)

View File

@@ -1174,16 +1174,14 @@ def expand_delete_servers(d, array_index):
req = []
n = 1
for i in range(n):
transformed = dict()
transformed = dict()
v = expand_delete_servers_id(d, new_ai)
if not is_empty_value(v):
transformed["id"] = v
v = expand_delete_servers_id(d, new_ai)
if not is_empty_value(v):
transformed["id"] = v
if transformed:
req.append(transformed)
if transformed:
req.append(transformed)
return req

View File

@@ -509,16 +509,14 @@ def expand_create_fixed_ips(d, array_index):
req = []
n = 1
for i in range(n):
transformed = dict()
transformed = dict()
v = navigate_value(d, ["ip_address"], new_array_index)
if not is_empty_value(v):
transformed["ip_address"] = v
v = navigate_value(d, ["ip_address"], new_array_index)
if not is_empty_value(v):
transformed["ip_address"] = v
if transformed:
req.append(transformed)
if transformed:
req.append(transformed)
return req
@@ -1011,17 +1009,15 @@ def expand_list_fixed_ips(d, array_index):
req = []
n = 1
for i in range(n):
transformed = dict()
transformed = dict()
v = navigate_value(d, ["ip_address"], new_array_index)
transformed["ip_address"] = v
v = navigate_value(d, ["ip_address"], new_array_index)
transformed["ip_address"] = v
for v in transformed.values():
if v is not None:
req.append(transformed)
break
for v in transformed.values():
if v is not None:
req.append(transformed)
break
return req if req else None

View File

@@ -175,7 +175,7 @@ def set_user_grants(module, client, user_name, grants):
try:
parsed_grants = []
# Fix privileges wording
for i, v in enumerate(current_grants):
for v in current_grants:
if v["privilege"] != "NO PRIVILEGES":
if v["privilege"] == "ALL PRIVILEGES":
v["privilege"] = "ALL"

View File

@@ -289,7 +289,7 @@ def create_or_update_executions(kc, config, realm="master"):
if exec_index != -1:
# Remove key that doesn't need to be compared with existing_exec
exclude_key = ["flowAlias", "subFlowType"]
for index_key, key in enumerate(new_exec, start=0):
for key in new_exec:
if new_exec[key] is None:
exclude_key.append(key)
# Compare the executions to see if it need changes

View File

@@ -326,7 +326,7 @@ def main():
if roles is None:
module.exit_json(msg="Nothing to do (no roles specified).")
else:
for role_index, role in enumerate(roles, start=0):
for role in roles:
if role["name"] is None and role["id"] is None:
module.fail_json(msg="Either the `name` or `id` has to be specified on each role.")
# Fetch missing role_id
@@ -350,7 +350,7 @@ def main():
result["proposed"] = list(assigned_roles_before) if assigned_roles_before else []
update_roles = []
for role_index, role in enumerate(roles, start=0):
for role in roles:
# Fetch roles to assign if state present
if state == "present":
for available_role in available_roles_before:

View File

@@ -254,7 +254,7 @@ def main():
changeset_copy["id"] = component_id
# Compare top-level parameters
for param, value in changeset.items():
for param in changeset:
before_component[param] = component[param]
if changeset_copy[param] != component[param] and param != "config":
@@ -266,8 +266,8 @@ def main():
before_component["config"][p] = component["config"][p] or []
except KeyError:
before_component["config"][p] = []
if changeset_copy["config"][p] != component["config"][p]:
changes += f"config.{p}: {component['config'][p]} -> {changeset_copy['config'][p]}, "
if v != component["config"][p]:
changes += f"config.{p}: {component['config'][p]} -> {v}, "
result["changed"] = True
# Check all the possible states of the resource and do what is needed to

View File

@@ -392,7 +392,7 @@ def main():
changeset_copy["id"] = key_id
# Compare top-level parameters
for param, value in changeset.items():
for param in changeset:
before_realm_key[param] = key[param]
if changeset_copy[param] != key[param] and param != "config":
@@ -402,8 +402,8 @@ def main():
# Compare parameters under the "config" key
for p, v in changeset_copy["config"].items():
before_realm_key["config"][p] = key["config"][p]
if changeset_copy["config"][p] != key["config"][p]:
changes += f"config.{p}: {key['config'][p]} -> {changeset_copy['config'][p]}, "
if v != key["config"][p]:
changes += f"config.{p}: {key['config'][p]} -> {v}, "
result["changed"] = True
# Sanitize linefeeds for the privateKey. Without this the JSON payload

View File

@@ -304,7 +304,7 @@ def main():
if roles is None:
module.exit_json(msg="Nothing to do (no roles specified).")
else:
for role_index, role in enumerate(roles, start=0):
for role in roles:
if role["name"] is None and role["id"] is None:
module.fail_json(msg="Either the `name` or `id` has to be specified on each role.")
# Fetch missing role_id
@@ -330,7 +330,7 @@ def main():
result["proposed"] = list(assigned_roles_before) if assigned_roles_before else []
update_roles = []
for role_index, role in enumerate(roles, start=0):
for role in roles:
# Fetch roles to assign if state present
if state == "present":
if any(assigned == role["name"] for assigned in assigned_roles_before):

View File

@@ -333,7 +333,7 @@ def main():
if roles is None:
module.exit_json(msg="Nothing to do (no roles specified).")
else:
for role_index, role in enumerate(roles, start=0):
for role in roles:
if role.get("name") is None and role.get("id") is None:
module.fail_json(msg="Either the `name` or `id` has to be specified on each role.")
# Fetch missing role_id
@@ -373,7 +373,7 @@ def main():
result["proposed"] = roles
update_roles = []
for role_index, role in enumerate(roles, start=0):
for role in roles:
# Fetch roles to assign if state present
if state == "present":
for available_role in available_roles_before:

View File

@@ -664,7 +664,7 @@ def main():
)
# Compare top-level parameters
for param, value in changeset.items():
for param in changeset:
before_realm_userprofile[param] = userprofile[param]
if changeset_copy[param] != userprofile[param] and param != "config":
@@ -674,8 +674,8 @@ def main():
# Compare parameters under the "config" userprofile
for p, v in changeset_copy["config"].items():
before_realm_userprofile["config"][p] = userprofile["config"][p]
if changeset_copy["config"][p] != userprofile["config"][p]:
changes += f"config.{p}: {userprofile['config'][p]} -> {changeset_copy['config'][p]}, "
if v != userprofile["config"][p]:
changes += f"config.{p}: {userprofile['config'][p]} -> {v}, "
result["changed"] = True
# Check all the possible states of the resource and do what is needed to

View File

@@ -2553,7 +2553,7 @@ class Nmcli:
supported_properties = self.get_supported_properties(setting)
unsupported_properties = []
for property, value in getattr(self, setting_key).items():
for property in getattr(self, setting_key):
if property not in supported_properties:
unsupported_properties.append(property)

View File

@@ -311,10 +311,6 @@ def main():
if p["name"]:
pkgs = p["name"].split(",")
pkg_files = []
for i, pkg in enumerate(pkgs):
pkg_files.append(None)
if module.check_mode:
check_packages(module, pkgs, p["state"])

View File

@@ -286,7 +286,7 @@ def remove_packages(module, xbps_path, packages):
def install_packages(module, xbps_path, state, packages):
"""Returns true if package install succeeds."""
toInstall = []
for i, package in enumerate(packages):
for package in packages:
"""If the package is installed and state == present or state == latest
and is up-to-date then skip"""
installed, updated = query_package(module, xbps_path, package)

View File

@@ -418,7 +418,7 @@ class XCCRedfishUtils(RedfishUtils):
# eject all inserted media one by one
ejected_media_list = []
for uri, data in resources.items():
for data in resources.values():
if data.get("Image") and data.get("Inserted", True):
returndict = self.virtual_media_eject_one(data.get("Image"))
if not returndict["ret"]: