simplify string formatting in some modules (#10727)

* simplify string formatting in some modules

* add changelog frag
This commit is contained in:
Alexei Znamensky 2025-08-31 21:46:43 +12:00 committed by GitHub
commit 6f40eff632
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 23 additions and 13 deletions

View file

@ -0,0 +1,10 @@
minor_changes:
- filesize - minor refactor to simplify string formatting (https://github.com/ansible-collections/community.general/pull/10727).
- iptables_state - minor refactor to simplify string formatting (https://github.com/ansible-collections/community.general/pull/10727).
- manageiq_group - minor refactor to simplify string formatting (https://github.com/ansible-collections/community.general/pull/10727).
- manageiq_tenant - minor refactor to simplify string formatting (https://github.com/ansible-collections/community.general/pull/10727).
- mssql_db - minor refactor to simplify string formatting (https://github.com/ansible-collections/community.general/pull/10727).
- openbsd_pkg - minor refactor to simplify string formatting (https://github.com/ansible-collections/community.general/pull/10727).
- ufw - minor refactor to simplify string formatting (https://github.com/ansible-collections/community.general/pull/10727).
- xenserver_facts - minor refactor to simplify string formatting (https://github.com/ansible-collections/community.general/pull/10727).
- zfs_facts - minor refactor to simplify string formatting (https://github.com/ansible-collections/community.general/pull/10727).

View file

@ -304,7 +304,7 @@ def split_size_unit(string, isint=False):
Support optional space(s) between the numeric value and the unit.
"""
unit = re.sub(r'(\d|\.)', r'', string).strip()
value = float(re.sub(r'%s' % unit, r'', string).strip())
value = float(re.sub(unit, r'', string).strip())
if isint and unit in ('B', ''):
if int(value) != value:
raise AssertionError("invalid blocksize value: bytes require an integer value")

View file

@ -414,7 +414,7 @@ def main():
COMMANDARGS.extend(['--table', table])
if wait is not None:
TESTCOMMAND.extend(['--wait', '%s' % wait])
TESTCOMMAND.extend(['--wait', '%d' % wait])
if modprobe is not None:
b_modprobe = to_bytes(modprobe, errors='surrogate_or_strict')
@ -502,7 +502,7 @@ def main():
MAINCOMMAND.insert(0, bin_iptables_restore)
if wait is not None:
MAINCOMMAND.extend(['--wait', '%s' % wait])
MAINCOMMAND.extend(['--wait', '%d' % wait])
if _back is not None:
b_back = to_bytes(_back, errors='surrogate_or_strict')

View file

@ -251,7 +251,7 @@ class ManageIQgroup(object):
if not tenant_res:
self.module.fail_json(msg="Tenant '%s' not found in manageiq" % tenant_name)
if len(tenant_res) > 1:
self.module.fail_json(msg="Multiple tenants found in manageiq with name '%s" % tenant_name)
self.module.fail_json(msg="Multiple tenants found in manageiq with name '%s'" % tenant_name)
tenant = tenant_res[0]
return tenant
else:
@ -276,7 +276,7 @@ class ManageIQgroup(object):
if not role_res:
self.module.fail_json(msg="Role '%s' not found in manageiq" % role_name)
if len(role_res) > 1:
self.module.fail_json(msg="Multiple roles found in manageiq with name '%s" % role_name)
self.module.fail_json(msg="Multiple roles found in manageiq with name '%s'" % role_name)
return role_res[0]
else:
# No role name or role id supplied

View file

@ -214,7 +214,7 @@ class ManageIQTenant(object):
self.module.fail_json(msg="Parent tenant '%s' not found in manageiq" % parent)
if len(parent_tenant_res) > 1:
self.module.fail_json(msg="Multiple parent tenants not found in manageiq with name '%s" % parent)
self.module.fail_json(msg="Multiple parent tenants not found in manageiq with name '%s'" % parent)
parent_tenant = parent_tenant_res[0]
parent_id = int(parent_tenant['id'])

View file

@ -210,7 +210,7 @@ def main():
rc, stdout, stderr = db_import(conn, cursor, module, db, target)
if rc != 0:
module.fail_json(msg="%s" % stderr)
module.fail_json(msg=stderr)
else:
module.exit_json(changed=True, db=db, msg=stdout)
else:
@ -229,7 +229,7 @@ def main():
rc, stdout, stderr = db_import(conn, cursor, module, db, target)
if rc != 0:
module.fail_json(msg="%s" % stderr)
module.fail_json(msg=stderr)
else:
module.exit_json(changed=True, db=db, msg=stdout)

View file

@ -576,7 +576,7 @@ def upgrade_packages(pkg_spec, module):
pkg_spec['*'] = {}
# Attempt to upgrade all packages.
pkg_spec['*']['rc'], pkg_spec['*']['stdout'], pkg_spec['*']['stderr'] = execute_command("%s" % upgrade_cmd, module)
pkg_spec['*']['rc'], pkg_spec['*']['stdout'], pkg_spec['*']['stderr'] = execute_command(upgrade_cmd, module)
# Try to find any occurrence of a package changing version like:
# "bzip2-1.0.6->1.0.6p0: ok".

View file

@ -546,7 +546,7 @@ def main():
insert_to = None
cmd.append([insert_to is not None, "insert %s" % insert_to])
cmd.append([value])
cmd.append([params['direction'], "%s" % params['direction']])
cmd.append([params['direction'], params['direction']])
cmd.append([params['interface'], "on %s" % params['interface']])
cmd.append([params['interface_in'], "in on %s" % params['interface_in']])
cmd.append([params['interface_out'], "out on %s" % params['interface_out']])

View file

@ -178,7 +178,7 @@ def main():
try:
session = get_xenapi_session()
except XenAPI.Failure as e:
module.fail_json(msg='%s' % e)
module.fail_json(msg=str(e))
data = {
'xenserver_version': obj.version,

View file

@ -188,9 +188,9 @@ class ZFSFacts(object):
cmd.append('-p')
if self.recurse:
cmd.append('-r')
if int(self.depth) != 0:
if self.depth != 0:
cmd.append('-d')
cmd.append('%s' % self.depth)
cmd.append('%d' % self.depth)
if self.type:
cmd.append('-t')
cmd.append(','.join(self.type))