Skip to content

Commit

Permalink
Fixed Salt's deferred imports to allow onedir builds while not breaki…
Browse files Browse the repository at this point in the history
…ng non-onedir builds

Fixes saltstack#146
Closes saltstack#144

Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
  • Loading branch information
s0undt3ch committed Dec 15, 2022
1 parent a5ac0d5 commit ed0b26c
Show file tree
Hide file tree
Showing 22 changed files with 399 additions and 195 deletions.
1 change: 1 addition & 0 deletions .pylint-spelling-words
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ nocover
nodeid
noqa
nox
onedir
openbsd
ordereddict
os
Expand Down
5 changes: 5 additions & 0 deletions changelog/146.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Fixed Salt's deferred imports to allow onedir builds while not breaking non-onedir builds:

* Additionally, stopped relying on `salt.utils.files` and `salt.utils.yaml`
* Stopped using `zmq` to forward events(this was where the breakage was showing) for a plain TCP implementation.
* The `event_listener` fixture is now started/stopped like a regular pytest fixture
2 changes: 1 addition & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ pytest-shell-utilities>=1.4.0
psutil
pyyaml
pyzmq
msgpack
msgpack>=0.5.2
virtualenv
4 changes: 3 additions & 1 deletion src/saltfactories/bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,9 @@ def verify_config(cls, config):
"""
Verify the configuration dictionary.
"""
import salt.utils.verify
# Do not move these deferred imports. It allows running against a Salt
# onedir build in salt's repo checkout.
import salt.utils.verify # pylint: disable=import-outside-toplevel

salt.utils.verify.verify_env(
cls._get_verify_config_entries(config),
Expand Down
4 changes: 4 additions & 0 deletions src/saltfactories/cli/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def default_config(root_dir, master_id, defaults=None, overrides=None):
"""
Return the default configuration for the daemon.
"""
# Do not move these deferred imports. It allows running against a Salt
# onedir build in salt's repo checkout.
import salt.utils.dictupdate

if defaults is None:
Expand Down Expand Up @@ -78,6 +80,8 @@ def verify_config(cls, config):
"""
Verify the configuration dictionary.
"""
# Do not move these deferred imports. It allows running against a Salt
# onedir build in salt's repo checkout.
import salt.config
import salt.utils.verify

Expand Down
7 changes: 5 additions & 2 deletions src/saltfactories/cli/key.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ def _default___cli_log_level_supported__(self):
try:
# Salt >= 3005
return "--log-level" in SaltKeyOptionParser._console_log_level_cli_flags
except AttributeError:
except AttributeError: # pragma: no cover
# Salt <= 3004
return SaltKeyOptionParser._skip_console_logging_config_ is False
return (
SaltKeyOptionParser._skip_console_logging_config_ # pylint: disable=no-member
is False
)

def get_minion_tgt(self, minion_tgt=None):
"""
Expand Down
16 changes: 11 additions & 5 deletions src/saltfactories/cli/spm.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ def default_config(root_dir, master_factory, defaults=None, overrides=None):
"""
Return the default configuration for the daemon.
"""
import salt.utils.dictupdate
# Do not move these deferred imports. It allows running against a Salt
# onedir build in salt's repo checkout.
import salt.utils.dictupdate # pylint: disable=import-outside-toplevel

if defaults is None:
defaults = {}
Expand Down Expand Up @@ -89,8 +91,10 @@ def verify_config(cls, config):
"""
Verify the configuration dictionary.
"""
import salt.config
import salt.utils.verify
# Do not move these deferred imports. It allows running against a Salt
# onedir build in salt's repo checkout.
import salt.config # pylint: disable=import-outside-toplevel
import salt.utils.verify # pylint: disable=import-outside-toplevel

prepend_root_dirs = [
"formula_path",
Expand Down Expand Up @@ -127,8 +131,10 @@ def write_config(cls, config):
"""
Verify the loaded configuration.
"""
import salt.config
import salt.utils.verify
# Do not move these deferred imports. It allows running against a Salt
# onedir build in salt's repo checkout.
import salt.config # pylint: disable=import-outside-toplevel
import salt.utils.verify # pylint: disable=import-outside-toplevel

cls.verify_config(config)
config_file = config.pop("spm_conf_file")
Expand Down
4 changes: 3 additions & 1 deletion src/saltfactories/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ def _set_functions_known_to_return_none(self):

@__client.default
def _set_client(self):
import salt.client
# Do not move these deferred imports. It allows running against a Salt
# onedir build in salt's repo checkout.
import salt.client # pylint: disable=import-outside-toplevel

return salt.client.get_local_client(mopts=self.master_config)

Expand Down
10 changes: 7 additions & 3 deletions src/saltfactories/daemons/master.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ def default_config(
"""
Return the default configuration.
"""
import salt.config
import salt.utils.dictupdate
# Do not move these deferred imports. It allows running against a Salt
# onedir build in salt's repo checkout.
import salt.config # pylint: disable=import-outside-toplevel
import salt.utils.dictupdate # pylint: disable=import-outside-toplevel

if defaults is None:
defaults = {}
Expand Down Expand Up @@ -274,7 +276,9 @@ def load_config(cls, config_file, config):
"""
Return the loaded configuration.
"""
import salt.config
# Do not move these deferred imports. It allows running against a Salt
# onedir build in salt's repo checkout.
import salt.config # pylint: disable=import-outside-toplevel

return salt.config.master_config(config_file)

Expand Down
10 changes: 7 additions & 3 deletions src/saltfactories/daemons/minion.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ def default_config(
"""
Return the default configuration.
"""
import salt.config
import salt.utils.dictupdate
# Do not move these deferred imports. It allows running against a Salt
# onedir build in salt's repo checkout.
import salt.config # pylint: disable=import-outside-toplevel
import salt.utils.dictupdate # pylint: disable=import-outside-toplevel

if defaults is None:
defaults = {}
Expand Down Expand Up @@ -224,7 +226,9 @@ def load_config(cls, config_file, config):
"""
Return the loaded configuration.
"""
import salt.config
# Do not move these deferred imports. It allows running against a Salt
# onedir build in salt's repo checkout.
import salt.config # pylint: disable=import-outside-toplevel

return salt.config.minion_config(config_file, minion_id=config["id"], cache_minion_id=True)

Expand Down
10 changes: 7 additions & 3 deletions src/saltfactories/daemons/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ def default_config(
"""
Return the default configuration.
"""
import salt.config
import salt.utils.dictupdate
# Do not move these deferred imports. It allows running against a Salt
# onedir build in salt's repo checkout.
import salt.config # pylint: disable=import-outside-toplevel
import salt.utils.dictupdate # pylint: disable=import-outside-toplevel

if defaults is None:
defaults = {}
Expand Down Expand Up @@ -240,7 +242,9 @@ def load_config(cls, config_file, config):
"""
Return the loaded configuration.
"""
import salt.config
# Do not move these deferred imports. It allows running against a Salt
# onedir build in salt's repo checkout.
import salt.config # pylint: disable=import-outside-toplevel

return salt.config.proxy_config(config_file, minion_id=config["id"], cache_minion_id=True)

Expand Down
10 changes: 7 additions & 3 deletions src/saltfactories/daemons/syndic.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ def default_config(
"""
Return the default configuration.
"""
import salt.config
import salt.utils.dictupdate
# Do not move these deferred imports. It allows running against a Salt
# onedir build in salt's repo checkout.
import salt.config # pylint: disable=import-outside-toplevel
import salt.utils.dictupdate # pylint: disable=import-outside-toplevel

if defaults is None:
defaults = {}
Expand Down Expand Up @@ -143,7 +145,9 @@ def load_config(cls, config_file, config):
"""
Return the loaded configuration.
"""
import salt.config
# Do not move these deferred imports. It allows running against a Salt
# onedir build in salt's repo checkout.
import salt.config # pylint: disable=import-outside-toplevel

conf_dir = pathlib.Path(config_file).parent.parent
master_config_file = str(conf_dir / "master")
Expand Down
10 changes: 8 additions & 2 deletions src/saltfactories/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,10 @@ def final_minion_config_tweaks(self, config):
pytest_key = "pytest-minion"
if pytest_key not in config: # pragma: no cover
config[pytest_key] = {}
config[pytest_key]["returner_address"] = self.event_listener.address
config[pytest_key]["returner_address"] = {
"host": self.event_listener.host,
"port": self.event_listener.port,
}
self.final_common_config_tweaks(config, "minion")

def final_master_config_tweaks(self, config):
Expand All @@ -172,7 +175,10 @@ def final_master_config_tweaks(self, config):
pytest_key = "pytest-master"
if pytest_key not in config: # pragma: no cover
config[pytest_key] = {}
config[pytest_key]["returner_address"] = self.event_listener.address
config[pytest_key]["returner_address"] = {
"host": self.event_listener.host,
"port": self.event_listener.port,
}
self.final_common_config_tweaks(config, "master")

def final_syndic_config_tweaks(self, config):
Expand Down
4 changes: 3 additions & 1 deletion src/saltfactories/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ def pytest_load_initial_conftests(*_):
"""
Register our pytest helpers.
"""
import salt.version
# Do not move these deferred imports. It allows running against a Salt
# onedir build in salt's repo checkout.
import salt.version # pylint: disable=import-outside-toplevel

if salt.version.__saltstack_version__ < "3004":
raise pytest.UsageError("Only salt>=3004 is supported")
Expand Down

0 comments on commit ed0b26c

Please sign in to comment.