Run pyupgrade against the files modified in the merge-forward

This commit is contained in:
Pedro Algarvio 2023-12-14 11:33:55 +00:00
parent e3ba31dc7a
commit b104d98e90
No known key found for this signature in database
GPG key ID: BB36BF6584A298FF
10 changed files with 46 additions and 48 deletions

View file

@ -590,7 +590,7 @@ def boot_time(time_format=None):
try:
return b_time.strftime(time_format)
except TypeError as exc:
raise SaltInvocationError("Invalid format string: {}".format(exc))
raise SaltInvocationError(f"Invalid format string: {exc}")
return b_time

View file

@ -67,7 +67,7 @@ def init(runlevel):
salt '*' system.init 3
"""
cmd = ["init", "{}".format(runlevel)]
cmd = ["init", f"{runlevel}"]
ret = __salt__["cmd.run"](cmd, python_shell=False)
return ret
@ -100,7 +100,7 @@ def reboot(at_time=None):
salt '*' system.reboot
"""
cmd = ["shutdown", "-r", ("{}".format(at_time) if at_time else "now")]
cmd = ["shutdown", "-r", (f"{at_time}" if at_time else "now")]
ret = __salt__["cmd.run"](cmd, python_shell=False)
return ret
@ -128,7 +128,7 @@ def shutdown(at_time=None):
else:
flag = "-h"
cmd = ["shutdown", flag, ("{}".format(at_time) if at_time else "now")]
cmd = ["shutdown", flag, (f"{at_time}" if at_time else "now")]
ret = __salt__["cmd.run"](cmd, python_shell=False)
return ret
@ -595,7 +595,7 @@ def set_computer_desc(desc):
pass
pattern = re.compile(r"^\s*PRETTY_HOSTNAME=(.*)$")
new_line = salt.utils.stringutils.to_str('PRETTY_HOSTNAME="{}"'.format(desc))
new_line = salt.utils.stringutils.to_str(f'PRETTY_HOSTNAME="{desc}"')
try:
with salt.utils.files.fopen("/etc/machine-info", "r+") as mach_info:
lines = mach_info.readlines()
@ -678,10 +678,10 @@ def set_reboot_required_witnessed():
os.makedirs(dir_path)
except OSError as ex:
raise SaltInvocationError(
"Error creating {} (-{}): {}".format(dir_path, ex.errno, ex.strerror)
f"Error creating {dir_path} (-{ex.errno}): {ex.strerror}"
)
rdict = __salt__["cmd.run_all"]("touch {}".format(NILRT_REBOOT_WITNESS_PATH))
rdict = __salt__["cmd.run_all"](f"touch {NILRT_REBOOT_WITNESS_PATH}")
errcode = rdict["retcode"]
return errcode == 0

View file

@ -135,7 +135,7 @@ def present(name, acl_type, acl_name="", perms="", recurse=False, force=False):
_octal_lookup = {0: "-", 1: "r", 2: "w", 4: "x"}
if not os.path.exists(name):
ret["comment"] = "{} does not exist".format(name)
ret["comment"] = f"{name} does not exist"
ret["result"] = False
return ret
@ -250,7 +250,7 @@ def present(name, acl_type, acl_name="", perms="", recurse=False, force=False):
)
ret.update(
{
"comment": "Updated permissions for {}".format(acl_name),
"comment": f"Updated permissions for {acl_name}",
"result": True,
"changes": changes,
}
@ -291,7 +291,7 @@ def present(name, acl_type, acl_name="", perms="", recurse=False, force=False):
)
ret.update(
{
"comment": "Applied new permissions for {}".format(acl_name),
"comment": f"Applied new permissions for {acl_name}",
"result": True,
"changes": changes,
}
@ -335,7 +335,7 @@ def absent(name, acl_type, acl_name="", perms="", recurse=False):
ret = {"name": name, "result": True, "changes": {}, "comment": ""}
if not os.path.exists(name):
ret["comment"] = "{} does not exist".format(name)
ret["comment"] = f"{name} does not exist"
ret["result"] = False
return ret
@ -433,7 +433,7 @@ def list_present(name, acl_type, acl_names=None, perms="", recurse=False, force=
_octal = {"r": 4, "w": 2, "x": 1, "-": 0}
_octal_perms = sum(_octal.get(i, i) for i in perms)
if not os.path.exists(name):
ret["comment"] = "{} does not exist".format(name)
ret["comment"] = f"{name} does not exist"
ret["result"] = False
return ret
@ -722,7 +722,7 @@ def list_absent(name, acl_type, acl_names=None, recurse=False):
ret = {"name": name, "result": True, "changes": {}, "comment": ""}
if not os.path.exists(name):
ret["comment"] = "{} does not exist".format(name)
ret["comment"] = f"{name} does not exist"
ret["result"] = False
return ret

View file

@ -16,9 +16,8 @@ def test_pip_install(install_salt, salt_call_cli):
"""
ret = subprocess.run(
install_salt.binary_paths["salt"] + ["--versions-report"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True,
capture_output=True,
text=True,
check=True,
shell=False,
)
@ -69,9 +68,8 @@ def test_pip_install(install_salt, salt_call_cli):
ret = subprocess.run(
install_salt.binary_paths["salt"] + ["--versions-report"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True,
capture_output=True,
text=True,
check=True,
shell=False,
)

View file

@ -533,7 +533,7 @@ def test__get_version():
"10.0": (10, 0),
}
for v in more_versions:
mock_version = MagicMock(return_value="glusterfs {}".format(v))
mock_version = MagicMock(return_value=f"glusterfs {v}")
with patch.dict(glusterfs.__salt__, {"cmd.run": mock_version}):
assert glusterfs._get_version() == more_versions[v]

View file

@ -337,7 +337,7 @@ def test_config_test(orig_env, bin_dir, mocked_env):
def test_config_test_cfgfile(orig_env, bin_dir, mocked_env):
cfgfile = "/path/to/syslog-ng.conf"
cmd_ret = {"retcode": 1, "stderr": "Syntax error...", "stdout": ""}
cmd_args = ["syslog-ng", "--syntax-only", "--cfgfile={}".format(cfgfile)]
cmd_args = ["syslog-ng", "--syntax-only", f"--cfgfile={cfgfile}"]
cmd_mock = MagicMock(return_value=cmd_ret)
with patch.dict(syslog_ng.__salt__, {"cmd.run_all": cmd_mock}), patch.dict(

View file

@ -21,7 +21,7 @@ def test_uwsgi_stats():
with patch.dict(uwsgi.__salt__, {"cmd.run": mock}):
result = uwsgi.stats(socket)
mock.assert_called_once_with(
["uwsgi", "--connect-and-read", "{}".format(socket)],
["uwsgi", "--connect-and-read", f"{socket}"],
python_shell=False,
)
assert result == {"a": 1, "b": 2}

View file

@ -59,7 +59,7 @@ def test_vagrant_init_positional(local_opts, tmp_path):
different="very",
)
mock_sdb.assert_called_with(
"sdb://vagrant_sdb_data/onetest?{}".format(path_nowhere),
f"sdb://vagrant_sdb_data/onetest?{path_nowhere}",
"test1",
local_opts,
)
@ -138,7 +138,7 @@ def test_vagrant_destroy(local_opts, tmp_path):
with patch.dict(vagrant.__utils__, {"sdb.sdb_get": mock_sdb_get}):
assert vagrant.destroy("test4")
mock_sdb.assert_any_call(
"sdb://vagrant_sdb_data/macfour?{}".format(path_mydir),
f"sdb://vagrant_sdb_data/macfour?{path_mydir}",
local_opts,
)
mock_sdb.assert_any_call("sdb://vagrant_sdb_data/test4", local_opts)

View file

@ -58,14 +58,14 @@ def test_rename(tmp_path):
mock_lex = MagicMock(side_effect=[False, True, True])
with patch.object(os.path, "isabs", mock_f):
comt = "Specified file {} is not an absolute path".format(name)
comt = f"Specified file {name} is not an absolute path"
ret.update({"comment": comt, "name": name})
assert filestate.rename(name, source) == ret
mock_lex = MagicMock(return_value=False)
with patch.object(os.path, "isabs", mock_t):
with patch.object(os.path, "lexists", mock_lex):
comt = 'Source file "{}" has already been moved out of place'.format(source)
comt = f'Source file "{source}" has already been moved out of place'
ret.update({"comment": comt, "result": True})
assert filestate.rename(name, source) == ret
@ -94,7 +94,7 @@ def test_rename(tmp_path):
with patch.object(os.path, "isabs", mock_t):
with patch.object(os.path, "lexists", mock_lex):
with patch.dict(filestate.__opts__, {"test": True}):
comt = 'File "{}" is set to be moved to "{}"'.format(source, name)
comt = f'File "{source}" is set to be moved to "{name}"'
ret.update({"name": name, "comment": comt, "result": None})
assert filestate.rename(name, source) == ret
@ -103,7 +103,7 @@ def test_rename(tmp_path):
with patch.object(os.path, "lexists", mock_lex):
with patch.object(os.path, "isdir", mock_f):
with patch.dict(filestate.__opts__, {"test": False}):
comt = "The target directory {} is not present".format(tmp_path)
comt = f"The target directory {tmp_path} is not present"
ret.update({"name": name, "comment": comt, "result": False})
assert filestate.rename(name, source) == ret
@ -116,7 +116,7 @@ def test_rename(tmp_path):
with patch.object(
shutil, "move", MagicMock(side_effect=IOError)
):
comt = 'Failed to move "{}" to "{}"'.format(source, name)
comt = f'Failed to move "{source}" to "{name}"'
ret.update({"name": name, "comment": comt, "result": False})
assert filestate.rename(name, source) == ret
@ -127,7 +127,7 @@ def test_rename(tmp_path):
with patch.object(os.path, "islink", mock_f):
with patch.dict(filestate.__opts__, {"test": False}):
with patch.object(shutil, "move", MagicMock()):
comt = 'Moved "{}" to "{}"'.format(source, name)
comt = f'Moved "{source}" to "{name}"'
ret.update(
{
"name": name,
@ -180,7 +180,7 @@ def test_rename(tmp_path):
), patch.object(
os, "unlink", MagicMock()
):
comt = 'Moved "{}" to "{}"'.format(source, name)
comt = f'Moved "{source}" to "{name}"'
ret.update(
{
"name": name,

View file

@ -51,7 +51,7 @@ def test_peered():
assert glusterfs.peered(name) == ret
mock_host_ips.return_value = ["1.2.3.42"]
comt = "Host {} already peered".format(name)
comt = f"Host {name} already peered"
ret.update({"comment": comt})
assert glusterfs.peered(name) == ret
@ -62,7 +62,7 @@ def test_peered():
"uuid2": {"hostnames": ["someAlias", name]},
}
mock_status.side_effect = [old, new]
comt = "Host {} successfully peered".format(name)
comt = f"Host {name} successfully peered"
ret.update({"comment": comt, "changes": {"old": old, "new": new}})
assert glusterfs.peered(name) == ret
mock_status.side_effect = None
@ -84,7 +84,7 @@ def test_peered():
ret.update({"name": name})
with patch.dict(glusterfs.__opts__, {"test": True}):
comt = "Peer {} will be added.".format(name)
comt = f"Peer {name} will be added."
ret.update({"comment": comt, "result": None})
assert glusterfs.peered(name) == ret
@ -117,41 +117,41 @@ def test_volume_present():
with patch.dict(glusterfs.__opts__, {"test": False}):
mock_list.return_value = [name]
mock_info.return_value = started_info
comt = "Volume {} already exists and is started".format(name)
comt = f"Volume {name} already exists and is started"
ret.update({"comment": comt})
assert glusterfs.volume_present(name, bricks, start=True) == ret
mock_info.return_value = stopped_info
comt = "Volume {} already exists and is now started".format(name)
comt = f"Volume {name} already exists and is now started"
ret.update(
{"comment": comt, "changes": {"old": "stopped", "new": "started"}}
)
assert glusterfs.volume_present(name, bricks, start=True) == ret
comt = "Volume {} already exists".format(name)
comt = f"Volume {name} already exists"
ret.update({"comment": comt, "changes": {}})
assert glusterfs.volume_present(name, bricks, start=False) == ret
with patch.dict(glusterfs.__opts__, {"test": True}):
comt = "Volume {} already exists".format(name)
comt = f"Volume {name} already exists"
ret.update({"comment": comt, "result": None})
assert glusterfs.volume_present(name, bricks, start=False) == ret
comt = "Volume {} already exists and will be started".format(name)
comt = f"Volume {name} already exists and will be started"
ret.update({"comment": comt, "result": None})
assert glusterfs.volume_present(name, bricks, start=True) == ret
mock_list.return_value = []
comt = "Volume {} will be created".format(name)
comt = f"Volume {name} will be created"
ret.update({"comment": comt, "result": None})
assert glusterfs.volume_present(name, bricks, start=False) == ret
comt = "Volume {} will be created and started".format(name)
comt = f"Volume {name} will be created and started"
ret.update({"comment": comt, "result": None})
assert glusterfs.volume_present(name, bricks, start=True) == ret
with patch.dict(glusterfs.__opts__, {"test": False}):
mock_list.side_effect = [[], [name]]
comt = "Volume {} is created".format(name)
comt = f"Volume {name} is created"
ret.update(
{
"comment": comt,
@ -162,14 +162,14 @@ def test_volume_present():
assert glusterfs.volume_present(name, bricks, start=False) == ret
mock_list.side_effect = [[], [name]]
comt = "Volume {} is created and is now started".format(name)
comt = f"Volume {name} is created and is now started"
ret.update({"comment": comt, "result": True})
assert glusterfs.volume_present(name, bricks, start=True) == ret
mock_list.side_effect = None
mock_list.return_value = []
mock_create.return_value = False
comt = "Creation of volume {} failed".format(name)
comt = f"Creation of volume {name} failed"
ret.update({"comment": comt, "result": False, "changes": {}})
assert glusterfs.volume_present(name, bricks) == ret
@ -196,23 +196,23 @@ def test_started():
glusterfs.__salt__,
{"glusterfs.info": mock_info, "glusterfs.start_volume": mock_start},
):
comt = "Volume {} does not exist".format(name)
comt = f"Volume {name} does not exist"
ret.update({"comment": comt})
assert glusterfs.started(name) == ret
mock_info.return_value = started_info
comt = "Volume {} is already started".format(name)
comt = f"Volume {name} is already started"
ret.update({"comment": comt, "result": True})
assert glusterfs.started(name) == ret
with patch.dict(glusterfs.__opts__, {"test": True}):
mock_info.return_value = stopped_info
comt = "Volume {} will be started".format(name)
comt = f"Volume {name} will be started"
ret.update({"comment": comt, "result": None})
assert glusterfs.started(name) == ret
with patch.dict(glusterfs.__opts__, {"test": False}):
comt = "Volume {} is started".format(name)
comt = f"Volume {name} is started"
ret.update(
{
"comment": comt,