Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sodium deprecations #57370

Merged
merged 13 commits into from May 22, 2020
1 change: 1 addition & 0 deletions changelog/57361.removed
@@ -0,0 +1 @@
On macOS pkg.installed (using brew) no longer swaps `caskroom/cask/` for `homebrew/cask/` when using outdated package names.
3 changes: 3 additions & 0 deletions changelog/57362.removed
@@ -0,0 +1,3 @@
napalm_network.load_template module - removed deprecated arguments
template_user, template_attrs, template_group, template_mode, and native NAPALM
template support. Use Salt's rendering pipeline instead.
1 change: 1 addition & 0 deletions changelog/57363.removed
@@ -0,0 +1 @@
selinux.fcontext_add_or_delete_policy module removed - use selinux.fcontext_add_policy or selinux.fcontext_delete_pollicy instead.
1 change: 1 addition & 0 deletions changelog/57366.removed
@@ -0,0 +1 @@
Deprecated `refresh_db` removed from pkgrepo state. Use `refresh` instead.
1 change: 1 addition & 0 deletions changelog/57367.removed
@@ -0,0 +1 @@
Deprecated internal functions salt.utils.locales.sdecode and .sdecode_if_string removed. Use salt.utils.data.decode instead.
1 change: 1 addition & 0 deletions changelog/57368.removed
@@ -0,0 +1 @@
Removed deprecated misc. internal Salt functions. See https://github.com/saltstack/salt/issues/57368 for more info.
7 changes: 7 additions & 0 deletions doc/topics/releases/sodium.rst
Expand Up @@ -4,6 +4,13 @@
Salt Release Notes - Codename Sodium
====================================

Python 2 Deprecation
====================

Python 2 support has been dropped in Salt 3001. See
https://community.saltstack.com/blog/sunsetting-python-2-support/ for more
info.


Salt mine updates
=================
Expand Down
2 changes: 0 additions & 2 deletions salt/modules/mac_brew_pkg.py
Expand Up @@ -304,7 +304,6 @@ def remove(name=None, pkgs=None, **kwargs):
salt '*' pkg.remove pkgs='["foo", "bar"]'
"""
try:
name, pkgs = _fix_cask_namespace(name, pkgs)
pkg_params = __salt__["pkg_resource.parse_targets"](name, pkgs, **kwargs)[0]
except MinionError as exc:
raise CommandExecutionError(exc)
Expand Down Expand Up @@ -441,7 +440,6 @@ def install(name=None, pkgs=None, taps=None, options=None, **kwargs):
salt '*' pkg.install 'package package package'
"""
try:
name, pkgs = _fix_cask_namespace(name, pkgs)
pkg_params, pkg_type = __salt__["pkg_resource.parse_targets"](
name, pkgs, kwargs.get("sources", {})
)
Expand Down
263 changes: 100 additions & 163 deletions salt/modules/napalm_network.py
Expand Up @@ -1941,22 +1941,6 @@ def load_template(
_loaded = {"result": True, "comment": "", "out": None}
loaded_config = None
# prechecks
deprecated_args = (
"template_user",
"template_attrs",
"template_group",
"template_mode",
)
for deprecated_arg in deprecated_args:
if template_vars.get(deprecated_arg):
del template_vars[deprecated_arg]
salt.utils.versions.warn_until(
"Sodium",
(
"The '{arg}' argument to 'net.load_template' is deprecated "
"and has been ignored"
).format(arg=deprecated_arg),
)
if template_engine not in salt.utils.templates.TEMPLATE_REGISTRY:
_loaded.update(
{
Expand All @@ -1982,158 +1966,112 @@ def load_template(
)
file_exists = __salt__["file.file_exists"](template_name)

if (
template_source
or file_exists
or salt_render
or isinstance(template_name, (tuple, list))
):
# either inline template
# either template in a custom path
# either abs path send
# either starts with salt:// and
# then use Salt render system

if context is None:
context = {}
context.update(template_vars)
# if needed to render the template send as inline arg
if template_source:
# render the content
_rendered = __salt__["file.apply_template_on_contents"](
contents=template_source,
if context is None:
context = {}
context.update(template_vars)
# if needed to render the template send as inline arg
if template_source:
# render the content
_rendered = __salt__["file.apply_template_on_contents"](
contents=template_source,
template=template_engine,
context=context,
defaults=defaults,
saltenv=saltenv,
)
if not isinstance(_rendered, six.string_types):
if "result" in _rendered:
_loaded["result"] = _rendered["result"]
else:
_loaded["result"] = False
if "comment" in _rendered:
_loaded["comment"] = _rendered["comment"]
else:
_loaded["comment"] = "Error while rendering the template."
return _loaded
else:
# render the file - either local, either remote
if not isinstance(template_name, (list, tuple)):
template_name = [template_name]
if template_hash_name and not isinstance(template_hash_name, (list, tuple)):
template_hash_name = [template_hash_name]
elif not template_hash_name:
template_hash_name = [None] * len(template_name)
if (
template_hash
and isinstance(template_hash, six.string_types)
and not (
template_hash.startswith("salt://")
or template_hash.startswith("file://")
)
):
# If the template hash is passed as string, and it's not a file
# (starts with the salt:// or file:// URI), then make it a list
# of 1 element (for the iteration below)
template_hash = [template_hash]
elif (
template_hash
and isinstance(template_hash, six.string_types)
and (
template_hash.startswith("salt://")
or template_hash.startswith("file://")
)
):
# If the template hash is a file URI, then provide the same value
# for each of the templates in the list, as probably they all
# share the same hash file, otherwise the user should provide
# this as a list
template_hash = [template_hash] * len(template_name)
elif not template_hash:
template_hash = [None] * len(template_name)
for tpl_index, tpl_name in enumerate(template_name):
tpl_hash = template_hash[tpl_index]
tpl_hash_name = template_hash_name[tpl_index]
_rand_filename = __salt__["random.hash"](tpl_name, "md5")
_temp_file = __salt__["file.join"]("/tmp", _rand_filename)
_managed = __salt__["file.get_managed"](
name=_temp_file,
source=tpl_name,
source_hash=tpl_hash,
source_hash_name=tpl_hash_name,
user=None,
group=None,
mode=None,
attrs=None,
template=template_engine,
context=context,
defaults=defaults,
saltenv=saltenv,
skip_verify=skip_verify,
)
if not isinstance(_rendered, six.string_types):
if "result" in _rendered:
_loaded["result"] = _rendered["result"]
else:
_loaded["result"] = False
if "comment" in _rendered:
_loaded["comment"] = _rendered["comment"]
else:
_loaded["comment"] = "Error while rendering the template."
return _loaded
else:
# render the file - either local, either remote
if not isinstance(template_name, (list, tuple)):
template_name = [template_name]
if template_hash_name and not isinstance(template_hash_name, (list, tuple)):
template_hash_name = [template_hash_name]
elif not template_hash_name:
template_hash_name = [None] * len(template_name)
if (
template_hash
and isinstance(template_hash, six.string_types)
and not (
template_hash.startswith("salt://")
or template_hash.startswith("file://")
)
if not isinstance(_managed, (list, tuple)) and isinstance(
_managed, six.string_types
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could take the time and stop using six.string_types in favor or str on places where code is updated.

):
# If the template hash is passed as string, and it's not a file
# (starts with the salt:// or file:// URI), then make it a list
# of 1 element (for the iteration below)
template_hash = [template_hash]
elif (
template_hash
and isinstance(template_hash, six.string_types)
and (
template_hash.startswith("salt://")
or template_hash.startswith("file://")
)
):
# If the template hash is a file URI, then provide the same value
# for each of the templates in the list, as probably they all
# share the same hash file, otherwise the user should provide
# this as a list
template_hash = [template_hash] * len(template_name)
elif not template_hash:
template_hash = [None] * len(template_name)
for tpl_index, tpl_name in enumerate(template_name):
tpl_hash = template_hash[tpl_index]
tpl_hash_name = template_hash_name[tpl_index]
_rand_filename = __salt__["random.hash"](tpl_name, "md5")
_temp_file = __salt__["file.join"]("/tmp", _rand_filename)
_managed = __salt__["file.get_managed"](
name=_temp_file,
source=tpl_name,
source_hash=tpl_hash,
source_hash_name=tpl_hash_name,
user=None,
group=None,
mode=None,
attrs=None,
template=template_engine,
context=context,
defaults=defaults,
saltenv=saltenv,
skip_verify=skip_verify,
)
if not isinstance(_managed, (list, tuple)) and isinstance(
_managed, six.string_types
):
_loaded["comment"] += _managed
_loaded["result"] = False
elif isinstance(_managed, (list, tuple)) and not len(_managed) > 0:
_loaded["comment"] += _managed
_loaded["result"] = False
elif isinstance(_managed, (list, tuple)) and not len(_managed) > 0:
_loaded["result"] = False
_loaded["comment"] += "Error while rendering the template."
elif isinstance(_managed, (list, tuple)) and not len(_managed[0]) > 0:
_loaded["result"] = False
_loaded["comment"] += _managed[-1] # contains the error message
if _loaded["result"]: # all good
_temp_tpl_file = _managed[0]
_temp_tpl_file_exists = __salt__["file.file_exists"](_temp_tpl_file)
if not _temp_tpl_file_exists:
_loaded["result"] = False
_loaded["comment"] += "Error while rendering the template."
elif isinstance(_managed, (list, tuple)) and not len(_managed[0]) > 0:
_loaded["result"] = False
_loaded["comment"] += _managed[-1] # contains the error message
if _loaded["result"]: # all good
_temp_tpl_file = _managed[0]
_temp_tpl_file_exists = __salt__["file.file_exists"](_temp_tpl_file)
if not _temp_tpl_file_exists:
_loaded["result"] = False
_loaded["comment"] += "Error while rendering the template."
return _loaded
_rendered += __salt__["file.read"](_temp_tpl_file)
__salt__["file.remove"](_temp_tpl_file)
else:
return _loaded # exit

loaded_config = _rendered
if _loaded["result"]: # all good
fun = "load_merge_candidate"
if replace: # replace requested
fun = "load_replace_candidate"
if salt.utils.napalm.not_always_alive(__opts__):
# if a not-always-alive proxy
# or regular minion
# do not close the connection after loading the config
# this will be handled in _config_logic
# after running the other features:
# compare_config, discard / commit
# which have to be over the same session
napalm_device["CLOSE"] = False # pylint: disable=undefined-variable
_loaded = salt.utils.napalm.call(
napalm_device, # pylint: disable=undefined-variable
fun,
**{"config": _rendered}
)
else:
salt.utils.versions.warn_until(
"Sodium",
"Native NAPALM templates support will be removed in the Sodium "
"release. Please consider using the Salt rendering pipeline instead."
"If you are using the 'netntp', 'netsnmp', or 'netusers' Salt "
"State modules, you can ignore this message",
)
# otherwise, use NAPALM render system, injecting pillar/grains/opts vars
load_templates_params = defaults if defaults else {}
load_templates_params.update(template_vars)
load_templates_params.update(
{
"template_name": template_name,
"template_source": template_source, # inline template
"pillar": __pillar__, # inject pillar content
"grains": __grains__, # inject grains content
"opts": __opts__, # inject opts content
}
)
return _loaded
_rendered += __salt__["file.read"](_temp_tpl_file)
__salt__["file.remove"](_temp_tpl_file)
else:
return _loaded # exit

loaded_config = _rendered
if _loaded["result"]: # all good
fun = "load_merge_candidate"
if replace: # replace requested
fun = "load_replace_candidate"
if salt.utils.napalm.not_always_alive(__opts__):
# if a not-always-alive proxy
# or regular minion
Expand All @@ -2142,12 +2080,11 @@ def load_template(
# after running the other features:
# compare_config, discard / commit
# which have to be over the same session
# so we'll set the CLOSE global explicitly as False
napalm_device["CLOSE"] = False # pylint: disable=undefined-variable
_loaded = salt.utils.napalm.call(
napalm_device, # pylint: disable=undefined-variable
"load_template",
**load_templates_params
fun,
**{"config": _rendered}
)
return _config_logic(
napalm_device, # pylint: disable=undefined-variable
Expand Down