Adding deprecation decorator to docker modules for 3009.

This commit is contained in:
Gareth J. Greenaway 2023-08-01 09:47:05 -07:00 committed by Megan Wilhite
parent 051dac0260
commit 6ea385a16c
5 changed files with 87 additions and 67 deletions

View file

@ -226,6 +226,12 @@ from salt.state import HighState
__docformat__ = "restructuredtext en"
__deprecated__ = (
3009,
"docker",
"https://github.com/saltstack/saltext-docker",
)
# pylint: disable=import-error
try:

View file

@ -60,6 +60,12 @@ log = logging.getLogger(__name__) # pylint: disable=invalid-name
__virtualname__ = "docker_container"
__virtual_aliases__ = ("moby_container",)
__deprecated__ = (
3009,
"docker",
"https://github.com/saltstack/saltext-docker",
)
def __virtual__():
"""
@ -163,7 +169,7 @@ def _parse_networks(networks):
]
except CommandExecutionError as exc:
raise CommandExecutionError(
"Failed to get list of existing networks: {}.".format(exc)
f"Failed to get list of existing networks: {exc}."
)
else:
missing_networks = [x for x in sorted(networks) if x not in all_networks]
@ -192,7 +198,7 @@ def _resolve_image(ret, image, client_timeout):
client_timeout=client_timeout,
)
except Exception as exc: # pylint: disable=broad-except
raise CommandExecutionError("Failed to pull {}: {}".format(image, exc))
raise CommandExecutionError(f"Failed to pull {image}: {exc}")
else:
ret["changes"]["image"] = pull_result
# Try resolving again now that we've pulled
@ -218,7 +224,7 @@ def running(
shutdown_timeout=None,
client_timeout=salt.utils.dockermod.CLIENT_TIMEOUT,
networks=None,
**kwargs
**kwargs,
):
"""
Ensure that a container with a specific configuration is present and
@ -1740,7 +1746,7 @@ def running(
ignore_collisions=ignore_collisions,
validate_ip_addrs=validate_ip_addrs,
client_timeout=client_timeout,
**kwargs
**kwargs,
)
temp_container_name = temp_container["Name"]
except KeyError as exc:
@ -1779,9 +1785,9 @@ def running(
result = __salt__["docker.rename"](new, orig)
except CommandExecutionError as exc:
result = False
comments.append("Failed to rename temp container: {}".format(exc))
comments.append(f"Failed to rename temp container: {exc}")
if result:
comments.append("Replaced container '{}'".format(orig))
comments.append(f"Replaced container '{orig}'")
else:
comments.append("Failed to replace container '{0}'")
return result
@ -1887,22 +1893,18 @@ def running(
if send_signal:
if __opts__["test"]:
comments.append(
"Signal {} would be sent to container".format(watch_action)
f"Signal {watch_action} would be sent to container"
)
else:
try:
__salt__["docker.signal"](name, signal=watch_action)
except CommandExecutionError as exc:
ret["result"] = False
comments.append(
"Failed to signal container: {}".format(exc)
)
comments.append(f"Failed to signal container: {exc}")
return _format_comments(ret, comments)
else:
ret["changes"]["signal"] = watch_action
comments.append(
"Sent signal {} to container".format(watch_action)
)
comments.append(f"Sent signal {watch_action} to container")
elif container_changes:
if not comments:
log.warning(
@ -1920,7 +1922,7 @@ def running(
# existing container and the temp container were detected,
# and no signal was sent to the container.
comments.append(
"Container '{}' is already configured as specified".format(name)
f"Container '{name}' is already configured as specified"
)
if net_changes:
@ -1981,11 +1983,9 @@ def running(
"configuration".format(net_name)
)
elif disconnected:
comments.append(
"Disconnected from network '{}'".format(net_name)
)
comments.append(f"Disconnected from network '{net_name}'")
elif connected:
comments.append("Connected to network '{}'".format(net_name))
comments.append(f"Connected to network '{net_name}'")
if network_failure:
ret["result"] = False
@ -1996,7 +1996,7 @@ def running(
if skip_comparison:
if not exists:
comments.append("Created container '{}'".format(name))
comments.append(f"Created container '{name}'")
else:
if not _replace(name, temp_container):
ret["result"] = False
@ -2023,9 +2023,7 @@ def running(
post_state = __salt__["docker.start"](name)["state"]["new"]
except Exception as exc: # pylint: disable=broad-except
ret["result"] = False
comments.append(
"Failed to start container '{}': '{}'".format(name, exc)
)
comments.append(f"Failed to start container '{name}': '{exc}'")
return _format_comments(ret, comments)
else:
post_state = __salt__["docker.state"](name)
@ -2070,9 +2068,7 @@ def running(
if pre_state != post_state:
ret["changes"]["state"] = {"old": pre_state, "new": post_state}
if pre_state is not None:
comments.append(
"State changed from '{}' to '{}'".format(pre_state, post_state)
)
comments.append(f"State changed from '{pre_state}' to '{post_state}'")
if exists and current_image_id != image_id:
comments.append("Container has a new image")
@ -2096,7 +2092,7 @@ def run(
ignore_collisions=False,
validate_ip_addrs=True,
client_timeout=salt.utils.dockermod.CLIENT_TIMEOUT,
**kwargs
**kwargs,
):
"""
.. versionadded:: 2018.3.0
@ -2186,7 +2182,7 @@ def run(
for unsupported in ("watch_action", "start", "shutdown_timeout", "follow"):
if unsupported in kwargs:
ret["result"] = False
ret["comment"] = "The '{}' argument is not supported".format(unsupported)
ret["comment"] = f"The '{unsupported}' argument is not supported"
return ret
if image is None:
@ -2259,12 +2255,12 @@ def run(
bg=bg,
replace=replace,
force=force,
**kwargs
**kwargs,
)
except Exception as exc: # pylint: disable=broad-except
log.exception("Encountered error running container")
ret["result"] = False
ret["comment"] = "Encountered error running container: {}".format(exc)
ret["comment"] = f"Encountered error running container: {exc}"
else:
if bg:
ret["comment"] = "Container was run in the background"
@ -2277,7 +2273,7 @@ def run(
ret["result"] = False if failhard and retcode != 0 else True
ret[
"comment"
] = "Container ran and exited with a return code of {}".format(retcode)
] = f"Container ran and exited with a return code of {retcode}"
if remove:
id_ = ret.get("changes", {}).get("Id")
@ -2286,7 +2282,7 @@ def run(
__salt__["docker.rm"](ret["changes"]["Id"])
except CommandExecutionError as exc:
ret.setdefault("warnings", []).append(
"Failed to auto_remove container: {}".format(exc)
f"Failed to auto_remove container: {exc}"
)
return ret
@ -2298,7 +2294,7 @@ def stopped(
shutdown_timeout=None,
unpause=False,
error_on_absent=True,
**kwargs
**kwargs,
):
"""
Ensure that a container (or containers) is stopped
@ -2402,7 +2398,7 @@ def stopped(
if not to_stop:
ret["result"] = True
if len(targets) == 1:
ret["comment"] = "Container '{}' is ".format(targets[0])
ret["comment"] = f"Container '{targets[0]}' is "
else:
ret["comment"] = "All specified containers are "
if "absent" in containers:
@ -2429,7 +2425,7 @@ def stopped(
if "comment" in changes:
stop_errors.append(changes["comment"])
else:
stop_errors.append("Failed to stop container '{}'".format(target))
stop_errors.append(f"Failed to stop container '{target}'")
if stop_errors:
ret["comment"] = "; ".join(stop_errors)
@ -2470,7 +2466,7 @@ def absent(name, force=False):
if name not in __salt__["docker.list_containers"](all=True):
ret["result"] = True
ret["comment"] = "Container '{}' does not exist".format(name)
ret["comment"] = f"Container '{name}' does not exist"
return ret
pre_state = __salt__["docker.state"](name)
@ -2480,23 +2476,23 @@ def absent(name, force=False):
if __opts__["test"]:
ret["result"] = None
ret["comment"] = "Container '{}' will be removed".format(name)
ret["comment"] = f"Container '{name}' will be removed"
return ret
try:
ret["changes"]["removed"] = __salt__["docker.rm"](name, force=force)
except Exception as exc: # pylint: disable=broad-except
ret["comment"] = "Failed to remove container '{}': {}".format(name, exc)
ret["comment"] = f"Failed to remove container '{name}': {exc}"
return ret
if name in __salt__["docker.list_containers"](all=True):
ret["comment"] = "Failed to remove container '{}'".format(name)
ret["comment"] = f"Failed to remove container '{name}'"
else:
if force and pre_state != "stopped":
method = "Forcibly"
else:
method = "Successfully"
ret["comment"] = "{} removed container '{}'".format(method, name)
ret["comment"] = f"{method} removed container '{name}'"
ret["result"] = True
return ret
@ -2530,5 +2526,5 @@ def mod_watch(name, sfun=None, **kwargs):
"name": name,
"changes": {},
"result": False,
"comment": "watch requisite is not implemented for {}".format(sfun),
"comment": f"watch requisite is not implemented for {sfun}",
}

View file

@ -48,6 +48,12 @@ log = logging.getLogger(__name__)
__virtualname__ = "docker_image"
__virtual_aliases__ = ("moby_image",)
__deprecated__ = (
3009,
"docker",
"https://github.com/saltstack/saltext-docker",
)
def __virtual__():
"""
@ -72,7 +78,7 @@ def present(
saltenv="base",
pillarenv=None,
pillar=None,
**kwargs
**kwargs,
):
"""
.. versionchanged:: 2018.3.0
@ -230,7 +236,7 @@ def present(
full_image = ":".join((name, tag))
else:
if tag:
name = "{}:{}".format(name, tag)
name = f"{name}:{tag}"
full_image = name
try:
@ -248,7 +254,7 @@ def present(
# Specified image is present
if not force:
ret["result"] = True
ret["comment"] = "Image {} already present".format(full_image)
ret["comment"] = f"Image {full_image} already present"
return ret
if build or sls:
@ -261,7 +267,7 @@ def present(
if __opts__["test"]:
ret["result"] = None
if (image_info is not None and force) or image_info is None:
ret["comment"] = "Image {} will be {}".format(full_image, action)
ret["comment"] = f"Image {full_image} will be {action}"
return ret
if build:
@ -325,7 +331,7 @@ def present(
name, insecure_registry=insecure_registry, client_timeout=client_timeout
)
except Exception as exc: # pylint: disable=broad-except
ret["comment"] = "Encountered error pulling {}: {}".format(full_image, exc)
ret["comment"] = f"Encountered error pulling {full_image}: {exc}"
return ret
if (
image_info is not None
@ -359,7 +365,7 @@ def present(
name, action
)
else:
ret["comment"] = "Image '{}' was {}".format(full_image, action)
ret["comment"] = f"Image '{full_image}' was {action}"
return ret
@ -436,7 +442,7 @@ def absent(name=None, images=None, force=False):
if not to_delete:
ret["result"] = True
if len(targets) == 1:
ret["comment"] = "Image {} is not present".format(name)
ret["comment"] = f"Image {name} is not present"
else:
ret["comment"] = "All specified images are not present"
return ret
@ -444,7 +450,7 @@ def absent(name=None, images=None, force=False):
if __opts__["test"]:
ret["result"] = None
if len(to_delete) == 1:
ret["comment"] = "Image {} will be removed".format(to_delete[0])
ret["comment"] = f"Image {to_delete[0]} will be removed"
else:
ret["comment"] = "The following images will be removed: {}".format(
", ".join(to_delete)
@ -470,7 +476,7 @@ def absent(name=None, images=None, force=False):
else:
ret["changes"] = result
if len(to_delete) == 1:
ret["comment"] = "Image {} was removed".format(to_delete[0])
ret["comment"] = f"Image {to_delete[0]} was removed"
else:
ret["comment"] = "The following images were removed: {}".format(
", ".join(to_delete)
@ -499,5 +505,5 @@ def mod_watch(name, sfun=None, **kwargs):
"name": name,
"changes": {},
"result": False,
"comment": "watch requisite is not implemented for {}".format(sfun),
"comment": f"watch requisite is not implemented for {sfun}",
}

View file

@ -45,6 +45,12 @@ log = logging.getLogger(__name__)
__virtualname__ = "docker_network"
__virtual_aliases__ = ("moby_network",)
__deprecated__ = (
3009,
"docker",
"https://github.com/saltstack/saltext-docker",
)
def __virtual__():
"""
@ -65,7 +71,7 @@ def _normalize_pools(existing, desired):
for pool in desired["Config"]:
subnet = ipaddress.ip_network(pool.get("Subnet"))
if pools["desired"][subnet.version] is not None:
raise ValueError("Only one IPv{} pool is permitted".format(subnet.version))
raise ValueError(f"Only one IPv{subnet.version} pool is permitted")
else:
pools["desired"][subnet.version] = pool
@ -91,7 +97,7 @@ def present(
validate_ip_addrs=True,
containers=None,
reconnect=True,
**kwargs
**kwargs,
):
"""
.. versionchanged:: 2018.3.0
@ -575,7 +581,7 @@ def present(
skip_translate=skip_translate,
ignore_collisions=ignore_collisions,
validate_ip_addrs=validate_ip_addrs,
**__utils__["args.clean_kwargs"](**kwargs)
**__utils__["args.clean_kwargs"](**kwargs),
)
except Exception as exc: # pylint: disable=broad-except
ret["comment"] = exc.__str__()
@ -621,7 +627,7 @@ def present(
# recreate the network with new config we'll update the comment later.
ret[
"comment"
] = "Network '{}' already exists, and is configured as specified".format(name)
] = f"Network '{name}' already exists, and is configured as specified"
log.trace("Details of docker network '%s': %s", name, network)
temp_net_name = "".join(
@ -658,7 +664,7 @@ def present(
temp_net_name,
skip_translate=True, # No need to translate (already did)
enable_ipv6=False,
**kwargs_tmp
**kwargs_tmp,
)
except CommandExecutionError as exc:
ret["comment"] = "Failed to create temp network for comparison: {}".format(
@ -800,7 +806,7 @@ def present(
__salt__["docker.create_network"](
name,
skip_translate=True, # No need to translate (already did)
**kwargs
**kwargs,
)
except Exception as exc: # pylint: disable=broad-except
ret["comment"] = "Failed to create network '{}': {}".format(
@ -927,12 +933,12 @@ def absent(name):
if network is None:
ret["result"] = True
ret["comment"] = "Network '{}' already absent".format(name)
ret["comment"] = f"Network '{name}' already absent"
return ret
if __opts__["test"]:
ret["result"] = None
ret["comment"] = "Network '{}' will be removed".format(name)
ret["comment"] = f"Network '{name}' will be removed"
return ret
return _remove_network(network)
@ -957,7 +963,7 @@ def _remove_network(network):
try:
__salt__["docker.disconnect_container_from_network"](cid, network["Name"])
except CommandExecutionError as exc:
errors = "Failed to disconnect container '{}' : {}".format(cname, exc)
errors = f"Failed to disconnect container '{cname}' : {exc}"
else:
ret["changes"].setdefault("disconnected", []).append(cname)
@ -968,7 +974,7 @@ def _remove_network(network):
try:
__salt__["docker.remove_network"](network["Name"])
except CommandExecutionError as exc:
ret["comment"] = "Failed to remove network: {}".format(exc)
ret["comment"] = f"Failed to remove network: {exc}"
else:
ret["changes"]["removed"] = True
ret["result"] = True

View file

@ -41,6 +41,12 @@ log = logging.getLogger(__name__) # pylint: disable=invalid-name
__virtualname__ = "docker_volume"
__virtual_aliases__ = ("moby_volume",)
__deprecated__ = (
3009,
"docker",
"https://github.com/saltstack/saltext-docker",
)
def __virtual__():
"""
@ -135,14 +141,14 @@ def present(name, driver=None, driver_opts=None, force=False):
if not volume:
if __opts__["test"]:
ret["result"] = None
ret["comment"] = "The volume '{}' will be created".format(name)
ret["comment"] = f"The volume '{name}' will be created"
return ret
try:
ret["changes"]["created"] = __salt__["docker.create_volume"](
name, driver=driver, driver_opts=driver_opts
)
except Exception as exc: # pylint: disable=broad-except
ret["comment"] = "Failed to create volume '{}': {}".format(name, exc)
ret["comment"] = f"Failed to create volume '{name}': {exc}"
return ret
else:
result = True
@ -168,7 +174,7 @@ def present(name, driver=None, driver_opts=None, force=False):
try:
ret["changes"]["removed"] = __salt__["docker.remove_volume"](name)
except Exception as exc: # pylint: disable=broad-except
ret["comment"] = "Failed to remove volume '{}': {}".format(name, exc)
ret["comment"] = f"Failed to remove volume '{name}': {exc}"
return ret
else:
try:
@ -176,7 +182,7 @@ def present(name, driver=None, driver_opts=None, force=False):
name, driver=driver, driver_opts=driver_opts
)
except Exception as exc: # pylint: disable=broad-except
ret["comment"] = "Failed to create volume '{}': {}".format(name, exc)
ret["comment"] = f"Failed to create volume '{name}': {exc}"
return ret
else:
result = True
@ -184,7 +190,7 @@ def present(name, driver=None, driver_opts=None, force=False):
return ret
ret["result"] = True
ret["comment"] = "Volume '{}' already exists.".format(name)
ret["comment"] = f"Volume '{name}' already exists."
return ret
@ -212,12 +218,12 @@ def absent(name, driver=None):
volume = _find_volume(name)
if not volume:
ret["result"] = True
ret["comment"] = "Volume '{}' already absent".format(name)
ret["comment"] = f"Volume '{name}' already absent"
return ret
try:
ret["changes"]["removed"] = __salt__["docker.remove_volume"](name)
ret["result"] = True
except Exception as exc: # pylint: disable=broad-except
ret["comment"] = "Failed to remove volume '{}': {}".format(name, exc)
ret["comment"] = f"Failed to remove volume '{name}': {exc}"
return ret