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

Port #51245 to master #55423

Merged
merged 5 commits into from
Nov 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 29 additions & 31 deletions salt/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import salt.syspaths
import salt.exceptions
import salt.defaults.exitcodes
import salt.utils.immutabletypes as immutabletypes

try:
import psutil
Expand Down Expand Up @@ -100,11 +101,7 @@ def _gather_buffer_space():
# TODO: Reserved for future use
_DFLT_IPC_RBUFFER = _gather_buffer_space() * .5

FLO_DIR = os.path.join(
os.path.dirname(os.path.dirname(__file__)),
'daemons', 'flo')

VALID_OPTS = {
VALID_OPTS = immutabletypes.freeze({
# The address of the salt master. May be specified as IP address or hostname
'master': (six.string_types, list),

Expand Down Expand Up @@ -1194,10 +1191,10 @@ def _gather_buffer_space():

# Thorium top file location
'thorium_top': six.string_types,
}
})

# default configurations
DEFAULT_MINION_OPTS = {
DEFAULT_MINION_OPTS = immutabletypes.freeze({
'interface': '0.0.0.0',
'master': 'salt',
'master_type': 'str',
Expand Down Expand Up @@ -1489,9 +1486,9 @@ def _gather_buffer_space():
'discovery': False,
'schedule': {},
'ssh_merge_pillar': True
}
})

DEFAULT_MASTER_OPTS = {
DEFAULT_MASTER_OPTS = immutabletypes.freeze({
'interface': '0.0.0.0',
'publish_port': 4505,
'zmq_backlog': 1000,
Expand Down Expand Up @@ -1816,12 +1813,12 @@ def _gather_buffer_space():
'auth_events': True,
'minion_data_cache_events': True,
'enable_ssh_minions': False,
}
})


# ----- Salt Proxy Minion Configuration Defaults ----------------------------------->
# These are merged with DEFAULT_MINION_OPTS since many of them also apply here.
DEFAULT_PROXY_MINION_OPTS = {
DEFAULT_PROXY_MINION_OPTS = immutabletypes.freeze({
'conf_file': os.path.join(salt.syspaths.CONFIG_DIR, 'proxy'),
'log_file': os.path.join(salt.syspaths.LOGS_DIR, 'proxy'),
'add_proxymodule_to_opts': False,
Expand All @@ -1847,9 +1844,10 @@ def _gather_buffer_space():
'pki_dir': os.path.join(salt.syspaths.CONFIG_DIR, 'pki', 'proxy'),
'cachedir': os.path.join(salt.syspaths.CACHE_DIR, 'proxy'),
'sock_dir': os.path.join(salt.syspaths.SOCK_DIR, 'proxy'),
}
})

# ----- Salt Cloud Configuration Defaults ----------------------------------->
DEFAULT_CLOUD_OPTS = {
DEFAULT_CLOUD_OPTS = immutabletypes.freeze({
'verify_env': True,
'default_include': 'cloud.conf.d/*.conf',
# Global defaults
Expand Down Expand Up @@ -1877,17 +1875,17 @@ def _gather_buffer_space():
'log_rotate_backup_count': 0,
'bootstrap_delay': None,
'cache': 'localfs',
}
})

DEFAULT_API_OPTS = {
DEFAULT_API_OPTS = immutabletypes.freeze({
# ----- Salt master settings overridden by Salt-API --------------------->
'api_pidfile': os.path.join(salt.syspaths.PIDFILE_DIR, 'salt-api.pid'),
'api_logfile': os.path.join(salt.syspaths.LOGS_DIR, 'api'),
'rest_timeout': 300,
# <---- Salt master settings overridden by Salt-API ----------------------
}
})

DEFAULT_SPM_OPTS = {
DEFAULT_SPM_OPTS = immutabletypes.freeze({
# ----- Salt master settings overridden by SPM --------------------->
'spm_conf_file': os.path.join(salt.syspaths.CONFIG_DIR, 'spm'),
'formula_path': salt.syspaths.SPM_FORMULA_PATH,
Expand All @@ -1908,15 +1906,15 @@ def _gather_buffer_space():
'spm_node_type': '',
'spm_share_dir': os.path.join(salt.syspaths.SHARE_DIR, 'spm'),
# <---- Salt master settings overridden by SPM ----------------------
}
})

VM_CONFIG_DEFAULTS = {
VM_CONFIG_DEFAULTS = immutabletypes.freeze({
'default_include': 'cloud.profiles.d/*.conf',
}
})

PROVIDER_CONFIG_DEFAULTS = {
PROVIDER_CONFIG_DEFAULTS = immutabletypes.freeze({
'default_include': 'cloud.providers.d/*.conf',
}
})
# <---- Salt Cloud Configuration Defaults ------------------------------------


Expand Down Expand Up @@ -2460,10 +2458,10 @@ def syndic_config(master_config_path,
master_defaults=None):

if minion_defaults is None:
minion_defaults = DEFAULT_MINION_OPTS
minion_defaults = DEFAULT_MINION_OPTS.copy()

if master_defaults is None:
master_defaults = DEFAULT_MASTER_OPTS
master_defaults = DEFAULT_MASTER_OPTS.copy()

opts = {}
master_opts = master_config(
Expand Down Expand Up @@ -2782,7 +2780,7 @@ def apply_cloud_config(overrides, defaults=None):
Return a cloud config
'''
if defaults is None:
defaults = DEFAULT_CLOUD_OPTS
defaults = DEFAULT_CLOUD_OPTS.copy()

config = defaults.copy()
if overrides:
Expand Down Expand Up @@ -3682,7 +3680,7 @@ def apply_minion_config(overrides=None,
Returns minion configurations dict.
'''
if defaults is None:
defaults = DEFAULT_MINION_OPTS
defaults = DEFAULT_MINION_OPTS.copy()
if overrides is None:
overrides = {}

Expand Down Expand Up @@ -3837,7 +3835,7 @@ def master_config(path, env_var='SALT_MASTER_CONFIG', defaults=None, exit_on_con
:py:func:`salt.client.client_config`.
'''
if defaults is None:
defaults = DEFAULT_MASTER_OPTS
defaults = DEFAULT_MASTER_OPTS.copy()

if not os.environ.get(env_var, None):
# No valid setting was given using the configuration variable.
Expand Down Expand Up @@ -3879,7 +3877,7 @@ def apply_master_config(overrides=None, defaults=None):
Returns master configurations dict.
'''
if defaults is None:
defaults = DEFAULT_MASTER_OPTS
defaults = DEFAULT_MASTER_OPTS.copy()
if overrides is None:
overrides = {}

Expand Down Expand Up @@ -4054,7 +4052,7 @@ def client_config(path, env_var='SALT_CLIENT_CONFIG', defaults=None):
:py:class:`~salt.client.LocalClient`.
'''
if defaults is None:
defaults = DEFAULT_MASTER_OPTS
defaults = DEFAULT_MASTER_OPTS.copy()

xdg_dir = salt.utils.xdg.xdg_config_dir()
if os.path.isdir(xdg_dir):
Expand Down Expand Up @@ -4122,10 +4120,10 @@ def api_config(path):
need to be stubbed out for salt-api
'''
# Let's grab a copy of salt-api's required defaults
opts = DEFAULT_API_OPTS
opts = DEFAULT_API_OPTS.copy()

# Let's override them with salt's master opts
opts.update(client_config(path, defaults=DEFAULT_MASTER_OPTS))
opts.update(client_config(path, defaults=DEFAULT_MASTER_OPTS.copy()))

# Let's set the pidfile and log_file values in opts to api settings
opts.update({
Expand Down
16 changes: 16 additions & 0 deletions salt/utils/immutabletypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
Immutable types
'''
from __future__ import absolute_import, unicode_literals
import copy

# Import python libs
try:
Expand Down Expand Up @@ -37,6 +38,15 @@ def __getitem__(self, key):
def __repr__(self):
return '<{0} {1}>'.format(self.__class__.__name__, repr(self.__obj))

def __deepcopy__(self, memo):
return copy.deepcopy(self.__obj)

def copy(self):
'''
Return an un-frozen copy of self
'''
return copy.deepcopy(self.__obj)


class ImmutableList(Sequence):
'''
Expand Down Expand Up @@ -64,6 +74,9 @@ def __getitem__(self, key):
def __repr__(self):
return '<{0} {1}>'.format(self.__class__.__name__, repr(self.__obj))

def __deepcopy__(self, memo):
return copy.deepcopy(self.__obj)


class ImmutableSet(Set):
'''
Expand All @@ -85,6 +98,9 @@ def __contains__(self, key):
def __repr__(self):
return '<{0} {1}>'.format(self.__class__.__name__, repr(self.__obj))

def __deepcopy__(self, memo):
return copy.deepcopy(self.__obj)


def freeze(obj):
'''
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/grains/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class TestGrainsReg(ModuleCase, LoaderModuleMockMixin):
'''

def setup_loader_modules(self):
self.opts = opts = salt.config.DEFAULT_MINION_OPTS
self.opts = opts = salt.config.DEFAULT_MINION_OPTS.copy()
utils = salt.loader.utils(opts, whitelist=['reg'])
return {
salt.modules.reg: {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/beacons/test_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class StatusBeaconTestCase(TestCase, LoaderModuleMockMixin):
'''

def setup_loader_modules(self):
opts = salt.config.DEFAULT_MINION_OPTS
opts = salt.config.DEFAULT_MINION_OPTS.copy()
opts['grains'] = salt.loader.grains(opts)
module_globals = {
'__opts__': opts,
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/engines/test_slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def setup_loader_modules(self):
return {slack: {}}

def setUp(self):
mock_opts = salt.config.DEFAULT_MINION_OPTS
mock_opts = salt.config.DEFAULT_MINION_OPTS.copy()
token = 'xoxb-xxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxx'

with patch.dict(slack.__opts__, mock_opts):
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/modules/test_boto_apigateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class BotoApiGatewayTestCaseBase(TestCase, LoaderModuleMockMixin):
conn = None

def setup_loader_modules(self):
self.opts = opts = salt.config.DEFAULT_MINION_OPTS
self.opts = opts = salt.config.DEFAULT_MINION_OPTS.copy()
utils = salt.loader.utils(
opts,
whitelist=['boto3', 'args', 'systemd', 'path', 'platform'])
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/modules/test_boto_cloudtrail.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class BotoCloudTrailTestCaseBase(TestCase, LoaderModuleMockMixin):
conn = None

def setup_loader_modules(self):
self.opts = opts = salt.config.DEFAULT_MINION_OPTS
self.opts = opts = salt.config.DEFAULT_MINION_OPTS.copy()
utils = salt.loader.utils(
opts,
whitelist=['boto3', 'args', 'systemd', 'path', 'platform'],
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/modules/test_boto_cloudwatch_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class BotoCloudWatchEventTestCaseBase(TestCase, LoaderModuleMockMixin):
conn = None

def setup_loader_modules(self):
self.opts = opts = salt.config.DEFAULT_MINION_OPTS
self.opts = opts = salt.config.DEFAULT_MINION_OPTS.copy()
utils = salt.loader.utils(
opts,
whitelist=['boto3', 'args', 'systemd', 'path', 'platform'],
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/modules/test_boto_cognitoidentity.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class BotoCognitoIdentityTestCaseBase(TestCase, LoaderModuleMockMixin):
conn = None

def setup_loader_modules(self):
self.opts = opts = salt.config.DEFAULT_MINION_OPTS
self.opts = opts = salt.config.DEFAULT_MINION_OPTS.copy()
utils = salt.loader.utils(
opts,
whitelist=['boto3', 'args', 'systemd', 'path', 'platform'],
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/modules/test_boto_elasticsearch_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class BotoElasticsearchDomainTestCaseBase(TestCase, LoaderModuleMockMixin):
conn = None

def setup_loader_modules(self):
self.opts = salt.config.DEFAULT_MINION_OPTS
self.opts = salt.config.DEFAULT_MINION_OPTS.copy()
utils = salt.loader.utils(
self.opts,
whitelist=['boto3', 'args', 'systemd', 'path', 'platform'],
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/modules/test_boto_elb.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class BotoElbTestCase(TestCase, LoaderModuleMockMixin):
'''

def setup_loader_modules(self):
opts = salt.config.DEFAULT_MASTER_OPTS
opts = salt.config.DEFAULT_MASTER_OPTS.copy()
utils = salt.loader.utils(
opts,
whitelist=['boto', 'args', 'systemd', 'path', 'platform'])
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/modules/test_boto_iot.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class BotoIoTTestCaseBase(TestCase, LoaderModuleMockMixin):
conn = None

def setup_loader_modules(self):
self.opts = opts = salt.config.DEFAULT_MINION_OPTS
self.opts = opts = salt.config.DEFAULT_MINION_OPTS.copy()
utils = salt.loader.utils(
opts,
whitelist=['boto3', 'args', 'systemd', 'path', 'platform'],
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/modules/test_boto_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class BotoLambdaTestCaseBase(TestCase, LoaderModuleMockMixin):
conn = None

def setup_loader_modules(self):
self.opts = opts = salt.config.DEFAULT_MINION_OPTS
self.opts = opts = salt.config.DEFAULT_MINION_OPTS.copy()
utils = salt.loader.utils(
opts,
whitelist=['boto3', 'args', 'systemd', 'path', 'platform'],
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/modules/test_boto_route53.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class BotoRoute53TestCase(TestCase, LoaderModuleMockMixin):
TestCase for salt.modules.boto_route53 module
'''
def setup_loader_modules(self):
self.opts = salt.config.DEFAULT_MINION_OPTS
self.opts = salt.config.DEFAULT_MINION_OPTS.copy()
self.opts['route53.keyid'] = 'GKTADJGHEIQSXMKKRBJ08H'
self.opts['route53.key'] = 'askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs'
utils = salt.loader.utils(self.opts)
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/modules/test_boto_s3_bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class BotoS3BucketTestCaseBase(TestCase, LoaderModuleMockMixin):
conn = None

def setup_loader_modules(self):
self.opts = opts = salt.config.DEFAULT_MINION_OPTS
self.opts = opts = salt.config.DEFAULT_MINION_OPTS.copy()
utils = salt.loader.utils(
opts,
whitelist=['boto3', 'args', 'systemd', 'path', 'platform'],
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/modules/test_boto_secgroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class BotoSecgroupTestCase(TestCase, LoaderModuleMockMixin):
'''

def setup_loader_modules(self):
opts = salt.config.DEFAULT_MASTER_OPTS
opts = salt.config.DEFAULT_MASTER_OPTS.copy()
utils = salt.loader.utils(
opts,
whitelist=['boto', 'args', 'systemd', 'path', 'platform'])
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/modules/test_boto_vpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class BotoVpcTestCaseBase(TestCase, LoaderModuleMockMixin):
conn3 = None

def setup_loader_modules(self):
self.opts = opts = salt.config.DEFAULT_MINION_OPTS
self.opts = opts = salt.config.DEFAULT_MINION_OPTS.copy()
utils = salt.loader.utils(
opts,
whitelist=['boto', 'boto3', 'args', 'systemd', 'path', 'platform'])
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/modules/test_dockermod.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class DockerTestCase(TestCase, LoaderModuleMockMixin):
'''
def setup_loader_modules(self):
utils = salt.loader.utils(
salt.config.DEFAULT_MINION_OPTS,
salt.config.DEFAULT_MINION_OPTS.copy(),
whitelist=['args', 'docker', 'json', 'state', 'thin',
'systemd', 'path', 'platform']
)
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/modules/test_nacl.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class NaclTest(TestCase, LoaderModuleMockMixin):
'''
def setup_loader_modules(self):
self.unencrypted_data = salt.utils.stringutils.to_bytes('hello')
self.opts = salt.config.DEFAULT_MINION_OPTS
self.opts = salt.config.DEFAULT_MINION_OPTS.copy()
utils = salt.loader.utils(self.opts)
funcs = salt.loader.minion_mods(self.opts, utils=utils, whitelist=['nacl'])

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/modules/test_solarisipspkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class IpsTestCase(TestCase, LoaderModuleMockMixin):
Test cases for salt.modules.solarisips
'''
def setup_loader_modules(self):
self.opts = opts = salt.config.DEFAULT_MINION_OPTS
self.opts = opts = salt.config.DEFAULT_MINION_OPTS.copy()
utils = salt.loader.utils(
opts,
whitelist=['pkg', 'path', 'platform'])
Expand Down
Loading