Rename 'environment' config option to 'saltenv'

'environment' predates the 'saltenv' nomenclature, and since we have
been using saltenv on the CLI for years, and now also have pillarenv, it
makes sense to make this change.
This commit is contained in:
Erik Johnson 2017-11-29 22:09:09 -06:00
parent 63e4b6970c
commit 683e2cc502
No known key found for this signature in database
GPG key ID: 5E5583C437808F3F
17 changed files with 98 additions and 57 deletions

View file

@ -1050,7 +1050,7 @@ class Single(object):
popts,
opts_pkg[u'grains'],
opts_pkg[u'id'],
opts_pkg.get(u'environment', u'base')
opts_pkg.get(u'saltenv', u'base')
)
pillar_data = pillar.compile_pillar()

View file

@ -242,7 +242,10 @@ VALID_OPTS = {
'autoload_dynamic_modules': bool,
# Force the minion into a single environment when it fetches files from the master
'environment': str,
'saltenv': str,
# Prevent saltenv from being overriden on the command line
'lock_saltenv': bool,
# Force the minion into a single pillar root when it fetches pillar data from the master
'pillarenv': str,
@ -1177,7 +1180,8 @@ DEFAULT_MINION_OPTS = {
'random_startup_delay': 0,
'failhard': False,
'autoload_dynamic_modules': True,
'environment': None,
'saltenv': None,
'lock_saltenv': False,
'pillarenv': None,
'pillarenv_from_saltenv': False,
'pillar_opts': False,
@ -1454,7 +1458,8 @@ DEFAULT_MASTER_OPTS = {
},
'top_file_merging_strategy': 'merge',
'env_order': [],
'environment': None,
'saltenv': None,
'lock_saltenv': False,
'default_top': 'base',
'file_client': 'local',
'git_pillar_base': 'master',
@ -3590,6 +3595,24 @@ def apply_minion_config(overrides=None,
if overrides:
opts.update(overrides)
if u'environment' in opts:
if u'saltenv' in opts:
log.warning(
u'The \'saltenv\' and \'environment\' minion config options '
u'cannot both be used. Ignoring \'environment\' in favor of '
u'\'saltenv\'.',
)
# Set environment to saltenv in case someone's custom module is
# refrencing __opts__['environment']
opts[u'environment'] = opts[u'saltenv']
else:
log.warning(
u'The \'environment\' minion config option has been renamed '
u'to \'saltenv\'. Using %s as the \'saltenv\' config value.',
opts[u'environment']
)
opts[u'saltenv'] = opts[u'environment']
opts['__cli'] = os.path.basename(sys.argv[0])
# No ID provided. Will getfqdn save us?
@ -3742,6 +3765,24 @@ def apply_master_config(overrides=None, defaults=None):
if overrides:
opts.update(overrides)
if u'environment' in opts:
if u'saltenv' in opts:
log.warning(
u'The \'saltenv\' and \'environment\' master config options '
u'cannot both be used. Ignoring \'environment\' in favor of '
u'\'saltenv\'.',
)
# Set environment to saltenv in case someone's custom runner is
# refrencing __opts__['environment']
opts[u'environment'] = opts[u'saltenv']
else:
log.warning(
u'The \'environment\' master config option has been renamed '
u'to \'saltenv\'. Using %s as the \'saltenv\' config value.',
opts[u'environment']
)
opts[u'saltenv'] = opts[u'environment']
if len(opts['sock_dir']) > len(opts['cachedir']) + 10:
opts['sock_dir'] = os.path.join(opts['cachedir'], '.salt-unix')

View file

@ -737,7 +737,7 @@ class SaltLoadPillar(ioflo.base.deeding.Deed):
'dst': (master.name, None, 'remote_cmd')}
load = {'id': self.opts.value['id'],
'grains': self.grains.value,
'saltenv': self.opts.value['environment'],
'saltenv': self.opts.value['saltenv'],
'ver': '2',
'cmd': '_pillar'}
self.road_stack.value.transmit({'route': route, 'load': load},

View file

@ -736,8 +736,8 @@ class SMinion(MinionBase):
if not os.path.isdir(pdir):
os.makedirs(pdir, 0o700)
ptop = os.path.join(pdir, u'top.sls')
if self.opts[u'environment'] is not None:
penv = self.opts[u'environment']
if self.opts[u'saltenv'] is not None:
penv = self.opts[u'saltenv']
else:
penv = u'base'
cache_top = {penv: {self.opts[u'id']: [u'cache']}}
@ -773,7 +773,7 @@ class SMinion(MinionBase):
self.opts,
self.opts[u'grains'],
self.opts[u'id'],
self.opts[u'environment'],
self.opts[u'saltenv'],
pillarenv=self.opts.get(u'pillarenv'),
).compile_pillar()
@ -1144,7 +1144,7 @@ class Minion(MinionBase):
self.opts,
self.opts[u'grains'],
self.opts[u'id'],
self.opts[u'environment'],
self.opts[u'saltenv'],
pillarenv=self.opts.get(u'pillarenv')
).compile_pillar()
@ -2032,7 +2032,7 @@ class Minion(MinionBase):
self.opts,
self.opts[u'grains'],
self.opts[u'id'],
self.opts[u'environment'],
self.opts[u'saltenv'],
pillarenv=self.opts.get(u'pillarenv'),
).compile_pillar()
except SaltClientError:
@ -3349,7 +3349,7 @@ class ProxyMinion(Minion):
self.opts,
self.opts[u'grains'],
self.opts[u'id'],
saltenv=self.opts[u'environment'],
saltenv=self.opts[u'saltenv'],
pillarenv=self.opts.get(u'pillarenv'),
).compile_pillar()
@ -3391,7 +3391,7 @@ class ProxyMinion(Minion):
# we can then sync any proxymodules down from the master
# we do a sync_all here in case proxy code was installed by
# SPM or was manually placed in /srv/salt/_modules etc.
self.functions[u'saltutil.sync_all'](saltenv=self.opts[u'environment'])
self.functions[u'saltutil.sync_all'](saltenv=self.opts[u'saltenv'])
# Pull in the utils
self.utils = salt.loader.utils(self.opts)

View file

@ -219,7 +219,7 @@ def _gather_pillar(pillarenv, pillar_override):
__opts__,
__grains__,
__opts__['id'],
__opts__['environment'],
__opts__['saltenv'],
pillar_override=pillar_override,
pillarenv=pillarenv
)

View file

@ -49,7 +49,7 @@ def _gather_pillar(pillarenv, pillar_override):
__opts__,
__grains__,
__opts__['id'],
__opts__['environment'],
__opts__['saltenv'],
pillar_override=pillar_override,
pillarenv=pillarenv
)

View file

@ -5290,7 +5290,7 @@ def _gather_pillar(pillarenv, pillar_override, **grains):
grains,
# Not sure if these two are correct
__opts__['id'],
__opts__['environment'],
__opts__['saltenv'],
pillar_override=pillar_override,
pillarenv=pillarenv
)

View file

@ -225,7 +225,7 @@ def send(tag,
data_dict['pillar'] = __pillar__
if with_env_opts:
data_dict['saltenv'] = __opts__.get('environment', 'base')
data_dict['saltenv'] = __opts__.get('saltenv', 'base')
data_dict['pillarenv'] = __opts__.get('pillarenv')
if kwargs:

View file

@ -237,7 +237,7 @@ def items(*args, **kwargs):
pillarenv = kwargs.get('pillarenv')
if pillarenv is None:
if __opts__.get('pillarenv_from_saltenv', False):
pillarenv = kwargs.get('saltenv') or __opts__['environment']
pillarenv = kwargs.get('saltenv') or __opts__['saltenv']
else:
pillarenv = __opts__['pillarenv']
@ -468,7 +468,7 @@ def ext(external, pillar=None):
__opts__,
__grains__,
__opts__['id'],
__opts__['environment'],
__opts__['saltenv'],
ext=external,
pillar_override=pillar)

View file

@ -509,7 +509,7 @@ class SaltCheck(object):
# state cache should be updated before running this method
search_list = []
cachedir = __opts__.get('cachedir', None)
environment = __opts__['environment']
environment = __opts__['saltenv']
if environment:
path = cachedir + os.sep + "files" + os.sep + environment
search_list.append(path)

View file

@ -271,9 +271,9 @@ def _get_opts(**kwargs):
if 'saltenv' in kwargs:
saltenv = kwargs['saltenv']
if saltenv is not None and not isinstance(saltenv, six.string_types):
opts['environment'] = str(kwargs['saltenv'])
opts['saltenv'] = str(kwargs['saltenv'])
else:
opts['environment'] = kwargs['saltenv']
opts['saltenv'] = kwargs['saltenv']
if 'pillarenv' in kwargs or opts.get('pillarenv_from_saltenv', False):
pillarenv = kwargs.get('pillarenv') or kwargs.get('saltenv')
@ -840,7 +840,7 @@ def highstate(test=None, queue=False, **kwargs):
kwargs.pop('env')
if 'saltenv' in kwargs:
opts['environment'] = kwargs['saltenv']
opts['saltenv'] = kwargs['saltenv']
if 'pillarenv' in kwargs:
opts['pillarenv'] = kwargs['pillarenv']
@ -1032,8 +1032,8 @@ def sls(mods, test=None, exclude=None, queue=False, **kwargs):
# Since this is running a specific SLS file (or files), fall back to the
# 'base' saltenv if none is configured and none was passed.
if opts['environment'] is None:
opts['environment'] = 'base'
if opts['saltenv'] is None:
opts['saltenv'] = 'base'
pillar_override = kwargs.get('pillar')
pillar_enc = kwargs.get('pillar_enc')
@ -1089,7 +1089,7 @@ def sls(mods, test=None, exclude=None, queue=False, **kwargs):
st_.push_active()
ret = {}
try:
high_, errors = st_.render_highstate({opts['environment']: mods})
high_, errors = st_.render_highstate({opts['saltenv']: mods})
if errors:
__context__['retcode'] = 1
@ -1411,8 +1411,8 @@ def sls_id(id_, mods, test=None, queue=False, **kwargs):
# Since this is running a specific ID within a specific SLS file, fall back
# to the 'base' saltenv if none is configured and none was passed.
if opts['environment'] is None:
opts['environment'] = 'base'
if opts['saltenv'] is None:
opts['saltenv'] = 'base'
pillar_override = kwargs.get('pillar')
pillar_enc = kwargs.get('pillar_enc')
@ -1446,7 +1446,7 @@ def sls_id(id_, mods, test=None, queue=False, **kwargs):
split_mods = mods.split(',')
st_.push_active()
try:
high_, errors = st_.render_highstate({opts['environment']: split_mods})
high_, errors = st_.render_highstate({opts['saltenv']: split_mods})
finally:
st_.pop_active()
errors += st_.state.verify_high(high_)
@ -1472,7 +1472,7 @@ def sls_id(id_, mods, test=None, queue=False, **kwargs):
if not ret:
raise SaltInvocationError(
'No matches for ID \'{0}\' found in SLS \'{1}\' within saltenv '
'\'{2}\''.format(id_, mods, opts['environment'])
'\'{2}\''.format(id_, mods, opts['saltenv'])
)
return ret
@ -1523,8 +1523,8 @@ def show_low_sls(mods, test=None, queue=False, **kwargs):
# Since this is dealing with a specific SLS file (or files), fall back to
# the 'base' saltenv if none is configured and none was passed.
if opts['environment'] is None:
opts['environment'] = 'base'
if opts['saltenv'] is None:
opts['saltenv'] = 'base'
pillar_override = kwargs.get('pillar')
pillar_enc = kwargs.get('pillar_enc')
@ -1555,7 +1555,7 @@ def show_low_sls(mods, test=None, queue=False, **kwargs):
mods = mods.split(',')
st_.push_active()
try:
high_, errors = st_.render_highstate({opts['environment']: mods})
high_, errors = st_.render_highstate({opts['saltenv']: mods})
finally:
st_.pop_active()
errors += st_.state.verify_high(high_)
@ -1610,8 +1610,8 @@ def show_sls(mods, test=None, queue=False, **kwargs):
# Since this is dealing with a specific SLS file (or files), fall back to
# the 'base' saltenv if none is configured and none was passed.
if opts['environment'] is None:
opts['environment'] = 'base'
if opts['saltenv'] is None:
opts['saltenv'] = 'base'
pillar_override = kwargs.get('pillar')
pillar_enc = kwargs.get('pillar_enc')
@ -1644,7 +1644,7 @@ def show_sls(mods, test=None, queue=False, **kwargs):
mods = mods.split(',')
st_.push_active()
try:
high_, errors = st_.render_highstate({opts['environment']: mods})
high_, errors = st_.render_highstate({opts['saltenv']: mods})
finally:
st_.pop_active()
errors += st_.state.verify_high(high_)

View file

@ -138,7 +138,7 @@ class AsyncRemotePillar(RemotePillarMixin):
def __init__(self, opts, grains, minion_id, saltenv, ext=None, functions=None,
pillar_override=None, pillarenv=None, extra_minion_data=None):
self.opts = opts
self.opts['environment'] = saltenv
self.opts['saltenv'] = saltenv
self.ext = ext
self.grains = grains
self.minion_id = minion_id
@ -165,7 +165,7 @@ class AsyncRemotePillar(RemotePillarMixin):
'''
load = {'id': self.minion_id,
'grains': self.grains,
'saltenv': self.opts['environment'],
'saltenv': self.opts['saltenv'],
'pillarenv': self.opts['pillarenv'],
'pillar_override': self.pillar_override,
'extra_minion_data': self.extra_minion_data,
@ -198,7 +198,7 @@ class RemotePillar(RemotePillarMixin):
def __init__(self, opts, grains, minion_id, saltenv, ext=None, functions=None,
pillar_override=None, pillarenv=None, extra_minion_data=None):
self.opts = opts
self.opts['environment'] = saltenv
self.opts['saltenv'] = saltenv
self.ext = ext
self.grains = grains
self.minion_id = minion_id
@ -224,7 +224,7 @@ class RemotePillar(RemotePillarMixin):
'''
load = {'id': self.minion_id,
'grains': self.grains,
'saltenv': self.opts['environment'],
'saltenv': self.opts['saltenv'],
'pillarenv': self.opts['pillarenv'],
'pillar_override': self.pillar_override,
'extra_minion_data': self.extra_minion_data,
@ -445,9 +445,9 @@ class Pillar(object):
else:
opts['grains'] = grains
# Allow minion/CLI saltenv/pillarenv to take precedence over master
opts['environment'] = saltenv \
opts['saltenv'] = saltenv \
if saltenv is not None \
else opts.get('environment')
else opts.get('saltenv')
opts['pillarenv'] = pillarenv \
if pillarenv is not None \
else opts.get('pillarenv')

View file

@ -404,7 +404,7 @@ def ext_pillar(minion_id, pillar, *repos): # pylint: disable=unused-argument
# Map env if env == '__env__' before checking the env value
if env == '__env__':
env = opts.get('pillarenv') \
or opts.get('environment') \
or opts.get('saltenv') \
or opts.get('git_pillar_base')
log.debug('__env__ maps to %s', env)

View file

@ -763,7 +763,7 @@ class State(object):
self.opts,
self.opts[u'grains'],
self.opts[u'id'],
self.opts[u'environment'],
self.opts[u'saltenv'],
pillar_override=self._pillar_override,
pillarenv=self.opts.get(u'pillarenv'))
return pillar.compile_pillar()
@ -2900,32 +2900,32 @@ class BaseHighState(object):
found = 0 # did we find any contents in the top files?
# Gather initial top files
merging_strategy = self.opts[u'top_file_merging_strategy']
if merging_strategy == u'same' and not self.opts[u'environment']:
if merging_strategy == u'same' and not self.opts[u'saltenv']:
if not self.opts[u'default_top']:
raise SaltRenderError(
u'top_file_merging_strategy set to \'same\', but no '
u'default_top configuration option was set'
)
if self.opts[u'environment']:
if self.opts[u'saltenv']:
contents = self.client.cache_file(
self.opts[u'state_top'],
self.opts[u'environment']
self.opts[u'saltenv']
)
if contents:
found = 1
tops[self.opts[u'environment']] = [
tops[self.opts[u'saltenv']] = [
compile_template(
contents,
self.state.rend,
self.state.opts[u'renderer'],
self.state.opts[u'renderer_blacklist'],
self.state.opts[u'renderer_whitelist'],
saltenv=self.opts[u'environment']
saltenv=self.opts[u'saltenv']
)
]
else:
tops[self.opts[u'environment']] = [{}]
tops[self.opts[u'saltenv']] = [{}]
else:
found = 0
@ -3257,8 +3257,8 @@ class BaseHighState(object):
matches = DefaultOrderedDict(OrderedDict)
# pylint: disable=cell-var-from-loop
for saltenv, body in six.iteritems(top):
if self.opts[u'environment']:
if saltenv != self.opts[u'environment']:
if self.opts[u'saltenv']:
if saltenv != self.opts[u'saltenv']:
continue
for match, data in six.iteritems(body):
def _filter_matches(_match, _data, _opts):

View file

@ -910,7 +910,7 @@ class GitProvider(object):
'''
if self.branch == '__env__':
target = self.opts.get('pillarenv') \
or self.opts.get('environment') \
or self.opts.get('saltenv') \
or 'base'
return self.opts['{0}_base'.format(self.role)] \
if target == 'base' \

View file

@ -90,7 +90,7 @@ def get_salt_vars():
__opts__,
__grains__,
__opts__.get('id'),
__opts__.get('environment'),
__opts__.get('saltenv'),
).compile_pillar()
else:
__pillar__ = {}

View file

@ -55,7 +55,7 @@ class PillarTestCase(TestCase):
'os': 'Ubuntu',
}
pillar = salt.pillar.Pillar(opts, grains, 'mocked-minion', 'dev')
self.assertEqual(pillar.opts['environment'], 'dev')
self.assertEqual(pillar.opts['saltenv'], 'dev')
self.assertEqual(pillar.opts['pillarenv'], 'dev')
def test_ext_pillar_no_extra_minion_data_val_dict(self):
@ -416,7 +416,7 @@ class PillarTestCase(TestCase):
'state_top': '',
'pillar_roots': [],
'extension_modules': '',
'environment': 'base',
'saltenv': 'base',
'file_roots': [],
}
grains = {
@ -584,7 +584,7 @@ class RemotePillarTestCase(TestCase):
salt.pillar.RemotePillar({}, self.grains, 'mocked-minion', 'dev')
mock_get_extra_minion_data.assert_called_once_with(
{'environment': 'dev'})
{'saltenv': 'dev'})
def test_multiple_keys_in_opts_added_to_pillar(self):
opts = {
@ -702,7 +702,7 @@ class AsyncRemotePillarTestCase(TestCase):
salt.pillar.RemotePillar({}, self.grains, 'mocked-minion', 'dev')
mock_get_extra_minion_data.assert_called_once_with(
{'environment': 'dev'})
{'saltenv': 'dev'})
def test_pillar_send_extra_minion_data_from_config(self):
opts = {