Skip to content

Commit

Permalink
Deprecate and stop using salt.features
Browse files Browse the repository at this point in the history
  • Loading branch information
s0undt3ch committed Jan 30, 2024
1 parent 3e5c721 commit 348c74b
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 45 deletions.
1 change: 1 addition & 0 deletions changelog/65951.deprecated.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Deprecate and stop using ``salt.features``
13 changes: 13 additions & 0 deletions salt/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import salt.defaults.exitcodes
import salt.exceptions
import salt.features
import salt.syspaths
import salt.utils.data
import salt.utils.dictupdate
Expand Down Expand Up @@ -1302,6 +1303,7 @@ def _gather_buffer_space():
"global_state_conditions": None,
"reactor_niceness": None,
"fips_mode": False,
"features": {},
}
)

Expand Down Expand Up @@ -1647,6 +1649,7 @@ def _gather_buffer_space():
"netapi_enable_clients": [],
"maintenance_interval": 3600,
"fileserver_interval": 3600,
"features": {},
}
)

Expand Down Expand Up @@ -1681,6 +1684,7 @@ def _gather_buffer_space():
"pki_dir": os.path.join(salt.syspaths.LIB_STATE_DIR, "pki", "proxy"),
"cachedir": os.path.join(salt.syspaths.CACHE_DIR, "proxy"),
"sock_dir": os.path.join(salt.syspaths.SOCK_DIR, "proxy"),
"features": {},
}
)

Expand Down Expand Up @@ -1714,6 +1718,7 @@ def _gather_buffer_space():
"log_rotate_backup_count": 0,
"bootstrap_delay": 0,
"cache": "localfs",
"features": {},
}
)

Expand Down Expand Up @@ -2324,6 +2329,7 @@ def minion_config(
if role != "master":
apply_sdb(opts)
_validate_opts(opts)
salt.features.setup_features(opts)
return opts


Expand All @@ -2335,6 +2341,7 @@ def mminion_config(path, overrides, ignore_config_errors=True):
_validate_opts(opts)
opts["grains"] = salt.loader.grains(opts)
opts["pillar"] = {}
salt.features.setup_features(opts)
return opts


Expand Down Expand Up @@ -2421,6 +2428,7 @@ def proxy_config(

apply_sdb(opts)
_validate_opts(opts)
salt.features.setup_features(opts)
return opts


Expand Down Expand Up @@ -2498,6 +2506,7 @@ def syndic_config(
if urllib.parse.urlparse(opts.get(config_key, "")).scheme == "":
prepend_root_dirs.append(config_key)
prepend_root_dir(opts, prepend_root_dirs)
salt.features.setup_features(opts)
return opts


Expand Down Expand Up @@ -2750,6 +2759,7 @@ def cloud_config(
prepend_root_dirs.append(opts["log_file"])
prepend_root_dir(opts, prepend_root_dirs)

salt.features.setup_features(opts)
# Return the final options
return opts

Expand Down Expand Up @@ -3923,6 +3933,7 @@ def master_config(
if salt.utils.data.is_dictlist(opts["nodegroups"]):
opts["nodegroups"] = salt.utils.data.repack_dictlist(opts["nodegroups"])
apply_sdb(opts)
salt.features.setup_features(opts)
return opts


Expand Down Expand Up @@ -4162,6 +4173,7 @@ def client_config(path, env_var="SALT_CLIENT_CONFIG", defaults=None):

# Return the client options
_validate_opts(opts)
salt.features.setup_features(opts)
return opts


Expand All @@ -4185,6 +4197,7 @@ def api_config(path):
)

prepend_root_dir(opts, ["api_pidfile", "api_logfile", "log_file", "pidfile"])
salt.features.setup_features(opts)
return opts


Expand Down
8 changes: 8 additions & 0 deletions salt/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ def setup_features(self, opts):
log.warning("Features already setup")

def get(self, key, default=None):
import salt.utils.versions

salt.utils.versions.warn_until(
3008,
"Please stop checking feature flags using 'salt.features' and instead "
"check the 'features' keyword on the configuration dictionary. The "
"'salt.features' module will go away in {version}.",
)
return self.features.get(key, default)


Expand Down
9 changes: 4 additions & 5 deletions salt/states/saltmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import salt.utils.data
import salt.utils.event
import salt.utils.versions
from salt.features import features

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -812,11 +811,11 @@ def runner(name, **kwargs):
"executed" if success else "failed",
)

if features.get("enable_deprecated_orchestration_flag", False):
if __opts__["features"].get("enable_deprecated_orchestration_flag", False):
ret["__orchestration__"] = True
salt.utils.versions.warn_until(
"Argon",
"The __orchestration__ return flag will be removed in Salt Argon. "
3008,
"The __orchestration__ return flag will be removed in {version}. "
"For more information see https://github.com/saltstack/salt/pull/59917.",
)

Expand Down Expand Up @@ -1061,7 +1060,7 @@ def wheel(name, **kwargs):
"executed" if success else "failed",
)

if features.get("enable_deprecated_orchestration_flag", False):
if __opts__["features"].get("enable_deprecated_orchestration_flag", False):
ret["__orchestration__"] = True
salt.utils.versions.warn_until(
"Argon",
Expand Down
3 changes: 1 addition & 2 deletions salt/states/x509.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@

import salt.exceptions
import salt.utils.versions
from salt.features import features

try:
from M2Crypto.RSA import RSAError
Expand All @@ -205,7 +204,7 @@ def __virtual__():
"""
only load this module if the corresponding execution module is loaded
"""
if features.get("x509_v2"):
if __opts__["features"].get("x509_v2"):
return (False, "Superseded, using x509_v2")
if "x509.get_pem_entry" in __salt__:
salt.utils.versions.warn_until(
Expand Down
3 changes: 1 addition & 2 deletions salt/states/x509_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@

import salt.utils.files
from salt.exceptions import CommandExecutionError, SaltInvocationError
from salt.features import features
from salt.state import STATE_INTERNAL_KEYWORDS as _STATE_INTERNAL_KEYWORDS

try:
Expand All @@ -211,7 +210,7 @@
def __virtual__():
if not HAS_CRYPTOGRAPHY:
return (False, "Could not load cryptography")
if not features.get("x509_v2"):
if not __opts__["features"].get("x509_v2"):
return (
False,
"x509_v2 needs to be explicitly enabled by setting `x509_v2: true` "
Expand Down
47 changes: 11 additions & 36 deletions salt/utils/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import salt.config as config
import salt.defaults.exitcodes
import salt.exceptions
import salt.features
import salt.syspaths as syspaths
import salt.utils.args
import salt.utils.data
Expand Down Expand Up @@ -1937,9 +1936,7 @@ class MasterOptionParser(
_default_logging_logfile_ = config.DEFAULT_MASTER_OPTS["log_file"]

def setup_config(self):
opts = config.master_config(self.get_config_file_path())
salt.features.setup_features(opts)
return opts
return config.master_config(self.get_config_file_path())


class MinionOptionParser(
Expand All @@ -1954,13 +1951,11 @@ class MinionOptionParser(
_default_logging_logfile_ = config.DEFAULT_MINION_OPTS["log_file"]

def setup_config(self):
opts = config.minion_config(
return config.minion_config(
self.get_config_file_path(), # pylint: disable=no-member
cache_minion_id=True,
ignore_config_errors=False,
)
salt.features.setup_features(opts)
return opts


class ProxyMinionOptionParser(
Expand Down Expand Up @@ -1991,11 +1986,9 @@ def setup_config(self):
except AttributeError:
minion_id = None

opts = config.proxy_config(
return config.proxy_config(
self.get_config_file_path(), cache_minion_id=False, minion_id=minion_id
)
salt.features.setup_features(opts)
return opts


class SyndicOptionParser(
Expand Down Expand Up @@ -2025,11 +2018,9 @@ class SyndicOptionParser(
]

def setup_config(self):
opts = config.syndic_config(
return config.syndic_config(
self.get_config_file_path(), self.get_config_file_path("minion")
)
salt.features.setup_features(opts)
return opts


class SaltCMDOptionParser(
Expand Down Expand Up @@ -2368,9 +2359,7 @@ def _mixin_after_parsed(self):
self.exit(42, "\nIncomplete options passed.\n\n")

def setup_config(self):
opts = config.client_config(self.get_config_file_path())
salt.features.setup_features(opts)
return opts
return config.client_config(self.get_config_file_path())


class SaltCPOptionParser(
Expand Down Expand Up @@ -2441,9 +2430,7 @@ def _mixin_after_parsed(self):
self.config["dest"] = self.args[-1]

def setup_config(self):
opts = config.master_config(self.get_config_file_path())
salt.features.setup_features(opts)
return opts
return config.master_config(self.get_config_file_path())


class SaltKeyOptionParser(
Expand Down Expand Up @@ -2735,7 +2722,6 @@ def setup_config(self):
# Since we're generating the keys, some defaults can be assumed
# or tweaked
keys_config["pki_dir"] = self.options.gen_keys_dir
salt.features.setup_features(keys_config)
return keys_config

def process_rotate_aes_key(self):
Expand Down Expand Up @@ -2984,7 +2970,6 @@ def setup_config(self):
opts = config.minion_config(
self.get_config_file_path(), cache_minion_id=True
)
salt.features.setup_features(opts)
return opts

def process_module_dirs(self):
Expand Down Expand Up @@ -3086,9 +3071,7 @@ def _mixin_after_parsed(self):
self.config["arg"] = []

def setup_config(self):
opts = config.client_config(self.get_config_file_path())
salt.features.setup_features(opts)
return opts
return config.client_config(self.get_config_file_path())


class SaltSSHOptionParser(
Expand Down Expand Up @@ -3428,9 +3411,7 @@ def _mixin_after_parsed(self):
break

def setup_config(self):
opts = config.master_config(self.get_config_file_path())
salt.features.setup_features(opts)
return opts
return config.master_config(self.get_config_file_path())


class SaltCloudParser(
Expand Down Expand Up @@ -3491,11 +3472,9 @@ def _mixin_after_parsed(self):

def setup_config(self):
try:
opts = config.cloud_config(self.get_config_file_path())
return config.cloud_config(self.get_config_file_path())
except salt.exceptions.SaltCloudConfigError as exc:
self.error(exc)
salt.features.setup_features(opts)
return opts


class SPMParser(
Expand Down Expand Up @@ -3551,9 +3530,7 @@ def _mixin_after_parsed(self):
self.error("Insufficient arguments")

def setup_config(self):
opts = salt.config.spm_config(self.get_config_file_path())
salt.features.setup_features(opts)
return opts
return salt.config.spm_config(self.get_config_file_path())


class SaltAPIParser(
Expand All @@ -3579,8 +3556,6 @@ class SaltAPIParser(
_default_logging_logfile_ = config.DEFAULT_API_OPTS[_logfile_config_setting_name_]

def setup_config(self):
opts = salt.config.api_config(
return salt.config.api_config(
self.get_config_file_path()
) # pylint: disable=no-member
salt.features.setup_features(opts)
return opts

0 comments on commit 348c74b

Please sign in to comment.