Allow pillar environment to be specified for salt-run

Example:
  salt-run state.sls deploy saltenv=base pillarenv=dev
This commit is contained in:
Eric Radman 2017-02-02 03:21:40 -05:00
parent 4480bd8858
commit c22f3f6dc7
2 changed files with 82 additions and 0 deletions

View File

@ -233,6 +233,9 @@ def state(name,
if pillar:
cmd_kw['kwarg']['pillar'] = pillar
if __opts__.get('pillarenv'):
cmd_kw['kwarg']['pillarenv'] = __opts__['pillarenv']
cmd_kw['kwarg']['saltenv'] = __env__
cmd_kw['kwarg']['queue'] = queue

View File

@ -0,0 +1,79 @@
# -*- coding: utf-8 -*-
'''
:codeauthor: :email:`Eric Radman <ericshane@eradman.com`
'''
# Import python libs
from __future__ import absolute_import
import tempfile
import os.path
# Import Salt Testing libs
from salttesting import TestCase, skipIf
from salttesting.helpers import ensure_in_syspath
from salttesting.mock import MagicMock, patch, NO_MOCK, NO_MOCK_REASON
ensure_in_syspath('../')
# Import Salt libs
import integration
from salt.states import saltmod
# Globals
saltmod.__opts__ = dict()
saltmod.__env__ = dict()
saltmod.__salt__ = dict()
@skipIf(NO_MOCK, NO_MOCK_REASON)
class StatemodTests(TestCase):
def setUp(self):
self.tmp_cachedir = tempfile.mkdtemp(dir=integration.TMP)
@patch('salt.states.saltmod.__salt__', MagicMock())
def test_statemod_state(self):
''' Smoke test for for salt.states.statemod.state(). Ensures that we
don't take an exception if optional parameters are not specified in
__opts__ or __env__.
'''
argv = []
saltmod.__opts__ = {
'id': 'webserver2',
'argv': argv,
'__role': 'master',
'cachedir': self.tmp_cachedir,
'extension_modules': os.path.join(self.tmp_cachedir, 'extmods'),
}
args = ('webserver_setup', 'webserver2')
kwargs = {
'tgt_type': 'glob',
'fail_minions': None,
'pillar': None,
'top': None,
'batch': None,
'orchestration_jid': None,
'sls': 'vroom',
'queue': False,
'concurrent': False,
'highstate': None,
'expr_form': None,
'ret': '',
'ssh': False,
'timeout': None, 'test': False,
'allow_fail': 0,
'saltenv': None,
'expect_minions': False
}
ret = saltmod.state(*args, **kwargs)
expected = {
'comment': 'States ran successfully.',
'changes': {},
'name': 'webserver_setup',
'result': True
}
self.assertEqual(ret, expected)
if __name__ == '__main__':
from integration import run_tests
run_tests(StatemodTests, needs_daemon=False)